def value_name(v: torch._C.Value) -> ONNXValueID: if _unique_id(v) in self.attrs: return self.attrs[_unique_id(v)] n: torch._C.Node = v.node() or v.uses()[0].user scope: str = self.node_scope.get(n, n.scopeName()) if len(scope) > 0: scope += "." scope = _remove_prefix(scope.split("/")[-1], "__module.") scope = _remove_prefix(scope, f"{_ppe_ignore_scope}.") return ONNXValueID(f"{scope}{v.debugName()}")
def onnx_value(v: torch._C.Value, name: ONNXValueID) -> onnx.ValueInfoProto: return onnx.helper.make_value_info( name, None if v.type() is None else _type_to_proto(cast(torch._C.TensorType, v.type())), doc_string=None if self.strip_doc_string else repr(v), )
def _unique_id(v: torch._C.Value) -> TorchValueID: return TorchValueID(v.unique())
def _custom_unpack_list(list_value: torch._C.Value) -> List[torch._C.Value]: list_node = list_value.node() assert list_node.kind() in ["prim::ListConstruct", "onnx::SequenceConstruct", "onnx::SequenceEmpty"], f"Unknown list operator: {list_node}" return list(list_node.inputs())
def _custom_is_packed_list(list_value: torch._C.Value) -> bool: return _is_value(list_value) and list_value.node().kind() in _list_create_ops
def _custom_unpack_list(list_value: torch._C.Value) -> List[torch._C.Value]: list_node = list_value.node() assert list_node.kind() in _list_create_ops, f"Unknown list operator: {list_node}" return list(list_node.inputs())