Repository navigation
refactor(refit): restore canonical HF pre/post hooks - #4525
Conversation
Signed-off-by: Youngeun Kwon <[email protected]>
Signed-off-by: Youngeun Kwon <[email protected]>
Signed-off-by: Youngeun Kwon <[email protected]>
Signed-off-by: Youngeun Kwon <[email protected]>
Signed-off-by: Youngeun Kwon <[email protected]>
youngeunkwon0405
left a comment
There was a problem hiding this comment.
Self-review (agent-assisted). The core contract checks out: source hooks dequantize before HF slicing and read the live parameter each refit; scale exclusion is consistent; the vLLM destination hooks match vLLM 0.29's checkpoint-loader layout bit-for-bit in CPU emulation (including refined/rectangular grids and repeated refits); TE quantized destinations commit whole and in place; and the refit_payload_mode removal is complete, also in a trial merge with main (no semantic conflict with #3724 or the Megatron-Bridge bump).
Inline: two CI blockers in the new test file (isort hook; [mxfp8] on H100), a validation relaxation that newly admits a config where refits are lost (with a pinning test), and a perf-evidence ask.
All suggested code was applied together to this head: ruff 0.9.9 clean; weight-sync + refit-signature tests 389 passed (388 at this head plus the new pinning case). CPU only; GPU and vLLM runtime behavior not verified here.
Generated by Claude Code
Signed-off-by: Youngeun Kwon <[email protected]>
Signed-off-by: Youngeun Kwon <[email protected]>
|
/ok to test adde433 |
Signed-off-by: Youngeun Kwon <[email protected]>
Signed-off-by: Youngeun Kwon <[email protected]>
|
/ok to test 2b3b5c8 |
Signed-off-by: Youngeun Kwon <[email protected]>
|
/ok to test b566d6b |
Signed-off-by: Youngeun Kwon <[email protected]>
|
/ok to test 503e360 |
Signed-off-by: Youngeun Kwon <[email protected]>
|
/ok to test 7aa6183 |
Signed-off-by: Youngeun Kwon <[email protected]>
|
/ok to test 5344232 |
Signed-off-by: Youngeun Kwon <[email protected]>
|
/ok to test 9853d1c |
Signed-off-by: Youngeun Kwon <[email protected]>
|
/ok to test db834af |
youngeunkwon0405
left a comment
There was a problem hiding this comment.
Please address those comments. Those are all doc/comment modification requests or variable renaming request, no logic changes.
Also, please check the test files. I believe that, due to this refactoring, many of the existing tests related to nccl-reshard refit path might become outdated or useless. It might be better to purge the stale test cases.
Signed-off-by: Youngeun Kwon <[email protected]>
Signed-off-by: Youngeun Kwon <[email protected]>
|
/ok to test 9013d0c |
youngeunkwon0405
left a comment
There was a problem hiding this comment.
Round-2 self-review (agent-assisted; 6 reviewers + 2 devil's advocates, all findings re-verified from source). Thanks for addressing the round-1 items: 25 of the 28 resolved threads are implemented at this head, the removal of refit_payload_mode and the source cache is complete, the TE 2.18 scale packing and the MCore/Bridge/vLLM 0.29 API usage check out with permalinks, and the stale-test purge is sound (13 deletions, all justified; expert ordering is still pinned by test_build_hf_to_local_param_map_train_side).
What this review asks for (each inline, with a verified suggestion):
- Transpose-cache escape hatch is inert (
nccl_reshard_utils.py): the guard and the doc footnote point at a key nothing applies to the inference provider. Suggested: read it frommcore_generation_config.model_overrides, plus the test fixture and footnote. - FP32 training → vLLM MXFP8 passes setup and fails inside the first refit on SM100; main rejected it at setup and the table footnote calls it unsupported. Suggested: setup-time rejection, flip the one grid cell in the test, reword the footnote.
- vLLM direct params lost in-place receive (
_default_param_specalways stages); the Megatron side and the design doc still describe in-place. Suggested: dispatch mirroringdirect_spec, with the two test adjustments (or a doc reword if always-staging is intended). - Dead
_scale_invskip + stale comment in_iter_local_hf_param_shards. - One duplicate
check_nccl_reshard_refit_supporttest.
Verification on a clean copy with all five applied: ruff 0.9.9 check / check --select I / format --check clean; test_nccl_reshard_utils.py 159 passed, test_nccl_reshard_backend.py 54 passed (vLLM import stub), test_megatron_worker.py 106 passed, test_group_experts.py 19 passed, test_megatron_bf16_refit.py 25 passed (CPU, torch 2.10; CUDA/TE-only cases skipped or failing identically at head). The changed pinning tests fail at this head exactly where expected (3 guard cases, 4 in-place cases) and pass with the fixes.
Deferred, not blocking the draft: the refit-timing numbers from thread 5 (scoped to "before Ready for review"), and refreshing the description's validation pins (db834af4e / 6f0bbc7ef; the exact-head /ok to test is comment 6178393103) before un-drafting. Low-severity notes not posted inline: the blockwise 128-alignment check in _dequantize_refit_source_group is stricter than TE/main and raises at first refit rather than at prepare (a documented scope limit), and vLLM 0.29 refines MoE FP8 block grids to 64×64 when intermediate/TP % 128 != 0 (the moe_block_shape read was reverted after thread 16), so a doc sentence stating the 128-grid requirement for vLLM blockwise destinations would help.
Generated by Claude Code
Signed-off-by: Youngeun Kwon <[email protected]>
|
/ok to test 74295f6 |
Signed-off-by: Youngeun Kwon <[email protected]>
|
/okay to test 43a166f |
terrykong
left a comment
There was a problem hiding this comment.
Thanks for this refactor. The source side is much simpler now: every source spec has its own pre hook, the per-layer source cache and the refit_payload_mode plumbing are gone (that plumbing had already broken the collective recovery path once), and LocalParamSpec.materialize() puts the dtype check in one place for all three transfer loops. Keeping MXFP8 and blockwise FP8 in separate vLLM hooks is the right call, and the exact-match test of the grouped decode against TE's own dequantize is a good guard. Both self-review rounds are fully addressed at 74295f6. The later push 43a166f (one quantize cast per expert group) changes none of the findings below; permalinks stay pinned to 74295f6.
Inline: one setup-time regression for vLLM blockwise-FP8 MoE layers (the comment on vllm_backend.py, with a short fix), a decode that now rejects unaligned blockwise experts, an error message that leads users to drop their training model_overrides, and two small cleanups. Nothing was run on a GPU for this review; the GPU-side claims are traced in the pinned vLLM, TE and Megatron source.
Before merge (not inline):
- L1 green at the exact head. The final commit changes the vLLM receive path (same-dtype params now receive in place) after the full-model runs at 9013d0c. grpo_nccl_reshard_refit.sh covers it.
- An FP8 refit timing after the change. The FP8 path now sends BF16 (2 bytes per element) and re-quantizes, instead of sending physical FP8 (1 byte). One FP8-source run against base would do.
- A matched baseline (same config and seed on base, or
refit_transport=null) for the Nemotron Nano-v3 MXFP8 maxima (175.4 and 4,412.8). L1 only runs dense Qwen3-0.6B in BF16, so it says nothing about these cells.
Visual explainer: https://terrykong.github.io/gh-pages-poc/terryk/pr-4525-fp8-wire-path.html
Visual explainer: https://terrykong.github.io/gh-pages-poc/terryk/pr-4525-moe-scale-grid.html
Generated by Claude Code
Co-authored-by: Terry Kong <[email protected]> Signed-off-by: Youngeun Kwon <[email protected]>
Signed-off-by: Youngeun Kwon <[email protected]>
|
/ok to test 6f688bd |
Signed-off-by: Youngeun Kwon <[email protected]>
|
/ok to test c82c334 |
|
Following up on the three before-merge checks in this review:
We regard these as occasional spikes in quantized async GRPO, with no established link to this refactoring PR. Large spikes also occur with |
…failures-and-redispatch main gained #4481, #4771, #4458, #4770, #4640, #4765, #4525 and #4670 since the previous merge. #4640 (rubric-mean and fixed-baseline GenRM scoring) rewrote the metric assertions in tests/unit/experience/test_rollouts.py that this branch also edits for nemo_gym_infra_redispatches: the resolution keeps main's per-key assertions and adds the redispatch count beside them, and the expected rollout_metrics dict carries both sides' new keys. test_rollouts.py, test_rollout_manager.py and test_nemo_gym.py pass locally on the merged tree. Co-Authored-By: Claude Fable 5.1 <[email protected]> Signed-off-by: alexandery <[email protected]>
…andery/gym-health-check-during-collection Carries the stack root's merge of main (8338530: #4481, #4771, #4458, #4770, #4640, #4765, #4525 and #4670) forward so this head stays current with main. No conflicts; test_rollouts.py, test_rollout_manager.py and test_nemo_gym.py pass locally on the merged tree. Co-Authored-By: Claude Fable 5.1 <[email protected]> Signed-off-by: alexandery <[email protected]>
…xandery/gym-rollout-metrics-hook Carries the stack's merge of main (8338530: #4481, #4771, #4458, #4770, #4640, #4765, #4525 and #4670) forward. #4640 (rubric-mean and fixed-baseline GenRM scoring) reports the shared GenRM fields once per group through _nemo_gym_group_metrics and skips them in both per-agent loops, which this branch had replaced with per_agent_result_metrics: the resolution keeps the helper on both paths and adds the same _SHARED_GENRM_METRICS skip inside it, so the manager no longer imports the constant. test_rollouts.py, test_rollout_manager.py and test_nemo_gym.py pass locally on the merged tree. Co-Authored-By: Claude Fable 5.1 <[email protected]> Signed-off-by: alexandery <[email protected]>
Restore the
pre/base/postcontract fornccl_reshard: source hooks prepare current weights in canonical HF layout, and destination hooks assemble and commit received weights, including quantization and scale updates. Transfer loops remain independent of local parameter storage.Quantized sources decode to BF16; unquantized BF16/FP16/FP32 sources preserve their dtype.
LocalParamSpec.wire_dtypeandmaterialize()keep buffers, metadata, receiver allocation, and byte accounting consistent. Remove_refit_layer_source_cacheandrefit_payload_mode; each preparation reads live parameters. Misc export excludes only source quantization scales associated with bulk weights, preserving destination-generated scales and unrelated entries such as KV-cache scales.Grouped expert preparation packs block-aligned encoded weights and logical scales, decodes the group once, then selects the HF projection. Unaligned blockwise FP8 experts retain per-expert decoding of partial edge blocks. Gate and up prepare independently without a shared cache. vLLM keeps MXFP8 and square-block FP8 quantization in separate hooks, honors refined runtime MoE scale grids, and quantizes aligned expert groups in one call. Matching unmerged unquantized destinations receive in place; cast, fused, quantized, and TRTLLM layout conversions retain staging. Other refit transports retain their existing transport paths.
Setup rejects unquantized FP32 → vLLM MXFP8 because the quantizer accepts BF16/FP16 input. TE FP8 compute over unquantized Megatron generation parameters requires the effective
model_overrides.disable_parameter_transpose_cacheoption, preventing reuse of stale cached compute weights.Validation
Current head
c82c334b7a3f893c779235d7f20b3f91c5b1d6a0includes Terry's refined-grid and config-message suggestions, the blockwise partial-block fallback, a shared FP8-storage predicate, and updated documentation. It merges main atd93b4eac7to satisfy the CI freshness gate; the refit methods are unchanged by this merge.c82c334b7a3f893c779235d7f20b3f91c5b1d6a0: 355 passed, 0 failed, 0 skipped; the job completed with exit0:0. All 978 source hashes matched this commit. Coverage includes source/destination hooks, grouped experts, metadata, refined 32/64 MoE scale grids, repeated refits, and real TE partial-block FP8 decoding. The TE cache diagnostic also passed. The.1006test environments used the exact upstream-pinnednemo-lensrevision4d045c03186b90afdc815db46b671f6a21bc7e98installed with--no-deps; the audit verified no other product-package changes. This resolved an initial pre-collection import failure caused by the image's older Lens version. The review-fix commit6f688bdcealso passed all 355 tests before the main merge.git diff --check, and focused Pyrefly 0.24.2 checking passed.43a166f9b1fecb29f11453e7ec48933da75461e1passed L1 CI, attempt 3.Full-model GRPO validation is pinned to the preceding head
9013d0c152cdb86a2afbaa908d259b195a3692d0, not the current head. Runs used async non-colocated Megatron → vLLM,nccl_reshard, online W&B, and a 30-minute job limit. That head also passed 340 GPU unit tests with no failures or skips.Values are
token_mult_prob_error. Actualflashinfer_trtllmMoE backend selection was verified on all eight generation workers in each case. Completed runs have the expected refits on all workers: 10 training steps for Qwen3/Nano and 6 for Qwen3.5. The preceding Qwen3.5 MXFP8 run completed six steps with finite errors 1.032–1.037 and HF fused-expert coverage. Qwen3 BF16, Qwen3 MXFP8, Nano MXFP8, completed Qwen3.5 MXFP8.Earlier matched Qwen3 base/PR controls showed comparable BF16 logprob agreement near 1.02, and MXFP8's initial NaN also occurred on base/null. The latest expanded matrix has no matching baseline for every anomaly; completion or finite metrics alone does not establish numerical equivalence. BF16/MXFP8 are the acceptance focus. The prior blockwise full-model failures remain unvalidated end to end; partial source blocks and refined destination scale grids are addressed by this follow-up and focused regression tests.
Historical matched Nano-v3 Megatron-generation
nccl_reshardruns measured a steps 2–10 mediantiming/train/prepare_for_generation/transfer_and_update_weightsof 0.7815 s on based7f5215f3and 0.7480 s on refactord0433fdf6. This measures transfer and destination update, not raw NCCL latency, and is not a current-head benchmark. The design document labels its older physical-FP8 performance table as predating this refactor.Commit
43a166f9b1fecb29f11453e7ec48933da75461e1addresses the per-expert vLLM blockwise quantization overhead by flattening aligned experts for one quantizer call per group, then restoring the weight and scale shapes. Regression tests compare this grouped result exactly with independent expert quantization. The historical timing measurements above predate this optimization.Matched Nano-v3 TRTLLM
nullcontrols completed at the same historical9013d0c152cdb86a2afbaa908d259b195a3692d0revision, with identical image, model pins, seed42, ten steps, and async topology. Only transport and logging destinations differed. Both controls completed with ten metric steps, eleven successful refits on each of eight training and eight generation workers, and no NaN/Inf error metrics. Actual source/destination storage andFLASHINFER_TRTLLMselection were verified.nccl_reshardmedian / maximumnullmedian / maximumThe MXFP8 → MXFP8 spike also occurs with
null, so that symptom is not exclusive tonccl_reshard. The BF16 → MXFP8 control did not reproduce its historicalnccl_reshardspike; that accuracy question remains inconclusive. One matched stochastic run cannot establish absence of rare spikes or prove a regression. These controls address the historical comparison and do not constitute full-model validation of the merged head.