pytorch - ✅(Solved) Fix `torch.compile` crashes on `aten._assert_tensor_metadata.default` [1 pull requests]

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…

Error Message

Traceback (most recent call last): File "bug.py", line 8, in <module> torch.compile(f)(x) # crashes ~~~~~~~~~~~~~~~~^^^ File "/.../lib/python3.14/site-packages/torch/_dynamo/eval_frame.py", line 1041, in compile_wrapper return fn(*args, **kwargs) File "/.../lib/python3.14/site-packages/torch/_dynamo/convert_frame.py", line 2432, in call result = self._torchdynamo_orig_backend( frame, cache_entry, self.hooks, frame_state, skip=1 ) File "/.../lib/python3.14/site-packages/torch/_dynamo/convert_frame.py", line 2150, in call result = self._inner_convert( frame, cache_entry, hooks, frame_state, skip=skip + 1 ) File "/.../lib/python3.14/site-packages/torch/_dynamo/convert_frame.py", line 735, in call result = _compile( frame.f_code, ...<16 lines>... convert_frame_box=self._box, ) File "/.../lib/python3.14/site-packages/torch/_dynamo/convert_frame.py", line 1919, in _compile guarded_code, tracer_output = compile_inner(code, one_graph, hooks) ~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^ File "/.../lib/python3.14/site-packages/torch/_utils_internal.py", line 96, in wrapper_function return function(*args, **kwargs) File "/.../lib/python3.14/site-packages/torch/_dynamo/convert_frame.py", line 1535, in compile_inner result = _compile_inner(code, one_graph, hooks) File "/.../lib/python3.14/site-packages/torch/_dynamo/convert_frame.py", line 1594, in _compile_inner dynamo_output = compile_frame( code, ...<11 lines>... package=package, ) File "/.../lib/python3.14/site-packages/torch/_dynamo/convert_frame.py", line 1442, in compile_frame bytecode, tracer_output = transform_code_object(code, transform) ~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^ File "/.../lib/python3.14/site-packages/torch/_dynamo/bytecode_transformation.py", line 1626, in transform_code_object tracer_output = transformations(instructions, code_options) File "/.../lib/python3.14/site-packages/torch/_dynamo/convert_frame.py", line 1414, in transform tracer_output = trace_frame( code, ...<14 lines>... package=package, ) File "/.../lib/python3.14/site-packages/torch/_dynamo/convert_frame.py", line 342, in _fn return fn(args, **kwargs) File "/.../lib/python3.14/site-packages/torch/_dynamo/convert_frame.py", line 875, in trace_frame run_tracer() ~~~~~~~~~~^^ File "/.../lib/python3.14/site-packages/torch/_dynamo/convert_frame.py", line 856, in run_tracer tracer.run() ~~~~~~~~~~^^ File "/.../lib/python3.14/site-packages/torch/_dynamo/symbolic_convert.py", line 1704, in run while self.step(): ~~~~~~~~~^^ File "/.../lib/python3.14/site-packages/torch/_dynamo/symbolic_convert.py", line 1371, in step self.dispatch_table[inst.opcode](self, inst) ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^ File "/.../lib/python3.14/site-packages/torch/_dynamo/symbolic_convert.py", line 908, in wrapper return inner_fn(self, inst) File "/.../lib/python3.14/site-packages/torch/_dynamo/symbolic_convert.py", line 4276, in CALL_KW self._call(inst, call_kw=True) ~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^ File "/.../lib/python3.14/site-packages/torch/_dynamo/symbolic_convert.py", line 4052, in _call self.call_function(fn, args, kwargs) ~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^ File "/.../lib/python3.14/site-packages/torch/_dynamo/symbolic_convert.py", line 1272, in call_function self.push(fn.call_function(self, args, kwargs)) # type: ignore[arg-type] ~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^ File "/.../lib/python3.14/site-packages/torch/_dynamo/variables/torch.py", line 2600, in call_function tensor_variable = wrap_fx_proxy( tx=tx, ...<4 lines>... ), ) File "/.../lib/python3.14/site-packages/torch/_dynamo/variables/builder.py", line 3073, in wrap_fx_proxy return wrap_fx_proxy_cls(target_cls=TensorVariable, **kwargs) File "/.../lib/python3.14/site-packages/torch/_dynamo/variables/builder.py", line 3148, in wrap_fx_proxy_cls out: VTTypeAlias = _wrap_fx_proxy( ~~~~~~~~~~~~~~^ target_cls, tx, proxy, example_value, subclass_type, **options ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ) ^ File "/.../lib/python3.14/site-packages/torch/_dynamo/variables/builder.py", line 3272, in _wrap_fx_proxy example_value = get_fake_value(proxy.node, tx, allow_non_graph_fake=True) File "/.../lib/python3.14/site-packages/torch/_dynamo/utils.py", line 3736, in get_fake_value return _get_fake_value_impl(node, tx, allow_non_graph_fake) File "/.../lib/python3.14/site-packages/torch/_dynamo/utils.py", line 3927, in _get_fake_value_impl _wrap_graph_break_with_torch_runtime_err( ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^ lambda: unimplemented( ^^^^^^^^^^^^^^^^^^^^^^ ...<5 lines>... ) ^ ) ^ File "/.../lib/python3.14/site-packages/torch/_dynamo/utils.py", line 3725, in _wrap_graph_break_with_torch_runtime_err raise exc.with_traceback(e.traceback) from None File "/.../lib/python3.14/site-packages/torch/_dynamo/utils.py", line 3722, in _wrap_graph_break_with_torch_runtime_err gb_fn() ~~~~~^^ File "/.../lib/python3.14/site-packages/torch/_dynamo/utils.py", line 3928, in <lambda> lambda: unimplemented( ~~~~~~~~~~~~~^ gb_type="RuntimeError when making fake tensor call", ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ...<3 lines>... from_exc=cause, ^^^^^^^^^^^^^^^ ) ^ File "/.../lib/python3.14/site-packages/torch/_dynamo/exc.py", line 653, in unimplemented raise Unsupported( msg, gb_type, skip_frame, real_stack=past_real_stack ) from from_exc torch._dynamo.exc.TorchRuntimeError: RuntimeError when making fake tensor call Explanation: Dynamo failed to run FX node with fake tensors: call_function aten._assert_tensor_metadata.default((FakeTensor(..., size=(10,)),), **{'size': [10]}): got AssertionError('Tensor sizes mismatch! Expected: [10], Got: torch.Size([10])') Hint: Your code may result in an error when running in eager. Please double check that your code doesn't contain a similar error when actually running eager/uncompiled. You can do this by removing the torch.compile call, or by using torch.compiler.set_stance("force_eager").

Developer debug context:

For more details about this graph break, please visit: https://meta-pytorch.github.io/compile-graph-break-site/gb/gb4315.html

from user code: File "bug.py", line 4, in f torch.ops.aten._assert_tensor_metadata.default(x, size=[10])

Fix Action

Fix / Workaround

Traceback (most recent call last):
  File "bug.py", line 8, in <module>
    torch.compile(f)(x)  # crashes
    ~~~~~~~~~~~~~~~~^^^
  File "/.../lib/python3.14/site-packages/torch/_dynamo/eval_frame.py", line 1041, in compile_wrapper
    return fn(*args, **kwargs)
  File "/.../lib/python3.14/site-packages/torch/_dynamo/convert_frame.py", line 2432, in __call__
    result = self._torchdynamo_orig_backend(
        frame, cache_entry, self.hooks, frame_state, skip=1
    )
  File "/.../lib/python3.14/site-packages/torch/_dynamo/convert_frame.py", line 2150, in __call__
    result = self._inner_convert(
        frame, cache_entry, hooks, frame_state, skip=skip + 1
    )
  File "/.../lib/python3.14/site-packages/torch/_dynamo/convert_frame.py", line 735, in __call__
    result = _compile(
        frame.f_code,
    ...<16 lines>...
        convert_frame_box=self._box,
    )
  File "/.../lib/python3.14/site-packages/torch/_dynamo/convert_frame.py", line 1919, in _compile
    guarded_code, tracer_output = compile_inner(code, one_graph, hooks)
                                  ~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^
  File "/.../lib/python3.14/site-packages/torch/_utils_internal.py", line 96, in wrapper_function
    return function(*args, **kwargs)
  File "/.../lib/python3.14/site-packages/torch/_dynamo/convert_frame.py", line 1535, in compile_inner
    result = _compile_inner(code, one_graph, hooks)
  File "/.../lib/python3.14/site-packages/torch/_dynamo/convert_frame.py", line 1594, in _compile_inner
    dynamo_output = compile_frame(
        code,
    ...<11 lines>...
        package=package,
    )
  File "/.../lib/python3.14/site-packages/torch/_dynamo/convert_frame.py", line 1442, in compile_frame
    bytecode, tracer_output = transform_code_object(code, transform)
                              ~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^
  File "/.../lib/python3.14/site-packages/torch/_dynamo/bytecode_transformation.py", line 1626, in transform_code_object
    tracer_output = transformations(instructions, code_options)
  File "/.../lib/python3.14/site-packages/torch/_dynamo/convert_frame.py", line 1414, in transform
    tracer_output = trace_frame(
        code,
    ...<14 lines>...
        package=package,
    )
  File "/.../lib/python3.14/site-packages/torch/_dynamo/convert_frame.py", line 342, in _fn
    return fn(*args, **kwargs)
  File "/.../lib/python3.14/site-packages/torch/_dynamo/convert_frame.py", line 875, in trace_frame
    run_tracer()
    ~~~~~~~~~~^^
  File "/.../lib/python3.14/site-packages/torch/_dynamo/convert_frame.py", line 856, in run_tracer
    tracer.run()
    ~~~~~~~~~~^^
  File "/.../lib/python3.14/site-packages/torch/_dynamo/symbolic_convert.py", line 1704, in run
    while self.step():
          ~~~~~~~~~^^
  File "/.../lib/python3.14/site-packages/torch/_dynamo/symbolic_convert.py", line 1371, in step
    self.dispatch_table[inst.opcode](self, inst)
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^
  File "/.../lib/python3.14/site-packages/torch/_dynamo/symbolic_convert.py", line 908, in wrapper
    return inner_fn(self, inst)
  File "/.../lib/python3.14/site-packages/torch/_dynamo/symbolic_convert.py", line 4276, in CALL_KW
    self._call(inst, call_kw=True)
    ~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^
  File "/.../lib/python3.14/site-packages/torch/_dynamo/symbolic_convert.py", line 4052, in _call
    self.call_function(fn, args, kwargs)
    ~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^
  File "/.../lib/python3.14/site-packages/torch/_dynamo/symbolic_convert.py", line 1272, in call_function
    self.push(fn.call_function(self, args, kwargs))  # type: ignore[arg-type]
              ~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^
  File "/.../lib/python3.14/site-packages/torch/_dynamo/variables/torch.py", line 2600, in call_function
    tensor_variable = wrap_fx_proxy(
        tx=tx,
    ...<4 lines>...
        ),
    )
  File "/.../lib/python3.14/site-packages/torch/_dynamo/variables/builder.py", line 3073, in wrap_fx_proxy
    return wrap_fx_proxy_cls(target_cls=TensorVariable, **kwargs)
  File "/.../lib/python3.14/site-packages/torch/_dynamo/variables/builder.py", line 3148, in wrap_fx_proxy_cls
    out: VTTypeAlias = _wrap_fx_proxy(
                       ~~~~~~~~~~~~~~^
        target_cls, tx, proxy, example_value, subclass_type, **options
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    )
    ^
  File "/.../lib/python3.14/site-packages/torch/_dynamo/variables/builder.py", line 3272, in _wrap_fx_proxy
    example_value = get_fake_value(proxy.node, tx, allow_non_graph_fake=True)
  File "/.../lib/python3.14/site-packages/torch/_dynamo/utils.py", line 3736, in get_fake_value
    return _get_fake_value_impl(node, tx, allow_non_graph_fake)
  File "/.../lib/python3.14/site-packages/torch/_dynamo/utils.py", line 3927, in _get_fake_value_impl
    _wrap_graph_break_with_torch_runtime_err(
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
        lambda: unimplemented(
        ^^^^^^^^^^^^^^^^^^^^^^
    ...<5 lines>...
        )
        ^
    )
    ^
  File "/.../lib/python3.14/site-packages/torch/_dynamo/utils.py", line 3725, in _wrap_graph_break_with_torch_runtime_err
    raise exc.with_traceback(e.__traceback__) from None
  File "/.../lib/python3.14/site-packages/torch/_dynamo/utils.py", line 3722, in _wrap_graph_break_with_torch_runtime_err
    gb_fn()
    ~~~~~^^
  File "/.../lib/python3.14/site-packages/torch/_dynamo/utils.py", line 3928, in <lambda>
    lambda: unimplemented(
            ~~~~~~~~~~~~~^
        gb_type="RuntimeError when making fake tensor call",
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    ...<3 lines>...
        from_exc=cause,
        ^^^^^^^^^^^^^^^
    )
    ^
  File "/.../lib/python3.14/site-packages/torch/_dynamo/exc.py", line 653, in unimplemented
    raise Unsupported(
        msg, gb_type, skip_frame, real_stack=past_real_stack
    ) from from_exc
torch._dynamo.exc.TorchRuntimeError: RuntimeError when making fake tensor call
  Explanation: Dynamo failed to run FX node with fake tensors: call_function aten._assert_tensor_metadata.default(*(FakeTensor(..., size=(10,)),), **{'size': [10]}): got AssertionError('Tensor sizes mismatch! Expected: [10], Got: torch.Size([10])')
  Hint: Your code may result in an error when running in eager. Please double check that your code doesn't contain a similar error when actually running eager/uncompiled. You can do this by removing the `torch.compile` call, or by using `torch.compiler.set_stance("force_eager")`.

PR fix notes

PR #179884: Fix aten._assert_tensor_metadata.default's fake implementation

Description (problem / solution / changelog)

This PR fixes aten._assert_tensor_metadata.default's fake implementation by aligning it with the correct signature (previously size was assumed to be a torch.Size and stride was assumed to be a tuple).

Closes #179883.

Changed files

  • test/test_fake_tensor.py (modified, +5/-0)
  • torch/_subclasses/fake_impls.py (modified, +8/-8)

Code Example

import torch

def f(x: torch.Tensor):
    torch.ops.aten._assert_tensor_metadata.default(x, size=[10])

x = torch.empty(10)
f(x)                 # works
torch.compile(f)(x)  # crashes

---

Traceback (most recent call last):
  File "bug.py", line 8, in <module>
    torch.compile(f)(x)  # crashes
    ~~~~~~~~~~~~~~~~^^^
  File "/.../lib/python3.14/site-packages/torch/_dynamo/eval_frame.py", line 1041, in compile_wrapper
    return fn(*args, **kwargs)
  File "/.../lib/python3.14/site-packages/torch/_dynamo/convert_frame.py", line 2432, in __call__
    result = self._torchdynamo_orig_backend(
        frame, cache_entry, self.hooks, frame_state, skip=1
    )
  File "/.../lib/python3.14/site-packages/torch/_dynamo/convert_frame.py", line 2150, in __call__
    result = self._inner_convert(
        frame, cache_entry, hooks, frame_state, skip=skip + 1
    )
  File "/.../lib/python3.14/site-packages/torch/_dynamo/convert_frame.py", line 735, in __call__
    result = _compile(
        frame.f_code,
    ...<16 lines>...
        convert_frame_box=self._box,
    )
  File "/.../lib/python3.14/site-packages/torch/_dynamo/convert_frame.py", line 1919, in _compile
    guarded_code, tracer_output = compile_inner(code, one_graph, hooks)
                                  ~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^
  File "/.../lib/python3.14/site-packages/torch/_utils_internal.py", line 96, in wrapper_function
    return function(*args, **kwargs)
  File "/.../lib/python3.14/site-packages/torch/_dynamo/convert_frame.py", line 1535, in compile_inner
    result = _compile_inner(code, one_graph, hooks)
  File "/.../lib/python3.14/site-packages/torch/_dynamo/convert_frame.py", line 1594, in _compile_inner
    dynamo_output = compile_frame(
        code,
    ...<11 lines>...
        package=package,
    )
  File "/.../lib/python3.14/site-packages/torch/_dynamo/convert_frame.py", line 1442, in compile_frame
    bytecode, tracer_output = transform_code_object(code, transform)
                              ~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^
  File "/.../lib/python3.14/site-packages/torch/_dynamo/bytecode_transformation.py", line 1626, in transform_code_object
    tracer_output = transformations(instructions, code_options)
  File "/.../lib/python3.14/site-packages/torch/_dynamo/convert_frame.py", line 1414, in transform
    tracer_output = trace_frame(
        code,
    ...<14 lines>...
        package=package,
    )
  File "/.../lib/python3.14/site-packages/torch/_dynamo/convert_frame.py", line 342, in _fn
    return fn(*args, **kwargs)
  File "/.../lib/python3.14/site-packages/torch/_dynamo/convert_frame.py", line 875, in trace_frame
    run_tracer()
    ~~~~~~~~~~^^
  File "/.../lib/python3.14/site-packages/torch/_dynamo/convert_frame.py", line 856, in run_tracer
    tracer.run()
    ~~~~~~~~~~^^
  File "/.../lib/python3.14/site-packages/torch/_dynamo/symbolic_convert.py", line 1704, in run
    while self.step():
          ~~~~~~~~~^^
  File "/.../lib/python3.14/site-packages/torch/_dynamo/symbolic_convert.py", line 1371, in step
    self.dispatch_table[inst.opcode](self, inst)
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^
  File "/.../lib/python3.14/site-packages/torch/_dynamo/symbolic_convert.py", line 908, in wrapper
    return inner_fn(self, inst)
  File "/.../lib/python3.14/site-packages/torch/_dynamo/symbolic_convert.py", line 4276, in CALL_KW
    self._call(inst, call_kw=True)
    ~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^
  File "/.../lib/python3.14/site-packages/torch/_dynamo/symbolic_convert.py", line 4052, in _call
    self.call_function(fn, args, kwargs)
    ~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^
  File "/.../lib/python3.14/site-packages/torch/_dynamo/symbolic_convert.py", line 1272, in call_function
    self.push(fn.call_function(self, args, kwargs))  # type: ignore[arg-type]
              ~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^
  File "/.../lib/python3.14/site-packages/torch/_dynamo/variables/torch.py", line 2600, in call_function
    tensor_variable = wrap_fx_proxy(
        tx=tx,
    ...<4 lines>...
        ),
    )
  File "/.../lib/python3.14/site-packages/torch/_dynamo/variables/builder.py", line 3073, in wrap_fx_proxy
    return wrap_fx_proxy_cls(target_cls=TensorVariable, **kwargs)
  File "/.../lib/python3.14/site-packages/torch/_dynamo/variables/builder.py", line 3148, in wrap_fx_proxy_cls
    out: VTTypeAlias = _wrap_fx_proxy(
                       ~~~~~~~~~~~~~~^
        target_cls, tx, proxy, example_value, subclass_type, **options
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    )
    ^
  File "/.../lib/python3.14/site-packages/torch/_dynamo/variables/builder.py", line 3272, in _wrap_fx_proxy
    example_value = get_fake_value(proxy.node, tx, allow_non_graph_fake=True)
  File "/.../lib/python3.14/site-packages/torch/_dynamo/utils.py", line 3736, in get_fake_value
    return _get_fake_value_impl(node, tx, allow_non_graph_fake)
  File "/.../lib/python3.14/site-packages/torch/_dynamo/utils.py", line 3927, in _get_fake_value_impl
    _wrap_graph_break_with_torch_runtime_err(
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
        lambda: unimplemented(
        ^^^^^^^^^^^^^^^^^^^^^^
    ...<5 lines>...
        )
        ^
    )
    ^
  File "/.../lib/python3.14/site-packages/torch/_dynamo/utils.py", line 3725, in _wrap_graph_break_with_torch_runtime_err
    raise exc.with_traceback(e.__traceback__) from None
  File "/.../lib/python3.14/site-packages/torch/_dynamo/utils.py", line 3722, in _wrap_graph_break_with_torch_runtime_err
    gb_fn()
    ~~~~~^^
  File "/.../lib/python3.14/site-packages/torch/_dynamo/utils.py", line 3928, in <lambda>
    lambda: unimplemented(
            ~~~~~~~~~~~~~^
        gb_type="RuntimeError when making fake tensor call",
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    ...<3 lines>...
        from_exc=cause,
        ^^^^^^^^^^^^^^^
    )
    ^
  File "/.../lib/python3.14/site-packages/torch/_dynamo/exc.py", line 653, in unimplemented
    raise Unsupported(
        msg, gb_type, skip_frame, real_stack=past_real_stack
    ) from from_exc
torch._dynamo.exc.TorchRuntimeError: RuntimeError when making fake tensor call
  Explanation: Dynamo failed to run FX node with fake tensors: call_function aten._assert_tensor_metadata.default(*(FakeTensor(..., size=(10,)),), **{'size': [10]}): got AssertionError('Tensor sizes mismatch! Expected: [10], Got: torch.Size([10])')
  Hint: Your code may result in an error when running in eager. Please double check that your code doesn't contain a similar error when actually running eager/uncompiled. You can do this by removing the `torch.compile` call, or by using `torch.compiler.set_stance("force_eager")`. 

  Developer debug context: 

 For more details about this graph break, please visit: https://meta-pytorch.github.io/compile-graph-break-site/gb/gb4315.html

from user code:
   File "bug.py", line 4, in f
    torch.ops.aten._assert_tensor_metadata.default(x, size=[10])

---

Collecting environment information...
PyTorch version: N/A
Is debug build: N/A
CUDA used to build PyTorch: N/A
ROCM used to build PyTorch: N/A

OS: macOS 26.3.1 (arm64)
GCC version: Could not collect
Clang version: 17.0.0 (clang-1700.6.3.2)
CMake version: version 4.2.3
Libc version: N/A

Python version: 3.14.2 (v3.14.2:df793163d58, Dec  5 2025, 12:18:06) [Clang 16.0.0 (clang-1600.0.26.6)] (64-bit runtime)
Python platform: macOS-26.3.1-arm64-arm-64bit-Mach-O
Is CUDA available: N/A
CUDA runtime version: Could not collect
CUDA_MODULE_LOADING set to: N/A
GPU models and configuration: Could not collect
Nvidia driver version: Could not collect
cuDNN version: Could not collect
Is XPU available: N/A
HIP runtime version: N/A
MIOpen runtime version: N/A
Is XNNPACK available: N/A
Caching allocator config: N/A

CPU:
Apple M4 Pro

Versions of relevant libraries:
[pip3] No relevant packages
[conda] Could not collect
RAW_BUFFERClick to expand / collapse

🐛 Describe the bug

import torch

def f(x: torch.Tensor):
    torch.ops.aten._assert_tensor_metadata.default(x, size=[10])

x = torch.empty(10)
f(x)                 # works
torch.compile(f)(x)  # crashes

Error logs

Traceback (most recent call last):
  File "bug.py", line 8, in <module>
    torch.compile(f)(x)  # crashes
    ~~~~~~~~~~~~~~~~^^^
  File "/.../lib/python3.14/site-packages/torch/_dynamo/eval_frame.py", line 1041, in compile_wrapper
    return fn(*args, **kwargs)
  File "/.../lib/python3.14/site-packages/torch/_dynamo/convert_frame.py", line 2432, in __call__
    result = self._torchdynamo_orig_backend(
        frame, cache_entry, self.hooks, frame_state, skip=1
    )
  File "/.../lib/python3.14/site-packages/torch/_dynamo/convert_frame.py", line 2150, in __call__
    result = self._inner_convert(
        frame, cache_entry, hooks, frame_state, skip=skip + 1
    )
  File "/.../lib/python3.14/site-packages/torch/_dynamo/convert_frame.py", line 735, in __call__
    result = _compile(
        frame.f_code,
    ...<16 lines>...
        convert_frame_box=self._box,
    )
  File "/.../lib/python3.14/site-packages/torch/_dynamo/convert_frame.py", line 1919, in _compile
    guarded_code, tracer_output = compile_inner(code, one_graph, hooks)
                                  ~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^
  File "/.../lib/python3.14/site-packages/torch/_utils_internal.py", line 96, in wrapper_function
    return function(*args, **kwargs)
  File "/.../lib/python3.14/site-packages/torch/_dynamo/convert_frame.py", line 1535, in compile_inner
    result = _compile_inner(code, one_graph, hooks)
  File "/.../lib/python3.14/site-packages/torch/_dynamo/convert_frame.py", line 1594, in _compile_inner
    dynamo_output = compile_frame(
        code,
    ...<11 lines>...
        package=package,
    )
  File "/.../lib/python3.14/site-packages/torch/_dynamo/convert_frame.py", line 1442, in compile_frame
    bytecode, tracer_output = transform_code_object(code, transform)
                              ~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^
  File "/.../lib/python3.14/site-packages/torch/_dynamo/bytecode_transformation.py", line 1626, in transform_code_object
    tracer_output = transformations(instructions, code_options)
  File "/.../lib/python3.14/site-packages/torch/_dynamo/convert_frame.py", line 1414, in transform
    tracer_output = trace_frame(
        code,
    ...<14 lines>...
        package=package,
    )
  File "/.../lib/python3.14/site-packages/torch/_dynamo/convert_frame.py", line 342, in _fn
    return fn(*args, **kwargs)
  File "/.../lib/python3.14/site-packages/torch/_dynamo/convert_frame.py", line 875, in trace_frame
    run_tracer()
    ~~~~~~~~~~^^
  File "/.../lib/python3.14/site-packages/torch/_dynamo/convert_frame.py", line 856, in run_tracer
    tracer.run()
    ~~~~~~~~~~^^
  File "/.../lib/python3.14/site-packages/torch/_dynamo/symbolic_convert.py", line 1704, in run
    while self.step():
          ~~~~~~~~~^^
  File "/.../lib/python3.14/site-packages/torch/_dynamo/symbolic_convert.py", line 1371, in step
    self.dispatch_table[inst.opcode](self, inst)
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^
  File "/.../lib/python3.14/site-packages/torch/_dynamo/symbolic_convert.py", line 908, in wrapper
    return inner_fn(self, inst)
  File "/.../lib/python3.14/site-packages/torch/_dynamo/symbolic_convert.py", line 4276, in CALL_KW
    self._call(inst, call_kw=True)
    ~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^
  File "/.../lib/python3.14/site-packages/torch/_dynamo/symbolic_convert.py", line 4052, in _call
    self.call_function(fn, args, kwargs)
    ~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^
  File "/.../lib/python3.14/site-packages/torch/_dynamo/symbolic_convert.py", line 1272, in call_function
    self.push(fn.call_function(self, args, kwargs))  # type: ignore[arg-type]
              ~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^
  File "/.../lib/python3.14/site-packages/torch/_dynamo/variables/torch.py", line 2600, in call_function
    tensor_variable = wrap_fx_proxy(
        tx=tx,
    ...<4 lines>...
        ),
    )
  File "/.../lib/python3.14/site-packages/torch/_dynamo/variables/builder.py", line 3073, in wrap_fx_proxy
    return wrap_fx_proxy_cls(target_cls=TensorVariable, **kwargs)
  File "/.../lib/python3.14/site-packages/torch/_dynamo/variables/builder.py", line 3148, in wrap_fx_proxy_cls
    out: VTTypeAlias = _wrap_fx_proxy(
                       ~~~~~~~~~~~~~~^
        target_cls, tx, proxy, example_value, subclass_type, **options
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    )
    ^
  File "/.../lib/python3.14/site-packages/torch/_dynamo/variables/builder.py", line 3272, in _wrap_fx_proxy
    example_value = get_fake_value(proxy.node, tx, allow_non_graph_fake=True)
  File "/.../lib/python3.14/site-packages/torch/_dynamo/utils.py", line 3736, in get_fake_value
    return _get_fake_value_impl(node, tx, allow_non_graph_fake)
  File "/.../lib/python3.14/site-packages/torch/_dynamo/utils.py", line 3927, in _get_fake_value_impl
    _wrap_graph_break_with_torch_runtime_err(
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
        lambda: unimplemented(
        ^^^^^^^^^^^^^^^^^^^^^^
    ...<5 lines>...
        )
        ^
    )
    ^
  File "/.../lib/python3.14/site-packages/torch/_dynamo/utils.py", line 3725, in _wrap_graph_break_with_torch_runtime_err
    raise exc.with_traceback(e.__traceback__) from None
  File "/.../lib/python3.14/site-packages/torch/_dynamo/utils.py", line 3722, in _wrap_graph_break_with_torch_runtime_err
    gb_fn()
    ~~~~~^^
  File "/.../lib/python3.14/site-packages/torch/_dynamo/utils.py", line 3928, in <lambda>
    lambda: unimplemented(
            ~~~~~~~~~~~~~^
        gb_type="RuntimeError when making fake tensor call",
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    ...<3 lines>...
        from_exc=cause,
        ^^^^^^^^^^^^^^^
    )
    ^
  File "/.../lib/python3.14/site-packages/torch/_dynamo/exc.py", line 653, in unimplemented
    raise Unsupported(
        msg, gb_type, skip_frame, real_stack=past_real_stack
    ) from from_exc
torch._dynamo.exc.TorchRuntimeError: RuntimeError when making fake tensor call
  Explanation: Dynamo failed to run FX node with fake tensors: call_function aten._assert_tensor_metadata.default(*(FakeTensor(..., size=(10,)),), **{'size': [10]}): got AssertionError('Tensor sizes mismatch! Expected: [10], Got: torch.Size([10])')
  Hint: Your code may result in an error when running in eager. Please double check that your code doesn't contain a similar error when actually running eager/uncompiled. You can do this by removing the `torch.compile` call, or by using `torch.compiler.set_stance("force_eager")`. 

  Developer debug context: 

 For more details about this graph break, please visit: https://meta-pytorch.github.io/compile-graph-break-site/gb/gb4315.html

from user code:
   File "bug.py", line 4, in f
    torch.ops.aten._assert_tensor_metadata.default(x, size=[10])

Versions

Collecting environment information...
PyTorch version: N/A
Is debug build: N/A
CUDA used to build PyTorch: N/A
ROCM used to build PyTorch: N/A

OS: macOS 26.3.1 (arm64)
GCC version: Could not collect
Clang version: 17.0.0 (clang-1700.6.3.2)
CMake version: version 4.2.3
Libc version: N/A

Python version: 3.14.2 (v3.14.2:df793163d58, Dec  5 2025, 12:18:06) [Clang 16.0.0 (clang-1600.0.26.6)] (64-bit runtime)
Python platform: macOS-26.3.1-arm64-arm-64bit-Mach-O
Is CUDA available: N/A
CUDA runtime version: Could not collect
CUDA_MODULE_LOADING set to: N/A
GPU models and configuration: Could not collect
Nvidia driver version: Could not collect
cuDNN version: Could not collect
Is XPU available: N/A
HIP runtime version: N/A
MIOpen runtime version: N/A
Is XNNPACK available: N/A
Caching allocator config: N/A

CPU:
Apple M4 Pro

Versions of relevant libraries:
[pip3] No relevant packages
[conda] Could not collect

cc @chauhang @penguinwu @eellison @aorenste @bdhirsh @bobrenjc93

extent analysis

TL;DR

The issue can be resolved by ensuring that the size argument in torch.ops.aten._assert_tensor_metadata.default is a torch.Size object instead of a list.

Guidance

  • The error occurs because torch.compile fails to run the FX node with fake tensors due to a mismatch in tensor sizes.
  • The size argument in torch.ops.aten._assert_tensor_metadata.default should be a torch.Size object, not a list.
  • To fix the issue, modify the f function to pass a torch.Size object as the size argument.
  • Verify that the code runs without errors after applying the fix.

Example

import torch

def f(x: torch.Tensor):
    torch.ops.aten._assert_tensor_metadata.default(x, size=torch.Size([10]))

x = torch.empty(10)
f(x)                 # works
torch.compile(f)(x)  # should work after fix

Notes

  • The provided error logs and stacktrace suggest that the issue is related to the torch.compile functionality and the way it handles fake tensors.
  • The fix assumes that the torch.Size object is the correct type for the size argument, based on the error message.

Recommendation

Apply workaround: Modify the size argument to be a torch.Size object, as shown in the example code. This should resolve the issue and allow the code to run without errors.

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 `torch.compile` crashes on `aten._assert_tensor_metadata.default` [1 pull requests]