Skip to content

perf(sc): pass jagged token ids and generation logprobs to the dump - #5226

Merged
yuki-97 merged 3 commits into
mainfrom
perf/sc-dump-jagged-columns
Nov 16, 2026
Merged

yuki-97 merged 3 commits into
mainfrom
perf/sc-dump-jagged-columns

Conversation

@ZhiyuLi-Nvidia

@ZhiyuLi-Nvidia ZhiyuLi-Nvidia commented Nov 14, 2026 •

Copy link
Copy Markdown
Contributor

What

The advantage stage padded the jagged token_ids, generation_logprobs, and prev_logprobs columns to dense tensors (tensor_field) before it built TrainChunk.sequences. The writer then trimmed the padding again to input_lengths.

This PR passes the three columns as the data plane returns them (data[...]). The same block already passes prompt_ids this way. The TrainChunk.sequences docstring now says that columns can be dense or jagged.

No writer change is needed. DebugWriter._validate, _share_chunk_storage, and JsonDebugWriter._write_part already handle jagged tensors through unbind().

Why

Mikhail Shilkov replayed one step (1024 samples, about 300M tokens) through the writer code. Padding and trimming again cost 6-30 s, depending on threads. Building from the jagged tensors took about 2 s.

Result

In a simulation at 305M tokens on one core, the stage plus the Arrow list-column build drops from 54.2 s to 2.2 s.

The simulation uses the row lengths of a real step, repeated 40 times. The token values are random, the Arrow build is my own stand-in for a lake writer, and each number is the median of 3 runs.

An end-to-end run (Qwen3-0.6B, 4096 tokens, 1024 samples per step, 5 steps, JSON writer) shows no gain in total step time. The JSON encoding takes about 12.7 s per 7.6M-token step, and this PR does not change it. The gain should show with writers that take jagged columns directly, such as a Parquet or Iceberg writer.

The same run checks correctness. All 5 dump files have 1024 rows and no row shorter than its input_lengths. The mean of exp|prev - gen| in each file matches the trainer's token_mult_prob_error to 4 digits.

Test

test_training_dump_takes_jagged_columns_without_padding runs for the grpo and opd estimators. A store returns jagged columns with mixed lengths. The test checks that the chunk reaches the writer jagged, and that the dumped rows equal the trimmed values.

96 unit tests passed in the nightly-gym container.

Notes

  • Behavior change: a jagged row that is shorter than its input_lengths now raises in DebugWriter._validate. The zero padding used to hide that case. The e2e run had no such row.
  • Out-of-tree writers set with async_rl.debug_writer.target now receive jagged token_ids, generation_logprobs, and prev_logprobs. A writer that assumes dense tensors must change. I did not find one in the repo, but I could not search all external code.

🤖 Generated with Claude Code

ZhiyuLi-Nvidia and others added 2 commits November 13, 2026 15:49
The advantage stage padded the jagged token_ids and generation_logprobs
columns to dense for TrainChunk.sequences, and the writer then trimmed
the padding again. Hand the columns over as fetched; the writer already
unbinds jagged and dense columns alike and trims to input_lengths.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
Signed-off-by: Zhiyu Li <[email protected]>
Drop the cost narration from the comment in the advantage stage and
record the chunk in the test with patch.object(wraps=...) instead of a
hand-written wrapper.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
Signed-off-by: Zhiyu Li <[email protected]>
@copy-pr-bot

copy-pr-bot Bot commented Nov 14, 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.

…equences

prev_logprobs went through the same pad-then-strip round trip as the
token ids and generation logprobs, and was padded a second time after the
estimator had already padded it. Pass it as the data plane returns it.

TrainChunk.sequences now says its columns may be dense or jagged. The
jagged-dump test also covers prev_logprobs, through the opd estimator.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
Signed-off-by: Zhiyu Li <[email protected]>
@ZhiyuLi-Nvidia
ZhiyuLi-Nvidia marked this pull request as ready for review November 14, 2026 07:07
@ZhiyuLi-Nvidia

Copy link
Copy Markdown
Contributor Author

@mikhailshilkov could you take a review?

@svcnvidia-nemo-ci svcnvidia-nemo-ci 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.

LGTM — no qualifying findings in the three changed files.

The raw-column handoff matches the writer’s dense/jagged handling. The new regression checks mixed-length GRPO and OPD dumps.

Validation was static only; I didn’t run tests or lint or verify live CI. One child’s report text wasn’t returned, so I inspected its producer-contract topic directly.

Note: formal approval is not available for this request, so this review is posted as a comment only.

Review generated by codex. This was a full review. Request a full review with /review reset=true.

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

LGTM, thank you!

@yuki-97 yuki-97 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 removing the padding round trip from training dumps.

Thanks also for sharing the simulation and end-to-end JSON results; they make the gain and its limits clear.

Scope: Training-dump column handoff, writer compatibility and regression coverage, at 296c912.

Checked:

  • Raw token and logprob columns preserve valid row prefixes; dense inputs still work. Dump handoff.
  • Validation, shared storage and background JSON writing accept jagged columns. Writer storage handling.
  • The mixed-length GRPO and OPD regression checks the real writer handoff and dumped values. Regression coverage.

LGTM — no changes requested. Static review only; tests were not run locally.

Generated by Codex (#4999 version)

@yuki-97 yuki-97 added the CI:Lfast Runs a fast test suite and re-use nightly `main` container (but sync dependencies to PRs version) label Nov 16, 2026
@yuki-97

yuki-97 commented Nov 16, 2026

Copy link
Copy Markdown
Contributor

/ok to test 296c912

@yuki-97
yuki-97 enabled auto-merge (squash) November 16, 2026 07:17
@yuki-97
yuki-97 merged commit 777664b into main Nov 16, 2026
98 checks passed
@yuki-97
yuki-97 deleted the perf/sc-dump-jagged-columns branch November 16, 2026 09:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CI:Lfast Runs a fast test suite and re-use nightly `main` container (but sync dependencies to PRs version)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants