Skip to content

Fix assertion logic in combined_1f1b_schedule_for_interleaved_pipelining - #4276

Merged
asolergi-nv merged 4 commits into
NVIDIA:mainfrom
joapolarbear:fix/interleaved-pp-overlap-moe-assert
Apr 28, 2026
Merged

Fix assertion logic in combined_1f1b_schedule_for_interleaved_pipelining#4276
asolergi-nv merged 4 commits into
NVIDIA:mainfrom
joapolarbear:fix/interleaved-pp-overlap-moe-assert

Conversation

@joapolarbear

Copy link
Copy Markdown
Contributor

Description

Fix incorrect assertion in combined_1f1b_schedule_for_interleaved_pipelining function at line 237.

Issue

The assertion at line 237-238 checks:

if input_tensor is not None:
    assert input_tensor_grad is not None

However, this is logically incorrect. The input_tensor_grad is the backward pass output that corresponds to b_input_tensor (backward input tensor), not input_tensor (forward input tensor).

Root Cause Analysis

  • input_tensor is set when f_model is not None (forward model exists) at lines 186-192
  • b_input_tensor is set when b_model is not None (backward model exists) at lines 198-202
  • input_tensor_grad is computed based on b_input_tensor at lines 436-447
  • These two paths are independent, so the assertion should validate the backward path

Fix

Change line 237 from:

if input_tensor is not None:
    assert input_tensor_grad is not None

to:

if b_input_tensor is not None:
    assert input_tensor_grad is not None

This ensures the assertion correctly validates that input_tensor_grad is not None when the backward input tensor exists, matching the actual data flow.

Type of change

  • Bug fix

Testing

The fix corrects the logical condition to match the data flow in the combined forward-backward step computation.

@copy-pr-bot

copy-pr-bot Bot commented Apr 13, 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.

@joapolarbear joapolarbear changed the title ADLR/megatron-lm - Fix assertion logic in combined_1f1b_schedule_for_interleaved_pipelining Fix assertion logic in combined_1f1b_schedule_for_interleaved_pipelining Apr 13, 2026
@joapolarbear
joapolarbear marked this pull request as ready for review April 13, 2026 13:34
@joapolarbear
joapolarbear requested review from a team as code owners April 13, 2026 13:34
@svcnvidia-nemo-ci
svcnvidia-nemo-ci requested a review from a team April 13, 2026 13:34
…ning

The assert checked forward microbatch's `input_tensor` against backward
microbatch's `input_tensor_grad`. In interleaved PP with VP>1, backward
has chunk reversal (`model_chunk_id = num_chunks - id - 1`), so forward
and backward are always on different VP stages in steady-state. This
causes false assertion failures when forward is on a non-first stage
(input_tensor != None) but backward is on a first stage
(input_tensor_grad == None).

Fix: check `b_input_tensor is not None` instead, which directly
corresponds to whether the backward microbatch received activation from
upstream and thus should produce input_tensor_grad.

Reproduction: PP=2 VP=2 EP=4 TP=1 with --overlap-moe-expert-parallel-comm
@joapolarbear
joapolarbear force-pushed the fix/interleaved-pp-overlap-moe-assert branch from a65f38a to 8c8df83 Compare April 13, 2026 13:36
@yaox12
yaox12 requested a review from Wohox April 15, 2026 02:04

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

LGTM, nice catch, thanks!

@Phlip79

Phlip79 commented Apr 15, 2026

Copy link
Copy Markdown
Member

/ok to test 4c8eb93

@Phlip79

Phlip79 commented Apr 15, 2026

Copy link
Copy Markdown
Member

/claude review

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

LGTM

@chtruong814 chtruong814 added the waiting-on-customer Waiting on the original author to respond label Apr 18, 2026
@joapolarbear

Copy link
Copy Markdown
Contributor Author

Hi @chtruong814 , I noticed the waiting-on-customer label was added — could you let me know what specifically is expected from my side? All review comments look resolved and the PR has 4 approvals, so I want to make sure I'm not missing any required signoff, DCO, or additional validation. Happy to address anything needed to move this toward merge. Thanks!

@chtruong814 chtruong814 added needs-follow-up Issue needs follow-up and removed waiting-on-customer Waiting on the original author to respond labels Apr 20, 2026
@svcnvidia-nemo-ci svcnvidia-nemo-ci added waiting-on-maintainers Waiting on maintainers to respond and removed needs-follow-up Issue needs follow-up labels Apr 21, 2026
@svcnvidia-nemo-ci svcnvidia-nemo-ci added the Final Review PR is in the "final review" stage label Apr 27, 2026
@deepakn94

Copy link
Copy Markdown
Contributor

/claude review

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

LGTM. Both fixes are correct:

  1. b_model_chunk_id is not None instead of truthiness check — prevents skipping backward post-processing when chunk ID is 0.
  2. b_input_tensor is not None correctly guards the input_tensor_grad assertion against the backward path's input tensor rather than the forward path's.

@asolergi-nv
asolergi-nv enabled auto-merge April 27, 2026 17:15
@asolergi-nv

Copy link
Copy Markdown
Contributor

/ok to test 3554b4c

@svcnvidia-nemo-ci svcnvidia-nemo-ci added Approved All necessary approvals have been made and removed Final Review PR is in the "final review" stage waiting-on-maintainers Waiting on maintainers to respond labels Apr 27, 2026
@asolergi-nv
asolergi-nv added this pull request to the merge queue Apr 28, 2026
@svcnvidia-nemo-ci

Copy link
Copy Markdown
Contributor

🔄 Merge queue validation started!

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

Merged via the queue into NVIDIA:main with commit c8a4bfd Apr 28, 2026
65 of 67 checks passed
yangbofun pushed a commit to xlm-research/Megatron-LM that referenced this pull request May 22, 2026
…ing (NVIDIA#4276)

Co-authored-by: Hanpeng Hu <haaanpeng@outlook.com>
Co-authored-by: Deepak Narayanan <deepakn94@gmail.com>
Co-authored-by: Antoni-Joan Solergibert <asolergibert@nvidia.com>
yhgalaxy pushed a commit to yhgalaxy/Megatron-LM that referenced this pull request Jun 17, 2026
…ing (NVIDIA#4276)

Co-authored-by: Hanpeng Hu <haaanpeng@outlook.com>
Co-authored-by: Deepak Narayanan <deepakn94@gmail.com>
Co-authored-by: Antoni-Joan Solergibert <asolergibert@nvidia.com>
Signed-off-by: yhgalaxy <yhgalaxy@outlook.com>
jon-barker pushed a commit to jon-barker/Megatron-LM that referenced this pull request Jul 10, 2026
…ing (NVIDIA#4276)

Co-authored-by: Hanpeng Hu <haaanpeng@outlook.com>
Co-authored-by: Deepak Narayanan <deepakn94@gmail.com>
Co-authored-by: Antoni-Joan Solergibert <asolergibert@nvidia.com>
Signed-off-by: Jon Barker <jbarker@aws-cmh-slurm-1-vscode-02.cm.cluster>
terminator123 pushed a commit to 021ai/Megatron-LM that referenced this pull request Aug 3, 2026
…ing (NVIDIA#4276)

Co-authored-by: Hanpeng Hu <haaanpeng@outlook.com>
Co-authored-by: Deepak Narayanan <deepakn94@gmail.com>
Co-authored-by: Antoni-Joan Solergibert <asolergibert@nvidia.com>
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.

10 participants