pytorch - 💡(How to fix) Fix [inductor] Tensor.view(dtype) after transpose().contiguous() fails with stale non-contiguous stride

Official PRs (…)
ON THIS PAGE

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

import torch import traceback

def fn(): x = torch.tensor( [[1.0, -2.5, 0.0], [3.25, -0.0, 5.5]], dtype=torch.float32, ).t() y = x.contiguous().view(torch.uint8) return y, torch.count_nonzero(y, dim=1)

try: eager = fn() print("eager_ok") print(eager[0]) print(eager[1]) except Exception: print("eager_error") traceback.print_exc(limit=10)

try: compiled = torch.compile(fn, backend="inductor") out = compiled() print("compiled_ok") print(out[0]) print(out[1]) except Exception: print("compiled_error") traceback.print_exc(limit=20)

Fix Action

Fix / Workaround

try: compiled = torch.compile(fn, backend="inductor") out = compiled() print("compiled_ok") print(out[0]) print(out[1]) except Exception: print("compiled_error") traceback.print_exc(limit=20)

Output:

eager_ok tensor([[ 0, 0, 128, 63, 0, 0, 80, 64], [ 0, 0, 32, 192, 0, 0, 0, 128], [ 0, 0, 0, 0, 0, 0, 176, 64]], dtype=torch.uint8) tensor([4, 3, 2]) E0528 13:33:48.714000 47742 torch/_subclasses/fake_tensor.py:2964] [5/0] failed while attempting to run meta for aten.view.dtype E0528 13:33:48.714000 47742 torch/_subclasses/fake_tensor.py:2964] [5/0] Traceback (most recent call last): E0528 13:33:48.714000 47742 torch/_subclasses/fake_tensor.py:2964] [5/0] File "/usr/local/lib/python3.12/dist-packages/torch/_subclasses/fake_tensor.py", line 2960, in _dispatch_impl E0528 13:33:48.714000 47742 torch/_subclasses/fake_tensor.py:2964] [5/0] r = func(*args, **kwargs) E0528 13:33:48.714000 47742 torch/_subclasses/fake_tensor.py:2964] [5/0] ^^^^^^^^^^^^^^^^^^^^^ E0528 13:33:48.714000 47742 torch/_subclasses/fake_tensor.py:2964] [5/0] File "/usr/local/lib/python3.12/dist-packages/torch/_ops.py", line 871, in call E0528 13:33:48.714000 47742 torch/_subclasses/fake_tensor.py:2964] [5/0] return self._op(*args, **kwargs) E0528 13:33:48.714000 47742 torch/_subclasses/fake_tensor.py:2964] [5/0] ^^^^^^^^^^^^^^^^^^^^^^^^^ E0528 13:33:48.714000 47742 torch/_subclasses/fake_tensor.py:2964] [5/0] RuntimeError: self.stride(-1) must be 1 to view Float as Byte (different element sizes), but got 3 compiled_error Traceback (most recent call last): File "/tmp/ipykernel_47742/831324313.py", line 25, in <cell line: 0> out = compiled() ^^^^^^^^^^ File "/usr/local/lib/python3.12/dist-packages/torch/_dynamo/eval_frame.py", line 1160, in compile_wrapper raise e.remove_dynamo_frames() from None # see TORCHDYNAMO_VERBOSE=1 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.12/dist-packages/torch/_inductor/compile_fx.py", line 1078, in _compile_fx_inner raise InductorError(e, currentframe()).with_traceback( File "/usr/local/lib/python3.12/dist-packages/torch/_inductor/compile_fx.py", line 1058, in _compile_fx_inner mb_compiled_graph = fx_codegen_and_compile( ^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.12/dist-packages/torch/_inductor/compile_fx.py", line 1846, in fx_codegen_and_compile return scheme.codegen_and_compile(gm, example_inputs, inputs_to_check, graph_kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.12/dist-packages/torch/_inductor/compile_fx.py", line 1522, in codegen_and_compile graph.run(*example_inputs) File "/usr/local/lib/python3.12/dist-packages/torch/_inductor/graph.py", line 1079, in run return super().run(*args) ^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.12/dist-packages/torch/fx/interpreter.py", line 197, in run self.env[node] = self.run_node(node) ^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.12/dist-packages/torch/_inductor/graph.py", line 1932, in run_node result = super().run_node(n) ^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.12/dist-packages/torch/fx/interpreter.py", line 294, in run_node return getattr(self, n.op)(n.target, args, kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.12/dist-packages/torch/_inductor/graph.py", line 1504, in call_function raise LoweringException( File "/usr/local/lib/python3.12/dist-packages/torch/_inductor/graph.py", line 1481, in call_function out = lowerings[target](*args, **kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.12/dist-packages/torch/_inductor/lowering.py", line 513, in wrapped out = decomp_fn(*args, **kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.12/dist-packages/torch/_inductor/lowering.py", line 997, in _view_dtype return to_dtype_bitcast(x, dtype) ^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.12/dist-packages/torch/_inductor/lowering.py", line 986, in to_dtype_bitcast return fallback_handler(aten.view.dtype)(x, dtype) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.12/dist-packages/torch/_inductor/lowering.py", line 2495, in handler wrap_tensors, ir.FallbackKernel.create(kernel, *args, **kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.12/dist-packages/torch/_inductor/ir.py", line 9129, in create ) = cls.process_kernel(kernel, *args, **kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.12/dist-packages/torch/_inductor/ir.py", line 6761, in process_kernel example_output = kernel(*new_args, **new_kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.12/dist-packages/torch/_ops.py", line 871, in call return self._op(*args, **kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.12/dist-packages/torch/_compile.py", line 54, in inner return disable_fn(*args, **kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^ torch._inductor.exc.InductorError: LoweringException: RuntimeError: self.stride(-1) must be 1 to view Float as Byte (different element sizes), but got 3 target: aten.view.dtype args[0]: TensorBox(StorageBox( ComputedBuffer(name='buf0', layout=FixedLayout('cpu', torch.float32, size=[3, 2], stride=[1, 3]), data=Pointwise( 'cpu', torch.float32, def inner_fn(index): i0, i1 = index tmp0 = ops.load(_tensor_constant0, i0 + 3 * i1) return tmp0 , ranges=[3, 2], origin_node=clone, origins=OrderedSet([clone, permute, lift_fresh_copy]), stack_traces = {, File "/tmp/ipykernel_47742/831324313.py", line 9, in fn, y = x.contiguous().view(torch.uint8), ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^, , }, stack_traces = {, File "/tmp/ipykernel_47742/831324313.py", line 8, in fn, ).t(), ^^^, , }, stack_traces = {, File "/tmp/ipykernel_47742/831324313.py", line 5, in fn, x = torch.tensor(, ^^^^^^^^^^^^^, , } ), _split_size=None, _original_inner_fn=None, _original_ranges=None, _original_reduction_ranges=None) )) args[1]: torch.uint8RuntimeError: self.stride(-1) must be 1 to view Float as Byte (different element sizes), but got 3 target: aten.view.dtype args[0]: TensorBox(StorageBox( ComputedBuffer(name='buf0', layout=FixedLayout('cpu', torch.float32, size=[3, 2], stride=[1, 3]), data=Pointwise( 'cpu', torch.float32, def inner_fn(index): i0, i1 = index tmp0 = ops.load(_tensor_constant0, i0 + 3 * i1) return tmp0 , ranges=[3, 2], origin_node=clone, origins=OrderedSet([clone, permute, lift_fresh_copy]), stack_traces = {, File "/tmp/ipykernel_47742/831324313.py", line 9, in fn, y = x.contiguous().view(torch.uint8), ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^, , }, stack_traces = {, File "/tmp/ipykernel_47742/831324313.py", line 8, in fn, ).t(), ^^^, , }, stack_traces = {, File "/tmp/ipykernel_47742/831324313.py", line 5, in fn, x = torch.tensor(, ^^^^^^^^^^^^^, , } ), _split_size=None, _original_inner_fn=None, _original_ranges=None, _original_reduction_ranges=None) )) args[1]: torch.uint8 Found from : File "/tmp/ipykernel_47742/831324313.py", line 9, in fn y = x.contiguous().view(torch.uint8) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Code Example

import torch
import traceback

def fn():
    x = torch.tensor(
        [[1.0, -2.5, 0.0], [3.25, -0.0, 5.5]],
        dtype=torch.float32,
    ).t()
    y = x.contiguous().view(torch.uint8)
    return y, torch.count_nonzero(y, dim=1)

try:
    eager = fn()
    print("eager_ok")
    print(eager[0])
    print(eager[1])
except Exception:
    print("eager_error")
    traceback.print_exc(limit=10)

try:
    compiled = torch.compile(fn, backend="inductor")
    out = compiled()
    print("compiled_ok")
    print(out[0])
    print(out[1])
except Exception:
    print("compiled_error")
    traceback.print_exc(limit=20)

---

eager_ok
tensor([[  0,   0, 128,  63,   0,   0,  80,  64],
        [  0,   0,  32, 192,   0,   0,   0, 128],
        [  0,   0,   0,   0,   0,   0, 176,  64]], dtype=torch.uint8)
tensor([4, 3, 2])
E0528 13:33:48.714000 47742 torch/_subclasses/fake_tensor.py:2964] [5/0] failed while attempting to run meta for aten.view.dtype
E0528 13:33:48.714000 47742 torch/_subclasses/fake_tensor.py:2964] [5/0] Traceback (most recent call last):
E0528 13:33:48.714000 47742 torch/_subclasses/fake_tensor.py:2964] [5/0]   File "/usr/local/lib/python3.12/dist-packages/torch/_subclasses/fake_tensor.py", line 2960, in _dispatch_impl
E0528 13:33:48.714000 47742 torch/_subclasses/fake_tensor.py:2964] [5/0]     r = func(*args, **kwargs)
E0528 13:33:48.714000 47742 torch/_subclasses/fake_tensor.py:2964] [5/0]         ^^^^^^^^^^^^^^^^^^^^^
E0528 13:33:48.714000 47742 torch/_subclasses/fake_tensor.py:2964] [5/0]   File "/usr/local/lib/python3.12/dist-packages/torch/_ops.py", line 871, in __call__
E0528 13:33:48.714000 47742 torch/_subclasses/fake_tensor.py:2964] [5/0]     return self._op(*args, **kwargs)
E0528 13:33:48.714000 47742 torch/_subclasses/fake_tensor.py:2964] [5/0]            ^^^^^^^^^^^^^^^^^^^^^^^^^
E0528 13:33:48.714000 47742 torch/_subclasses/fake_tensor.py:2964] [5/0] RuntimeError: self.stride(-1) must be 1 to view Float as Byte (different element sizes), but got 3
compiled_error
Traceback (most recent call last):
  File "/tmp/ipykernel_47742/831324313.py", line 25, in <cell line: 0>
    out = compiled()
          ^^^^^^^^^^
  File "/usr/local/lib/python3.12/dist-packages/torch/_dynamo/eval_frame.py", line 1160, in compile_wrapper
    raise e.remove_dynamo_frames() from None  # see TORCHDYNAMO_VERBOSE=1
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/dist-packages/torch/_inductor/compile_fx.py", line 1078, in _compile_fx_inner
    raise InductorError(e, currentframe()).with_traceback(
  File "/usr/local/lib/python3.12/dist-packages/torch/_inductor/compile_fx.py", line 1058, in _compile_fx_inner
    mb_compiled_graph = fx_codegen_and_compile(
                        ^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/dist-packages/torch/_inductor/compile_fx.py", line 1846, in fx_codegen_and_compile
    return scheme.codegen_and_compile(gm, example_inputs, inputs_to_check, graph_kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/dist-packages/torch/_inductor/compile_fx.py", line 1522, in codegen_and_compile
    graph.run(*example_inputs)
  File "/usr/local/lib/python3.12/dist-packages/torch/_inductor/graph.py", line 1079, in run
    return super().run(*args)
           ^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/dist-packages/torch/fx/interpreter.py", line 197, in run
    self.env[node] = self.run_node(node)
                     ^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/dist-packages/torch/_inductor/graph.py", line 1932, in run_node
    result = super().run_node(n)
             ^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/dist-packages/torch/fx/interpreter.py", line 294, in run_node
    return getattr(self, n.op)(n.target, args, kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/dist-packages/torch/_inductor/graph.py", line 1504, in call_function
    raise LoweringException(
  File "/usr/local/lib/python3.12/dist-packages/torch/_inductor/graph.py", line 1481, in call_function
    out = lowerings[target](*args, **kwargs)
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/dist-packages/torch/_inductor/lowering.py", line 513, in wrapped
    out = decomp_fn(*args, **kwargs)
          ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/dist-packages/torch/_inductor/lowering.py", line 997, in _view_dtype
    return to_dtype_bitcast(x, dtype)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/dist-packages/torch/_inductor/lowering.py", line 986, in to_dtype_bitcast
    return fallback_handler(aten.view.dtype)(x, dtype)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/dist-packages/torch/_inductor/lowering.py", line 2495, in handler
    wrap_tensors, ir.FallbackKernel.create(kernel, *args, **kwargs)
                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/dist-packages/torch/_inductor/ir.py", line 9129, in create
    ) = cls.process_kernel(kernel, *args, **kwargs)
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/dist-packages/torch/_inductor/ir.py", line 6761, in process_kernel
    example_output = kernel(*new_args, **new_kwargs)
                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/dist-packages/torch/_ops.py", line 871, in __call__
    return self._op(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/dist-packages/torch/_compile.py", line 54, in inner
    return disable_fn(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^
torch._inductor.exc.InductorError: LoweringException: RuntimeError: self.stride(-1) must be 1 to view Float as Byte (different element sizes), but got 3
  target: aten.view.dtype
  args[0]: TensorBox(StorageBox(
    ComputedBuffer(name='buf0', layout=FixedLayout('cpu', torch.float32, size=[3, 2], stride=[1, 3]), data=Pointwise(
      'cpu',
      torch.float32,
      def inner_fn(index):
          i0, i1 = index
          tmp0 = ops.load(_tensor_constant0, i0 + 3 * i1)
          return tmp0
      ,
      ranges=[3, 2],
      origin_node=clone,
      origins=OrderedSet([clone, permute, lift_fresh_copy]),
      stack_traces = {,
        File "/tmp/ipykernel_47742/831324313.py", line 9, in fn,
          y = x.contiguous().view(torch.uint8),
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^,
      ,
      },
      stack_traces = {,
        File "/tmp/ipykernel_47742/831324313.py", line 8, in fn,
          ).t(),
            ^^^,
      ,
      },
      stack_traces = {,
        File "/tmp/ipykernel_47742/831324313.py", line 5, in fn,
          x = torch.tensor(,
              ^^^^^^^^^^^^^,
      ,
      }
    ), _split_size=None, _original_inner_fn=None, _original_ranges=None, _original_reduction_ranges=None)
  ))
  args[1]: torch.uint8RuntimeError: self.stride(-1) must be 1 to view Float as Byte (different element sizes), but got 3
  target: aten.view.dtype
  args[0]: TensorBox(StorageBox(
    ComputedBuffer(name='buf0', layout=FixedLayout('cpu', torch.float32, size=[3, 2], stride=[1, 3]), data=Pointwise(
      'cpu',
      torch.float32,
      def inner_fn(index):
          i0, i1 = index
          tmp0 = ops.load(_tensor_constant0, i0 + 3 * i1)
          return tmp0
      ,
      ranges=[3, 2],
      origin_node=clone,
      origins=OrderedSet([clone, permute, lift_fresh_copy]),
      stack_traces = {,
        File "/tmp/ipykernel_47742/831324313.py", line 9, in fn,
          y = x.contiguous().view(torch.uint8),
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^,
      ,
      },
      stack_traces = {,
        File "/tmp/ipykernel_47742/831324313.py", line 8, in fn,
          ).t(),
            ^^^,
      ,
      },
      stack_traces = {,
        File "/tmp/ipykernel_47742/831324313.py", line 5, in fn,
          x = torch.tensor(,
              ^^^^^^^^^^^^^,
      ,
      }
    ), _split_size=None, _original_inner_fn=None, _original_ranges=None, _original_reduction_ranges=None)
  ))
  args[1]: torch.uint8
Found from : 
   File "/tmp/ipykernel_47742/831324313.py", line 9, in fn
    y = x.contiguous().view(torch.uint8)
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^


Set TORCHDYNAMO_VERBOSE=1 for the internal stack trace (please do this especially if you're reporting a bug to PyTorch). For even more developer context, set TORCH_LOGS="+dynamo"
RAW_BUFFERClick to expand / collapse

🐛 Describe the bug

Tensor.view(dtype) works in eager mode after transpose().contiguous(). However, compiling the same function with torch.compile(..., backend="inductor") fails during lowering of aten.view.dtype.

The input is first transposed and then made contiguous:

x = torch.tensor(..., dtype=torch.float32).t() y = x.contiguous().view(torch.uint8)

Eager execution succeeds and returns the expected uint8 bitcast view. In compiled mode, Inductor raises:

RuntimeError: self.stride(-1) must be 1 to view Float as Byte (different element sizes), but got 3

The Inductor error shows that the tensor being lowered to aten.view.dtype still has layout stride=[1, 3], even though the source code explicitly calls .contiguous() before view(torch.uint8). This looks like Inductor may be using stale/non-contiguous stride metadata from before the .contiguous() call when lowering the dtype reinterpret view.

import torch
import traceback

def fn():
    x = torch.tensor(
        [[1.0, -2.5, 0.0], [3.25, -0.0, 5.5]],
        dtype=torch.float32,
    ).t()
    y = x.contiguous().view(torch.uint8)
    return y, torch.count_nonzero(y, dim=1)

try:
    eager = fn()
    print("eager_ok")
    print(eager[0])
    print(eager[1])
except Exception:
    print("eager_error")
    traceback.print_exc(limit=10)

try:
    compiled = torch.compile(fn, backend="inductor")
    out = compiled()
    print("compiled_ok")
    print(out[0])
    print(out[1])
except Exception:
    print("compiled_error")
    traceback.print_exc(limit=20)

Output:

eager_ok
tensor([[  0,   0, 128,  63,   0,   0,  80,  64],
        [  0,   0,  32, 192,   0,   0,   0, 128],
        [  0,   0,   0,   0,   0,   0, 176,  64]], dtype=torch.uint8)
tensor([4, 3, 2])
E0528 13:33:48.714000 47742 torch/_subclasses/fake_tensor.py:2964] [5/0] failed while attempting to run meta for aten.view.dtype
E0528 13:33:48.714000 47742 torch/_subclasses/fake_tensor.py:2964] [5/0] Traceback (most recent call last):
E0528 13:33:48.714000 47742 torch/_subclasses/fake_tensor.py:2964] [5/0]   File "/usr/local/lib/python3.12/dist-packages/torch/_subclasses/fake_tensor.py", line 2960, in _dispatch_impl
E0528 13:33:48.714000 47742 torch/_subclasses/fake_tensor.py:2964] [5/0]     r = func(*args, **kwargs)
E0528 13:33:48.714000 47742 torch/_subclasses/fake_tensor.py:2964] [5/0]         ^^^^^^^^^^^^^^^^^^^^^
E0528 13:33:48.714000 47742 torch/_subclasses/fake_tensor.py:2964] [5/0]   File "/usr/local/lib/python3.12/dist-packages/torch/_ops.py", line 871, in __call__
E0528 13:33:48.714000 47742 torch/_subclasses/fake_tensor.py:2964] [5/0]     return self._op(*args, **kwargs)
E0528 13:33:48.714000 47742 torch/_subclasses/fake_tensor.py:2964] [5/0]            ^^^^^^^^^^^^^^^^^^^^^^^^^
E0528 13:33:48.714000 47742 torch/_subclasses/fake_tensor.py:2964] [5/0] RuntimeError: self.stride(-1) must be 1 to view Float as Byte (different element sizes), but got 3
compiled_error
Traceback (most recent call last):
  File "/tmp/ipykernel_47742/831324313.py", line 25, in <cell line: 0>
    out = compiled()
          ^^^^^^^^^^
  File "/usr/local/lib/python3.12/dist-packages/torch/_dynamo/eval_frame.py", line 1160, in compile_wrapper
    raise e.remove_dynamo_frames() from None  # see TORCHDYNAMO_VERBOSE=1
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/dist-packages/torch/_inductor/compile_fx.py", line 1078, in _compile_fx_inner
    raise InductorError(e, currentframe()).with_traceback(
  File "/usr/local/lib/python3.12/dist-packages/torch/_inductor/compile_fx.py", line 1058, in _compile_fx_inner
    mb_compiled_graph = fx_codegen_and_compile(
                        ^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/dist-packages/torch/_inductor/compile_fx.py", line 1846, in fx_codegen_and_compile
    return scheme.codegen_and_compile(gm, example_inputs, inputs_to_check, graph_kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/dist-packages/torch/_inductor/compile_fx.py", line 1522, in codegen_and_compile
    graph.run(*example_inputs)
  File "/usr/local/lib/python3.12/dist-packages/torch/_inductor/graph.py", line 1079, in run
    return super().run(*args)
           ^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/dist-packages/torch/fx/interpreter.py", line 197, in run
    self.env[node] = self.run_node(node)
                     ^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/dist-packages/torch/_inductor/graph.py", line 1932, in run_node
    result = super().run_node(n)
             ^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/dist-packages/torch/fx/interpreter.py", line 294, in run_node
    return getattr(self, n.op)(n.target, args, kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/dist-packages/torch/_inductor/graph.py", line 1504, in call_function
    raise LoweringException(
  File "/usr/local/lib/python3.12/dist-packages/torch/_inductor/graph.py", line 1481, in call_function
    out = lowerings[target](*args, **kwargs)
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/dist-packages/torch/_inductor/lowering.py", line 513, in wrapped
    out = decomp_fn(*args, **kwargs)
          ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/dist-packages/torch/_inductor/lowering.py", line 997, in _view_dtype
    return to_dtype_bitcast(x, dtype)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/dist-packages/torch/_inductor/lowering.py", line 986, in to_dtype_bitcast
    return fallback_handler(aten.view.dtype)(x, dtype)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/dist-packages/torch/_inductor/lowering.py", line 2495, in handler
    wrap_tensors, ir.FallbackKernel.create(kernel, *args, **kwargs)
                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/dist-packages/torch/_inductor/ir.py", line 9129, in create
    ) = cls.process_kernel(kernel, *args, **kwargs)
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/dist-packages/torch/_inductor/ir.py", line 6761, in process_kernel
    example_output = kernel(*new_args, **new_kwargs)
                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/dist-packages/torch/_ops.py", line 871, in __call__
    return self._op(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/dist-packages/torch/_compile.py", line 54, in inner
    return disable_fn(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^
torch._inductor.exc.InductorError: LoweringException: RuntimeError: self.stride(-1) must be 1 to view Float as Byte (different element sizes), but got 3
  target: aten.view.dtype
  args[0]: TensorBox(StorageBox(
    ComputedBuffer(name='buf0', layout=FixedLayout('cpu', torch.float32, size=[3, 2], stride=[1, 3]), data=Pointwise(
      'cpu',
      torch.float32,
      def inner_fn(index):
          i0, i1 = index
          tmp0 = ops.load(_tensor_constant0, i0 + 3 * i1)
          return tmp0
      ,
      ranges=[3, 2],
      origin_node=clone,
      origins=OrderedSet([clone, permute, lift_fresh_copy]),
      stack_traces = {,
        File "/tmp/ipykernel_47742/831324313.py", line 9, in fn,
          y = x.contiguous().view(torch.uint8),
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^,
      ,
      },
      stack_traces = {,
        File "/tmp/ipykernel_47742/831324313.py", line 8, in fn,
          ).t(),
            ^^^,
      ,
      },
      stack_traces = {,
        File "/tmp/ipykernel_47742/831324313.py", line 5, in fn,
          x = torch.tensor(,
              ^^^^^^^^^^^^^,
      ,
      }
    ), _split_size=None, _original_inner_fn=None, _original_ranges=None, _original_reduction_ranges=None)
  ))
  args[1]: torch.uint8RuntimeError: self.stride(-1) must be 1 to view Float as Byte (different element sizes), but got 3
  target: aten.view.dtype
  args[0]: TensorBox(StorageBox(
    ComputedBuffer(name='buf0', layout=FixedLayout('cpu', torch.float32, size=[3, 2], stride=[1, 3]), data=Pointwise(
      'cpu',
      torch.float32,
      def inner_fn(index):
          i0, i1 = index
          tmp0 = ops.load(_tensor_constant0, i0 + 3 * i1)
          return tmp0
      ,
      ranges=[3, 2],
      origin_node=clone,
      origins=OrderedSet([clone, permute, lift_fresh_copy]),
      stack_traces = {,
        File "/tmp/ipykernel_47742/831324313.py", line 9, in fn,
          y = x.contiguous().view(torch.uint8),
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^,
      ,
      },
      stack_traces = {,
        File "/tmp/ipykernel_47742/831324313.py", line 8, in fn,
          ).t(),
            ^^^,
      ,
      },
      stack_traces = {,
        File "/tmp/ipykernel_47742/831324313.py", line 5, in fn,
          x = torch.tensor(,
              ^^^^^^^^^^^^^,
      ,
      }
    ), _split_size=None, _original_inner_fn=None, _original_ranges=None, _original_reduction_ranges=None)
  ))
  args[1]: torch.uint8
Found from : 
   File "/tmp/ipykernel_47742/831324313.py", line 9, in fn
    y = x.contiguous().view(torch.uint8)
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^


Set TORCHDYNAMO_VERBOSE=1 for the internal stack trace (please do this especially if you're reporting a bug to PyTorch). For even more developer context, set TORCH_LOGS="+dynamo"

Versions

PyTorch version: 2.10.0+cpu

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