Whole episodes in, contiguous chunks out.
Parameters
capacityint= 1_000_000Attributes
episodeslist of EpisodeNotes
Episodes shorter than the requested chunk length are skipped rather than padded. Padding would put frames into the sequence that the dynamics never produced, and the model has no way to tell them from real ones.
Sampling picks an episode uniformly and then a start position within it uniformly, which is what the world-model papers' released code does. Note the consequence: a step in a short episode is more likely to be drawn than a step in a long one. Sampling uniformly over all valid start positions instead would remove that bias, and is a deliberate non-choice here — matching the reference matters more than correcting it.
Examples
>>> import lucid
>>> from lucid.utils.rollout import Episode, SequenceReplay
>>> replay = SequenceReplay()
>>> replay.add(Episode(lucid.zeros((20, 3, 8, 8)), lucid.zeros((20, 2)),
... lucid.zeros((20,)), lucid.ones((20,))))
>>> batch = replay.sample(4, 5)
>>> batch.observations.shape, batch.actions.shape
((4, 5, 3, 8, 8), (4, 5, 2))Used by 1
Constructors
1Properties
1Instance methods
2Store an episode, evicting the oldest until the budget is met.
Parameters
episodeEpisodeRaises
ValueErrorDraw contiguous chunks.
Parameters
batch_sizeintlengthintReturns
EpisodeBatched, with a leading batch axis — observations is
(batch_size, length, C, H, W) and the rest follow. It is
the same NamedTuple because the fields mean the same thing;
only the rank differs.
Raises
ValueErrorlength steps long.