Skip to content

Commit

Permalink
Add complete type name in error message when fail to export model (py…
Browse files Browse the repository at this point in the history
…torch#67750)

Summary:
Pull Request resolved: pytorch#67750

Add more information about why exporting model fails.

Before: error message:
```
E1102 22:57:42.984015 3220949 ExceptionTracer.cpp:221] exception stack complete
terminate called after throwing an instance of 'c10::Error'
  what():  __torch__ types other than torchbind (__torch__.torch.classes)are not supported in lite interpreter. Workaround: instead of using arbitrary class type (class Foo()), define a pytorch class (class Foo(torch.nn.Module)). The problematic type is: __torch__.dper3.core.schema_utils.IdListFeature
Exception raised from getFunctionTuple at caffe2/torch/csrc/jit/serialization/export_module.cpp:246 (most recent call first):
```

After
```
E1102 22:57:42.984015 3220949 ExceptionTracer.cpp:221] exception stack complete
terminate called after throwing an instance of 'c10::Error'
  what():  __torch__ types other than torchbind (__torch__.torch.classes)are not supported in lite interpreter. Workaround: instead of using arbitrary class type (class Foo()), define a pytorch class (class Foo(torch.nn.Module)).
Exception raised from getFunctionTuple at caffe2/torch/csrc/jit/serialization/export_module.cpp:246 (most recent call first):
```
ghstack-source-id: 143009294

Test Plan: CI

Reviewed By: larryliu0820

Differential Revision: D32129397

fbshipit-source-id: 0594a98a59f727dc284acd1c9bebcd7589ee7cbb
  • Loading branch information
cccclai authored and facebook-github-bot committed Nov 11, 2021
1 parent 1f07efd commit a229c3e
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
3 changes: 2 additions & 1 deletion test/mobile/test_lite_script_module.py
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,8 @@ def forward(self, arg):
script_module = torch.jit.script(MyTestModule())
with self.assertRaisesRegex(RuntimeError,
r"Workaround: instead of using arbitrary class type \(class Foo\(\)\), "
r"define a pytorch class \(class Foo\(torch\.nn\.Module\)\)\.$"):
r"define a pytorch class \(class Foo\(torch\.nn\.Module\)\)\. "
r"The problematic type is: "):
script_module._save_to_buffer_for_lite_interpreter()

def test_unsupported_return_list_with_module_class(self):
Expand Down
3 changes: 2 additions & 1 deletion torch/csrc/jit/serialization/export_module.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,8 @@ std::pair<IValue, IValue> getFunctionTuple(
"__torch__ types other than torchbind (__torch__.torch.classes)"
"are not supported in lite interpreter. ",
"Workaround: instead of using arbitrary class type (class Foo()), ",
"define a pytorch class (class Foo(torch.nn.Module)).");
"define a pytorch class (class Foo(torch.nn.Module)). The problematic type is: ",
type_str);
}
types.emplace_back(type_str);
}
Expand Down

0 comments on commit a229c3e

Please sign in to comment.