Skip to content

TorchScript is unable to distinguish int and ScalarType #47964

@zasdfgbnm

Description

@zasdfgbnm

🐛 Bug

I am adding a new operator tensor.view(dtype) in #47951, and getting lots of JIT failures.

With #47951, the script to reproduce this issue is

import torch

def f(x):
    return x.view(-1)

s = torch.jit.script(f)
print(s.graph)

x = torch.randn(5, 5, 5)
s(x)

and there will be an error message

graph(%x.1 : Tensor):
  %4 : int = prim::Constant[value=-1]() # jit-view.py:4:18
  %5 : Tensor = aten::view(%x.1, %4) # jit-view.py:4:11
  return (%5)

Traceback (most recent call last):
  File "jit-view.py", line 10, in <module>
    s(x)
RuntimeError: The following operation failed in the TorchScript interpreter.
Traceback of TorchScript (most recent call last):
  File "jit-view.py", line 4, in f
def f(x):
    return x.view(-1)
           ~~~~~~ <--- HERE
RuntimeError: Viewing a tensor as a new dtype with different bytes is not supported.

cc @gmagogsfm @mruberry

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions