Skip to content
Open
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
20 changes: 18 additions & 2 deletions torchrl/data/replay_buffers/samplers.py
Original file line number Diff line number Diff line change
Expand Up @@ -1556,14 +1556,30 @@ def _get_index(
out_of_traj = relative_starts < 0
if out_of_traj.any():
# a negative start means sampling fewer elements
# Convert seq_length to tensor to avoid torch.compile inductor C++ codegen
# bug with mixed scalar/tensor int64 in blendv operations (see PyTorch #xyz)
seq_length_t = torch.as_tensor(
seq_length,
dtype=relative_starts.dtype,
device=relative_starts.device,
)
seq_length = torch.where(
~out_of_traj, seq_length, seq_length + relative_starts
~out_of_traj, seq_length_t, seq_length_t + relative_starts
)
relative_starts = torch.where(
~out_of_traj, relative_starts, torch.zeros_like(relative_starts)
)
relative_starts = torch.where(~out_of_traj, relative_starts, 0)
if self.span[1]:
out_of_traj = relative_starts + seq_length > lengths[traj_idx]
if out_of_traj.any():
# a negative start means sampling fewer elements
# Convert seq_length to tensor if it's still a scalar
if not isinstance(seq_length, torch.Tensor):
seq_length = torch.as_tensor(
seq_length,
dtype=relative_starts.dtype,
device=relative_starts.device,
)
seq_length = torch.minimum(
seq_length, lengths[traj_idx] - relative_starts
)
Expand Down
Loading