Skip to content

Commit 690bc1c

Browse files
Thiago Crepaldipytorchmergebot
authored andcommitted
[ONNX] Raise exception for unimplemented ops for non-caffe2 builds
Currently, when an operator symbolic hits an unimplemented scenario, the symbolic may print a warning and return, allowing a non-ONNX operator be emitted into the graph This PRs maintains this behavior for 1) Caffe2 builds or 2) non-caffe2 builds with `operator_export_type != ONNX`. If none of the conditions above are met, the converter raises a `RuntimeError` exception otherwise. This is needed so that exporter can detect detect unsupported ONNX operators when ATEN fallback is used (for non-caffe2 scenarios) Pull Request resolved: pytorch#75468 Approved by: https://github.com/BowenBao
1 parent f6c275f commit 690bc1c

File tree

2 files changed

+6
-5
lines changed

2 files changed

+6
-5
lines changed

torch/onnx/symbolic_helper.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -358,7 +358,11 @@ def _get_tensor_dim_size(x, dim):
358358
return None
359359

360360
def _unimplemented(op, msg):
361-
warnings.warn("ONNX export failed on " + op + " because " + msg + " not supported")
361+
# For BC reasons, the behavior for Caffe2 does not raise exception for unimplemented operators
362+
if torch.onnx._CAFFE2_ATEN_FALLBACK:
363+
warnings.warn("ONNX export failed on " + op + " because " + msg + " not supported")
364+
elif _operator_export_type == torch.onnx.OperatorExportTypes.ONNX:
365+
_onnx_unsupported(f"{op}, {msg}")
362366

363367

364368
def _onnx_unsupported(op_name):

torch/onnx/symbolic_opset9.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1037,10 +1037,7 @@ def symbolic_fn(g, input, output_size):
10371037
if mod != [0] * len(mod):
10381038
if output_size == [1] * len(output_size):
10391039
return g.op("GlobalMaxPool", input), None
1040-
if sym_help.is_caffe2_aten_fallback():
1041-
return _unimplemented(name, "output size that are not factor of input size")
1042-
else:
1043-
return sym_help._onnx_unsupported(name + ", since output size is not factor of input size")
1040+
return _unimplemented(name, "output size that are not factor of input size")
10441041
k = [int(dim[i] / output_size[i]) for i in range(0, len(dim))]
10451042
# call max_poolxd_with_indices to get indices in the output
10461043
if type == "MaxPool":

0 commit comments

Comments
 (0)