Skip to content

Commit 66c3672

Browse files
authored
Fix: Prevent Invalid next_state References When optimize_memory=True (#918)
1 parent c05e483 commit 66c3672

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

lerobot/scripts/server/buffer.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -286,9 +286,10 @@ def sample(self, batch_size: int) -> BatchTransition:
286286
raise RuntimeError("Cannot sample from an empty buffer. Add transitions first.")
287287

288288
batch_size = min(batch_size, self.size)
289+
high = max(0, self.size - 1) if self.optimize_memory and self.size < self.capacity else self.size
289290

290291
# Random indices for sampling - create on the same device as storage
291-
idx = torch.randint(low=0, high=self.size, size=(batch_size,), device=self.storage_device)
292+
idx = torch.randint(low=0, high=high, size=(batch_size,), device=self.storage_device)
292293

293294
# Identify image keys that need augmentation
294295
image_keys = [k for k in self.states if k.startswith("observation.image")] if self.use_drq else []

0 commit comments

Comments
 (0)