Repository navigation
fix(data-plane): preserve sparse media in mixed TransferQueue batches - #4684
Conversation
|
/ok to test eed9cda |
Moves Gym from 6f295d7dd (main's pin since #4753) to 3f6f20593, Gym main as of 2026-10-19 and the pin the Super 3.5 RLVR-on-main runs used. Of the 19 Gym commits, the only dependency change is that nemo-gym now declares requests directly (Gym #4684). Relocked with uv 0.11.28, the version docker/Dockerfile installs. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: Yi-Fu Wu <[email protected]>
terrykong
left a comment
There was a problem hiding this comment.
@ZhiyuLi-Nvidia could you help review?
0d123cb to
9371383
Compare
|
/ok to test 9371383 |
There was a problem hiding this comment.
Thanks for this. The row-set fetch for packed media is the right fix. But the PR needs a rebase: on current main its per-token path raises before it can recover.
Why it breaks on main. #4332 (merged 2026-10-14, after this branch) made TQDataPlaneClient.get_samples raise KeyError when TQ narrows the requested fields (nemo_rl/data_plane/adapters/transfer_queue.py:1509). fetch_columns fetches per-token fields over all rows and then checks what is missing, so the adapter raises before the retry runs. GitHub shows the PR as mergeable only because the files don't overlap.
Unit results (rebased onto main 26d52d998, same node and image, test_sparse_multimodal_fetch.py + test_tq_lifecycle.py):
| this PR, rebased | proposed change | |
|---|---|---|
| Result | 34 failed, 43 passed | 87 passed |
| Mixed text + image reads | KeyError at transfer_queue.py:1511 |
Rebuilt: pixels per row set, empty media on text rows |
Image-only read [2, 1] |
pass | pass |
test_missing_expected_pixels_fail |
fails: expects ValueError, gets the adapter's KeyError |
pass (asserts KeyError) |
Production LoC vs main (all files) |
+117 / −20 | +76 / −20 |
Proposed change
- Keep the packed-media grouping by geometry tags and the empty-row rebuild. That's the core of this PR.
- Drop the per-token probe/retry, the per-token zero-fill and the explicit "dropped fields" check.
main's adapter guard already fails loudly on a missing field. - Document on
DataPlaneClient.get_samplesthat every requested field must exist on every requested row. - Tests:
- Write per-token fields on every row (zeros on text rows).
- Add an audio-only row and a
[3, 1]read for mixed modalities. - Add
test_sparse_per_token_media_fails(a producer that writes the mask on image rows only must raise).
Full diffs (branch pr-4684-simplified on my fork: this PR's two commits rebased onto main, plus two commits on top):
- Proposed change on top of this PR:
column_io.py+11/−57,interfaces.py+5/−0 (docstring),test_sparse_multimodal_fetch.py+29/−7. - Whole branch vs
main:column_io.py+68/−10,worker_mixin.py+3/−10,interfaces.py+5/−0, tests +163/−0.
Feel free to cherry-pick the two top commits (3b14168da, 927f28a42).
Open question before an e2e run. The proposed reader assumes every row carries the per-token media fields. The real producer doesn't do that yet. add_grpo_token_loss_masks_and_generation_logprobs writes media_token_validity_mask only when its batch has media (nemo_rl/algorithms/grpo.py:2403), and the single controller calls it once per prompt group (nemo_rl/experience/payload.py:156). So a train read that mixes an image group with a text-only group is still sparse in the mask, and both versions raise there. Two ways to close it:
- Reader: fetch per-token fields only from rows that have packed-media tags, and zero-fill the rest. Decide this up front from the tags, with no probe. This matches the producer, since every row of a media group carries media tags. It adds about 15 lines and leaves text-only recipes untouched.
- Producer: always write the mask in multimodal runs, zeros on text rows. This needs a "multimodal run" flag passed to the four callers, and text-only LLM recipes must never get the field.
I'd lean to (1). Which fits the MOPD setup you validated with? Once that's settled, a mixed image/text e2e run should confirm it.
|
@ZhiyuLi-Nvidia I tried the producer-side approach and took your two commits. The missing writer is The fix declares the processor's per-token fields plus the validity mask once at setup, then fills missing message fields with text defaults before flattening. Existing values are retained. Pure-text runs get no extra fields. Captured rollouts use a separate producer with no per-token media columns, so that path stays unchanged. 372 CPU tests pass: 87 real-TQ sparse-media/lifecycle tests, 2 capture/finalization controls through real TQ, and 283 payload/replay/setup tests. The old producer reproduces the missing-mask error; the fixed producer passes through both driver and worker readers. Captured image/text groups also retain their pixels. Lint and pinned type checks pass. No new GPU run. The complete production diff is +114/-22 versus main, so it's larger than the estimate once the producer wiring is included. One limit: this doesn't migrate old ordinary replay rows that already lack the fields; those rows need regeneration. Could you take another look at this version? |
|
/ok to test 1092075 |
ZhiyuLi-Nvidia
left a comment
There was a problem hiding this comment.
Thanks. The producer-side fix looks right for the single controller. One remaining path is still sparse, and I'm proposing a small change for it below. It's non-blocking.
Remaining gap: grpo_sync dynamic sampling. SyncRolloutActor flattens each generation batch in its own call (_flatten_rollout_message_log_for_tq → add_grpo_token_loss_masks_and_generation_logprobs), so has_media is decided per batch. _apply_dynamic_sampling then concatenates metas across generation batches (grpo_sync.py:236). In a VLM run with mixed image and text data, a text-only generation batch next to a media batch leaves media_token_validity_mask sparse, and the train read raises KeyError on main's strict guard. This isn't a regression (main fails there today), but this PR's fill only covers record_to_train_batch.
Proposed change (cdbf899 on top of this PR, +37/−29 production, +32/−2 tests):
- Move the per-token fill from
record_to_train_batchintoadd_grpo_token_loss_masks_and_generation_logprobsas an optionalper_token_multimodal_fieldsargument, so both producers share one implementation:- A schema that includes the mask forces
has_media, so every message gets the mask. - Any schema field a message still lacks is set to zeros, the text value: 0 is text for
mm_token_type_ids/token_type_ids. That's what AutoModel already builds when the field is absent. - With the default
(), the function behaves exactly as before.
- A schema that includes the mask forces
- Add
per_token_multimodal_schema(processor)inmultimodal_utils.py. It returns()whenprocessor is None, i.e. text-only runs.setup.pyuses it instead of the inline expression, andgrpo_syncpasses it toSyncRolloutActor. - Tests:
test_prompt_group_producer_contractgets aproducerparameter (prompt_group,grpo_sync). Thegrpo_synccase writes each generation batch the way the actor does: real_flatten_rollout_message_log_for_tq, thenkv_first_write.test_sync_rollout_actor.pygets one line for the new attribute, because that test builds the actor without calling__init__.
Verified with the repo's unit flow (uv run --group test bash ./tests/run_unit.sh in the CI container) on 10 files covering the data plane, payload, replay buffer, single-controller setup and the sync rollout actor:
| this PR (1092075) | with the proposed change | |
|---|---|---|
| Result | 575 passed | 579 passed |
test_prompt_group_producer_contract[grpo_sync-*] |
n/a | 4 pass (sparse → KeyError; dense → correct mask / mm_token_type_ids) |
Feel free to cherry-pick it, or I can open it as a follow-up PR if you'd rather keep this one as is.
|
@ZhiyuLi-Nvidia Thanks, I took cdbf899. Sharing the fill in the GRPO helper covers both producers and keeps the captured-rollout path unchanged. 394 CPU tests passed locally: 93 real-TQ tests including both producer paths and the captured image/text controls, plus 301 payload/replay/setup/sync tests. The old sparse producer reproduces the missing-mask error; the schema-enabled producer preserves the mask and token-type values through both readers. Lint and formatting pass. The broader type check reports the same 132 diagnostics on the parent and this commit, with no added diagnostics. No GPU run. Could you take another look? The existing limitation remains: this does not migrate older ordinary replay rows that lack the fields. |
|
/ok to test 5e48c6c |
ZhiyuLi-Nvidia
left a comment
There was a problem hiding this comment.
Thank you @aroshanghias-nvd for the fix. LGTM!
|
/ok to test e84109b |
Signed-off-by: Ali Roshan Ghias <[email protected]>
Signed-off-by: Ali Roshan Ghias <[email protected]>
Drop the per-token probe/retry: main's TQ adapter raises on narrowed fields, so per-token media fields must be written on every row by producers. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: Zhiyu Li <[email protected]> Signed-off-by: Ali Roshan Ghias <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: Zhiyu Li <[email protected]> Signed-off-by: Ali Roshan Ghias <[email protected]>
…llout Signed-off-by: Ali Roshan Ghias <[email protected]>
…r too grpo_sync dynamic sampling concatenates rows flattened by separate SyncRolloutActor calls, so a text-only generation batch next to a media batch left media_token_validity_mask sparse and the strict TQ read raised. Move the per-token fill into add_grpo_token_loss_masks_and_generation_logprobs so both producers share it, add per_token_multimodal_schema(processor), and pass the schema to the grpo_sync rollout actor. Text-only runs are unchanged. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: Zhiyu Li <[email protected]> Signed-off-by: Ali Roshan Ghias <[email protected]>
record_to_train_batch now receives per_token_multimodal_fields from TQReplayBuffer.commit. The checkpoint-scenario stub that replaces it did not accept the argument, so every prompt raised TypeError and 151 single_controller checkpoint tests failed. Mirror the change already made to the stub in test_tq_replay_buffer.py. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: Zhiyu Li <[email protected]>
e84109b to
7dca0e1
Compare
|
/ok to test 7dca0e1 |
…bject.__new__ The #4160 tests in test_grpo.py build SyncRolloutActor without __init__, so rollout_to_tq hit AttributeError on the new per_token_multimodal_fields attribute. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: Zhiyu Li <[email protected]>
|
/ok to test 22c1515 |
What does this PR do?
Preserve packed media when fetching mixed image/text batches from TransferQueue.
TransferQueue returns the intersection of fields stored on the requested rows. Text-only rollouts do not store pixels, so fetching them together with image rows silently drops the image tensors while retaining the image token IDs. In an instrumented 20-step control, the ten image samples that lost pixels were exactly the ten samples filtered for high TMPE.
Use the existing per-row geometry tags to fetch packed media only for the rows carrying it, group fields with the same row set, and restore empty entries for text rows in the original order. Driver reads and worker scoring/training share this helper. Missing requested fields raise an error. Homogeneous batches still use one fetch; storage and checkpoint formats are unchanged.
Issues
No linked issue.
Usage
Automatic for existing data-plane reads; no configuration changes.
Validation
GPU validation used the existing integration stack with this fetch correction and a separate empty-diagnostics guard. It was not a full tip-of-main stack or v1-baseline parity test. The diagnostics guard is not part of this PR.
Before review