Skip to content

fix(fsdp): disable parameter prefetching during evaluation - #9372

Merged
wujingyue merged 11 commits into
NVIDIA:mainfrom
WEIXILIN0307:fix/mfsdp-v2-evaluation-cursor
Nov 25, 2026
Merged

wujingyue merged 11 commits into
NVIDIA:mainfrom
WEIXILIN0307:fix/mfsdp-v2-evaluation-cursor

Conversation

@WEIXILIN0307

@WEIXILIN0307 WEIXILIN0307 commented Nov 12, 2026 •

Copy link
Copy Markdown
Contributor

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_steps covers both registration and recorded prefetch orders, evaluation with and without torch.no_grad(), and resumed backward.
  • On eight EOS H100 GPUs, the pre-follow-up merge candidate 98a3e2eb6b9da011cdb99b76fbd91b8dbecbf931 passed 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.

@copy-pr-bot

copy-pr-bot Bot commented Nov 12, 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.

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>
@wujingyue
wujingyue force-pushed the fix/mfsdp-v2-evaluation-cursor branch from 4110362 to 7feafb2 Compare November 22, 2026 17:30
@wujingyue wujingyue changed the title [MFSDP] Preserve the training cursor during evaluation fix(fsdp): disable parameter prefetching during evaluation Nov 22, 2026

@wujingyue wujingyue 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 the PR! The intention makes sense.

I reimplemented it and will merge it soon.

@wujingyue
wujingyue marked this pull request as ready for review November 22, 2026 17:33
@wujingyue
wujingyue requested a review from a team as a code owner November 22, 2026 17:33
@svcnvidia-nemo-ci
svcnvidia-nemo-ci requested a review from a team November 22, 2026 17:33
@nemo-automation-bot nemo-automation-bot Bot added the Approved All necessary approvals have been made label Nov 22, 2026

Copy link
Copy Markdown
Contributor

/ok to test 7feafb2

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

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:

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.

[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.

@wujingyue
wujingyue added this pull request to the merge queue Nov 23, 2026
@nemo-automation-bot

Copy link
Copy Markdown

🔄 Merge queue validation started!

You can track the progress here: https://github.com/NVIDIA/Megatron-LM/actions/runs/45247572367

@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Nov 23, 2026
@wujingyue
wujingyue added this pull request to the merge queue Nov 23, 2026
@nemo-automation-bot

Copy link
Copy Markdown

🔄 Merge queue validation started!

You can track the progress here: https://github.com/NVIDIA/Megatron-LM/actions/runs/45309060676

@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Nov 24, 2026
@wujingyue wujingyue self-assigned this Nov 24, 2026
@wujingyue
wujingyue force-pushed the fix/mfsdp-v2-evaluation-cursor branch from c6b78bb to 7feafb2 Compare November 24, 2026 20:17
@wujingyue
wujingyue added this pull request to the merge queue Nov 24, 2026
@wujingyue

Copy link
Copy Markdown
Contributor

@WEIXILIN0307 FYI, I removed your last commit because it's a YAGNI. I'm trying to merge this again.

@nemo-automation-bot

Copy link
Copy Markdown

🔄 Merge queue validation started!

You can track the progress here: https://github.com/NVIDIA/Megatron-LM/actions/runs/45507501961

Merged via the queue into NVIDIA:main with commit d130970 Nov 25, 2026
91 checks passed
SophusDavid added a commit to flytiger-eco/Megatron-LM-for-sail that referenced this pull request Nov 27, 2026
* 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>

This branch was previously deployed

2 inactive deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Approved All necessary approvals have been made community-request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants