Skip to content

[Pipeline] Use microbatched reference in test_schedule_releases_output_before_backward - #199624

Closed
pablo-garay wants to merge 1 commit into
pytorch:mainfrom
pablo-garay:fix-pipelining-test-microbatch-ref
Closed

pablo-garay wants to merge 1 commit into
pytorch:mainfrom
pablo-garay:fix-pipelining-test-microbatch-ref

Conversation

@pablo-garay

@pablo-garay pablo-garay commented Oct 3, 2026 •

Copy link
Copy Markdown
Contributor

StageTest::test_schedule_releases_output_before_backward (both ScheduleGPipe and Schedule1F1B), added in #196963, has failed deterministically on MI300 (periodic-rocm-mi300, distributed, 4 GPUs) since it landed. It passes on CUDA (T4 x4) and MI350 at the same commits.

test_stage.py, line 917, in test_schedule_releases_output_before_backward
Mismatched elements: 111494 / 262144 (42.5%)
Greatest absolute difference: 0.011597447097301483 at index (34, 452) (up to 4e-05 allowed)
Greatest relative difference: 347.6016540527344 at index (485, 506) (up to 1e-05 allowed)

Example job: https://github.com/pytorch/pytorch/actions/runs/36972654380/job/110734361600

Root cause

The test checks pipeline gradients against a reference that does one full-batch forward and backward pass (M=256). The schedule runs 8 microbatches (M=32). If the backend picks GEMM kernels for M=32 and M=256 that round differently, a pre-activation near zero can land on the other side of the ReLU. That barely changes the forward output, but it switches the gradient for that unit on or off, so many gradient elements move well past rtol=1e-5, atol=4e-5.

I checked this on a single GPU using the same model, shapes, and loss. A 1-ulp nudge to the microbatched forward pass caused one ReLU flip in 1 of 10 seeds. That flip shifted 34.8% of the layers.0.net1.weight gradient elements past the test's tolerance (max abs diff 1.9e-3), while the forward outputs still matched under assert_close's default tolerances. Without a flip, the two paths agreed to about 1e-6. test_manual, which compares chunked and full-batch forward outputs at default tolerances, passes in the same MI300 job, so the forward data is not corrupted. Only the ReLU gradients differ.

Fix

Run the reference forward and backward pass over the same microbatches as the schedule. The reference then uses the same GEMM shapes as the stages and matches them bit for bit, so the test still checks for gradient corruption from the early output release without depending on how different batch sizes round. Tolerances are unchanged.

Testing

  • 4x MI210 (gfx90a): the 2 test_schedule_releases_output_before_backward variants and all 8 StageTest tests pass with this change. The original test also passes on gfx90a, so the MI300 failure could not be reproduced there.
  • Single GPU: the microbatched reference and the microbatched run produce bit-identical gradients.
  • MI300 confirmation needs ciflow/periodic-rocm-mi300.

…t_before_backward

The test compared pipeline gradients against a full-batch reference. On MI300 the full-batch and microbatch GEMMs round differently, which can flip the sign of a near-zero ReLU input and shift a large fraction of gradient elements past rtol=1e-5/atol=4e-5. Run the reference on the same microbatches as the schedule.

Signed-off-by: pablo-garay <[email protected]>
@pytorch-bot

pytorch-bot Bot commented Oct 3, 2026 •

Copy link
Copy Markdown

🔗 Helpful Links

🧪 See artifacts and rendered test results at hud.pytorch.org/pr/199624

Note: Links to docs will display an error until the docs builds have been completed.

✅ You can merge normally! (1 Unrelated Failure)

As of commit e989a21 with merge base 68d6289 (image):

FLAKY - The following job failed but was likely due to flakiness present on trunk:

This comment was automatically generated by Dr. CI and updates every 15 minutes.

@pytorch-bot pytorch-bot Bot added the topic: not user facing topic category label Oct 3, 2026
@github-actions github-actions Bot added bot-triaged This is a label only to be used by the auto triage bot missing actionable issue A PR without a linked actionable issue or maintainer sponsor triaged This issue has been looked at a team member, and triaged and prioritized into an appropriate module labels Oct 3, 2026
@jithunnair-amd jithunnair-amd added ciflow/periodic-rocm-mi350 Trigger "distributed_4gpu" config (only runs distributed tests that need >2GPUs) CI on ROCm MI350 ciflow/periodic-rocm-mi300 Trigger "distributed" config CI on ROCm MI300/MI325 ciflow/periodic-rocm-mi200 Trigger "distributed" config CI on ROCm MI200 keep-going Don't stop on first failure, keep running tests until the end ci-no-td Do not run TD on this PR labels Oct 5, 2026

@jeffdaily jeffdaily left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The MI300 failure is deterministic (the same 42.5% mismatch on every periodic run) and comes from M=32 vs M=256 GEMM rounding flipping ReLU inputs, which no reasonable tolerance can absorb. The microbatched reference is gradient-equivalent here (sum-reduced MSE, scale_grads=False), leaves the release-before-backward asserts unchanged, and makes the gradient check tighter. Both variants pass on the first try on periodic MI300 and MI210 at e989a21.

Drafted with AI assistance (Claude); reviewed by me.

@jeffdaily

Copy link
Copy Markdown
Collaborator

@pytorchbot merge -i

@pytorch-bot pytorch-bot Bot added the ciflow/trunk Trigger trunk jobs on your pull request label Oct 5, 2026
@pytorchmergebot

Copy link
Copy Markdown
Collaborator

Merge started

Your change will be merged while ignoring the following 1 checks: periodic-rocm-mi350 / linux-noble-rocm-py3.11-mi350 / test (distributed_4gpu, 1, 2, amd-dpx-linux.rocm.gpu.gfx950.4, module:rocm, oncall:distributed)

Learn more about merging in the wiki.

Questions? Feedback? Please reach out to the PyTorch DevX Team

Advanced Debugging
Check the merge workflow status
here

cyyever pushed a commit to BakeLab/pytorch that referenced this pull request Oct 11, 2026
…t_before_backward (pytorch#199624)

`StageTest::test_schedule_releases_output_before_backward` (both `ScheduleGPipe` and `Schedule1F1B`), added in pytorch#196963, has failed deterministically on MI300 (`periodic-rocm-mi300`, distributed, 4 GPUs) since it landed. It passes on CUDA (T4 x4) and MI350 at the same commits.

```
test_stage.py, line 917, in test_schedule_releases_output_before_backward
Mismatched elements: 111494 / 262144 (42.5%)
Greatest absolute difference: 0.011597447097301483 at index (34, 452) (up to 4e-05 allowed)
Greatest relative difference: 347.6016540527344 at index (485, 506) (up to 1e-05 allowed)
```

Example job: https://github.com/pytorch/pytorch/actions/runs/36972654380/job/110734361600

## Root cause

The test checks pipeline gradients against a reference that does one full-batch forward and backward pass (M=256). The schedule runs 8 microbatches (M=32). If the backend picks GEMM kernels for M=32 and M=256 that round differently, a pre-activation near zero can land on the other side of the ReLU. That barely changes the forward output, but it switches the gradient for that unit on or off, so many gradient elements move well past `rtol=1e-5, atol=4e-5`.

I checked this on a single GPU using the same model, shapes, and loss. A 1-ulp nudge to the microbatched forward pass caused one ReLU flip in 1 of 10 seeds. That flip shifted 34.8% of the `layers.0.net1.weight` gradient elements past the test's tolerance (max abs diff 1.9e-3), while the forward outputs still matched under `assert_close`'s default tolerances. Without a flip, the two paths agreed to about 1e-6. `test_manual`, which compares chunked and full-batch forward outputs at default tolerances, passes in the same MI300 job, so the forward data is not corrupted. Only the ReLU gradients differ.

## Fix

Run the reference forward and backward pass over the same microbatches as the schedule. The reference then uses the same GEMM shapes as the stages and matches them bit for bit, so the test still checks for gradient corruption from the early output release without depending on how different batch sizes round. Tolerances are unchanged.

## Testing

- 4x MI210 (gfx90a): the 2 `test_schedule_releases_output_before_backward` variants and all 8 `StageTest` tests pass with this change. The original test also passes on gfx90a, so the MI300 failure could not be reproduced there.
- Single GPU: the microbatched reference and the microbatched run produce bit-identical gradients.
- MI300 confirmation needs `ciflow/periodic-rocm-mi300`.

This PR was authored with the help of an AI assistant.

Pull Request resolved: pytorch#199624
Approved by: https://github.com/jeffdaily
@jeffdaily

Copy link
Copy Markdown
Collaborator

@pytorchbot cherry-pick --onto release/2.15 -c fixnewfeature

@pytorchbot

Copy link
Copy Markdown
Collaborator

Cherry picking #199624

The cherry pick PR is at #201197 and it is recommended to link a fixnewfeature cherry pick PR with an issue. The following tracker issues are updated:

Details for Dev Infra team Raised by workflow job

atalman pushed a commit that referenced this pull request Oct 19, 2026
…t_before_backward (#201197)

[Pipeline] Use microbatched reference in test_schedule_releases_output_before_backward (#199624)

`StageTest::test_schedule_releases_output_before_backward` (both `ScheduleGPipe` and `Schedule1F1B`), added in #196963, has failed deterministically on MI300 (`periodic-rocm-mi300`, distributed, 4 GPUs) since it landed. It passes on CUDA (T4 x4) and MI350 at the same commits.

```
test_stage.py, line 917, in test_schedule_releases_output_before_backward
Mismatched elements: 111494 / 262144 (42.5%)
Greatest absolute difference: 0.011597447097301483 at index (34, 452) (up to 4e-05 allowed)
Greatest relative difference: 347.6016540527344 at index (485, 506) (up to 1e-05 allowed)
```

Example job: https://github.com/pytorch/pytorch/actions/runs/36972654380/job/110734361600

## Root cause

The test checks pipeline gradients against a reference that does one full-batch forward and backward pass (M=256). The schedule runs 8 microbatches (M=32). If the backend picks GEMM kernels for M=32 and M=256 that round differently, a pre-activation near zero can land on the other side of the ReLU. That barely changes the forward output, but it switches the gradient for that unit on or off, so many gradient elements move well past `rtol=1e-5, atol=4e-5`.

I checked this on a single GPU using the same model, shapes, and loss. A 1-ulp nudge to the microbatched forward pass caused one ReLU flip in 1 of 10 seeds. That flip shifted 34.8% of the `layers.0.net1.weight` gradient elements past the test's tolerance (max abs diff 1.9e-3), while the forward outputs still matched under `assert_close`'s default tolerances. Without a flip, the two paths agreed to about 1e-6. `test_manual`, which compares chunked and full-batch forward outputs at default tolerances, passes in the same MI300 job, so the forward data is not corrupted. Only the ReLU gradients differ.

## Fix

Run the reference forward and backward pass over the same microbatches as the schedule. The reference then uses the same GEMM shapes as the stages and matches them bit for bit, so the test still checks for gradient corruption from the early output release without depending on how different batch sizes round. Tolerances are unchanged.

## Testing

- 4x MI210 (gfx90a): the 2 `test_schedule_releases_output_before_backward` variants and all 8 `StageTest` tests pass with this change. The original test also passes on gfx90a, so the MI300 failure could not be reproduced there.
- Single GPU: the microbatched reference and the microbatched run produce bit-identical gradients.
- MI300 confirmation needs `ciflow/periodic-rocm-mi300`.

This PR was authored with the help of an AI assistant.

Pull Request resolved: #199624
Approved by: https://github.com/jeffdaily

(cherry picked from commit 630d63a)

Co-authored-by: pablo-garay <[email protected]>

This branch was previously deployed

1 inactive deployment
bedrock — e989a213 Deployed Oct 3, 2026 by pytorchbot
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bot-triaged This is a label only to be used by the auto triage bot ci-no-td Do not run TD on this PR ciflow/periodic-rocm-mi200 Trigger "distributed" config CI on ROCm MI200 ciflow/periodic-rocm-mi300 Trigger "distributed" config CI on ROCm MI300/MI325 ciflow/periodic-rocm-mi350 Trigger "distributed_4gpu" config (only runs distributed tests that need >2GPUs) CI on ROCm MI350 ciflow/trunk Trigger trunk jobs on your pull request keep-going Don't stop on first failure, keep running tests until the end Merged missing actionable issue A PR without a linked actionable issue or maintainer sponsor open source topic: not user facing topic category triaged This issue has been looked at a team member, and triaged and prioritized into an appropriate module

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants