Skip to content

Record MFSDP execution order for prefetch - #8478

Merged
wujingyue merged 1 commit into
NVIDIA:mainfrom
wujingyue:feat/mfsdp-record-prefetch-order
Nov 1, 2026
Merged

wujingyue merged 1 commit into
NVIDIA:mainfrom
wujingyue:feat/mfsdp-record-prefetch-order

Conversation

@wujingyue

@wujingyue wujingyue commented Oct 25, 2026 •

Copy link
Copy Markdown
Contributor
  • I, the PR author, have personally reviewed every line of this PR.

What does this PR do?

I'm aware of #8485 and will rebase this PR on top of it after it lands.

When MFSDP modules execute in a different order from their registration, construction-order prefetch can gather the wrong next layer. Choose fully_shard_context(FsdpContext(prefetch_order=PrefetchOrder.RECORDED)) to record the first ordinary eager forward/backward pass and use those orders for subsequent prefetching.

with fully_shard_context(FsdpContext(prefetch_order=PrefetchOrder.RECORDED)) as context:
    fully_shard(model, mesh=mesh, placements=placements)

loss = model(inputs).square().mean()
loss.backward()  # context.post_backward() ends recording.

Record forward entry in pre_forward() and backward entry in pre_backward(). Only modules participating in backward enter its trace. Checkpoint recomputation does not add another forward occurrence. Repeated calls to a shared layer are skipped while it is already in BACKWARD and its weights remain available. Recording and replay use the same existing guard, so backward calls A → A → B record A → B in this case.

PrefetchOrder.REGISTRATION remains the default; PrefetchOrder.RECORDED selects the observed order. This reuses the existing ExecutionOrder objects and prefetch budgets; parameters are gathered on demand while recording. Discard the context if recording fails. Subsequent passes must repeat the recorded call order consistently across data-parallel peers.

The final autograd callback ends recording in context.post_backward(), alongside its existing weight cleanup and gradient synchronization.

Validation

Rebased onto origin/main at 79ee5c98a, using #8479's explicit
FsdpContext construction API.

On two RTX A6000 GPUs with NGC 26.08, the context, execution-order, and fully-shard
suites passed 65 tests per rank, with 13 skips requiring four GPUs.
The context regression registers two layers in the opposite order from execution,
runs a forward/backward pass, and checks both recorded orders.

Black, isort, Pylint (10/10), Ruff, and git diff --check passed.
Canonical CI uses NGC 26.09 and is pending on the rebased head.

Issue tracking

Related to #7764 and #7998. Original runtime-prefetch work by @shjwudp in #7998; this implements the reduced scope independently.

Code provenance

No code copied from other repositories.

@copy-pr-bot

copy-pr-bot Bot commented Oct 25, 2026

Copy link
Copy Markdown

Auto-sync is disabled for draft pull requests in this repository. Workflows must be run manually.

Contributors can view more details about this message here.

@wujingyue
wujingyue force-pushed the feat/mfsdp-record-prefetch-order branch from 6c46595 to 289ed9a Compare October 25, 2026 15:36
@wujingyue wujingyue changed the title Record runtime prefetch order for ordinary MFSDP training Record MFSDP execution order for prefetch Oct 25, 2026
@wujingyue
wujingyue force-pushed the feat/mfsdp-record-prefetch-order branch 2 times, most recently from fa3919e to c0edc7c Compare October 25, 2026 17:02
@wujingyue
wujingyue changed the base branch from main to pull-request/8479 October 26, 2026 00:05
@wujingyue
wujingyue marked this pull request as ready for review October 28, 2026 00:38
@wujingyue
wujingyue requested a review from a team as a code owner October 28, 2026 00:38
@wujingyue
wujingyue force-pushed the feat/mfsdp-record-prefetch-order branch from 47a2fff to 27b2ca9 Compare October 28, 2026 00:44
@wujingyue
wujingyue requested review from a team as code owners October 28, 2026 00:44
@copy-pr-bot

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

@XiaodaNV

Copy link
Copy Markdown
Contributor

Following up on the discussion in #8432: this doesn't record recomputation yet, so re-entered recomputation still gathers MXFP8 rowwise planes on demand.

I will take that as a follow-up after this lands: record (module, FORWARD) in backward order when recomputing, prefetch each successor for its recorded phase, and advance/prefetch from the recomputation's pre_forward. Does that sound right to you?

@wujingyue

Copy link
Copy Markdown
Contributor Author

I will take that as a follow-up after this lands: record (module, FORWARD) in backward order when recomputing, prefetch each successor for its recorded phase, and advance/prefetch from the recomputation's pre_forward. Does that sound right to you?

You'll probably also have to wait for #8485, which I plan to merge next.

@XiaodaNV

Copy link
Copy Markdown
Contributor

I will take that as a follow-up after this lands: record (module, FORWARD) in backward order when recomputing, prefetch each successor for its recorded phase, and advance/prefetch from the recomputation's pre_forward. Does that sound right to you?

You'll probably also have to wait for #8485, which I plan to merge next.

Sounds good, I'll build it on top of #8485.

Signed-off-by: Jingyue Wu <jingyuew@nvidia.com>
@wujingyue
wujingyue force-pushed the feat/mfsdp-record-prefetch-order branch from 2d4d113 to 6ec9fc7 Compare October 31, 2026 03:50
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to a conflict with the base branch Oct 31, 2026
@wujingyue
wujingyue enabled auto-merge October 31, 2026 14:59
@wujingyue
wujingyue added this pull request to the merge queue Oct 31, 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/41241652389

@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Oct 31, 2026
@wujingyue
wujingyue added this pull request to the merge queue Nov 1, 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/41257787183

Merged via the queue into NVIDIA:main with commit 2d7ea24 Nov 1, 2026
119 of 120 checks passed
@wujingyue
wujingyue deleted the feat/mfsdp-record-prefetch-order branch November 1, 2026 02:17

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 complexity: low

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants