Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BugFix] Fix is_memmap attribute for memmap_like and memmap #625

Merged
merged 1 commit into from
Jan 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions tensordict/_td.py
Original file line number Diff line number Diff line change
Expand Up @@ -1679,6 +1679,11 @@ def _populate(
self._is_memmap = True
self._is_shared = False # since they are mutually exclusive
self._device = torch.device("cpu")
else:
dest._is_memmap = True
dest._is_shared = False # since they are mutually exclusive
dest._device = torch.device("cpu")

dest._is_locked = True
return dest

Expand Down
1 change: 1 addition & 0 deletions test/test_tensorclass.py
Original file line number Diff line number Diff line change
Expand Up @@ -1735,6 +1735,7 @@ class MyClass:
assert isinstance(cmemmap.x, MemoryMappedTensor)
assert isinstance(cmemmap.y.x, MemoryMappedTensor)
assert cmemmap.z == "foo"
assert cmemmap.is_memmap()


class TestNesting:
Expand Down
2 changes: 2 additions & 0 deletions test/test_tensordict.py
Original file line number Diff line number Diff line change
Expand Up @@ -2848,6 +2848,7 @@ def test_memmap_like(self, td_name, device, use_dir, tmpdir, num_threads):
for key in td.keys(True):
assert td[key] is not tdmemmap[key]
assert (tdmemmap == 0).all()
assert tdmemmap.is_memmap()

def test_memmap_prefix(self, td_name, device, tmp_path):
if td_name == "memmap_td":
Expand Down Expand Up @@ -6158,6 +6159,7 @@ def test_memmap_like(self, tmpdir):
)
tdm = td.memmap_like(prefix=tmpdir)
assert tdm.names == ["a", "b", "c", "d"]
assert tdm.is_memmap()

def test_memmap_td(self):
td = self.memmap_td("cpu")
Expand Down
Loading