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

[BUG] dumps() failing on ReplayBuffer with LazyMemmapStorage #2390

Closed
3 tasks done
kalyan0510 opened this issue Aug 11, 2024 · 1 comment
Closed
3 tasks done

[BUG] dumps() failing on ReplayBuffer with LazyMemmapStorage #2390

kalyan0510 opened this issue Aug 11, 2024 · 1 comment
Assignees
Labels
bug Something isn't working

Comments

@kalyan0510
Copy link

Describe the bug

Calling dumps(path) on ReplayBuffer with LazyMemmapStorage fails with an error.
cause: replay_buffer._storage._storage.saved_path seems to be set to None.

To Reproduce

Steps to reproduce the behavior.
Execute the example code provided in the doc for ReplayBuffer:dumps()
or this code

import os

import torch
from tensordict import TensorDict
from torchrl.data import TensorDictReplayBuffer, LazyMemmapStorage, ReplayBuffer

replay_buffer = ReplayBuffer(
    storage=LazyMemmapStorage(10000),
    prefetch=None,
    batch_size=40,
    pin_memory=True)

replay_buffer.extend(TensorDict({
        'actions': torch.ones(10,10,10, dtype=torch.int32),
    }, batch_size=[10]))

print(replay_buffer.storage._storage.saved_path) # None
replay_buffer.dumps(path='/home/kalyan/tmp')
replay_buffer.dumps(path=os.path.join('/home/kalyan/tmp'))
None
Traceback (most recent call last):
  File "/home/kalyan/.config/JetBrains/PyCharm2024.1/scratches/screatch5.py", line 18, in <module>
    replay_buffer.dumps(path='/home/kalyan/tmp')
  File "/home/kalyan/anaconda3/envs/rlostrack/lib/python3.8/site-packages/torchrl/data/replay_buffers/replay_buffers.py", line 465, in dumps
    self._storage.dumps(path / "storage")
  File "/home/kalyan/anaconda3/envs/rlostrack/lib/python3.8/site-packages/torchrl/data/replay_buffers/storages.py", line 97, in dumps
    self.checkpointer.dumps(self, path)
  File "/home/kalyan/anaconda3/envs/rlostrack/lib/python3.8/site-packages/torchrl/data/replay_buffers/checkpointers.py", line 96, in dumps
    and Path(_storage.saved_path).absolute() == Path(path).absolute()
  File "/home/kalyan/anaconda3/envs/rlostrack/lib/python3.8/pathlib.py", line 1042, in __new__
    self = cls._from_parts(args, init=False)
  File "/home/kalyan/anaconda3/envs/rlostrack/lib/python3.8/pathlib.py", line 683, in _from_parts
    drv, root, parts = self._parse_args(args)
  File "/home/kalyan/anaconda3/envs/rlostrack/lib/python3.8/pathlib.py", line 667, in _parse_args
    a = os.fspath(a)
TypeError: expected str, bytes or os.PathLike object, not NoneType

Expected behavior

save the rb

System info

import torchrl, numpy, sys
print(torchrl.__version__, numpy.__version__, sys.version, sys.platform)
0.5.0 1.24.4 3.8.19 | packaged by conda-forge | (default, Mar 20 2024, 12:47:35)
[GCC 12.3.0] linux

tensordict.__version__ = 0.5.0 (installed from nightly)

Reason and Possible fixes

When storage init with scratch dir, it fixed the problem
LazyMemmapStorage(10000, scratch_dir='/home/kalyan/tmp')

Checklist

  • I have checked that there is no similar issue in the repo (required)
  • I have read the documentation (required)
  • I have provided a minimal working example to reproduce the bug (required)
@kalyan0510 kalyan0510 added the bug Something isn't working label Aug 11, 2024
@N00bcak
Copy link
Contributor

N00bcak commented Aug 13, 2024

Hi,

The fix is already in the latest main. You might want to check your nightly build's source code to see if the fix is already present:

_storage.is_memmap()
and _storage.saved_path
and Path(_storage.saved_path).absolute() == Path(path).absolute()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants