pytorch - ✅(Solved) Fix A lot of TestNN dynamo_wrapped cases failed on cpu [1 pull requests, 1 comments, 2 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#177119Fetched 2026-04-08 00:22:08
View on GitHub
Comments
1
Participants
2
Timeline
50
Reactions
0
Author
Assignees
Timeline (top)
mentioned ×18subscribed ×18labeled ×6referenced ×5

Error Message

Traceback (most recent call last): File "/home/sdp/ecao/miniforge3/envs/daisyden/lib/python3.10/site-packages/torch/fx/graph_module.py", line 444, in call return super(self.cls, obj).call(*args, **kwargs) # type: ignore[misc] File "/home/sdp/ecao/miniforge3/envs/daisyden/lib/python3.10/site-packages/torch/nn/modules/module.py", line 1779, in _wrapped_call_impl return self._call_impl(*args, **kwargs) File "/home/sdp/ecao/miniforge3/envs/daisyden/lib/python3.10/site-packages/torch/nn/modules/module.py", line 1790, in _call_impl return forward_call(*args, **kwargs) File "<eval_with_key>.5", line 59, in forward add = torch.add(getitem_29, getitem_37); getitem_29 = getitem_37 = None TypeError: add(): argument 'input' (position 1) must be Tensor, not NoneType

Call using an FX-traced Module, line 59 of the traced Module's generated forward function: getitem_37 = validate_outputs_10[1]; validate_outputs_10 = None add = torch.add(getitem_29, getitem_37); getitem_29 = getitem_37 = None

    add_backward1_2 = torch__dynamo_compiled_autograd_ops_AddBackward1([getitem_16], [True], 7);  getitem_16 = None

    getitem_38 = add_backward1_2[0];  add_backward1_2 = None

====================================================================================================================== short test summary info ======================================================================================================================
FAILED [1.4639s] test/test_nn.py::TestNN::test_triplet_margin_loss_swap_no_reduce - TypeError: add(): argument 'input' (position 1) must be Tensor, not NoneType

Fix Action

Fixed

PR fix notes

PR #166396: [xpu][test][1/N] Enable tests of test_nn.py on Intel GPU - instantiate TestNN with instantiate_device_type_tests

Description (problem / solution / changelog)

For https://github.com/pytorch/pytorch/issues/114850, we will port aten unit tests to Intel GPU. This PR will work on test/test_nn.py TEST_NN class for single GPU test only. We could enable Intel GPU with following methods and try the best to keep the original code styles:

  1. Use torch.accelerator to extend cude specific test to XPU.
  2. Added skipIfXPU decorator for cases with known issues on Intel GPU
  3. Enabled 'xpu' for some test pathes

Changed files

  • test/test_nn.py (modified, +612/-666)
  • torch/testing/_internal/common_device_type.py (modified, +13/-0)
  • torch/testing/_internal/common_utils.py (modified, +6/-0)

Code Example

test_swap_module_params_poisons_acc_grad
test_normalize
test_relu_inplace_on_view
test_triplet_margin_loss
test_triplet_margin_loss_swap
test_triplet_margin_loss_no_reduce
test_triplet_margin_loss_swap_no_reduce
test_upsamplingLinear1d
test_upsampling_not_recompute_scale_factor
test_upsampling_bfloat16
test_unflatten
test_linear_autograd
test_upsamplingNearest1d
test_upsamplingBiMode2d
test_upsamplingTrilinear3d

---

Traceback (most recent call last):
  File "/home/sdp/ecao/miniforge3/envs/daisyden/lib/python3.10/site-packages/torch/fx/graph_module.py", line 444, in __call__
    return super(self.cls, obj).__call__(*args, **kwargs)  # type: ignore[misc]
  File "/home/sdp/ecao/miniforge3/envs/daisyden/lib/python3.10/site-packages/torch/nn/modules/module.py", line 1779, in _wrapped_call_impl
    return self._call_impl(*args, **kwargs)
  File "/home/sdp/ecao/miniforge3/envs/daisyden/lib/python3.10/site-packages/torch/nn/modules/module.py", line 1790, in _call_impl
    return forward_call(*args, **kwargs)
  File "<eval_with_key>.5", line 59, in forward
    add = torch.add(getitem_29, getitem_37);  getitem_29 = getitem_37 = None
TypeError: add(): argument 'input' (position 1) must be Tensor, not NoneType

Call using an FX-traced Module, line 59 of the traced Module's generated forward function:
    getitem_37 = validate_outputs_10[1];  validate_outputs_10 = None
    add = torch.add(getitem_29, getitem_37);  getitem_29 = getitem_37 = None

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ <--- HERE
    add_backward1_2 = torch__dynamo_compiled_autograd_ops_AddBackward1([getitem_16], [True], 7);  getitem_16 = None

    getitem_38 = add_backward1_2[0];  add_backward1_2 = None

====================================================================================================================== short test summary info ======================================================================================================================
FAILED [1.4639s] test/test_nn.py::TestNN::test_triplet_margin_loss_swap_no_reduce - TypeError: add(): argument 'input' (position 1) must be Tensor, not NoneType

---

PYTORCH_TEST_WITH_DYNAMO=1  pytest -v test/test_nn.py -k test_linear_autograd
_______________________________________________________________________________________________ TestNN.test_linear_autograd_device_cpu_nobias_weightCSR ___________________________________________________________________________________________________
Traceback (most recent call last):
  File "/home/sdp/ecao/miniforge3/envs/daisyden/lib/python3.10/site-packages/torch/_dynamo/compiled_autograd.py", line 356, in begin_capture
    inputs[idx] = self.wrap_fake(x, self.source("inputs", idx))
  File "/home/sdp/ecao/miniforge3/envs/daisyden/lib/python3.10/site-packages/torch/_dynamo/compiled_autograd.py", line 302, in wrap_fake
    return self.fake_tensor_mode.from_tensor(x, source=source)
  File "/home/sdp/ecao/miniforge3/envs/daisyden/lib/python3.10/site-packages/torch/_subclasses/fake_tensor.py", line 3149, in from_tensor
    return self.fake_tensor_converter.from_real_tensor(
  File "/home/sdp/ecao/miniforge3/envs/daisyden/lib/python3.10/site-packages/torch/_subclasses/fake_tensor.py", line 425, in from_real_tensor
    out = self.meta_converter(
  File "/home/sdp/ecao/miniforge3/envs/daisyden/lib/python3.10/site-packages/torch/_subclasses/meta_utils.py", line 2118, in __call__
    r = self.meta_tensor(
  File "/home/sdp/ecao/miniforge3/envs/daisyden/lib/python3.10/site-packages/torch/_subclasses/meta_utils.py", line 2008, in meta_tensor
    assert_metadata_eq(assert_eq, t, r, skip_symbolic=True, skip_leaf=skip_leaf)
  File "/home/sdp/ecao/miniforge3/envs/daisyden/lib/python3.10/site-packages/torch/_subclasses/meta_utils.py", line 176, in assert_metadata_eq
    return go(m1, m2)
  File "/home/sdp/ecao/miniforge3/envs/daisyden/lib/python3.10/site-packages/torch/_subclasses/meta_utils.py", line 165, in go
    assert_eq(m1.is_view, m2._is_view())
  File "/home/sdp/ecao/miniforge3/envs/daisyden/lib/python3.10/site-packages/torch/_subclasses/meta_utils.py", line 97, in assert_eq
    raise AssertionError(f"{a} != {b}")
AssertionError: True != False

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/home/sdp/daisyden/test/test_nn.py", line 7032, in test_linear_autograd
    module = nn.Linear(4, 4, bias=bias, device=device)
  File "/home/sdp/daisyden/test/test_nn.py", line 7036, in torch_dynamo_resume_in_test_linear_autograd_at_7032
    module.weight = nn.Parameter(module.weight.to_sparse_csr())
  File "/home/sdp/daisyden/test/test_nn.py", line 7057, in torch_dynamo_resume_in_test_linear_autograd_at_7036
    grads = torch.autograd.grad(res, [module.weight, inp], grad_output)
  File "/home/sdp/ecao/miniforge3/envs/daisyden/lib/python3.10/site-packages/torch/autograd/__init__.py", line 532, in grad
    result = _engine_run_backward(
  File "/home/sdp/ecao/miniforge3/envs/daisyden/lib/python3.10/site-packages/torch/autograd/graph.py", line 865, in _engine_run_backward
    return Variable._execution_engine.run_backward(  # Calls into the C++ engine to run the backward pass
  File "/home/sdp/ecao/miniforge3/envs/daisyden/lib/python3.10/site-packages/torch/_dynamo/compiled_autograd.py", line 358, in begin_capture
    raise NotImplementedError(
NotImplementedError: Found tensor of type <class 'torch.Tensor'>, which is not supported by FakeTensorMode. You can turn off compiled autograd by either:
1. Moving the unsupported autograd call outside of the torch.compile'd region.
2. Wrapping the unsupported autograd call in the torch._dynamo.compiled_autograd._disable() context manager.
3. Setting torch._dynamo.config.compiled_autograd=False for the torch.compile call containing the unsupported autograd call.
4. Setting torch._dynamo.config.compiled_autograd=False at the start of the program.

To execute this test, run the following from the base repo dir:
    PYTORCH_TEST_WITH_DYNAMO=1 python test/test_nn.py TestNN.test_linear_autograd_device_cpu_nobias_weightCSR

This message can be suppressed by setting PYTORCH_PRINT_REPRO_ON_FAILURE=0
================================================================================================================== short test summary info ===================================================================================================================
FAILED [1.0669s] test/test_nn.py::TestNN::test_linear_autograd_device_cpu_bias_weightCOO - AssertionError: Guard failed on the same frame it was created. This is a bug - please create an issue.Guard fail reason: !0/5/0: Unexpected recompilation: runtime guards failed even though they passed during recompilation-reason analysis. Please ope...
FAILED [0.3753s] test/test_nn.py::TestNN::test_linear_autograd_device_cpu_bias_weightCSC - AssertionError: Guard failed on the same frame it was created. This is a bug - please create an issue.Guard fail reason: !0/5/0: Unexpected recompilation: runtime guards failed even though they passed during recompilation-reason analysis. Please ope...
FAILED [0.3529s] test/test_nn.py::TestNN::test_linear_autograd_device_cpu_bias_weightCSR - AssertionError: Guard failed on the same frame it was created. This is a bug - please create an issue.Guard fail reason: !0/5/0: Unexpected recompilation: runtime guards failed even though they passed during recompilation-reason analysis. Please ope...
FAILED [0.2376s] test/test_nn.py::TestNN::test_linear_autograd_device_cpu_nobias_weightCOO - NotImplementedError: Found tensor of type <class 'torch.Tensor'>, which is not supported by FakeTensorMode. You can turn off compiled autograd by either:
FAILED [0.2507s] test/test_nn.py::TestNN::test_linear_autograd_device_cpu_nobias_weightCSC - NotImplementedError: Found tensor of type <class 'torch.Tensor'>, which is not supported by FakeTensorMode. You can turn off compiled autograd by either:
FAILED [0.2394s] test/test_nn.py::TestNN::test_linear_autograd_device_cpu_nobias_weightCSR - NotImplementedError: Found tensor of type <class 'torch.Tensor'>, which is not supported by FakeTensorMode. You can turn off compiled autograd by either:

---

pytest -v test/test_nn.py -k test_linear_autograd
======================================================================================================================== test session starts ========================================================================================================================
platform linux -- Python 3.10.20, pytest-7.3.2, pluggy-1.6.0 -- /home/sdp/ecao/miniforge3/envs/daisyden/bin/python3.10
cachedir: .pytest_cache
hypothesis profile 'dev' -> database=None, max_examples=10, suppress_health_check=[HealthCheck.too_slow]
rootdir: /home/sdp/daisyden
configfile: pytest.ini
plugins: xdoctest-1.3.0, hypothesis-6.56.4, flakefinder-1.1.0, cpp-2.3.0, rerunfailures-14.0, xdist-3.3.1, subtests-0.13.1
collected 2283 items / 2275 deselected / 8 selected
Running 8 items in this shard

test/test_nn.py::TestNN::test_linear_autograd_device_cpu_bias_weightCOO PASSED [0.1496s]                                                                                                                                                                      [ 12%]
test/test_nn.py::TestNN::test_linear_autograd_device_cpu_bias_weightCSC PASSED [0.0653s]                                                                                                                                                                      [ 25%]
test/test_nn.py::TestNN::test_linear_autograd_device_cpu_bias_weightCSR PASSED [0.0138s]                                                                                                                                                                      [ 37%]
test/test_nn.py::TestNN::test_linear_autograd_device_cpu_bias_weightStrided PASSED [0.0061s]                                                                                                                                                                  [ 50%]
test/test_nn.py::TestNN::test_linear_autograd_device_cpu_nobias_weightCOO PASSED [0.0103s]                                                                                                                                                                    [ 62%]
test/test_nn.py::TestNN::test_linear_autograd_device_cpu_nobias_weightCSC PASSED [0.0110s]                                                                                                                                                                    [ 75%]
test/test_nn.py::TestNN::test_linear_autograd_device_cpu_nobias_weightCSR PASSED [0.0097s]                                                                                                                                                                    [ 87%]
test/test_nn.py::TestNN::test_linear_autograd_device_cpu_nobias_weightStrided PASSED [0.0059s]
RAW_BUFFERClick to expand / collapse

🐛 Describe the bug

A lot of cpu cases in TestNN got failed with PYTORCH_TEST_WITH_DYNAMO=1, without dyanmo_wrapped the test passed. The problem can be reproduced with nightly build.

test_swap_module_params_poisons_acc_grad
test_normalize
test_relu_inplace_on_view
test_triplet_margin_loss
test_triplet_margin_loss_swap
test_triplet_margin_loss_no_reduce
test_triplet_margin_loss_swap_no_reduce
test_upsamplingLinear1d
test_upsampling_not_recompute_scale_factor
test_upsampling_bfloat16
test_unflatten
test_linear_autograd
test_upsamplingNearest1d
test_upsamplingBiMode2d
test_upsamplingTrilinear3d

Some log:

Traceback (most recent call last):
  File "/home/sdp/ecao/miniforge3/envs/daisyden/lib/python3.10/site-packages/torch/fx/graph_module.py", line 444, in __call__
    return super(self.cls, obj).__call__(*args, **kwargs)  # type: ignore[misc]
  File "/home/sdp/ecao/miniforge3/envs/daisyden/lib/python3.10/site-packages/torch/nn/modules/module.py", line 1779, in _wrapped_call_impl
    return self._call_impl(*args, **kwargs)
  File "/home/sdp/ecao/miniforge3/envs/daisyden/lib/python3.10/site-packages/torch/nn/modules/module.py", line 1790, in _call_impl
    return forward_call(*args, **kwargs)
  File "<eval_with_key>.5", line 59, in forward
    add = torch.add(getitem_29, getitem_37);  getitem_29 = getitem_37 = None
TypeError: add(): argument 'input' (position 1) must be Tensor, not NoneType

Call using an FX-traced Module, line 59 of the traced Module's generated forward function:
    getitem_37 = validate_outputs_10[1];  validate_outputs_10 = None
    add = torch.add(getitem_29, getitem_37);  getitem_29 = getitem_37 = None

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ <--- HERE
    add_backward1_2 = torch__dynamo_compiled_autograd_ops_AddBackward1([getitem_16], [True], 7);  getitem_16 = None

    getitem_38 = add_backward1_2[0];  add_backward1_2 = None

====================================================================================================================== short test summary info ======================================================================================================================
FAILED [1.4639s] test/test_nn.py::TestNN::test_triplet_margin_loss_swap_no_reduce - TypeError: add(): argument 'input' (position 1) must be Tensor, not NoneType
PYTORCH_TEST_WITH_DYNAMO=1  pytest -v test/test_nn.py -k test_linear_autograd
_______________________________________________________________________________________________ TestNN.test_linear_autograd_device_cpu_nobias_weightCSR ___________________________________________________________________________________________________
Traceback (most recent call last):
  File "/home/sdp/ecao/miniforge3/envs/daisyden/lib/python3.10/site-packages/torch/_dynamo/compiled_autograd.py", line 356, in begin_capture
    inputs[idx] = self.wrap_fake(x, self.source("inputs", idx))
  File "/home/sdp/ecao/miniforge3/envs/daisyden/lib/python3.10/site-packages/torch/_dynamo/compiled_autograd.py", line 302, in wrap_fake
    return self.fake_tensor_mode.from_tensor(x, source=source)
  File "/home/sdp/ecao/miniforge3/envs/daisyden/lib/python3.10/site-packages/torch/_subclasses/fake_tensor.py", line 3149, in from_tensor
    return self.fake_tensor_converter.from_real_tensor(
  File "/home/sdp/ecao/miniforge3/envs/daisyden/lib/python3.10/site-packages/torch/_subclasses/fake_tensor.py", line 425, in from_real_tensor
    out = self.meta_converter(
  File "/home/sdp/ecao/miniforge3/envs/daisyden/lib/python3.10/site-packages/torch/_subclasses/meta_utils.py", line 2118, in __call__
    r = self.meta_tensor(
  File "/home/sdp/ecao/miniforge3/envs/daisyden/lib/python3.10/site-packages/torch/_subclasses/meta_utils.py", line 2008, in meta_tensor
    assert_metadata_eq(assert_eq, t, r, skip_symbolic=True, skip_leaf=skip_leaf)
  File "/home/sdp/ecao/miniforge3/envs/daisyden/lib/python3.10/site-packages/torch/_subclasses/meta_utils.py", line 176, in assert_metadata_eq
    return go(m1, m2)
  File "/home/sdp/ecao/miniforge3/envs/daisyden/lib/python3.10/site-packages/torch/_subclasses/meta_utils.py", line 165, in go
    assert_eq(m1.is_view, m2._is_view())
  File "/home/sdp/ecao/miniforge3/envs/daisyden/lib/python3.10/site-packages/torch/_subclasses/meta_utils.py", line 97, in assert_eq
    raise AssertionError(f"{a} != {b}")
AssertionError: True != False

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/home/sdp/daisyden/test/test_nn.py", line 7032, in test_linear_autograd
    module = nn.Linear(4, 4, bias=bias, device=device)
  File "/home/sdp/daisyden/test/test_nn.py", line 7036, in torch_dynamo_resume_in_test_linear_autograd_at_7032
    module.weight = nn.Parameter(module.weight.to_sparse_csr())
  File "/home/sdp/daisyden/test/test_nn.py", line 7057, in torch_dynamo_resume_in_test_linear_autograd_at_7036
    grads = torch.autograd.grad(res, [module.weight, inp], grad_output)
  File "/home/sdp/ecao/miniforge3/envs/daisyden/lib/python3.10/site-packages/torch/autograd/__init__.py", line 532, in grad
    result = _engine_run_backward(
  File "/home/sdp/ecao/miniforge3/envs/daisyden/lib/python3.10/site-packages/torch/autograd/graph.py", line 865, in _engine_run_backward
    return Variable._execution_engine.run_backward(  # Calls into the C++ engine to run the backward pass
  File "/home/sdp/ecao/miniforge3/envs/daisyden/lib/python3.10/site-packages/torch/_dynamo/compiled_autograd.py", line 358, in begin_capture
    raise NotImplementedError(
NotImplementedError: Found tensor of type <class 'torch.Tensor'>, which is not supported by FakeTensorMode. You can turn off compiled autograd by either:
1. Moving the unsupported autograd call outside of the torch.compile'd region.
2. Wrapping the unsupported autograd call in the torch._dynamo.compiled_autograd._disable() context manager.
3. Setting torch._dynamo.config.compiled_autograd=False for the torch.compile call containing the unsupported autograd call.
4. Setting torch._dynamo.config.compiled_autograd=False at the start of the program.

To execute this test, run the following from the base repo dir:
    PYTORCH_TEST_WITH_DYNAMO=1 python test/test_nn.py TestNN.test_linear_autograd_device_cpu_nobias_weightCSR

This message can be suppressed by setting PYTORCH_PRINT_REPRO_ON_FAILURE=0
================================================================================================================== short test summary info ===================================================================================================================
FAILED [1.0669s] test/test_nn.py::TestNN::test_linear_autograd_device_cpu_bias_weightCOO - AssertionError: Guard failed on the same frame it was created. This is a bug - please create an issue.Guard fail reason: !0/5/0: Unexpected recompilation: runtime guards failed even though they passed during recompilation-reason analysis. Please ope...
FAILED [0.3753s] test/test_nn.py::TestNN::test_linear_autograd_device_cpu_bias_weightCSC - AssertionError: Guard failed on the same frame it was created. This is a bug - please create an issue.Guard fail reason: !0/5/0: Unexpected recompilation: runtime guards failed even though they passed during recompilation-reason analysis. Please ope...
FAILED [0.3529s] test/test_nn.py::TestNN::test_linear_autograd_device_cpu_bias_weightCSR - AssertionError: Guard failed on the same frame it was created. This is a bug - please create an issue.Guard fail reason: !0/5/0: Unexpected recompilation: runtime guards failed even though they passed during recompilation-reason analysis. Please ope...
FAILED [0.2376s] test/test_nn.py::TestNN::test_linear_autograd_device_cpu_nobias_weightCOO - NotImplementedError: Found tensor of type <class 'torch.Tensor'>, which is not supported by FakeTensorMode. You can turn off compiled autograd by either:
FAILED [0.2507s] test/test_nn.py::TestNN::test_linear_autograd_device_cpu_nobias_weightCSC - NotImplementedError: Found tensor of type <class 'torch.Tensor'>, which is not supported by FakeTensorMode. You can turn off compiled autograd by either:
FAILED [0.2394s] test/test_nn.py::TestNN::test_linear_autograd_device_cpu_nobias_weightCSR - NotImplementedError: Found tensor of type <class 'torch.Tensor'>, which is not supported by FakeTensorMode. You can turn off compiled autograd by either:
pytest -v test/test_nn.py -k test_linear_autograd
======================================================================================================================== test session starts ========================================================================================================================
platform linux -- Python 3.10.20, pytest-7.3.2, pluggy-1.6.0 -- /home/sdp/ecao/miniforge3/envs/daisyden/bin/python3.10
cachedir: .pytest_cache
hypothesis profile 'dev' -> database=None, max_examples=10, suppress_health_check=[HealthCheck.too_slow]
rootdir: /home/sdp/daisyden
configfile: pytest.ini
plugins: xdoctest-1.3.0, hypothesis-6.56.4, flakefinder-1.1.0, cpp-2.3.0, rerunfailures-14.0, xdist-3.3.1, subtests-0.13.1
collected 2283 items / 2275 deselected / 8 selected
Running 8 items in this shard

test/test_nn.py::TestNN::test_linear_autograd_device_cpu_bias_weightCOO PASSED [0.1496s]                                                                                                                                                                      [ 12%]
test/test_nn.py::TestNN::test_linear_autograd_device_cpu_bias_weightCSC PASSED [0.0653s]                                                                                                                                                                      [ 25%]
test/test_nn.py::TestNN::test_linear_autograd_device_cpu_bias_weightCSR PASSED [0.0138s]                                                                                                                                                                      [ 37%]
test/test_nn.py::TestNN::test_linear_autograd_device_cpu_bias_weightStrided PASSED [0.0061s]                                                                                                                                                                  [ 50%]
test/test_nn.py::TestNN::test_linear_autograd_device_cpu_nobias_weightCOO PASSED [0.0103s]                                                                                                                                                                    [ 62%]
test/test_nn.py::TestNN::test_linear_autograd_device_cpu_nobias_weightCSC PASSED [0.0110s]                                                                                                                                                                    [ 75%]
test/test_nn.py::TestNN::test_linear_autograd_device_cpu_nobias_weightCSR PASSED [0.0097s]                                                                                                                                                                    [ 87%]
test/test_nn.py::TestNN::test_linear_autograd_device_cpu_nobias_weightStrided PASSED [0.0059s]

Versions

pip list|grep torch torch 2.11.0.dev20260131+cpu torchaudio 2.11.0.dev20260310+cpu torchvision 0.25.0.dev20260131+cpu

cc @nikitaved @pearu @cpuhrsch @amjames @bhosmer @jcaip @jgong5 @mingfeima @XiaobingSuper @sanchitintel @ashokei @jingxu10 @jerryzh168 @aditew01 @chauhang @penguinwu @xmfan @aditvenk

extent analysis

Fix Plan

1. Disable Compiled Autograd for Unsupported Operations

To fix the issue, we need to disable compiled autograd for unsupported operations. We can do this by wrapping the unsupported autograd call in the torch._dynamo.compiled_autograd._disable() context manager.

import torch
from torch._dynamo import compiled_autograd

# Disable compiled autograd for unsupported operations
with compiled_autograd._disable():
    # Perform the unsupported autograd call
    module.weight = nn.Parameter(module.weight.to_sparse_csr())

2. Set Compiled Autograd to False

Alternatively, we can set torch._dynamo.config.compiled_autograd to False for the torch.compile call containing the unsupported autograd call.

import torch
from torch._dynamo import config

# Set compiled autograd to False
config.compiled_autograd = False

# Perform the torch.compile call
torch.compile(module)

3. Move Unsupported Autograd Call Outside of Compiled Region

We can also move the unsupported autograd call outside of the compiled region.

import torch

# Move the unsupported autograd call outside of the compiled region
module.weight = nn.Parameter(module.weight.to_sparse_csr())

Verification

To verify that the fix worked, we can run the tests again with the PYTORCH_TEST_WITH_DYNAMO=1 environment variable set.

PYTORCH_TEST_WITH_DYNAMO=1 pytest -v test/test_nn.py -k test_linear_autograd

If the tests pass, it indicates that the fix was successful.

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