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

[Deprecation] Deprecate ambiguous device for memmap replay buffer #1624

Merged
merged 2 commits into from
Oct 10, 2023
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
16 changes: 14 additions & 2 deletions torchrl/data/replay_buffers/storages.py
Original file line number Diff line number Diff line change
Expand Up @@ -586,8 +586,14 @@ def _init(self, data: Union[TensorDictBase, torch.Tensor]) -> None:
data.clone()
.expand(self.max_size, *data.shape)
.memmap_like(prefix=self.scratch_dir)
.to(self.device)
)
if self.device.type != "cpu":
warnings.warn(
"Support for Memmap device other than CPU will be deprecated in v0.4.0.",
category=DeprecationWarning,
)
out = out.to(self.device).memmap_()

for key, tensor in sorted(
out.items(include_nested=True, leaves_only=True), key=str
):
Expand All @@ -603,8 +609,14 @@ def _init(self, data: Union[TensorDictBase, torch.Tensor]) -> None:
data.clone()
.expand(self.max_size, *data.shape)
.memmap_like(prefix=self.scratch_dir)
.to(self.device)
)
if self.device.type != "cpu":
warnings.warn(
"Support for Memmap device other than CPU will be deprecated in v0.4.0.",
category=DeprecationWarning,
)
out = out.to(self.device).memmap_()

for key, tensor in sorted(
out.items(include_nested=True, leaves_only=True), key=str
):
Expand Down
2 changes: 1 addition & 1 deletion tutorials/sphinx-tutorials/pretrained_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@
#
from torchrl.data import LazyMemmapStorage, ReplayBuffer

storage = LazyMemmapStorage(1000, device=device)
storage = LazyMemmapStorage(1000)
rb = ReplayBuffer(storage=storage, transform=r3m)

##############################################################################
Expand Down
Loading