pytorch - ✅(Solved) Fix DISABLED test_saved_tensors_hooks_base_saved_tensors_hooks_filtering_mode_donated (__main__.TestAOTModuleSimplified) [1 pull requests, 1 comments, 1 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
pytorch/pytorch#181102Fetched 2026-04-23 07:22:37
View on GitHub
Comments
1
Participants
1
Timeline
8
Reactions
0
Participants
Timeline (top)
labeled ×3mentioned ×2subscribed ×2commented ×1

Error Message

Traceback (most recent call last): File "/__w/pytorch/pytorch/test/functorch/test_aotdispatch.py", line 8722, in test_saved_tensors_hooks_base self._test_pack_hooks( File "/__w/pytorch/pytorch/test/functorch/test_aotdispatch.py", line 8588, in _test_pack_hooks self.assertEqual(ref_x_grad, x_grad, atol=1e-2, rtol=1e-2) File "/opt/conda/envs/py_3.10/lib/python3.10/site-packages/torch/testing/_internal/common_utils.py", line 4445, in assertEqual raise error_metas.pop()[0].to_error( # type: ignore[index] AssertionError: Tensor-likes are not close!

Mismatched elements: 2 / 4 (50.0%) Greatest absolute difference: 4.622615164007481e+18 at index (1, 0) (up to 0.01 allowed) Greatest relative difference: 1.0 at index (1, 0) (up to 0.01 allowed)

The failure occurred for item [0]

To execute this test, run the following from the base repo dir: python test/functorch/test_aotdispatch.py TestAOTModuleSimplified.test_saved_tensors_hooks_base_saved_tensors_hooks_filtering_mode_donated

This message can be suppressed by setting PYTORCH_PRINT_REPRO_ON_FAILURE=0

Root Cause

This test was disabled because it is failing in CI. See recent examples and the most recent trunk workflow logs.

Fix Action

Fix / Workaround

Traceback (most recent call last):
  File "/__w/pytorch/pytorch/test/functorch/test_aotdispatch.py", line 8722, in test_saved_tensors_hooks_base
    self._test_pack_hooks(
  File "/__w/pytorch/pytorch/test/functorch/test_aotdispatch.py", line 8588, in _test_pack_hooks
    self.assertEqual(ref_x_grad, x_grad, atol=1e-2, rtol=1e-2)
  File "/opt/conda/envs/py_3.10/lib/python3.10/site-packages/torch/testing/_internal/common_utils.py", line 4445, in assertEqual
    raise error_metas.pop()[0].to_error(  # type: ignore[index]
AssertionError: Tensor-likes are not close!

To execute this test, run the following from the base repo dir:
    python test/functorch/test_aotdispatch.py TestAOTModuleSimplified.test_saved_tensors_hooks_base_saved_tensors_hooks_filtering_mode_donated

Test file path: `functorch/test_aotdispatch.py`

PR fix notes

PR #181239: [aot_autograd] Switch _test_pack_hooks default backend from inductor to aot_eager

Description (problem / solution / changelog)

The _test_pack_hooks helper validates that AOT autograd correctly inlines saved_tensors_hooks (pack/unpack) into the forward/backward graphs. The test compares eager-mode gradients against compiled gradients across various hook types (bf16, fp8, CPU offload, etc.) and filtering modes (donated, no_static, all).

The test was flaky in CI with the inductor backend (3 failures / 3 successes over 6 hours). The failure showed gradient values of ~4.6e+18, indicating the inductor-generated backward kernel was reading freed GPU memory. Investigation traced this to inductor's memory planner reusing donated buffer memory before the backward kernel finishes reading it — a hardware/timing-dependent issue that could not be reproduced locally on H100 but manifests on CI GPUs.

Switch the default backend to aot_eager, which still exercises the full AOT autograd pipeline (graph partitioning, hook inlining, donated buffer identification) without going through inductor's triton codegen and memory planning. This is consistent with the existing test_saved_tensors_hooks_params which already uses backend="aot_eager" explicitly.

The change also makes the test ~4x faster (6.5s vs 25.5s).

Fixes https://github.com/pytorch/pytorch/issues/181102

Changed files

  • test/functorch/test_aotdispatch.py (modified, +1/-1)

Code Example

Traceback (most recent call last):
  File "/__w/pytorch/pytorch/test/functorch/test_aotdispatch.py", line 8722, in test_saved_tensors_hooks_base
    self._test_pack_hooks(
  File "/__w/pytorch/pytorch/test/functorch/test_aotdispatch.py", line 8588, in _test_pack_hooks
    self.assertEqual(ref_x_grad, x_grad, atol=1e-2, rtol=1e-2)
  File "/opt/conda/envs/py_3.10/lib/python3.10/site-packages/torch/testing/_internal/common_utils.py", line 4445, in assertEqual
    raise error_metas.pop()[0].to_error(  # type: ignore[index]
AssertionError: Tensor-likes are not close!

Mismatched elements: 2 / 4 (50.0%)
Greatest absolute difference: 4.622615164007481e+18 at index (1, 0) (up to 0.01 allowed)
Greatest relative difference: 1.0 at index (1, 0) (up to 0.01 allowed)

The failure occurred for item [0]

To execute this test, run the following from the base repo dir:
    python test/functorch/test_aotdispatch.py TestAOTModuleSimplified.test_saved_tensors_hooks_base_saved_tensors_hooks_filtering_mode_donated

This message can be suppressed by setting PYTORCH_PRINT_REPRO_ON_FAILURE=0
RAW_BUFFERClick to expand / collapse

Platforms: linux

This test was disabled because it is failing in CI. See recent examples and the most recent trunk workflow logs.

Over the past 6 hours, it has been determined flaky in 3 workflow(s) with 3 failures and 3 successes.

Debugging instructions (after clicking on the recent samples link): DO NOT ASSUME THINGS ARE OKAY IF THE CI IS GREEN. We now shield flaky tests from developers so CI will thus be green but it will be harder to parse the logs. To find relevant log snippets:

  1. Click on the workflow logs linked above
  2. Click on the Test step of the job so that it is expanded. Otherwise, the grepping will not work.
  3. Grep for test_saved_tensors_hooks_base_saved_tensors_hooks_filtering_mode_donated
  4. There should be several instances run (as flaky tests are rerun in CI) from which you can study the logs.
<details><summary>Sample error message</summary>
Traceback (most recent call last):
  File "/__w/pytorch/pytorch/test/functorch/test_aotdispatch.py", line 8722, in test_saved_tensors_hooks_base
    self._test_pack_hooks(
  File "/__w/pytorch/pytorch/test/functorch/test_aotdispatch.py", line 8588, in _test_pack_hooks
    self.assertEqual(ref_x_grad, x_grad, atol=1e-2, rtol=1e-2)
  File "/opt/conda/envs/py_3.10/lib/python3.10/site-packages/torch/testing/_internal/common_utils.py", line 4445, in assertEqual
    raise error_metas.pop()[0].to_error(  # type: ignore[index]
AssertionError: Tensor-likes are not close!

Mismatched elements: 2 / 4 (50.0%)
Greatest absolute difference: 4.622615164007481e+18 at index (1, 0) (up to 0.01 allowed)
Greatest relative difference: 1.0 at index (1, 0) (up to 0.01 allowed)

The failure occurred for item [0]

To execute this test, run the following from the base repo dir:
    python test/functorch/test_aotdispatch.py TestAOTModuleSimplified.test_saved_tensors_hooks_base_saved_tensors_hooks_filtering_mode_donated

This message can be suppressed by setting PYTORCH_PRINT_REPRO_ON_FAILURE=0
</details>

Test file path: functorch/test_aotdispatch.py

For all disabled tests (by GitHub issue), see https://hud.pytorch.org/disabled.

cc @chauhang @penguinwu

extent analysis

TL;DR

The most likely fix involves investigating and addressing the numerical instability or precision issues causing the AssertionError in the test_saved_tensors_hooks_base_saved_tensors_hooks_filtering_mode_donated test.

Guidance

  • Review the test logs by following the provided debugging instructions to identify patterns or specific conditions leading to the AssertionError.
  • Investigate potential numerical instability or precision issues in the test_saved_tensors_hooks_base_saved_tensors_hooks_filtering_mode_donated test, focusing on the comparison of ref_x_grad and x_grad tensors.
  • Consider relaxing the tolerance values (atol and rtol) in the assertEqual method to accommodate potential minor discrepancies in floating-point calculations.
  • Run the test locally using the provided command to reproduce and debug the issue: python test/functorch/test_aotdispatch.py TestAOTModuleSimplified.test_saved_tensors_hooks_base_saved_tensors_hooks_filtering_mode_donated.

Notes

The provided error message and debugging instructions suggest that the issue is related to numerical precision, but without further investigation, it's difficult to determine the root cause.

Recommendation

Apply a workaround by relaxing the tolerance values in the assertEqual method, as this may help mitigate the issue caused by numerical instability. This change can be reverted once the root cause is identified and addressed.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING

pytorch - ✅(Solved) Fix DISABLED test_saved_tensors_hooks_base_saved_tensors_hooks_filtering_mode_donated (__main__.TestAOTModuleSimplified) [1 pull requests, 1 comments, 1 participants]