You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
PersistentDataset not usable anymore (v1.5.1) ? #8599
Since the modifications to the PersistentDataset made in version 1.5.1, the persistent dataset does not allow to save and load metadata. This mean we cannot invert back the initial transforms or even know the original filename (and probably a lot more).
To Reproduce
Steps to reproduce the behavior:
Install MONAI version 1.5.1
Load and transform an image through the PersistentDataset
Re-load the image from cache
Try to invert and save the image
Expected behavior
The original image and outputted image should be the same
#8566 fixed the vulnerabilities associated with the pickle module and torch.load(..., weights_only=False) by defensively serialising PyTorch tensors only. It looks like MetaTensors didn't make the cut.
warnings.warn(f"Corrupt cache file detected: {hashfile}. Deleting and recomputing.")
hashfile.unlink()
and recomputes the tensor every time, effectively bypassing the main benefit of caching.
While I appreciate the severity of the security issues addressed by #8566 is high, I feel like the breaking nature of this change wasn't properly advertised. The pull request marked itself as a non-breaking change, its pre-merge check even identified this problem, and we get this notice at the end of a class docstring:
Legacy cache files may not be loadable and may need to be recomputed.
This warranted a deprecation path in 1.5.x, or bumping the version to 1.6.0 at the very least per semantic versioning conventions. This is a breaking change that fundamentally alters PersistentDataset behaviour for anyone using transforms that produce MetaTensors i.e. most non-trivial preprocessing pipelines.
I think the broader issue remains: this is a breaking change to core functionality that was introduced in a patch release without deprecation warnings or migration guidance. Users upgrading from 1.5.0 to 1.5.1 will find their caches invalidated with no clear path forward beyond manually clearing and rebuilding them.
Note: I also observed differences between the input and output .nrrd files when comparing them directly (54KB vs 108KB), but I think that's due to the input file using shorts, but LoadImage converting to float32 and Rotate90 introducing minor floating-point precision effects in the spatial metadata.
I had noticed similar issues with PersistentDataset no longer supporting MetaTensor objects, so I have submitted this PR with my solution. PersistentDataset now accepts track_meta and weights_only directly, allowing for MetaTensors to be cached and read with track_meta=True and weights_only=False. The default arguments preserve the current behavior of the library, so it does not resolve the backwards compatibility issue you had mentioned.
Activity
iyassou commentedon Oct 22, 2025
#8566 fixed the vulnerabilities associated with the
picklemodule andtorch.load(..., weights_only=False)by defensively serialising PyTorch tensors only. It looks like MetaTensors didn't make the cut.MONAI/monai/data/dataset.py
Lines 211 to 213 in 9c6d819
Objects are saved to cache after being converted to PyTorch tensors with the default argument of
track_meta=FalseMONAI/monai/data/dataset.py
Line 401 in 9c6d819
and loaded in weights-only mode
MONAI/monai/data/dataset.py
Line 380 in 9c6d819
I've tried converting with
track_meta=Truebut that sets this offMONAI/monai/data/dataset.py
Lines 384 to 387 in 9c6d819
and recomputes the tensor every time, effectively bypassing the main benefit of caching.
While I appreciate the severity of the security issues addressed by #8566 is high, I feel like the breaking nature of this change wasn't properly advertised. The pull request marked itself as a non-breaking change, its pre-merge check even identified this problem, and we get this notice at the end of a class docstring:
MONAI/monai/data/dataset.py
Line 214 in 9c6d819
This warranted a deprecation path in 1.5.x, or bumping the version to 1.6.0 at the very least per semantic versioning conventions. This is a breaking change that fundamentally alters PersistentDataset behaviour for anyone using transforms that produce MetaTensors i.e. most non-trivial preprocessing pipelines.
fix: pin MONAI version
iyassou commentedon Oct 22, 2025
Environment:
sys.version == '3.12.11 (main, Jul 11 2025, 22:26:01) [Clang 20.1.4 ]'uv -v:uv 0.7.21 (Homebrew 2025-07-14)uv add monai[all]==1.5.1After some more digging it seems like MetaTensors are supported, but NumPy arrays aren't.
@SebGoll I've recreated your specific example using this sample .nrrd file:
Running this example as is yields:
I was able to get the cache file read by:
track_meta=Trueat this lineMONAI/monai/data/dataset.py
Line 401 in 9c6d819
TraceKeysas safe globals before usingPersistentDataset:I think the broader issue remains: this is a breaking change to core functionality that was introduced in a patch release without deprecation warnings or migration guidance. Users upgrading from 1.5.0 to 1.5.1 will find their caches invalidated with no clear path forward beyond manually clearing and rebuilding them.
Note: I also observed differences between the input and output .nrrd files when comparing them directly (54KB vs 108KB), but I think that's due to the input file using shorts, but LoadImage converting to float32 and Rotate90 introducing minor floating-point precision effects in the spatial metadata.
mccle commentedon Nov 12, 2025
Hello @SebGoll and @iyassou,
I had noticed similar issues with
PersistentDatasetno longer supportingMetaTensorobjects, so I have submitted this PR with my solution.PersistentDatasetnow acceptstrack_metaandweights_onlydirectly, allowing forMetaTensors to be cached and read withtrack_meta=Trueandweights_only=False. The default arguments preserve the current behavior of the library, so it does not resolve the backwards compatibility issue you had mentioned.Fix #8599: Add track_meta and weights_only arguments to PersistentDat…
Fix Project-MONAI#8599: Add track_meta and weights_only arguments to …
Fix Project-MONAI#8599: Add track_meta and weights_only arguments to …
Fix Project-MONAI#8599: Add track_meta and weights_only arguments to …