Skip to content

fix(data-plane): preserve sparse media in mixed TransferQueue batches - #4684

Merged
ZhiyuLi-Nvidia merged 8 commits into
mainfrom
fix-mixed-media-tq-fetch
Oct 28, 2026
Merged

ZhiyuLi-Nvidia merged 8 commits into
mainfrom
fix-mixed-media-tq-fetch

Conversation

@aroshanghias-nvd

Copy link
Copy Markdown
Contributor

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

  • 74 targeted CPU tests pass on this PR branch, including the real TransferQueue simple backend, mixed/reordered/repeated rows, image/audio media, missing-field failures, existing multimodal transport, local SFT, and CPU broadcast coverage. The new mixed-row regression fails under the original fetch implementation.
  • Ruff, formatting, and the repository-pinned type checker pass.
  • A 20-update multimodal MOPD integration run completed with 160 samples. All 40 image samples retained pixels, including 13 mixed image/text worker batches. No samples were filtered by TMPE at the unchanged threshold of 2; the maximum per-sequence TMPE was 1.077. One image sample was excluded by the existing length limit.
  • All 80 captured model forwards preserved fetched tokens, positions, and media. Saved MOPD advantages matched the configured equation exactly, with 86,221 valid training tokens and checkpoint step/version 20.

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

  • Followed the contributor guidelines and signed off the commit.
  • Added regression tests and ran the targeted CPU and GPU checks above.
  • Documented the internal fetch contract; no user-facing configuration changes.
  • Repository CI.

@copy-pr-bot

copy-pr-bot Bot commented Oct 12, 2026

Copy link
Copy Markdown

This pull request requires additional validation before any workflows can run on NVIDIA's runners.

Pull request vetters can view their responsibilities here.

Contributors can view more details about this message here.

Comment thread nemo_rl/data_plane/column_io.py Resolved
Comment thread nemo_rl/data_plane/column_io.py Resolved
@pthombre

Copy link
Copy Markdown
Contributor

/ok to test eed9cda

@pthombre pthombre added the CI:L1 Run doctests, unit tests, and functional tests label Oct 13, 2026
pthombre
pthombre previously approved these changes Oct 14, 2026
yfw added a commit that referenced this pull request Oct 21, 2026
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 terrykong left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ZhiyuLi-Nvidia could you help review?

@ZhiyuLi-Nvidia

Copy link
Copy Markdown
Contributor

/ok to test 9371383

@ZhiyuLi-Nvidia ZhiyuLi-Nvidia left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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_samples that 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):

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:

  1. 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.
  2. 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.

@aroshanghias-nvd

Copy link
Copy Markdown
Contributor Author

@ZhiyuLi-Nvidia I tried the producer-side approach and took your two commits. The missing writer is record_to_train_batch: it calls the GRPO mask helper per prompt group, which removes the validity mask for text-only groups. Processor token-type fields can be missing there too.

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?

@aroshanghias-nvd

Copy link
Copy Markdown
Contributor Author

/ok to test 1092075

@ZhiyuLi-Nvidia ZhiyuLi-Nvidia left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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_batch into add_grpo_token_loss_masks_and_generation_logprobs as an optional per_token_multimodal_fields argument, 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.
  • Add per_token_multimodal_schema(processor) in multimodal_utils.py. It returns () when processor is None, i.e. text-only runs. setup.py uses it instead of the inline expression, and grpo_sync passes it to SyncRolloutActor.
  • Tests:
    • test_prompt_group_producer_contract gets a producer parameter (prompt_group, grpo_sync). The grpo_sync case writes each generation batch the way the actor does: real _flatten_rollout_message_log_for_tq, then kv_first_write.
    • test_sync_rollout_actor.py gets 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.

@aroshanghias-nvd

Copy link
Copy Markdown
Contributor Author

@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.

@aroshanghias-nvd

Copy link
Copy Markdown
Contributor Author

/ok to test 5e48c6c

ZhiyuLi-Nvidia
ZhiyuLi-Nvidia previously approved these changes Oct 26, 2026

@ZhiyuLi-Nvidia ZhiyuLi-Nvidia left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you @aroshanghias-nvd for the fix. LGTM!

@ZhiyuLi-Nvidia

Copy link
Copy Markdown
Contributor

/ok to test e84109b

aroshanghias-nvd and others added 5 commits October 27, 2026 11:06
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]>
ZhiyuLi-Nvidia and others added 2 commits October 27, 2026 11:06
…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]>
@ZhiyuLi-Nvidia
ZhiyuLi-Nvidia force-pushed the fix-mixed-media-tq-fetch branch from e84109b to 7dca0e1 Compare October 27, 2026 18:06
@ZhiyuLi-Nvidia

Copy link
Copy Markdown
Contributor

/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]>
@ZhiyuLi-Nvidia

Copy link
Copy Markdown
Contributor

/ok to test 22c1515

@ZhiyuLi-Nvidia
ZhiyuLi-Nvidia merged commit 0e36f2e into main Oct 28, 2026
254 of 280 checks passed
@ZhiyuLi-Nvidia
ZhiyuLi-Nvidia deleted the fix-mixed-media-tq-fetch branch October 28, 2026 14:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CI:L1 Run doctests, unit tests, and functional tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants