Repository navigation
[Pipeline] Use microbatched reference in test_schedule_releases_output_before_backward - #199624
pablo-garay wants to merge 1 commit into
Conversation
…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]>
🔗 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 ( 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. |
jeffdaily
left a comment
There was a problem hiding this comment.
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.
|
@pytorchbot merge -i |
Merge startedYour 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 |
…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
|
@pytorchbot cherry-pick --onto release/2.15 -c fixnewfeature |
Cherry picking #199624The 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 teamRaised by workflow job |
…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]>
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.