Skip to content

Commit

Permalink
[BugFix] Fix is_memmap attribute for memmap_like and memmap (#625)
Browse files Browse the repository at this point in the history
  • Loading branch information
vmoens authored Jan 17, 2024
1 parent 617a449 commit a9234fc
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 0 deletions.
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

0 comments on commit a9234fc

Please sign in to comment.