[Doc] Document CatFrames with collectors and image replay buffers - #4229
YeonwooSung wants to merge 2 commits into
Conversation
🔗 Helpful Links🧪 See artifacts and rendered test results at hud.pytorch.org/pr/pytorch/rl/4229
Note: Links to docs will display an error until the docs builds have been completed.
|
vmoens
left a comment
There was a problem hiding this comment.
The helper-based collector/replay example runs and returns [32, 4, 84, 84] stacks. The explicit alternative is missing the reshape/window-selection steps and mixes unrelated samples.
| slice_len=frame_stack, | ||
| traj_key=("collector", "traj_ids"), | ||
| ), | ||
| batch_size=batch_size * frame_stack, # B windows of length N |
There was a problem hiding this comment.
[P2] Reshape sampled windows before CatFrames and retain their last step
SliceSampler returns the B windows flattened as [B*N]; it does not make a [B, N] TensorDict for this transform. Consequently CatFrames treats the entire sample as one time sequence, so the first N-1 rows of later windows incorporate frames from an unrelated preceding window. A synthetic increasing-frame replay reproduces stacks such as [52, 53, 54, 66]; 12 of 16 rows were wrong with N=4. Match the helper by reshaping to [-1, N] before CatFrames and selecting [:, -1] afterward, or remove this purported equivalent recipe.
There was a problem hiding this comment.
Fixed in f5ef733. The explicit recipe now matches make_rb_transform_and_sampler: reshape(-1, N) before CatFrames and [:, -1] after it. A synthetic increasing-frame buffer reproduced the bleed ([54, 55, 56, 61] and only 16/64 consecutive rows with N=4); after the reshape/last-step pair every window is consecutive and the sample shape is [B, N] like the helper. The surrounding prose and the pitfalls list call out that SliceSampler returns [B * N], not [B, N].
SliceSampler returns flattened [B*N] windows. The explicit buffer recipe now reshapes to [B, N] and keeps the last step so CatFrames does not mix frames across unrelated slices.
|
Addressed the CHANGES_REQUESTED review in f5ef733. The helper-based collector/replay example was already correct. The explicit |
vmoens
left a comment
There was a problem hiding this comment.
Re-reviewed f5ef733. The manual replay recipe now restores the [batch, time] slice layout before CatFrames and selects the last item of each slice afterward. Sampling batch_size * frame_stack raw transitions matches the helper recipe.
I ran both rendered CartPole replay examples with a smaller collection/storage size; both return 32 samples with pixels_trsf shape [32, 4, 84, 84]. No remaining actionables.
Description
Adds a focused Sphinx recipe for using
CatFrameswith a data collector and a replay buffer on images, which was missing from the reference docs.Two legitimate placements are documented and cross-linked:
docs/source/reference/envs_transforms.rst): stateful stacking for the policy, reset /InitTrackerbehavior, anddim=-3for CHW images.docs/source/reference/data_replaybuffers.rst): store unstacked rawpixels, rebuild the stack inrb.sample(), and wire aCollectorthroughextend/sample. Shows bothCatFrames.make_rb_transform_and_samplerand the explicitSliceSamplerform.The recipe also covers why raw uint8 frames are what you store, how the collector's
("collector", "traj_ids")interact with the slice sampler, and the common pitfalls of stacking twice (env and buffer on the same key) or using the vector defaultdim=-1on pixels.Copy-paste snippets use
# doctest: +SKIPwhere gym / pixel rendering is required. TheCatFramesclass docstring now points at both sections.Code example
Rebuild four-frame CHW stacks when sampling, while storing individual frames. Synthetic numbered grayscale pixels make sequence continuity visible without rendering dependencies.
Motivation and Context
Using
CatFramesfor inference was already documented; reconstructing a frame stack when sampling from a replay buffer was not, especially for images (stack dim-3, not the vector default). Visual RL relies on this pattern, and the collector +extend+samplepath is easy to get wrong (double stacking, wrong dim, no time axis).close #2618
Types of changes
What types of changes does your code introduce? Remove all that do not apply:
Checklist
Go over all the following points, and put an
xin all the boxes that apply.If you are unsure about any of these, don't hesitate to ask. We are here to help!