Skip to content

Instantly share code, notes, and snippets.

@wanchaol
Created January 29, 2020 18:03
Show Gist options
  • Save wanchaol/69db3b745aba300345fd5e584cab9016 to your computer and use it in GitHub Desktop.
Save wanchaol/69db3b745aba300345fd5e584cab9016 to your computer and use it in GitHub Desktop.
import torch
@torch.jit.script
class MyClass(object):
def my_method(self):
# type: () -> Tensor
return torch.randn(10)
@torch.jit.ignore
def mod_init():
return MyClass()
@torch.jit.script
def test_script_mod():
# type: () -> Tensor
res = mod_init()
return res.my_method()
========
RuntimeError:
Tried to access nonexistent attribute or method 'my_method' of type 'Tensor'.:
File "/home/wanchaol/test_script.py", line 34
# type: () -> Tensor
res = mod_init()
return res.my_method()
~~~~~~~~~~~~~ <--- HERE
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment