Skip to content

fix(nightly): make dpo-nanov3-30B3AB-1n8g-automodel-ep8.v2 deterministic - #4619

Merged
yuki-97 merged 5 commits into
r0.8.0from
joyang/dpo-nanov3-deterministic
Oct 15, 2026
Merged

yuki-97 merged 5 commits into
r0.8.0from
joyang/dpo-nanov3-deterministic

Conversation

@joyang-nv

@joyang-nv joyang-nv commented Oct 9, 2026 •

Copy link
Copy Markdown
Member

What does this PR do?

Fixes the nightly dpo-nanov3-30B3AB-1n8g-automodel-ep8.v2. It has failed check_metrics in every pipeline since it was added: 9 of 9 pipelines from Sep 28 to Oct 8. It does this by:

  1. making the policy forward and backward bitwise deterministic for this recipe;
  2. replacing gates that sat inside run-to-run noise.

Root cause

Training itself is healthy: all 15 steps finish and the loss falls. The gates were inside numerical noise:

Gate Old 10 identical runs on TOT main (non-deterministic)
train/loss[1] < 0.694 0.6949 ± 0.0031 (0.6900–0.7002)
train/loss[11] < 0.57 0.5768 ± 0.0124 (0.5617–0.6021)
step 11–14 time < 5 s 5.12 ± 0.08 s (passed 1 of 10)
  • Seed and data order are not the cause. Per-step token counts are identical in every run.
  • Where the noise comes from. At step 1 the policy equals the reference, so both DPO rewards should be 0 and the loss should be ln 2. Non-deterministic kernels make the training forward and the reference forward differ. Step-1 rewards were -0.3 to -0.6 nats per sequence, and that difference propagates through training.

Fix

  • New opt-in switch policy.automodel_cfg.deterministic (NotRequired[bool], default false, policy workers only). When true:
    • CUBLAS_WORKSPACE_CONFIG=:4096:8 and NVTE_ALLOW_NONDETERMINISTIC_ALGO=0 are added to the policy workers' runtime env, so they are set before the process starts;
    • AutomodelPolicyWorker.__init__ calls torch.use_deterministic_algorithms(True, warn_only=True) and sets the cuDNN deterministic flags.
  • This recipe sets deterministic: true.
  • New gates (rationale is in a comment in the test script):
Gate New Why
train/loss[1], train/preference_loss[1] abs(x - 0.6931) < 0.0005 Before the first update, policy == reference, so loss = -log σ(0) = ln 2 for preference_loss=dpo, preference_loss_weight=1, sft_loss_weight=0. Holds across containers, and fails as soon as the forwards diverge (non-deterministic runs were off by 0.003–0.005)
train/loss[11], train/preference_loss[11] < 0.61 Between the 95% (0.6007) and 99% (0.6136) one-sided prediction bounds of the 10 non-deterministic runs, so a container or kernel change that moves the deterministic trajectory still passes
step 11–14 time < 6.5 s Deterministic runs measure 5.62–5.73 s
  • Docs: deterministic: false is added to the dpo, sft, rm, grpo_math_1B and distillation_math exemplars and their reference configs, and the env vars are documented in docs/design-docs/env-vars.md.

Validation

Run on cw_dfw H100 with container rl.72126403.sqsh, 1n8g.

Run loss[1] step-1 rewards (chosen / rejected) loss[11] step 11–14 time Gates
deterministic, run 1 0.693147 0.0000 / 0.0000 0.5685 5.67 s 5/5 PASS
deterministic, run 2 0.693147 0.0000 / 0.0000 0.5685 5.63 s 5/5 PASS
deterministic, run 3 0.693147 0.0000 / 0.0000 0.5685 5.62 s 5/5 PASS
  • Bitwise reproducibility: across the three runs, loss, grad_norm and both rewards are identical at all 15 steps (max |diff| = 0.0).
  • Unit tests: policy utility tests: 19 passed; value config guard: 1 passed; distillation config/reference checks: 2 passed.
  • Why the runs used the pre-rename code. They ran on main 9046a59 with this exact patch, the worker file then being dtensor_policy_worker_v2.py. Current containers do not yet have the renamed AutomodelPolicyWorker venv, a known issue.

Cost of determinism (3 baseline runs vs 2 deterministic runs, same window):

  • steady step time 5.21 → 5.88 s (+12.9%);
  • training tokens/s/GPU 331 → 292 (−11.7%);
  • peak memory unchanged;
  • step 1 is about 34 s faster, because Mamba's Triton kernels skip timing-based autotuning in deterministic mode;
  • net, the 15-step job takes about 1 minute longer.

Alternatives tried:

  • MAMBA_DETERMINISTIC=1 alone: no speed cost, but runs still differed (max loss diff 0.10). Not enough.
  • dispatcher=torch instead of HybridEP: single run, no systematic change.
  • activation_checkpointing=false: OOM at step 2, as the recipe comment warns.

1n4g validation

The 1n4g child recipe inherits deterministic: true from the 1n8g recipe. It also inherited PYTORCH_CUDA_ALLOC_CONF=expandable_segments:True, which caused a large 4-GPU performance regression. The child now disables that allocator option while keeping determinism and reshard_after_forward=true, and its step-time gate is set to < 6 s.

Validation used one node with 4 NVIDIA GB200 GPUs, container nvcr.io#nvidian/nemo-rl:v0.8.0.rc0, seed 42, fixed model/data caches and three fresh 15-step runs on the same node. Each run started from the same initial model without resume. The step-time and throughput columns use steps 11–14, matching the checker's end-exclusive mean(..., -5, -1) expression.

Run loss[1] loss[15] step 11–14 time tokens/s/GPU peak GPU memory Result with < 6 s
1 0.693147 0.590519 5.660 s 564.8 144.11 GB PASS
2 0.693147 0.590519 5.291 s 602.4 143.33 GB PASS
3 0.693147 0.590519 5.366 s 594.6 143.33 GB PASS
mean ± sample stddev 0.693147 ± 0 0.590519 ± 0 5.439 ± 0.195 s 587.3 ± 19.8 143.59 ± 0.45 GB 3/3 PASS
  • Correctness and determinism: all three runs completed 15/15 steps, all five loss/preference-loss gates passed, and the complete 15-point loss and preference-loss curves were bitwise identical across runs (max pairwise difference 0.0). Step-1 loss differs from ln 2 by about 1.9e-9.
  • Memory safety: no OOM occurred in any run. Disabling expandable segments increased sampled peak GPU memory by 4.14 GB (+2.97%) relative to the original deterministic 1n4g runs.
  • Performance: relative to the original deterministic 1n4g configuration with inherited expandable segments, step time changed from 16.942 s to 5.439 s (-67.90%), throughput from 188.0 to 587.3 tokens/s/GPU (+212.33%), and complete test wall time from 553.5 to 373.4 s (-32.55%). Setting only reshard_after_forward=false did not help (16.842 s), isolating the allocator setting as the relevant cause.
  • Exit-code interpretation: the three validation runs were executed before the gate was updated and therefore returned metric-check exit code 1 against the old < 5 s threshold. Training itself succeeded in all runs; re-evaluating the recorded metrics against the new < 6 s threshold passes 3/3.
  • Revision note: the runs used after SHA 2262da5 plus the exact child override, before the recipe rename. Commit 56d77347 applies the same override and the < 6 s gate to the current dpo-nanov3-30B3AB-1n4g-automodel-ep4 files.

🤖 Generated with Claude Code

@joyang-nv joyang-nv added the CI:L1 Run doctests, unit tests, and functional tests label Oct 9, 2026
@copy-pr-bot

copy-pr-bot Bot commented Oct 9, 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.

@github-actions github-actions Bot added the Documentation Improvements or additions to documentation label Oct 9, 2026
joyang-nv and others added 3 commits October 14, 2026 20:28
…ministic

The test has failed every night since it was added. Its step-1 gate
(loss < 0.694, ln 2 + 0.0009) and step-11 gate (< 0.57) sat inside
run-to-run numerical noise, and its step-time gate (< 5 s) sat below the
median step time.

At step 1 the policy equals the reference, so the DPO loss should be
exactly ln 2. Without deterministic kernels, the training forward and
the reference forward differ slightly. Across 10 identical runs on TOT
main:
- step-1 loss was 0.6949 +/- 0.0031;
- step-11 loss was 0.5768 +/- 0.0124;
- step 11-14 time was 5.12 +/- 0.08 s.
The seed and the data order were identical in every run.

Add an opt-in automodel_cfg.deterministic switch. It sets
CUBLAS_WORKSPACE_CONFIG and NVTE_ALLOW_NONDETERMINISTIC_ALGO=0 in the
worker runtime environment, and turns on torch deterministic algorithms
(warn_only) in the Automodel policy worker. Enable it for this recipe.
With it, two runs were bitwise identical, the step-1 loss is exactly
ln 2, and the steady step time rises about 13% (5.2 -> 5.9 s).
MAMBA_DETERMINISTIC=1 alone was not enough.

New gates:
- |loss[1] - ln 2| < 5e-4, which checks that the policy and reference
  forwards agree;
- loss[11] < 0.61, between the 95% and 99% one-sided prediction
  bounds of the non-deterministic distribution, so that a container or
  kernel change does not trip it;
- step time < 6.5 s.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Jonas Yang <[email protected]>
…nv-vars guide

- Add `deterministic: false` under automodel_cfg in the dpo, sft, rm and
  grpo_math_1B exemplars, and mirror it in tests/unit/reference_configs.
- Note in the schema that the switch applies to policy workers only.
- Note in docs/design-docs/env-vars.md which env vars it sets.
- Sort the test imports (ruff isort).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Jonas Yang <[email protected]>
@yuki-97
yuki-97 force-pushed the joyang/dpo-nanov3-deterministic branch from 2262da5 to a8805c1 Compare October 15, 2026 03:28
@yuki-97
yuki-97 changed the base branch from main to r0.8.0 October 15, 2026 03:29
@github-actions github-actions Bot added the CI Relating to CI label Oct 15, 2026
@yuki-97 yuki-97 added cherry-pick-to-main Opt in: cherry-pick this PR's commit from the release branch back into main CI:Lfast Runs a fast test suite and re-use nightly `main` container (but sync dependencies to PRs version) and removed CI:L1 Run doctests, unit tests, and functional tests labels Oct 15, 2026
@github-actions github-actions Bot removed the CI Relating to CI label Oct 15, 2026

@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 tracing this nightly's failures to non-deterministic kernels and fixing them at the source: the opt-in automodel_cfg.deterministic switch makes the policy forward and backward bitwise reproducible, and the gates are re-derived from that.

Great to see the three bitwise-identical runs, the measured cost comparison and the 1n4g allocator A/B posted in the description: the effect of each change can be read off clearly.

Scope: the full diff (18 files): switch wiring in lm_policy.py and the Automodel worker, the 1n8g recipe and test-script gates, the 1n4g child recipe, exemplar and reference configs, docs, and unit tests.

Checked:

  • Gate math: ln 2 = 0.693147 sits well inside the ±0.0005 step-1 window, and loss[11] < 0.61 lies between the 95% and 99% one-sided prediction bounds recomputed from the 10-run statistics (0.6006 / 0.6135).
  • Ordering: the two env vars travel through the worker runtime env, so they exist before the process starts, and use_deterministic_algorithms(True, warn_only=True) runs at the top of AutomodelPolicyWorkerImpl.__init__, before any cuBLAS handle is created.
  • Reach: distillation teacher/student and the reward-model environment all build Policy, so the switch applies on every Automodel policy path.
  • 1n4g child: it picks up deterministic: true through defaults:, and the PYTORCH_CUDA_ALLOC_CONF: "" override and < 6 s gate are backed by the 5.439 s measurement in the description; its step-1 window (0.69314 to 0.69316) already matches the ln 2 behavior.

Remaining comments are on exemplar discoverability, the scope of the new key (value model), and the schema comment wording.

nit, not blocking merging — the PR title and description use main's recipe name dpo-nanov3-30B3AB-1n8g-fsdp8ep8-automodel.v2, while on r0.8.0 the files are dpo-nanov3-30B3AB-1n8g-automodel-ep8.v2.*; consider using the r0.8.0 name.

Comment thread examples/configs/dpo.yaml Resolved
Comment thread nemo_rl/models/policy/__init__.py Resolved
Comment thread nemo_rl/models/policy/__init__.py Resolved
@fujial-code fujial-code changed the title fix(nightly): make dpo-nanov3-30B3AB-1n8g-fsdp8ep8-automodel.v2 deterministic fix(nightly): make dpo-nanov3-30B3AB-1n8g-automodel-ep8.v2 deterministic Oct 15, 2026
@fujial-code

Copy link
Copy Markdown
Contributor

/ok to test c791f5b

@yuki-97
yuki-97 enabled auto-merge (squash) October 15, 2026 09:00
@yuki-97
yuki-97 merged commit 1678c66 into r0.8.0 Oct 15, 2026
167 of 169 checks passed
@yuki-97
yuki-97 deleted the joyang/dpo-nanov3-deterministic branch October 15, 2026 11:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cherry-pick-to-main Opt in: cherry-pick this PR's commit from the release branch back into main CI:Lfast Runs a fast test suite and re-use nightly `main` container (but sync dependencies to PRs version) Documentation Improvements or additions to documentation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants