Repository navigation
[Pipeline] Use microbatched reference in test_schedule_releases_output_before_backward - #201197
Merged
Merged
Conversation
…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)
🔗 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 FailuresAs of commit b583bc2 with merge base 2cce586 ( This comment was automatically generated by Dr. CI and updates every 15 minutes. |
atalman
approved these changes
Oct 19, 2026
39 of 57 tasks
This branch was previously deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
StageTest::test_schedule_releases_output_before_backward(bothScheduleGPipeandSchedule1F1B), 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.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.weightgradient elements past the test's tolerance (max abs diff 1.9e-3), while the forward outputs still matched underassert_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
test_schedule_releases_output_before_backwardvariants and all 8StageTesttests pass with this change. The original test also passes on gfx90a, so the MI300 failure could not be reproduced there.ciflow/periodic-rocm-mi300.