Repository navigation
fix(fsdp): disable parameter prefetching during evaluation - #9372
Conversation
Signed-off-by: Jingyue Wu <jingyuew@nvidia.com>
Signed-off-by: Jingyue Wu <jingyuew@nvidia.com>
Signed-off-by: Jingyue Wu <jingyuew@nvidia.com>
Signed-off-by: Jingyue Wu <jingyuew@nvidia.com>
Signed-off-by: Jingyue Wu <jingyuew@nvidia.com>
Signed-off-by: Jingyue Wu <jingyuew@nvidia.com>
Signed-off-by: Jingyue Wu <jingyuew@nvidia.com>
Signed-off-by: Jingyue Wu <jingyuew@nvidia.com>
Signed-off-by: Jingyue Wu <jingyuew@nvidia.com>
Signed-off-by: Jingyue Wu <jingyuew@nvidia.com>
Signed-off-by: Jingyue Wu <jingyuew@nvidia.com>
4110362 to
7feafb2
Compare
wujingyue
left a comment
There was a problem hiding this comment.
Thanks for the PR! The intention makes sense.
I reimplemented it and will merge it soon.
|
/ok to test 7feafb2 |
svcnvidia-nemo-ci
left a comment
There was a problem hiding this comment.
I found one correctness regression: an eval-mode child inside a training model stops consuming its event in the shared execution trace, so the next module raises an execution-order error.
The focused CPU probes confirmed that repeated forward-only evaluation now preserves the cursor, but mixed train/eval modules succeed on base and fail on this head for both prefetch orders. The mixed-mode probe used real PyTorch autograd and source-loaded hooks, with CUDA streams, collectives and parameter storage mocked. Command: python /workspace/review-probes/mixed_mode_autograd_probe.py. Image: 766267172432.dkr.ecr.us-east-1.amazonaws.com/megatron-lm:a924ee5d51113f16ade6aa74e8716cf344c24465-aws-h100.
Exact-head linting and process-group-usage-check passed. GPU CI is still waiting at cicd-wait-in-queue; I did not rerun repository suites or verify GPU execution.
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.
| # order from the training trace, which includes backward events. | ||
| # Disabling prefetch may slow evaluation by losing all-gather/compute overlap. | ||
| # TODO: Use a separate forward-only execution order to restore that overlap. | ||
| if not cast(nn.Module, self).training: |
There was a problem hiding this comment.
[Correctness] Keep eval-mode children in a training pass's shared trace
A child can have .training=False while its parent is training, for example when keeping a pretrained component in evaluation mode during fine-tuning. This return skips that child's forward event, but the context has one shared cursor. After the root consumes its event, the eval-mode child leaves the cursor unchanged; the next training child then fails the execution-order check, which still expects the skipped child.
I reproduced this with two linear children and real CPU autograd, mocking communication/storage: after one normal training step, calling only model[0].eval() makes the next forward fail at position 1 on this head. Base succeeds, and the regression affects both REGISTRATION and RECORDED.
Make bypassing the training trace coherent for the enclosing pass rather than deciding independently from each child's flag. Preserve event consumption for eval-mode children within a training pass while keeping whole-model forward-only evaluation from consuming the trace. Add a focused regression for both prefetch orders: warm up training, set one child to eval without changing the root, then verify another forward/backward completes and the cursor returns to its starting position.
|
🔄 Merge queue validation started! You can track the progress here: https://github.com/NVIDIA/Megatron-LM/actions/runs/45247572367 |
|
🔄 Merge queue validation started! You can track the progress here: https://github.com/NVIDIA/Megatron-LM/actions/runs/45309060676 |
c6b78bb to
7feafb2
Compare
|
@WEIXILIN0307 FYI, I removed your last commit because it's a YAGNI. I'm trying to merge this again. |
|
🔄 Merge queue validation started! You can track the progress here: https://github.com/NVIDIA/Megatron-LM/actions/runs/45507501961 |
* Cache FsdpMuon's rank ranges and pass them to gather/scatter (NVIDIA#9702) Signed-off-by: Tong Liu <tongliu@nvidia.com> Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com> * perf(attention): avoid DSv4 grouped output projection layout copies (NVIDIA#9058) Signed-off-by: Nitin Vegesna <nvegesna@nvidia.com> * Write MTP draft-step attention metadata with one Triton kernel (NVIDIA#9688) Signed-off-by: Keshav Santhanam <ksanthanam@nvidia.com> Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com> * Configure offline logits distillation from the run config (NVIDIA#9635) Signed-off-by: Asha Anoosheh <aanoosheh@nvidia.com> Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com> * fix(fsdp): disable parameter prefetching during evaluation (NVIDIA#9372) Signed-off-by: Jingyue Wu <jingyuew@nvidia.com> Co-authored-by: Jingyue Wu <jingyuew@nvidia.com> * ci(release): publish python packages with trusted publishers (NVIDIA#9748) Signed-off-by: oliver könig <okoenig@nvidia.com> * build: declare optional TileLang and NVSHMEM dependencies (NVIDIA#8462) Signed-off-by: Ajay Balasa <abalasa@nvidia.com> * Allow sequence parallelism in dynamic DSA-over-GQA inference (NVIDIA#9691) Signed-off-by: Keshav Santhanam <ksanthanam@nvidia.com> Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com> * ckpt adapter-only save/load (NVIDIA#9426) Signed-off-by: dimapihtar <dpykhtar@nvidia.com> Signed-off-by: Dmytro Pykhtar <dpykhtar@nvidia.com> * Hook DDP into backward_dw when expert wgrad overlap delays wgrad (NVIDIA#8613) Signed-off-by: guihong-nv <guihongl@nvidia.com> Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com> * [MFSDP] Install MFSDP v2 sharded .grad views only when they change (NVIDIA#9500) Signed-off-by: tongliu <tongliu@nvidia.com> Signed-off-by: Jingyue Wu <jingyuew@nvidia.com> Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com> Co-authored-by: Jingyue Wu <jingyuew@nvidia.com> * chore: rotate oncall schedule * ci: remove label-driven cherry-pick workflow (NVIDIA#9780) Signed-off-by: oliver könig <okoenig@nvidia.com> Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com> * test(gtp): fix partial-CG test training on TE's uninitialized dummy wgrad (NVIDIA#9737) Signed-off-by: Jiangfei Duan <jiangfeid@nvidia.com> Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com> * Port Bridge Llama, GPT-OSS and DeepSeek-V3 conversion into MLM (NVIDIA#9608) Signed-off-by: Kamran Jafari <kjafarisadeg@nvidia.com> * Overlap M-FSDP DP-Outer gradient reduction with backward again, reducing repeated reductions separately (NVIDIA#9652) Signed-off-by: Ritesh Patel <ripatel@nvidia.com> * perf(cuda_graphs): capture each Hybrid block as one TE graph, MTP layers included (NVIDIA#9489) Signed-off-by: Lifu Zhang <lifuz@nvidia.com> Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com> * Keep MTP draft-KV prefix reuse from cascading across turns (NVIDIA#8936) Signed-off-by: Keshav Santhanam <ksanthanam@nvidia.com> Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com> * cuda_graphs: keep garbage collection out of graph capture and graph-less delete_cuda_graphs (NVIDIA#9739) Signed-off-by: Lawrence McAfee <lmcafee@nvidia.com> Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com> --------- Signed-off-by: Tong Liu <tongliu@nvidia.com> Signed-off-by: Nitin Vegesna <nvegesna@nvidia.com> Signed-off-by: Keshav Santhanam <ksanthanam@nvidia.com> Signed-off-by: Asha Anoosheh <aanoosheh@nvidia.com> Signed-off-by: Jingyue Wu <jingyuew@nvidia.com> Signed-off-by: oliver könig <okoenig@nvidia.com> Signed-off-by: Ajay Balasa <abalasa@nvidia.com> Signed-off-by: dimapihtar <dpykhtar@nvidia.com> Signed-off-by: Dmytro Pykhtar <dpykhtar@nvidia.com> Signed-off-by: guihong-nv <guihongl@nvidia.com> Signed-off-by: tongliu <tongliu@nvidia.com> Signed-off-by: Jiangfei Duan <jiangfeid@nvidia.com> Signed-off-by: Kamran Jafari <kjafarisadeg@nvidia.com> Signed-off-by: Ritesh Patel <ripatel@nvidia.com> Signed-off-by: Lifu Zhang <lifuz@nvidia.com> Signed-off-by: Lawrence McAfee <lmcafee@nvidia.com> Signed-off-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> Co-authored-by: Tong Liu <tongliu@nvidia.com> Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com> Co-authored-by: nvegesna-netizen <nvegesna@nvidia.com> Co-authored-by: Keshav Santhanam <ksanthanam@nvidia.com> Co-authored-by: Asha Anoosheh <aanoosheh@nvidia.com> Co-authored-by: WEIXILIN <weixilin307@gmail.com> Co-authored-by: Jingyue Wu <jingyuew@nvidia.com> Co-authored-by: oliver könig <okoenig@nvidia.com> Co-authored-by: Ajay <abalasa@nvidia.com> Co-authored-by: Dmytro Pykhtar <37850217+dimapihtar@users.noreply.github.com> Co-authored-by: Guihong Li <guihongl@nvidia.com> Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com> Co-authored-by: Jiangfei Duan <30710061+JF-D@users.noreply.github.com> Co-authored-by: Kamran Jafari <kjafarisadeg@nvidia.com> Co-authored-by: Ritesh Patel <ripatel@nvidia.com> Co-authored-by: Lifu Zhang <lifuz@nvidia.com> Co-authored-by: Lawrence McAfee <85179052+lmcafee-nvidia@users.noreply.github.com> Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Summary
Forward-only evaluation cannot consume FSDP's training execution order, which includes backward events. Prefetching evaluation weights from that order can advance the training cursor incorrectly and break evaluation or the next training step.
Gather parameters on demand while a module is in evaluation mode, leaving the training cursor untouched. Training keeps its existing execution-order recording and prefetch behavior. Evaluation temporarily loses all-gather/compute overlap until a separate forward-only prefetch order is supported.
Validation
test_repeated_evaluation_between_training_stepscovers both registration and recorded prefetch orders, evaluation with and withouttorch.no_grad(), and resumed backward.98a3e2eb6b9da011cdb99b76fbd91b8dbecbf931passed the 330-case sequence containing this regression on every rank. Rank 0: 319 passed, 11 skipped. Runtime: PyTorch 26.11 and NCCL 2.32.6.Code provenance
No external code copied.