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

[Feature] RNG for RBs #2379

Merged
merged 4 commits into from
Aug 8, 2024
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
amend
  • Loading branch information
vmoens committed Aug 8, 2024
commit c96e75cdf713430ad0d5b93a9369b1da7bf6b97c
39 changes: 20 additions & 19 deletions test/test_rb.py
Original file line number Diff line number Diff line change
Expand Up @@ -1259,33 +1259,34 @@ def test_slice_rng(self):
@pytest.mark.parametrize("size", [3, 5, 100])
@pytest.mark.parametrize("prefetch", [0])
class TestBuffers:
_default_params_rb = {}
_default_params_td_rb = {}
_default_params_prb = {"alpha": 0.8, "beta": 0.9}
_default_params_td_prb = {"alpha": 0.8, "beta": 0.9}

default_constr = {
ReplayBuffer: ReplayBuffer,
PrioritizedReplayBuffer: functools.partial(
PrioritizedReplayBuffer, alpha=0.8, beta=0.9
),
TensorDictReplayBuffer: TensorDictReplayBuffer,
TensorDictPrioritizedReplayBuffer: functools.partial(
TensorDictPrioritizedReplayBuffer, alpha=0.8, beta=0.9
),
TensorDictReplayBufferRNG: TensorDictReplayBufferRNG,
ReplayBufferRNG: ReplayBufferRNG,
}

def _get_rb(self, rbtype, size, storage, prefetch):
if storage is not None:
storage = storage(size)
if rbtype is ReplayBuffer:
params = self._default_params_rb
elif rbtype is PrioritizedReplayBuffer:
params = self._default_params_prb
elif rbtype is TensorDictReplayBuffer:
params = self._default_params_td_rb
elif rbtype is TensorDictPrioritizedReplayBuffer:
params = self._default_params_td_prb
else:
raise NotImplementedError(rbtype)
rb = rbtype(storage=storage, prefetch=prefetch, batch_size=3, **params)
rb = self.default_constr[rbtype](
storage=storage, prefetch=prefetch, batch_size=3
)
return rb

def _get_datum(self, rbtype):
if rbtype is ReplayBuffer:
if rbtype in (ReplayBuffer, ReplayBufferRNG):
data = torch.randint(100, (1,))
elif rbtype is PrioritizedReplayBuffer:
data = torch.randint(100, (1,))
elif rbtype is TensorDictReplayBuffer:
elif rbtype in (TensorDictReplayBuffer, TensorDictReplayBufferRNG):
data = TensorDict({"a": torch.randint(100, (1,))}, [])
elif rbtype is TensorDictPrioritizedReplayBuffer:
data = TensorDict({"a": torch.randint(100, (1,))}, [])
Expand All @@ -1294,11 +1295,11 @@ def _get_datum(self, rbtype):
return data

def _get_data(self, rbtype, size):
if rbtype is ReplayBuffer:
if rbtype in (ReplayBuffer, ReplayBufferRNG):
data = [torch.randint(100, (1,)) for _ in range(size)]
elif rbtype is PrioritizedReplayBuffer:
data = [torch.randint(100, (1,)) for _ in range(size)]
elif rbtype is TensorDictReplayBuffer:
elif rbtype in (TensorDictReplayBuffer, TensorDictReplayBufferRNG):
data = TensorDict(
{
"a": torch.randint(100, (size,)),
Expand Down
Loading