Skip to content

[Pipeline] Use microbatched reference in test_schedule_releases_output_before_backward - #201197

Merged
atalman merged 1 commit into
release/2.15from
cherry-pick-199624-by-pytorch_bot_bot_
Oct 19, 2026
Merged

atalman merged 1 commit into
release/2.15from
cherry-pick-199624-by-pytorch_bot_bot_

Conversation

@pytorchbot

Copy link
Copy Markdown
Collaborator

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 (#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)
@pytorch-bot

pytorch-bot Bot commented Oct 16, 2026 •

Copy link
Copy Markdown

🔗 Helpful Links

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

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

✅ No Failures

As of commit b583bc2 with merge base 2cce586 (image):
💚 Looks good so far! There are no failures yet. 💚

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

@atalman
atalman merged commit 95bf94c into release/2.15 Oct 19, 2026

This branch was previously deployed

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants