Skip to content

perf(test): cache SwinUNETR SSL weights instead of re-downloading#8987

Open
aymuos15 wants to merge 2 commits into
Project-MONAI:devfrom
aymuos15:perf/swinunetr-cache-ssl-weights
Open

perf(test): cache SwinUNETR SSL weights instead of re-downloading#8987
aymuos15 wants to merge 2 commits into
Project-MONAI:devfrom
aymuos15:perf/swinunetr-cache-ssl-weights

Conversation

@aymuos15

@aymuos15 aymuos15 commented Jul 9, 2026

Copy link
Copy Markdown
Contributor

Description

Cache the SwinUNETR SSL pretrained weights (~750 MB) under tests/testing_data/ instead of a per-run tempfile.TemporaryDirectory(), so test_filter_swinunetr reuses them across runs instead of re-downloading every time. download_url skips the download when the cached file's hash matches, so repeated runs replace a ~750 MB download with a local hash-check (~5x faster). The cache path is gitignored and behavior/coverage are unchanged.

Changes

  • tests/networks/nets/test_swin_unetr.py: download the weights to tests/testing_data/temp_ssl_pretrained_weights.pth (new TESTS_PATH constant) instead of a temporary directory; drop the tempfile import and add from pathlib import Path.

Types of changes

  • Non-breaking change (fix or new feature that would not break existing functionality).
  • Breaking change (fix or new feature that would cause existing functionality to change).
  • New tests added to cover the changes.
  • Integration tests passed locally by running ./runtests.sh -f -u --net --coverage.
  • Quick tests passed locally by running ./runtests.sh --quick --unittests.
  • In-line docstrings updated.
  • Documentation updated.

Signed-off-by: Soumya Snigdha Kundu <soumya_snigdha.kundu@kcl.ac.uk>
@coderabbitai

coderabbitai Bot commented Jul 9, 2026

Copy link
Copy Markdown
Contributor
📝 Walkthrough

Walkthrough

The test file test_swin_unetr.py was updated to replace tempfile-based temporary directory usage with a deterministic file path constructed from a new TESTS_PATH constant. The test_filter_swinunetr test now downloads pretrained weights to a fixed path under testing_data/ with a temp_-prefixed filename, instead of using a per-test temporary directory. Remaining test logic (loading weights, model construction, filtered state copy, assertions) is unchanged.

Estimated code review effort: 1 (Trivial) | ~3 minutes

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Title check ✅ Passed The title is concise and accurately summarizes the main change: caching SwinUNETR SSL weights to avoid repeated downloads.
Description check ✅ Passed The description covers the change, rationale, file impact, and type of change, matching the template's main sections.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
tests/networks/nets/test_swin_unetr.py (1)

38-39: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Use Path / operator consistently.

Path is imported but os.path.join is still used for path construction. Prefer the / operator for consistency.

♻️ Proposed refactor
-            weight_path = os.path.join(TESTS_PATH, "testing_data", f"temp_{file_name}")
+            weight_path = TESTS_PATH / "testing_data" / f"temp_{file_name}"

Also applies to: 118-118

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@tests/networks/nets/test_swin_unetr.py` around lines 38 - 39, The path
construction in test_swin_unetr.py is inconsistent because Path is imported but
os.path.join is still used in the test setup. Update the affected path-building
code to use the Path "/" operator consistently, using TESTS_PATH and any related
path variables/helpers in this file instead of os.path.join so the tests follow
one style throughout.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@tests/networks/nets/test_swin_unetr.py`:
- Around line 38-39: The path construction in test_swin_unetr.py is inconsistent
because Path is imported but os.path.join is still used in the test setup.
Update the affected path-building code to use the Path "/" operator
consistently, using TESTS_PATH and any related path variables/helpers in this
file instead of os.path.join so the tests follow one style throughout.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: b17c3e53-2745-4f30-b342-84bb44ad3b2f

📥 Commits

Reviewing files that changed from the base of the PR and between 229f519 and 7741301.

📒 Files selected for processing (1)
  • tests/networks/nets/test_swin_unetr.py

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant