Skip to content

feat(draft): preserve split-step normalization parity - #3706

Merged
terrykong merged 52 commits into
NVIDIA-NeMo:mainfrom
seonjinn:seonjinn/draft-cotrain-step-state-20260818
Sep 22, 2026
Merged

terrykong merged 52 commits into
NVIDIA-NeMo:mainfrom
seonjinn:seonjinn/draft-cotrain-step-state-20260818

Conversation

@seonjinn

@seonjinn seonjinn commented Aug 19, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • Accumulates draft-loss statistics across split microbatches.
  • Normalizes draft gradients and metrics using the DP-global draft-token count.
  • Preserves pipeline-wide gradient-norm reporting and clears state on abort or retry.

Scope

Split-step state and lifecycle handling around the soft-CE primitive; no new draft model or runtime integration.

Validation

  • Exact head: 76c2648d75c76b9f107f5de3d28f48cfa879316b
  • 27 current-head GitHub checks pass; remaining unit jobs are queued.

Prior distributed evidence

  • OCI 6327354, 6326981, 6327012, 6327013: split lifecycle, PP2 grad-norm propagation, and DP2/DP4 uneven/zero-count FP32/BF16 parity passed.

Dependencies / Remaining

Depends on #3703. The branch-up-to-date check is the only current failure.

Signed-off-by: seonjinn <sna@nvidia.com>
Signed-off-by: seonjinn <sna@nvidia.com>
@seonjinn
seonjinn requested review from a team as code owners August 19, 2026 00:08
@copy-pr-bot

copy-pr-bot Bot commented Aug 19, 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.

@seonjinn

Copy link
Copy Markdown
Contributor Author

Self-review: review-pr-team

Reviewed the PR3-only range on top of #3703, including split-step loss semantics, DP reduction ordering, draft-only gradient rescaling, metrics, and tests.

Resolved during self-review:

  • Preserved the runtime policy-loss metric contract instead of applying an invalid combined-loss normalization.
  • Made the reduction expectation device-local for GPU execution.
  • Corrected the OCI selector so the TQ draft-grad-norm test is exercised.

No unresolved correctness, security, or design findings remain in the PR3-only range.

Validation: OCI-Hsg job 6299067 completed successfully with 6 base tests, 2 MCore split tests, DP=2 NCCL uneven-count gradient/metric parity, Ruff, and compile checks.

Signed-off-by: seonjinn <sna@nvidia.com>
Signed-off-by: seonjinn <sna@nvidia.com>
Signed-off-by: seonjinn <sna@nvidia.com>
Signed-off-by: seonjinn <sna@nvidia.com>
Signed-off-by: seonjinn <sna@nvidia.com>
Signed-off-by: seonjinn <sna@nvidia.com>
@seonjinn
seonjinn force-pushed the seonjinn/draft-cotrain-step-state-20260818 branch from 3f5cadd to 1392bb9 Compare August 19, 2026 01:26
Signed-off-by: seonjinn <sna@nvidia.com>
Signed-off-by: seonjinn <sna@nvidia.com>
Signed-off-by: seonjinn <sna@nvidia.com>
Signed-off-by: seonjinn <sna@nvidia.com>
Signed-off-by: seonjinn <sna@nvidia.com>
Signed-off-by: seonjinn <sna@nvidia.com>
@seonjinn seonjinn added the CI:L2 Run doctests, unit tests, functional tests, and convergence tests label Aug 20, 2026
@seonjinn

Copy link
Copy Markdown
Contributor Author

/review-pr-team

@seonjinn

Copy link
Copy Markdown
Contributor Author

/ok to test 40badee

@seonjinn seonjinn left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Self-review before requesting reviewers.

Method: a focused review agent, then an adversarial pass with empirical CPU execution of the real modules.

The headline claim survived a serious challenge worth recording: a candidate CRITICAL argued the split path normalizes by the draft's own count while the monolithic path uses the policy's global_valid_toks, breaking parity. Refuted on four grounds: (1) roll_tensor(token_mask, shifts=-1) zeroes the vacated last slot, so the draft mask count equals sum(token_mask[:, 1:]) -- exactly the policy formula -- per sample, by construction; (2) both counts ride the same DP all-reduce; (3) the gradient scale composition (scale_gradients(1/n) then correct_main_grads x n x 1/draft_count) nets to raw/draft_count in both paths; (4) an empirical CPU run with a mask exercising the shifted first slot produced identical losses (relative diff 0.0). Also verified clean: zero-count guards, single-DP-collective accumulation, abort/retry state freshness, PP grad-norm collective symmetry for non-owner ranks.

Follow-up commit: the split-vs-monolithic parity regression test (inline) and the draft_loss shared constant (inline).

Notes: CI on this head is green except two non-code failures (an HF-CDN 429 download flake and the label-gated quality check). One pre-existing limitation worth a body line: draft + CP>1 fails the loss's mask/logits shape check identically in both paths -- not a parity regression, but worth stating. #3725 stacks on this PR and relies on the scale_gradients -> correct_main_grads -> optimizer.step() finalization order; flag any reordering there.

Comment thread tests/unit/models/megatron/test_draft_step_state.py
Comment thread nemo_rl/algorithms/loss/wrapper.py Outdated
@seonjinn

Copy link
Copy Markdown
Contributor Author

/ok to test fb138a7

terrykong
terrykong previously approved these changes Sep 17, 2026
@seonjinn seonjinn added CI:Lfast Runs a fast test suite and re-use nightly `main` container (but sync dependencies to PRs version) and removed CI:L2 Run doctests, unit tests, functional tests, and convergence tests labels Sep 17, 2026
@seonjinn
seonjinn dismissed terrykong’s stale review September 17, 2026 09:58

The merge-base changed after approval.

@seonjinn

Copy link
Copy Markdown
Contributor Author

/ok to test 89a0a09

@seonjinn

Copy link
Copy Markdown
Contributor Author

/ok to test 6d5c106

@seonjinn

Copy link
Copy Markdown
Contributor Author

/ok to test 53a9e12

Copied pull-request branches use push events, so Codecov needs an explicit PR number. Pass commit_parent for upload-coverage instead of base_sha, which is only supported by pr-base-picking. Preserve the coverage threshold and all training behavior.

Signed-off-by: seonjinn <sna@nvidia.com>
@github-actions github-actions Bot added the CI Relating to CI label Sep 18, 2026
@seonjinn

Copy link
Copy Markdown
Contributor Author

/ok to test e94b052

Preserve split-step normalization alongside the merged draft optimizer support. Keep both type-check entries and inherit the shared CI workflow from main.

Signed-off-by: seonjinn <sna@nvidia.com>
@github-actions github-actions Bot removed the CI Relating to CI label Sep 19, 2026
@seonjinn

Copy link
Copy Markdown
Contributor Author

/ok to test 18138e8

@seonjinn

seonjinn commented Sep 20, 2026 •

Copy link
Copy Markdown
Contributor Author

/ok to test 0cbe19c

1 similar comment
@seonjinn

Copy link
Copy Markdown
Contributor Author

/ok to test 0cbe19c

Preserve deferred draft normalization alongside the indexed teacher head contract.

Signed-off-by: seonjinn <sna@nvidia.com>
@seonjinn

Copy link
Copy Markdown
Contributor Author

/ok to test b4fbcc4

@terrykong
terrykong enabled auto-merge (squash) September 22, 2026 04:46
@terrykong
terrykong merged commit a9c3178 into NVIDIA-NeMo:main Sep 22, 2026
84 checks passed
@yfw yfw mentioned this pull request Sep 22, 2026
4 tasks done
seonjinn added a commit to seonjinn/RL that referenced this pull request Sep 22, 2026
Signed-off-by: seonjinn <sna@nvidia.com>
seonjinn added a commit to seonjinn/RL that referenced this pull request Sep 22, 2026
Signed-off-by: seonjinn <sna@nvidia.com>
seonjinn added a commit to seonjinn/RL that referenced this pull request Sep 22, 2026
Signed-off-by: seonjinn <sna@nvidia.com>
seonjinn added a commit to seonjinn/RL that referenced this pull request Sep 22, 2026
Signed-off-by: seonjinn <sna@nvidia.com>
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.

3 participants