From d99cf3c4dd2c55c292aae93f7f6962085618d51c Mon Sep 17 00:00:00 2001 From: vmoens Date: Tue, 16 Jan 2024 17:42:39 +0000 Subject: [PATCH] amend --- tensordict/persistent.py | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/tensordict/persistent.py b/tensordict/persistent.py index 0d1e0b70c..6eab894d4 100644 --- a/tensordict/persistent.py +++ b/tensordict/persistent.py @@ -566,7 +566,8 @@ def _memmap_( inplace, like, ) -> T: - + if inplace: + raise RuntimeError("Cannot call memmap inplace in a persistent tensordict.") # re-implements this to make it faster using the meta-data def save_metadata(data: TensorDictBase, filepath, metadata=None): if metadata is None: @@ -591,16 +592,13 @@ def save_metadata(data: TensorDictBase, filepath, metadata=None): "memmap_like() must be called when the TensorDict is (partially) " "populated. Set a tensor first." ) - dest = ( - self - if inplace - else TensorDict( + dest = TensorDict( {}, batch_size=self.batch_size, names=self.names if self._has_names() else None, device=torch.device("cpu"), ) - ) + dest._is_memmap = True for key, value in self._items_metadata(): if not value["array"]: value = self._get_str(key) @@ -658,8 +656,6 @@ def _populate( futures.append( executor.submit(save_metadata, dest, prefix / "meta.json", metadata) ) - dest._is_memmap = True - dest.lock_() return dest _load_memmap = TensorDict._load_memmap