@@ -686,9 +686,19 @@ def _optimize_graph(
686
686
graph = _C ._jit_pass_canonicalize (graph )
687
687
_C ._jit_pass_lint (graph )
688
688
if GLOBALS .onnx_shape_inference :
689
- _C ._jit_pass_onnx_graph_shape_type_inference (
690
- graph , params_dict , GLOBALS .export_onnx_opset_version
691
- )
689
+ try :
690
+ _C ._jit_pass_onnx_graph_shape_type_inference (
691
+ graph , params_dict , GLOBALS .export_onnx_opset_version
692
+ )
693
+ except RuntimeError as exc :
694
+ if (
695
+ _C_onnx ._CAFFE2_ATEN_FALLBACK
696
+ and exc .args [0 ]
697
+ == "ScalarType UNKNOWN_SCALAR is an unexpected tensor scalar type!"
698
+ ):
699
+ # Caffe2 builds can have UNKNOWN_SCALAR for some tensors
700
+ pass
701
+
692
702
return graph
693
703
694
704
@@ -1183,9 +1193,18 @@ def _model_to_graph(
1183
1193
_C ._jit_pass_dce_allow_deleting_nodes_with_side_effects (graph )
1184
1194
1185
1195
if GLOBALS .onnx_shape_inference :
1186
- _C ._jit_pass_onnx_graph_shape_type_inference (
1187
- graph , params_dict , GLOBALS .export_onnx_opset_version
1188
- )
1196
+ try :
1197
+ _C ._jit_pass_onnx_graph_shape_type_inference (
1198
+ graph , params_dict , GLOBALS .export_onnx_opset_version
1199
+ )
1200
+ except RuntimeError as exc :
1201
+ if (
1202
+ _C_onnx ._CAFFE2_ATEN_FALLBACK
1203
+ and exc .args [0 ]
1204
+ == "ScalarType UNKNOWN_SCALAR is an unexpected tensor scalar type!"
1205
+ ):
1206
+ # Caffe2 builds can have UNKNOWN_SCALAR for some tensors
1207
+ pass
1189
1208
1190
1209
params_dict = _C ._jit_pass_onnx_eliminate_unused_items (graph , params_dict )
1191
1210
0 commit comments