Skip to content

perf(grpo): tune Qwen3-30B sync and async BF16 recipes - #5007

Merged
terrykong merged 9 commits into
mainfrom
youngeunk/perf-qwen30b-async-training-mbs4
Nov 17, 2026
Merged

terrykong merged 9 commits into
mainfrom
youngeunk/perf-qwen30b-async-training-mbs4

Conversation

@youngeunkwon0405

@youngeunkwon0405 youngeunkwon0405 commented Oct 31, 2026 •

Copy link
Copy Markdown
Contributor

What does this PR do?

Tune the Qwen3-30B-A3B BF16 sync and async 1-off recipes for larger microbatches while controlling memory use.

Recipe changes

  • Increase training MBS 1 → 4 and logprob MBS 2 → 8, with packed-token budgets 16,384 / 32,768, to amortize per-microbatch overhead.
  • Use 1,024-token logprob chunks, deferred FP32 logits, and async selective moe_act recomputation to limit memory at the larger batch sizes. Sync keeps activation checkpointing disabled.
  • Tune rollout batching to max_num_seqs=256 / max_num_batched_tokens=8192. Async uses nccl_reshard with a 0.5% memory target per staging buffer to bound refit memory.

Logic change

ChunkedDistributedLogprob.backward now reuses one owned FP32 buffer and scatter_add_ instead of allocating a full-vocabulary int64 one-hot tensor and extra FP32 temporaries. This reduces backward memory use while preserving the gradient formula and leaving saved logits unchanged.

BF16 recipe benchmarks

Four nodes / 16 GB200 GPUs, global batch 2,048, maximum sequence length 4,096.

Mode Baseline: train 1 / LP 2 (s/step) Final: train 4 / LP 8 (s/step) Speedup (baseline / final) Runs
Sync 160.75 114.13 1.41× baseline / final
Async 1-off 133.74 66.40 2.01× baseline / final

Baseline and sync timings are medians of steps 2–9; final async is the mean of steps 4–8. Source/runtime revisions differ: final async used Rubin development source e5897ade9, rather than the current PR head. These are recorded benchmark results, not an isolated recipe-only comparison.

All runs completed ten updates and evaluation. Numerical outliers remain in the linked runs; these short tests do not establish convergence.

@copy-pr-bot

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

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

Copy link
Copy Markdown
Contributor Author

/ok to test dd32c31

@youngeunkwon0405
youngeunkwon0405 requested review from seonjinn and removed request for seonjinn October 31, 2026 06:49
@youngeunkwon0405
youngeunkwon0405 marked this pull request as draft October 31, 2026 06:50
@youngeunkwon0405

Copy link
Copy Markdown
Contributor Author

/ok to test 993d29c

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

Agent-team review of head dd32c31 (rl-expert, bug-finder, test-agent, expert-megatron-lm, devil's advocate). Summary: the backward rewrite is correct and the recipe's Megatron/vLLM settings are valid on the pinned stack; the one ask (inline) is the GPU evidence the description already lists as pending.

Verified

  • ChunkedDistributedLogprob.backward is equivalent to the previous implementation and to DistributedLogprob.backward: CPU TP=1 (12/12) and a CPU TP=2 emulation with true cross-rank MAX/SUM reductions, including rows whose target lives on the other rank (bf16 gradients bit-identical to the old backward on both ranks; fp32 within 2.4e-7 of full-vocab autograd). The new exp(x-max)/sum normalizer is slightly closer to fp64 than the old exp(x-max-log sum). Per-chunk transient memory at B=1, C=1024, V=151,936 drops from ~3.5 GiB to ~0.6 GiB; the zeros_like gradient buffer (~4.6 GiB in bf16) is unchanged.
  • Mutation testing of the new test: sign, grad weighting, scatter semantics, max-shift (caught by the logit_scale=40 cases) and saved-input aliasing (copy=False trips autograd's version counter at the repeated backward) are all caught. The three TP>1-only behaviours (masked scatter source, the two all-reduces) are unobservable at TP=1 but are exercised on GPU by test_distributed_logprob.py (tp=2, chunk=4) and test_get_next_token_logprobs_chunk_equivalence in the Lfast Distributed shard, which is green on this head.
  • Recipe: recompute_granularity: selective + recompute_modules: [moe_act] is validated by MCore at startup (validate_megatron_config → ConfigContainer.validate() → Bridge model.finalize() → MCoreTransformerConfig.__post_init__, where moe_act requires moe_grouped_gemm, which the parent recipe sets). defer_fp32_logits + logprob_chunk_size satisfy the setup guard; check_nccl_reshard_refit_support passes on the resolved config; the BF16 TRT-LLM nccl_reshard placement check resolves linear by vLLM 0.29.0 default at EP=1; both NRL_REFIT_BUFFER_MEMORY_RATIO placements are read (the misc producer and consumer size their buffers independently from their own env) and agree.

Notes (no action needed)

  • logprob_batch_size: 2 (L15) and PYTORCH_CUDA_ALLOC_CONF (L29) are already inherited from grpo-qwen3-30ba3b-4n4g.yaml (L14, L38), so tools/config_cli.py minimize strips exactly these two of the added lines; performance/ is outside the pre-commit glob, so nothing fails. Keep for explicitness or drop; the description's "use the validated fixed CUDA allocator" reads as a change but was already in effect.
  • The sibling async recipes (nemotron3-super 32n4g, deepseek-v3 fp8) pin NRL_REFIT_NUM_BUFFERS: "1" next to the 0.005 ratio; this recipe keeps the default 2 (two ~0.93 GiB staging buffers per side). Fine if intentional.
  • Test L17 and L33-37 patch torch.distributed.nn.functional.all_reduce, which nothing on the chunked forward/backward path calls any more. Harmless dead code.
  • CI: the three red checks on this head look unrelated to the PR. fast_L1_Functional_Tests_SingleController_2 died in MegatronPolicyWorker.__init__ with EADDRINUSE on port 1588 before any training ran; sphinx-build failed linkcheck on an opentelemetry.io URL; CI quality check only aggregates. Worth a re-trigger.
  • Follow-ups outside this diff: the comment at setup.py L1924-L1928 ("validation doesn't re-run after attribute assignment") is stale given the finalize() chain above (#2291 may be closable); the exemplar comments at grpo_math_1B.yaml L261 and policy/__init__.py L435 describe ["moe"] as "expert activations only", but MCore's moe replays the whole MoE layer while moe_act is the narrow boundary this recipe uses; the Ray-actor test in test_model_utils.py L1009-L1016 never runs the chunked backward.

Generated by Claude Code

@youngeunkwon0405 youngeunkwon0405 changed the title perf(grpo): enable Qwen3-30B async training MBS 4 perf(grpo): enable Qwen3-30B async training and logprob MBS 4 Nov 2, 2026
@youngeunkwon0405

Copy link
Copy Markdown
Contributor Author

/ok to test 2f9d043

@youngeunkwon0405 youngeunkwon0405 self-assigned this Nov 2, 2026
@youngeunkwon0405
youngeunkwon0405 marked this pull request as ready for review November 2, 2026 23:11

@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 actionable findings from static inspection.

Reviewed the backward rewrite, recipe changes, and regression test, including affected batching, packed-loss, refit, and distributed-test paths.

Limitations: no tests, linters, or GPU runs were executed. Upstream Megatron-Bridge, Megatron-LM, and vLLM implementation sources weren't available for independent verification. The description supplies a 137 s → 81 s comparison but still marks current-head GPU validation as pending. One delegated test/evidence report wasn't available; I inspected that 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.

@youngeunkwon0405
youngeunkwon0405 marked this pull request as draft November 3, 2026 04:28
@youngeunkwon0405
youngeunkwon0405 marked this pull request as ready for review November 3, 2026 06:05
@youngeunkwon0405

Copy link
Copy Markdown
Contributor Author

/ok to test 24064b1

@youngeunkwon0405

Copy link
Copy Markdown
Contributor Author

/ok to test 15ae390

@youngeunkwon0405 youngeunkwon0405 changed the title perf(grpo): enable Qwen3-30B async training and logprob MBS 4 perf(grpo): enable Qwen3-30B sync and async microbatch size 4 Nov 3, 2026
@youngeunkwon0405

Copy link
Copy Markdown
Contributor Author

/ok to test d55b095

@youngeunkwon0405

Copy link
Copy Markdown
Contributor Author

/ok to test ff3fe86

@copy-pr-bot

copy-pr-bot Bot commented Nov 4, 2026

Copy link
Copy Markdown

/ok to test ff3fe86

@youngeunkwon0405, there was an error processing your request: E2

See the following link for more information: https://docs.gha-runners.nvidia.com/cpr/e/2/

@youngeunkwon0405 youngeunkwon0405 changed the title perf(grpo): enable Qwen3-30B sync and async microbatch size 4 perf(grpo): tune Qwen3-30B sync and async BF16 recipes Nov 4, 2026
@youngeunkwon0405

Copy link
Copy Markdown
Contributor Author

/ok to test ff3fe86

@youngeunkwon0405

Copy link
Copy Markdown
Contributor Author

/ok to test ac9c312

@youngeunkwon0405

Copy link
Copy Markdown
Contributor Author

Hi @parthmannan can I ask for your approval on this PR?

@parthmannan parthmannan 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!

@terrykong
terrykong merged commit 50e2172 into main Nov 17, 2026
174 of 176 checks passed
@terrykong
terrykong deleted the youngeunk/perf-qwen30b-async-training-mbs4 branch November 17, 2026 17:46
jthomson04 added a commit to jthomson04/RL that referenced this pull request Nov 17, 2026
…ym rollout) into jthomson04/dynamo-1.7

Brings in NVIDIA-NeMo#4979's merge of main 89329fc (NVIDIA-NeMo#5030, NVIDIA-NeMo#5120, NVIDIA-NeMo#5007, NVIDIA-NeMo#5187, NVIDIA-NeMo#5265). Git merged the five files both sides changed without a conflict: the Dynamo guide, nemo_gym.py and three test files. pyproject.toml, uv.lock and the submodule pins are unchanged.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
Signed-off-by: jthomson04 <[email protected]>
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