I am working on a model that utilize GraphModule, and convert it to TorchScript. The model I trained gives reasonable results, but every time I initialize a new model the following warning always pop up.
UserWarning: The TorchScript type system doesn’t support instance-level annotations on empty non-base types in __init__
. Instead, either 1) use a type annotation in the class body, or 2) wrap the type in torch.jit.Attribute
.
When I looked at Torch.fx.GraphModule.__init__
, I found these lines
# Dictionary to store metadata
self.meta: Dict[str, Any] = {}
self._replace_hook = None
self._create_node_hooks: List[Callable] = []
self._erase_node_hooks: List[Callable] = []
which likely are the reasons for the warning. I tried deleting the annotations to
# Dictionary to store metadata
self.meta = {}
self._replace_hook = None
self._create_node_hooks = []
self._erase_node_hooks = []
and the warning disappear. I would like to know the reason behind the warning, i.e., why jit.script doesn’t want the annotations of empty collections in __init__
, and what is the proper practice to handle this without modifying Torch.fx.GraphModule.__init__
.
My model is based on python-3.11.9, and torch-2.4.1 with cuda-11.8.