Repository navigation
feat: NCCL-Reshard refit merge PR (final) - #2971
Conversation
|
/okay to test 9ceff77 |
9ceff77 to
232ae10
Compare
|
/okay to test 232ae10 |
232ae10 to
d15dd19
Compare
|
/okay to test 037ae16 |
cef3f9d to
1605032
Compare
|
/okay to test 1605032 |
1605032 to
1388e0b
Compare
|
/okay to test 1388e0b |
f81da1f to
c293e41
Compare
|
/okay to test df61d48 |
|
/okay to test 4739e3a |
|
/okay to test 2cee864 |
2cee864 to
b2fee20
Compare
|
/okay to test b2fee20 |
097850d to
c577374
Compare
|
/okay to test c577374 |
c577374 to
1ea8fd8
Compare
|
/okay to test 1ea8fd8 |
|
/okay to test 375aaae |
terrykong
left a comment
There was a problem hiding this comment.
Thanks for this — the reshard core is impressive work. We hand-traced the expert-mesh EP/TP rank mapping (against Megatron-LM's expert RankGenerator with ETP=1), the gen-side rank arithmetic, the bulk/misc partition, and the merged-param slice math, and found them correct. The pure-function planning seam in nccl_reshard_utils.py makes the metadata logic CPU-testable, the three-impl xferdtensor dispatch behind one contract is clean, and check_nccl_reshard_refit_support is an unusually thorough validator — I checked every requirement the design doc lists and all seven are backed by a real violation. The measured refit times and KL ranges in the description are much appreciated.
Most of the feedback is about the configuration and guard surface around the feature rather than the reshard itself:
- How the transport is selected. Every existing refit transport is chosen by one enum,
policy.generation.refit_transport; this adds a sixth as a boolean on a different config node. That makes it undiscoverable fromdocs/guides/refit.md, and makesnccl_reshard_refit: true+refit_transport: nixlexpressible and unvalidated. - Where misconfigurations are caught. The validator is reached from exactly one place in
grpo.setup(), so three combinations bypass it — andppo.py/distillation.py/opd.py/single_controller.pyvalidate nothing at all. - A present-day silent no-op.
grpo_sync.pycallsrefit_policy_generationwithout forwarding the flag, so withdata_plane.enabled: truesetup builds the communicators and then every refit quietly falls back to the old path. The existingpolicy_generation.weight_synchronizerattribute — already used by the sparse and NIXL transports — would fix this with no change togrpo_sync.py. - Guards on the direct write into vLLM storage. The one other code path that writes straight into
w13_weightrejectsenable_eplbbecause "ownership can change after metadata exchange" — the same assumption this PR makes when it fixes the expert→rank map at setup, and it's unguarded here. - Docs.
refit.md(the page users read to pick a transport) isn't updated, and the design doc's requirements list omits gen-sidepipeline_parallel_size=1and the MoE expert-naming constraint that the code enforces.
Also: one latent layer→PP-stage mapping bug for bare-layers.N models under PP>1, an unvalidated NRL_REFIT_NUM_STREAMS, a base-class that advertises half the reshard protocol to value/DTensor workers, and two test-coverage asks (the pure-CPU reshard geometry, and the config validator).
Two notes needing no action now: _restore_placement / restore_refit_info_placements are untested and would bundle naturally into a geometry test file; and NcclReshardWeightSynchronizer reads megatron_cfg/vllm_cfg keys directly where CollectiveWeightSynchronizer stays backend-agnostic — defensible while this is Megatron→vLLM only, worth revisiting if the DTensor path lands.
Review notes: 6 review agents. All analysis is static — no GPU environment was available, so nothing here was verified by execution; repo linters deferred to CI.
Generated by Claude Code
Signed-off-by: Youngeun Kwon <[email protected]> Downsizing the implementation to make only support FFN params. Co-Authored-By: Claude Opus 4.8 <[email protected]> Signed-off-by: Youngeun Kwon <[email protected]> optional parallel misc Co-Authored-By: Claude Opus 4.8 <[email protected]> Signed-off-by: Youngeun Kwon <[email protected]> Add vLLM expert-parallel (EP) support to nccl_xfer refit Gen-side EP (EP == TP): build separate expert/non-expert dst meshes mirroring the train src side -- experts shard by index (Shard(0)) over the EP ranks, dense stays TP-sharded; gen-backend guard relaxed to allow expert_parallel_size == tensor_parallel_size. The gen-side w13/w2 spec is shape-driven so it needs no change. Validated golden at parity across nano/30B(+/-PP)/super/235B/DSv3 (gen EP4-EP32). Co-Authored-By: Claude Opus 4.8 <[email protected]> Signed-off-by: Youngeun Kwon <[email protected]> xferdtensor_python: exact-transfer reshard as the default fallback Add xferdtensor_python (exact overlap P2P to one representative replica + cached split-comm broadcast to DP replicas) and make it the default when the real nccl.m2n.reshard op is unavailable. xferdtensor_golden (full broadcast) is now selected only via NRL_XFERDTENSOR_GOLDEN=true. Also release cached allocator blocks (synchronize + empty_cache) between the bulk reshard and the misc broadcast on both the Megatron and vLLM sides: the misc packed_broadcast allocates via NCCL cudaMalloc outside PyTorch's caching allocator, and blocks still cached from the bulk reshard starve that allocation on memory-tight configs (235B misc headroom gen-side; DSv3 pp16ep16 train-side hang -> gen stuck in misc recv -> PIPELINE_MODEL_PARALLEL watchdog SIGABRT). Validated (default path, KL == golden, weight_sync vs ~7.7s broadcast): 4B tp2->tp4 / pp2->tp4 0.0004 @0.3s; 30B ep4tp2->tp4 0.0018 @1.1s; nemotron-super 0.0021 @2.2s; 30B genEP noPP/PP (->TP4.EP4) 0.0018/0.0020 @1.0s; 235B tp4pp8ep16->tp8 @gpu_mem 0.85 0.0043 @1.9s (with NRL_REFIT_BUFFER_MEMORY_RATIO=0.005); DSv3 pp16ep16->tp32 0.0018 @2.4s. Co-Authored-By: Claude Fable 5 <[email protected]> Signed-off-by: Youngeun Kwon <[email protected]> update xferdtensor_python_impl Co-Authored-By: Claude Fable 5 <[email protected]> Signed-off-by: Youngeun Kwon <[email protected]> rename nccl_xfer_refit -> nccl_reshard_refit and migrate into the weight_sync framework The reshard API's product name is nccl_reshard; rename the whole surface to match: config key +policy.nccl_reshard_refit, worker methods (nccl_reshard_refit / prepare_nccl_reshard_refit_info / init_nccl_reshard_comm_group), env NRL_NCCL_RESHARD_REFIT_PARALLEL_MISC, and the utils module. Migrate the transport into nemo_rl/weight_sync/: - add NcclReshardWeightSynchronizer + factory routing (create_weight_synchronizer(nccl_reshard_refit=True) for non-colocated) - grpo setup bootstraps via weight_synchronizer.init_communicator() (init_collective + per-PP-stage bulk comm groups + refit metadata) and refit_policy_generation syncs via weight_synchronizer.sync_weights() - move nccl_reshard_utils.py / xferdtensor.py / xferdtensor_python.py from nemo_rl/distributed/ to nemo_rl/weight_sync/ (unit tests mirrored to tests/unit/weight_sync/, pyrefly.toml updated) Validated: 1102 unit tests; full 30-case CI matrix (L0 x13, gen-EP x6, L1 235B/DSv3, FP8 x9) all at golden-parity KL through the framework path; refit latency unchanged vs the pre-migration runs (235B 1.7-2.0s, DSv3 2.3-2.7s vs ~8s broadcast). Co-Authored-By: Claude Fable 5 <[email protected]> Signed-off-by: Youngeun Kwon <[email protected]> reshard: stream-safe transfers, always-serial misc, misc-phase timers - xferdtensor() gains an optional 8th 'stream' arg, forwarded to xferdtensor_python_impl and to nccl.m2n.reshard (raw stream handle, omitted when None so wheels without the kwarg keep working). Both workers pass their active stream (gen: per-stage stream; train: nccl_reshard_stream = the current stream) so LocalParamSpec pre/post and the reshard communication are ordered on one stream — the real op's side-stream comm raced against pre/post (reported by the NCCL team); the Python impl now honors the caller's stream explicitly. - Remove the NRL_NCCL_RESHARD_REFIT_PARALLEL_MISC opt-in: the bulk reshard and misc broadcast now always run serially (bulk -> misc). The overlap deadlocked nondeterministically (misc recv + PP watchdog) and was never used. - Time the misc phase on both sides with a rank-0 print: '[nccl_reshard_refit] misc broadcast (train side) / misc recv+load (gen side)'. Validated (python path): 1102 unit tests; L0 4B/30B smokes at reference KL; L1 235B (KL 0.0044, weight_sync 1.70-1.88s; misc train 1.44s / gen 0.33-0.36s) and DSv3 (KL 0.0018, 2.27-2.59s, 10/10 steps; misc gen 0.73-0.92s). Co-Authored-By: Claude Fable 5 <[email protected]> Signed-off-by: Youngeun Kwon <[email protected]> remove accidentally-committed pytest result artifacts tests/unit/unit_results.json and tests/unit/unit_results/*.json are per-run pytest artifacts (each embeds the run's git SHA, which trips the CI secret detector as a hex high-entropy string). They were swept in by a wholesale 'git add tests/' during the weight_sync migration. Remove them and gitignore the paths so they cannot be committed again. Co-Authored-By: Claude Fable 5 <[email protected]> Signed-off-by: Youngeun Kwon <[email protected]> trim verbose comments in xferdtensor.py Co-Authored-By: Claude Fable 5 <[email protected]> Signed-off-by: Youngeun Kwon <[email protected]> docs: add nccl-reshard-refit design doc Design doc for the experimental nccl_reshard_refit path: how to enable it, the setup/refit execution flow and derived metadata, the misc path, the backend-agnostic vs backend-dependent split and how to extend new backends, and the xferdtensor transports (nccl4py m2n reshard + xferdtensor_python_impl backup). Co-Authored-By: Claude Fable 5 <[email protected]> Signed-off-by: Youngeun Kwon <[email protected]> drop unnecessary changes Co-Authored-By: Claude Fable 5 <[email protected]> Signed-off-by: Youngeun Kwon <[email protected]> nccl_reshard_refit: fix refit deadlock on tied-embedding models The misc packed_broadcast producer emitted the tied lm_head.weight while the consumer's misc_meta dropped it (a legacy skip left over from when embeddings took the bulk path). That extra param shifted the packed-broadcast buffer boundaries so the producer issued more broadcasts than the consumer, deadlocking the refit (both golden and python transports, any tied-embedding model, e.g. Qwen3-0.6B). Embeddings now route to misc like every other non-FFN param and vLLM re-ties lm_head on load, so drop the stale skip; producer and consumer agree again. The functional smoke runs the default transport (xferdtensor_python fallback when nccl.m2n is absent). Co-Authored-By: Claude Opus 4.8 <[email protected]> Signed-off-by: Youngeun Kwon <[email protected]> support grouped-gemm moe (e.g., qwen3.5) and make the hf_name prefix more generic Co-Authored-By: Claude Opus 4.8 <[email protected]> Signed-off-by: Youngeun Kwon <[email protected]>
Signed-off-by: Youngeun Kwon <[email protected]>
Co-Authored-By: Claude Opus 4.8 <[email protected]> Signed-off-by: Youngeun Kwon <[email protected]>
375aaae to
e78f181
Compare
Co-Authored-By: Terry Kong <[email protected]> Signed-off-by: Youngeun Kwon <[email protected]>
e78f181 to
aa341e6
Compare
|
/okay to test aa341e6 |
|
Hi @terrykong, thanks for your detailed review and comments. I have rebased the branch and addressed your comments in the new commit. |
…unction Signed-off-by: Youngeun Kwon <[email protected]>
|
/okay to test 0c59579 |
…perts layout The nccl_reshard refit path landed on main (#2971) while this branch was open, so the rebase is the first time it meets vLLM 0.25. _build_hf_to_gen_backend_mapping derives the generation-backend parameter name from the HF name, producing model.layers.N.mlp.experts.w13_weight but 0.25 hangs the fused-MoE weights off a nested submodule -- RoutedExperts is an nn.Module assigned as MoERunner.routed_experts (vllm 0.25.1 fused_moe/runner/moe_runner.py:266), and RoutedExperts owns w13_weight / w2_weight -- so named_parameters() actually reports model.layers.N.mlp.experts.routed_experts.w13_weight The existing _to_vllm_name fallback indexes real names by their layer-relative suffix, which differs by exactly that segment and so does not match either. An unresolved grouped expert is a hard ValueError, so every MoE model would fail to refit over nccl_reshard on 0.25. Index the real names a second time with the '.routed_experts.' segment dropped and consult that only after both existing lookups miss. On a 0.20-style model the extra index is identical to the existing one, so this is a no-op there. The mapping tests drive a synthetic named_parameters() and all used 0.20-style names, so none of them covered this; add one built from the 0.25 layout, which raises without the fix. Signed-off-by: Terry Kong <[email protected]>
…perts layout The nccl_reshard refit path landed on main (#2971) while this branch was open, so the rebase is the first time it meets vLLM 0.25. _build_hf_to_gen_backend_mapping derives the generation-backend parameter name from the HF name, producing model.layers.N.mlp.experts.w13_weight but 0.25 hangs the fused-MoE weights off a nested submodule -- RoutedExperts is an nn.Module assigned as MoERunner.routed_experts (vllm 0.25.1 fused_moe/runner/moe_runner.py:266), and RoutedExperts owns w13_weight / w2_weight -- so named_parameters() actually reports model.layers.N.mlp.experts.routed_experts.w13_weight The existing _to_vllm_name fallback indexes real names by their layer-relative suffix, which differs by exactly that segment and so does not match either. An unresolved grouped expert is a hard ValueError, so every MoE model would fail to refit over nccl_reshard on 0.25. Index the real names a second time with the '.routed_experts.' segment dropped and consult that only after both existing lookups miss. On a 0.20-style model the extra index is identical to the existing one, so this is a no-op there. The mapping tests drive a synthetic named_parameters() and all used 0.20-style names, so none of them covered this; add one built from the 0.25 layout, which raises without the fix. Signed-off-by: Terry Kong <[email protected]>
What does this PR do ?
The same feature as #2808, but reducing the target scope to the dominant parameters only for the sake of the code, better sustainability, and expandability.
Slides (NV-internal)
https://docs.google.com/presentation/d/1O_B_yhHNl1ftj-lvyOsFmc3JMrYWRwBwbxOZ2qcNKw0/edit?slide=id.p#slide=id.p
Figjam diagram: https://www.figma.com/board/gCWl55AMYqs8QDz3zUnWzo/Nemo-RL?node-id=239-660&t=3FrnXGperomkER8o-1
DGX-H100 - xferdtensor_python_impl (fallback path)
DGX-GB200 (python_impl numbers)
Issues
List issues that this PR closes (syntax):
Usage
# Add a code snippet demonstrating how to use thisBefore your PR is "Ready for review"
Pre checks:
Additional Information