Enabling MetaTensor Persistent Caching#8940
Conversation
Signed-off-by: Eric Kerfoot <17726042+ericspod@users.noreply.github.com>
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (2)
💤 Files with no reviewable changes (1)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughWalkthrough
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
for more information, see https://pre-commit.ci
There was a problem hiding this comment.
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
monai/data/dataset.py (1)
280-283:⚠️ Potential issue | 🟡 Minor | ⚡ Quick winStale docstring: Raises section describes removed behavior.
Lines 280-282 document a
ValueErrorthat is no longer raised since the guard was removed. Delete this section.🧹 Proposed fix
- Raises: - ValueError: When both `track_meta=True` and `weights_only=True`, since this combination - prevents cached MetaTensors from being reloaded and causes perpetual cache regeneration. """🤖 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 `@monai/data/dataset.py` around lines 280 - 283, The Raises section in the docstring describes a ValueError condition (when both track_meta=True and weights_only=True are set) that is no longer raised by the code since the guard was removed. Delete the entire Raises section (lines 280-283) that documents this ValueError behavior to keep the docstring accurate and in sync with the current implementation.
🧹 Nitpick comments (1)
tests/data/test_persistentdataset.py (1)
282-285: 🧹 Nitpick | 🔵 Trivial | 💤 Low valueUse f-string conversion flag instead of
str().Per Ruff RUF010: replace
{str(Path(tempdir)/"out.txt")}with{Path(tempdir)/"out.txt"!s}.♻️ Proposed fix
class _BadType: def __reduce__(self): # something more insecure than this could be done with os.system - return (os.system, (f'echo "Code injected!" > {str(Path(tempdir)/"out.txt")}',)) + return (os.system, (f'echo "Code injected!" > {Path(tempdir)/"out.txt"!s}',))🤖 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/data/test_persistentdataset.py` around lines 282 - 285, In the _BadType class's __reduce__ method, replace the explicit str() call wrapping the Path object inside the f-string with f-string conversion syntax. Change {str(Path(tempdir)/"out.txt")} to {Path(tempdir)/"out.txt"!s} in the f-string to use the conversion flag instead of calling str() explicitly.Source: Linters/SAST tools
🤖 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.
Outside diff comments:
In `@monai/data/dataset.py`:
- Around line 280-283: The Raises section in the docstring describes a
ValueError condition (when both track_meta=True and weights_only=True are set)
that is no longer raised by the code since the guard was removed. Delete the
entire Raises section (lines 280-283) that documents this ValueError behavior to
keep the docstring accurate and in sync with the current implementation.
---
Nitpick comments:
In `@tests/data/test_persistentdataset.py`:
- Around line 282-285: In the _BadType class's __reduce__ method, replace the
explicit str() call wrapping the Path object inside the f-string with f-string
conversion syntax. Change {str(Path(tempdir)/"out.txt")} to
{Path(tempdir)/"out.txt"!s} in the f-string to use the conversion flag instead
of calling str() explicitly.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: dc50f62c-53a3-4d79-bce8-33e2e5e57fb7
📒 Files selected for processing (3)
monai/data/dataset.pymonai/data/utils.pytests/data/test_persistentdataset.py
Addresses GHSA-636w-j999-g7x5.
Description
This modifies the
PersistentDatasetclass to permit storingMetaTensorobjects. This is done by relying on thetorch.loadfunctionality to load only safe object types and those white-listed withtorch.serialization.add_safe_globals. This also uses sha256 hashing in place of md5 in case of security concerns.Types of changes
./runtests.sh -f -u --net --coverage../runtests.sh --quick --unittests --disttests.make htmlcommand in thedocs/folder.