justinchuby / torch-onnx

Prototype of the next torch exporter
MIT License
1 stars 1 forks source link

Analysis interface #22

Closed justinchuby closed 3 weeks ago

justinchuby commented 3 weeks ago

torch_onnx.analyze(exported_program) will print model information, param sizes, identify unsupported nodes using the dispatcher, and generate reproduction script.

Goal: human readable messages and simple reproduction steps.

justinchuby commented 3 weeks ago

PyTorch ONNX Conversion Analysis

Model information

The model has 127398144 parameters and 0 buffers (non-trainable parameters).

Inputs:

Outputs:

The FX graph has {model_info.fx_node_count} nodes in total. Number of FX nodes per op:

Of the call_function nodes, the counts of operators used are:

ONNX conversion information

The model contains operators the dispatcher could not find ONNX equivalents for. This may be due to missing implementations or a bug in the dispatcher.

Errors grouped by operator:

justinchuby commented 3 weeks ago

PyTorch ONNX Conversion Error report

Error message:

Traceback (most recent call last):
  File "/Users/justinc/Documents/GitHub/torch-onnx/src/torch_onnx/_core.py", line 490, in _add_nodes
    _handle_call_function_node_with_lowering(
  File "/Users/justinc/Documents/GitHub/torch-onnx/src/torch_onnx/_core.py", line 372, in _handle_call_function_node_with_lowering
    raise RuntimeError(
RuntimeError: No ONNX function found for <OpOverload(op='aten.remainder', overload='Tensor')>. Failure message: No decompositions defined for the real-valued input

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/Users/justinc/Documents/GitHub/torch-onnx/src/torch_onnx/_patch.py", line 137, in torch_onnx_export_adaptor
    ir_model = torch_onnx.exported_program_to_ir(program)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/justinc/Documents/GitHub/torch-onnx/src/torch_onnx/_core.py", line 626, in exported_program_to_ir
    values = _add_nodes(exported_program, model, lower=lower, registry=registry)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/justinc/Documents/GitHub/torch-onnx/src/torch_onnx/_core.py", line 501, in _add_nodes
    raise RuntimeError(
RuntimeError: Error when translating node %remainder : [num_users=1] = call_function[target=torch.ops.aten.remainder.Tensor](args = (%arg0_1, %arg1_1), kwargs = {}). See the stack trace for more information.

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/Users/justinc/Documents/GitHub/torch-onnx/src/torch_onnx/_patch.py", line 180, in _torch_onnx_utils_export_adaptor
    torch_onnx_export_adaptor(*args, **kwargs)
  File "/Users/justinc/Documents/GitHub/torch-onnx/src/torch_onnx/_patch.py", line 160, in torch_onnx_export_adaptor
    raise OnnxConversionError(
torch_onnx._patch.OnnxConversionError: Failed to convert the exported program to an ONNX model. This is step 2/2 of exporting the model to ONNX. Please create an issue in the PyTorch GitHub repository against the *onnx* component and attach the full error stack as well as reproduction scripts. You can run `torch_onnx.analyze()` to produce an error report after obtaining an ExportedProgram with `torch.export.export()`.

Exported program:

ExportedProgram:
    class GraphModule(torch.nn.Module):
        def forward(self, arg0_1: "f32[4, 2, 3]", arg1_1: "f32[1, 2, 1]"):
            # File: /Users/justinc/Documents/GitHub/torch-onnx/tests/pytorch_test.py:7306 in forward, code: return torch.remainder(input, other)
            remainder: "f32[4, 2, 3]" = torch.ops.aten.remainder.Tensor(arg0_1, arg1_1);  arg0_1 = arg1_1 = None
            return (remainder,)

Graph signature: ExportGraphSignature(input_specs=[InputSpec(kind=<InputKind.USER_INPUT: 1>, arg=TensorArgument(name='arg0_1'), target=None, persistent=None), InputSpec(kind=<InputKind.USER_INPUT: 1>, arg=TensorArgument(name='arg1_1'), target=None, persistent=None)], output_specs=[OutputSpec(kind=<OutputKind.USER_OUTPUT: 1>, arg=TensorArgument(name='remainder'), target=None)])
Range constraints: {}

Analysis

PyTorch ONNX Conversion Analysis

Model Information

The model has 0 parameters and 0 buffers (non-trainable parameters).

Inputs:

Outputs:

The FX graph has 4 nodes in total. Number of FX nodes per op:

Of the call_function nodes, the counts of operators used are:

ONNX Conversion Information

The model contains operators the dispatcher could not find ONNX equivalents for. This may be due to missing implementations or a bug in the dispatcher.

Errors grouped by operator:

justinchuby commented 3 weeks ago

PyTorch ONNX Conversion Error report

Error message:

Traceback (most recent call last):
  File "/Users/justinc/Documents/GitHub/torch-onnx/src/torch_onnx/_core.py", line 490, in _add_nodes
    _handle_call_function_node_with_lowering(
  File "/Users/justinc/Documents/GitHub/torch-onnx/src/torch_onnx/_core.py", line 368, in _handle_call_function_node_with_lowering
    onnx_function, message = _dispatching.dispatch(node, registry)
                             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/justinc/Documents/GitHub/torch-onnx/src/torch_onnx/_dispatching.py", line 323, in dispatch
    overload, message = get_matching_overload(
                        ^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/justinc/Documents/GitHub/torch-onnx/src/torch_onnx/_dispatching.py", line 208, in get_matching_overload
    named_args = _get_named_fx_node_args(node)
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/justinc/Documents/GitHub/torch-onnx/src/torch_onnx/_dispatching.py", line 186, in _get_named_fx_node_args
    torch_schema: torch.FunctionSchema = node.target._schema
                                         ^^^^^^^^^^^^^^^^^^^
AttributeError: 'builtin_function_or_method' object has no attribute '_schema'

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/Users/justinc/Documents/GitHub/torch-onnx/src/torch_onnx/_patch.py", line 137, in torch_onnx_export_adaptor
    ir_model = torch_onnx.exported_program_to_ir(program)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/justinc/Documents/GitHub/torch-onnx/src/torch_onnx/_core.py", line 626, in exported_program_to_ir
    values = _add_nodes(exported_program, model, lower=lower, registry=registry)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/justinc/Documents/GitHub/torch-onnx/src/torch_onnx/_core.py", line 501, in _add_nodes
    raise RuntimeError(
RuntimeError: Error when translating node %ge : [num_users=1] = call_function[target=operator.ge](args = (%_local_scalar_dense_1, -9223372036854775808), kwargs = {}). See the stack trace for more information.

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/Users/justinc/Documents/GitHub/torch-onnx/src/torch_onnx/_patch.py", line 180, in _torch_onnx_utils_export_adaptor
    torch_onnx_export_adaptor(*args, **kwargs)
  File "/Users/justinc/Documents/GitHub/torch-onnx/src/torch_onnx/_patch.py", line 160, in torch_onnx_export_adaptor
    raise OnnxConversionError(
torch_onnx._patch.OnnxConversionError: Failed to convert the exported program to an ONNX model. This is step 2/2 of exporting the model to ONNX. Please create an issue in the PyTorch GitHub repository against the *onnx* component and attach the full error stack as well as reproduction scripts. You can run `torch_onnx.analyze()` to produce an error report after obtaining an ExportedProgram with `torch.export.export()`.

Exported program:

ExportedProgram:
    class GraphModule(torch.nn.Module):
        def forward(self, arg0_1: "f32[10, 3, 5]", arg1_1: "f32[10, 3, 4]", arg2_1: "f32[10, 4, 5]", arg3_1: "i64[]", arg4_1: "f32[]"):
            # File: /Users/justinc/Documents/GitHub/torch-onnx/tests/pytorch_test.py:7662 in forward, code: return torch.baddbmm(input, batch1, batch2, alpha=alpha, beta=beta)
            _local_scalar_dense: "Sym(f4)" = torch.ops.aten._local_scalar_dense.default(arg4_1);  arg4_1 = None
            _local_scalar_dense_1: "Sym(u4)" = torch.ops.aten._local_scalar_dense.default(arg3_1);  arg3_1 = None

            # File: /Users/justinc/Documents/GitHub/torch-onnx/venv/lib/python3.11/site-packages/torch/_export/pass_base.py:54 in _create_dummy_node_metadata, code: return NodeMetadata({"stack_trace": "".join(traceback.format_stack(limit=1))})
            ge: "Sym(u4 >= -9223372036854775808)" = _local_scalar_dense_1 >= -9223372036854775808
            scalar_tensor: "f32[]" = torch.ops.aten.scalar_tensor.default(ge);  ge = None
            _assert_async = torch.ops.aten._assert_async.msg(scalar_tensor, '_local_scalar_dense_1 is outside of inline constraint [-9223372036854775808, 9223372036854775807].');  scalar_tensor = None
            le: "Sym(u4 <= 9223372036854775807)" = _local_scalar_dense_1 <= 9223372036854775807
            scalar_tensor_1: "f32[]" = torch.ops.aten.scalar_tensor.default(le);  le = None
            _assert_async_1 = torch.ops.aten._assert_async.msg(scalar_tensor_1, '_local_scalar_dense_1 is outside of inline constraint [-9223372036854775808, 9223372036854775807].');  scalar_tensor_1 = None

            # File: /Users/justinc/Documents/GitHub/torch-onnx/tests/pytorch_test.py:7662 in forward, code: return torch.baddbmm(input, batch1, batch2, alpha=alpha, beta=beta)
            baddbmm: "f32[10, 3, 5]" = torch.ops.aten.baddbmm.default(arg0_1, arg1_1, arg2_1, beta = _local_scalar_dense, alpha = _local_scalar_dense_1);  arg0_1 = arg1_1 = arg2_1 = _local_scalar_dense = _local_scalar_dense_1 = None
            return (baddbmm,)

Graph signature: ExportGraphSignature(input_specs=[InputSpec(kind=<InputKind.USER_INPUT: 1>, arg=TensorArgument(name='arg0_1'), target=None, persistent=None), InputSpec(kind=<InputKind.USER_INPUT: 1>, arg=TensorArgument(name='arg1_1'), target=None, persistent=None), InputSpec(kind=<InputKind.USER_INPUT: 1>, arg=TensorArgument(name='arg2_1'), target=None, persistent=None), InputSpec(kind=<InputKind.USER_INPUT: 1>, arg=TensorArgument(name='arg3_1'), target=None, persistent=None), InputSpec(kind=<InputKind.USER_INPUT: 1>, arg=TensorArgument(name='arg4_1'), target=None, persistent=None)], output_specs=[OutputSpec(kind=<OutputKind.USER_OUTPUT: 1>, arg=TensorArgument(name='baddbmm'), target=None)])
Range constraints: {f0: ValueRanges(lower=-oo, upper=oo, is_bool=False), u0: ValueRanges(lower=-9223372036854775808, upper=9223372036854775807, is_bool=False), f1: ValueRanges(lower=-oo, upper=oo, is_bool=False), u1: ValueRanges(lower=-9223372036854775808, upper=9223372036854775807, is_bool=False), f2: ValueRanges(lower=-oo, upper=oo, is_bool=False), u2: ValueRanges(lower=-9223372036854775808, upper=9223372036854775807, is_bool=False), f3: ValueRanges(lower=-oo, upper=oo, is_bool=False), u3: ValueRanges(lower=-9223372036854775808, upper=9223372036854775807, is_bool=False), f4: ValueRanges(lower=-oo, upper=oo, is_bool=False), u4: ValueRanges(lower=-9223372036854775808, upper=9223372036854775807, is_bool=False)}

Analysis

PyTorch ONNX Conversion Analysis

Model Information

The model has 0 parameters and 0 buffers (non-trainable parameters).

Inputs:

Outputs:

The FX graph has 15 nodes in total. Number of FX nodes per op:

Of the call_function nodes, the counts of operators used are:

ONNX Conversion Information

The model contains operators the dispatcher could not find ONNX equivalents for. This may be due to missing implementations or a bug in the dispatcher.

Errors grouped by operator:

justinchuby commented 3 weeks ago

PyTorch ONNX Conversion Error report

Error message:

Traceback (most recent call last):
  File "/Users/justinc/Documents/GitHub/torch-onnx/src/torch_onnx/_core.py", line 490, in _add_nodes
    _handle_call_function_node_with_lowering(
  File "/Users/justinc/Documents/GitHub/torch-onnx/src/torch_onnx/_core.py", line 368, in _handle_call_function_node_with_lowering
    onnx_function, message = _dispatching.dispatch(node, registry)
                             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/justinc/Documents/GitHub/torch-onnx/src/torch_onnx/_dispatching.py", line 323, in dispatch
    overload, message = get_matching_overload(
                        ^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/justinc/Documents/GitHub/torch-onnx/src/torch_onnx/_dispatching.py", line 208, in get_matching_overload
    named_args = _get_named_fx_node_args(node)
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/justinc/Documents/GitHub/torch-onnx/src/torch_onnx/_dispatching.py", line 186, in _get_named_fx_node_args
    torch_schema: torch.FunctionSchema = node.target._schema
                                         ^^^^^^^^^^^^^^^^^^^
AttributeError: 'builtin_function_or_method' object has no attribute '_schema'

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/Users/justinc/Documents/GitHub/torch-onnx/src/torch_onnx/_patch.py", line 137, in torch_onnx_export_adaptor
    ir_model = torch_onnx.exported_program_to_ir(program)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/justinc/Documents/GitHub/torch-onnx/src/torch_onnx/_core.py", line 626, in exported_program_to_ir
    values = _add_nodes(exported_program, model, lower=lower, registry=registry)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/justinc/Documents/GitHub/torch-onnx/src/torch_onnx/_core.py", line 501, in _add_nodes
    raise RuntimeError(
RuntimeError: Error when translating node %ge : [num_users=1] = call_function[target=operator.ge](args = (%_local_scalar_dense, 0), kwargs = {}). See the stack trace for more information.

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/Users/justinc/Documents/GitHub/torch-onnx/src/torch_onnx/_patch.py", line 180, in _torch_onnx_export_adapter_with_error_report
    torch_onnx_export_adaptor(*args, **kwargs)
  File "/Users/justinc/Documents/GitHub/torch-onnx/src/torch_onnx/_patch.py", line 160, in torch_onnx_export_adaptor
    raise OnnxConversionError(
torch_onnx._patch.OnnxConversionError: Failed to convert the exported program to an ONNX model. This is step 2/2 of exporting the model to ONNX. Please create an issue in the PyTorch GitHub repository against the *onnx* component and attach the full error stack as well as reproduction scripts. You can run `torch_onnx.analyze()` to produce an error report after obtaining an ExportedProgram with `torch.export.export()`.

Exported program:

ExportedProgram:
    class GraphModule(torch.nn.Module):
        def forward(self, arg0_1: "f32[6, 4, 3]", arg1_1: "i64[]", arg2_1: "i64[]"):
            # File: /Users/justinc/Documents/GitHub/torch-onnx/tests/pytorch_test.py:5743 in forward, code: split_list: List[Tensor] = input.split(split_sizes)
            _local_scalar_dense: "Sym(u8)" = torch.ops.aten._local_scalar_dense.default(arg1_1);  arg1_1 = None

            # File: /Users/justinc/Documents/GitHub/torch-onnx/venv/lib/python3.11/site-packages/torch/_export/pass_base.py:54 in _create_dummy_node_metadata, code: return NodeMetadata({"stack_trace": "".join(traceback.format_stack(limit=1))})
            ge: "Sym(u8 >= 0)" = _local_scalar_dense >= 0
            scalar_tensor: "f32[]" = torch.ops.aten.scalar_tensor.default(ge);  ge = None
            _assert_async = torch.ops.aten._assert_async.msg(scalar_tensor, '_local_scalar_dense is outside of inline constraint [0, 6].');  scalar_tensor = None
            le: "Sym(u8 <= 6)" = _local_scalar_dense <= 6
            scalar_tensor_1: "f32[]" = torch.ops.aten.scalar_tensor.default(le);  le = None
            _assert_async_1 = torch.ops.aten._assert_async.msg(scalar_tensor_1, '_local_scalar_dense is outside of inline constraint [0, 6].');  scalar_tensor_1 = None

            # File: /Users/justinc/Documents/GitHub/torch-onnx/tests/pytorch_test.py:5743 in forward, code: split_list: List[Tensor] = input.split(split_sizes)
            _local_scalar_dense_1: "Sym(u9)" = torch.ops.aten._local_scalar_dense.default(arg2_1);  arg2_1 = None

            # File: /Users/justinc/Documents/GitHub/torch-onnx/venv/lib/python3.11/site-packages/torch/_export/pass_base.py:54 in _create_dummy_node_metadata, code: return NodeMetadata({"stack_trace": "".join(traceback.format_stack(limit=1))})
            ge_1: "Sym(u9 >= 0)" = _local_scalar_dense_1 >= 0
            scalar_tensor_2: "f32[]" = torch.ops.aten.scalar_tensor.default(ge_1);  ge_1 = None
            _assert_async_2 = torch.ops.aten._assert_async.msg(scalar_tensor_2, '_local_scalar_dense_1 is outside of inline constraint [0, 6].');  scalar_tensor_2 = None
            le_1: "Sym(u9 <= 6)" = _local_scalar_dense_1 <= 6
            scalar_tensor_3: "f32[]" = torch.ops.aten.scalar_tensor.default(le_1);  le_1 = None
            _assert_async_3 = torch.ops.aten._assert_async.msg(scalar_tensor_3, '_local_scalar_dense_1 is outside of inline constraint [0, 6].');  scalar_tensor_3 = None

            # File: /Users/justinc/Documents/GitHub/torch-onnx/tests/pytorch_test.py:5743 in forward, code: split_list: List[Tensor] = input.split(split_sizes)
            split_with_sizes = torch.ops.aten.split_with_sizes.default(arg0_1, [_local_scalar_dense, _local_scalar_dense_1]);  arg0_1 = _local_scalar_dense = _local_scalar_dense_1 = None
            getitem: "f32[u8, 4, 3]" = split_with_sizes[0]
            getitem_1: "f32[u9, 4, 3]" = split_with_sizes[1];  split_with_sizes = None

            # File: /Users/justinc/Documents/GitHub/torch-onnx/venv/lib/python3.11/site-packages/torch/_export/passes/add_runtime_assertions_for_constraints_pass.py:153 in call, code: node.meta["stack_trace"] = "".join(traceback.format_stack(limit=1))
            sym_size: "Sym(u8)" = torch.ops.aten.sym_size.int(getitem, 0)
            sym_constrain_range = torch.ops.aten.sym_constrain_range.default(sym_size, min = 0, max = 6)
            mul: "Sym(-u8)" = -1 * sym_size
            le_2: "Sym(-u8 <= 0)" = mul <= 0;  mul = None
            _assert_scalar = torch.ops.aten._assert_scalar.default(le_2, 'Deferred runtime assertion failed -u0 <= 0');  le_2 = None
            sym_size_1: "Sym(u9)" = torch.ops.aten.sym_size.int(getitem_1, 0)
            sym_constrain_range_1 = torch.ops.aten.sym_constrain_range.default(sym_size_1, min = 0, max = 6)
            mul_1: "Sym(-u9)" = -1 * sym_size_1
            le_3: "Sym(-u9 <= 0)" = mul_1 <= 0;  mul_1 = None
            _assert_scalar_1 = torch.ops.aten._assert_scalar.default(le_3, 'Deferred runtime assertion failed -u1 <= 0');  le_3 = None
            add: "Sym(u8 + u9)" = sym_size + sym_size_1;  sym_size = sym_size_1 = None
            eq: "Sym(Eq(u8 + u9, 6))" = add == 6;  add = None
            _assert_scalar_2 = torch.ops.aten._assert_scalar.default(eq, 'Deferred runtime assertion failed Eq(u0 + u1, 6)');  eq = None

            # File: /Users/justinc/Documents/GitHub/torch-onnx/tests/pytorch_test.py:5747 in forward, code: return torch.cat(out, dim=0)
            cat: "f32[u8 + u9, 4, 3]" = torch.ops.aten.cat.default([getitem, getitem_1]);  getitem = getitem_1 = None
            return (cat,)

Graph signature: ExportGraphSignature(input_specs=[InputSpec(kind=<InputKind.USER_INPUT: 1>, arg=TensorArgument(name='arg0_1'), target=None, persistent=None), InputSpec(kind=<InputKind.USER_INPUT: 1>, arg=TensorArgument(name='arg1_1'), target=None, persistent=None), InputSpec(kind=<InputKind.USER_INPUT: 1>, arg=TensorArgument(name='arg2_1'), target=None, persistent=None)], output_specs=[OutputSpec(kind=<OutputKind.USER_OUTPUT: 1>, arg=TensorArgument(name='cat'), target=None)])
Range constraints: {u0: ValueRanges(lower=0, upper=6, is_bool=False), u1: ValueRanges(lower=0, upper=6, is_bool=False), u2: ValueRanges(lower=0, upper=6, is_bool=False), u3: ValueRanges(lower=0, upper=6, is_bool=False), u4: ValueRanges(lower=0, upper=6, is_bool=False), u5: ValueRanges(lower=0, upper=6, is_bool=False), u6: ValueRanges(lower=0, upper=6, is_bool=False), u7: ValueRanges(lower=0, upper=6, is_bool=False), u8: ValueRanges(lower=0, upper=6, is_bool=False), u9: ValueRanges(lower=0, upper=6, is_bool=False)}

Analysis

PyTorch ONNX Conversion Analysis

Model Information

The model has 0 parameters and 0 buffers (non-trainable parameters).

Inputs:

Outputs:

The FX graph has 35 nodes in total. Number of FX nodes per op:

Of the call_function nodes, the counts of operators used are:

ONNX Conversion Information

The model contains operators the dispatcher could not find ONNX equivalents for. This may be due to missing implementations or a bug in the dispatcher.

Errors grouped by operator:

justinchuby commented 3 weeks ago

PyTorch ONNX Conversion Error report

Error message:

Traceback (most recent call last):
  File "/Users/justinc/Documents/GitHub/torch-onnx/src/torch_onnx/_patch.py", line 156, in torch_onnx_export_adaptor
    onnx.checker.check_model(proto, full_check=True)
  File "/Users/justinc/Documents/GitHub/torch-onnx/venv/lib/python3.11/site-packages/onnx/checker.py", line 179, in check_model
    C.check_model(
onnx.onnx_cpp2py_export.shape_inference.InferenceError: [ShapeInferenceError] Inference error(s): (op_type:_aten_native_batch_norm_inference_onnx, node name: node__aten_native_batch_norm_inference_onnx_2): [ShapeInferenceError] Inferred shape and existing shape differ in dimension 0: (33) vs (0)

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/Users/justinc/Documents/GitHub/torch-onnx/src/torch_onnx/_patch.py", line 180, in _torch_onnx_export_adapter_with_error_report
    torch_onnx_export_adaptor(*args, **kwargs)
  File "/Users/justinc/Documents/GitHub/torch-onnx/src/torch_onnx/_patch.py", line 160, in torch_onnx_export_adaptor
    raise OnnxConversionError(
torch_onnx._patch.OnnxConversionError: Failed to convert the exported program to an ONNX model. This is step 2/2 of exporting the model to ONNX. Please create an issue in the PyTorch GitHub repository against the *onnx* component and attach the full error stack as well as reproduction scripts. You can run `torch_onnx.analyze()` to produce an error report after obtaining an ExportedProgram with `torch.export.export()`.

Exported program:

ExportedProgram:
    class GraphModule(torch.nn.Module):
        def forward(self, arg0_1: "f32[33, 16, 3]", arg1_1: "f32[33]", arg2_1: "f32[33]", arg3_1: "f32[33]", arg4_1: "f32[33]", arg5_1: "f32[33]", arg6_1: "i64[]", arg7_1: "f32[20, 16, 50]"):
            # File: /Users/justinc/Documents/GitHub/torch-onnx/tests/pytorch_test.py:128 in forward, code: out = self.conv(x)
            convolution: "f32[20, 33, 24]" = torch.ops.aten.convolution.default(arg7_1, arg0_1, arg1_1, [2], [0], [1], False, [0], 1);  arg7_1 = arg0_1 = arg1_1 = None

            # File: /Users/justinc/Documents/GitHub/torch-onnx/tests/pytorch_test.py:129 in forward, code: return self.bn(out)
            _native_batch_norm_legit_no_training = torch.ops.aten._native_batch_norm_legit_no_training.default(convolution, arg2_1, arg3_1, arg4_1, arg5_1, 0.1, 1e-05);  convolution = arg2_1 = arg3_1 = arg4_1 = arg5_1 = None
            getitem: "f32[20, 33, 24]" = _native_batch_norm_legit_no_training[0];  _native_batch_norm_legit_no_training = None
            return (getitem,)

Graph signature: ExportGraphSignature(input_specs=[InputSpec(kind=<InputKind.PARAMETER: 2>, arg=TensorArgument(name='arg0_1'), target='conv.weight', persistent=None), InputSpec(kind=<InputKind.PARAMETER: 2>, arg=TensorArgument(name='arg1_1'), target='conv.bias', persistent=None), InputSpec(kind=<InputKind.PARAMETER: 2>, arg=TensorArgument(name='arg2_1'), target='bn.weight', persistent=None), InputSpec(kind=<InputKind.PARAMETER: 2>, arg=TensorArgument(name='arg3_1'), target='bn.bias', persistent=None), InputSpec(kind=<InputKind.BUFFER: 3>, arg=TensorArgument(name='arg4_1'), target='bn.running_mean', persistent=True), InputSpec(kind=<InputKind.BUFFER: 3>, arg=TensorArgument(name='arg5_1'), target='bn.running_var', persistent=True), InputSpec(kind=<InputKind.BUFFER: 3>, arg=TensorArgument(name='arg6_1'), target='bn.num_batches_tracked', persistent=True), InputSpec(kind=<InputKind.USER_INPUT: 1>, arg=TensorArgument(name='arg7_1'), target=None, persistent=None)], output_specs=[OutputSpec(kind=<OutputKind.USER_OUTPUT: 1>, arg=TensorArgument(name='getitem'), target=None)])
Range constraints: {}

Analysis

PyTorch ONNX Conversion Analysis

Model Information

The model has 1683 parameters and 67 buffers (non-trainable parameters).

Inputs:

Outputs:

The FX graph has 12 nodes in total. Number of FX nodes per op:

Of the call_function nodes, the counts of operators used are:

ONNX Conversion Information

All operators in the model have ONNX equivalents.

justinchuby commented 3 weeks ago

PyTorch ONNX Conversion Error report

torch.export.export error

Error message:

Traceback (most recent call last):
  File "/Users/justinc/Documents/GitHub/torch-onnx/venv/lib/python3.11/site-packages/torch/_dynamo/utils.py", line 1190, in wrap_fake_exception
    return fn()
           ^^^^
  File "/Users/justinc/Documents/GitHub/torch-onnx/venv/lib/python3.11/site-packages/torch/_dynamo/variables/builder.py", line 1881, in <lambda>
    lambda: tx.fake_mode.from_tensor(
            ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/justinc/Documents/GitHub/torch-onnx/venv/lib/python3.11/site-packages/torch/_subclasses/fake_tensor.py", line 1666, in from_tensor
    return self.fake_tensor_converter(
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/justinc/Documents/GitHub/torch-onnx/venv/lib/python3.11/site-packages/torch/_subclasses/fake_tensor.py", line 349, in __call__
    return self.from_real_tensor(
           ^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/justinc/Documents/GitHub/torch-onnx/venv/lib/python3.11/site-packages/torch/_subclasses/fake_tensor.py", line 286, in from_real_tensor
    raise UnsupportedFakeTensorException("quantized nyi in meta tensors")
torch._subclasses.fake_tensor.UnsupportedFakeTensorException: quantized nyi in meta tensors

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Users/justinc/Documents/GitHub/torch-onnx/src/torch_onnx/_patch.py", line 125, in torch_onnx_export_adaptor
    program = torch.export.export(
              ^^^^^^^^^^^^^^^^^^^^
  File "/Users/justinc/Documents/GitHub/torch-onnx/venv/lib/python3.11/site-packages/torch/export/__init__.py", line 174, in export
    return _export(
           ^^^^^^^^
  File "/Users/justinc/Documents/GitHub/torch-onnx/venv/lib/python3.11/site-packages/torch/export/_trace.py", line 635, in wrapper
    raise e
  File "/Users/justinc/Documents/GitHub/torch-onnx/venv/lib/python3.11/site-packages/torch/export/_trace.py", line 618, in wrapper
    ep = fn(*args, **kwargs)
         ^^^^^^^^^^^^^^^^^^^
  File "/Users/justinc/Documents/GitHub/torch-onnx/venv/lib/python3.11/site-packages/torch/export/exported_program.py", line 83, in wrapper
    return fn(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^
  File "/Users/justinc/Documents/GitHub/torch-onnx/venv/lib/python3.11/site-packages/torch/export/_trace.py", line 860, in _export
    gm_torch_level = _export_to_torch_ir(
                     ^^^^^^^^^^^^^^^^^^^^
  File "/Users/justinc/Documents/GitHub/torch-onnx/venv/lib/python3.11/site-packages/torch/export/_trace.py", line 347, in _export_to_torch_ir
    gm_torch_level, _ = torch._dynamo.export(
                        ^^^^^^^^^^^^^^^^^^^^^
  File "/Users/justinc/Documents/GitHub/torch-onnx/venv/lib/python3.11/site-packages/torch/_dynamo/eval_frame.py", line 1311, in inner
    result_traced = opt_f(*args, **kwargs)
                    ^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/justinc/Documents/GitHub/torch-onnx/venv/lib/python3.11/site-packages/torch/nn/modules/module.py", line 1532, in _wrapped_call_impl
    return self._call_impl(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/justinc/Documents/GitHub/torch-onnx/venv/lib/python3.11/site-packages/torch/nn/modules/module.py", line 1541, in _call_impl
    return forward_call(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/justinc/Documents/GitHub/torch-onnx/venv/lib/python3.11/site-packages/torch/_dynamo/eval_frame.py", line 451, in _fn
    return fn(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^
  File "/Users/justinc/Documents/GitHub/torch-onnx/venv/lib/python3.11/site-packages/torch/nn/modules/module.py", line 1532, in _wrapped_call_impl
    return self._call_impl(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/justinc/Documents/GitHub/torch-onnx/venv/lib/python3.11/site-packages/torch/nn/modules/module.py", line 1541, in _call_impl
    return forward_call(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/justinc/Documents/GitHub/torch-onnx/venv/lib/python3.11/site-packages/torch/_dynamo/convert_frame.py", line 921, in catch_errors
    return callback(frame, cache_entry, hooks, frame_state, skip=1)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/justinc/Documents/GitHub/torch-onnx/venv/lib/python3.11/site-packages/torch/_dynamo/convert_frame.py", line 400, in _convert_frame_assert
    return _compile(
           ^^^^^^^^^
  File "/opt/homebrew/Cellar/python@3.11/3.11.8/Frameworks/Python.framework/Versions/3.11/lib/python3.11/contextlib.py", line 81, in inner
    return func(*args, **kwds)
           ^^^^^^^^^^^^^^^^^^^
  File "/Users/justinc/Documents/GitHub/torch-onnx/venv/lib/python3.11/site-packages/torch/_dynamo/convert_frame.py", line 676, in _compile
    guarded_code = compile_inner(code, one_graph, hooks, transform)
                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/justinc/Documents/GitHub/torch-onnx/venv/lib/python3.11/site-packages/torch/_dynamo/utils.py", line 262, in time_wrapper
    r = func(*args, **kwargs)
        ^^^^^^^^^^^^^^^^^^^^^
  File "/Users/justinc/Documents/GitHub/torch-onnx/venv/lib/python3.11/site-packages/torch/_dynamo/convert_frame.py", line 535, in compile_inner
    out_code = transform_code_object(code, transform)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/justinc/Documents/GitHub/torch-onnx/venv/lib/python3.11/site-packages/torch/_dynamo/bytecode_transformation.py", line 1036, in transform_code_object
    transformations(instructions, code_options)
  File "/Users/justinc/Documents/GitHub/torch-onnx/venv/lib/python3.11/site-packages/torch/_dynamo/convert_frame.py", line 165, in _fn
    return fn(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^
  File "/Users/justinc/Documents/GitHub/torch-onnx/venv/lib/python3.11/site-packages/torch/_dynamo/convert_frame.py", line 482, in transform
    tracer = InstructionTranslator(
             ^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/justinc/Documents/GitHub/torch-onnx/venv/lib/python3.11/site-packages/torch/_dynamo/symbolic_convert.py", line 2115, in __init__
    self.symbolic_locals = VariableTracker.apply(
                           ^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/justinc/Documents/GitHub/torch-onnx/venv/lib/python3.11/site-packages/torch/_dynamo/variables/base.py", line 217, in apply
    result = {
             ^
  File "/Users/justinc/Documents/GitHub/torch-onnx/venv/lib/python3.11/site-packages/torch/_dynamo/variables/base.py", line 218, in <dictcomp>
    k: cls.apply(fn, v, cache, skip_fn) for k, v in list(value.items())
       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/justinc/Documents/GitHub/torch-onnx/venv/lib/python3.11/site-packages/torch/_dynamo/variables/base.py", line 203, in apply
    result = fn(update_object_dict(value))
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/justinc/Documents/GitHub/torch-onnx/venv/lib/python3.11/site-packages/torch/_dynamo/symbolic_convert.py", line 2116, in <lambda>
    lambda x: x.realize(), self.symbolic_locals
              ^^^^^^^^^^^
  File "/Users/justinc/Documents/GitHub/torch-onnx/venv/lib/python3.11/site-packages/torch/_dynamo/variables/lazy.py", line 58, in realize
    self._cache.realize(self.parents_tracker)
  File "/Users/justinc/Documents/GitHub/torch-onnx/venv/lib/python3.11/site-packages/torch/_dynamo/variables/lazy.py", line 24, in realize
    self.vt = VariableBuilder(tx, self.source)(self.value)
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/justinc/Documents/GitHub/torch-onnx/venv/lib/python3.11/site-packages/torch/_dynamo/variables/builder.py", line 269, in __call__
    vt = self._wrap(value)
         ^^^^^^^^^^^^^^^^^
  File "/Users/justinc/Documents/GitHub/torch-onnx/venv/lib/python3.11/site-packages/torch/_dynamo/variables/builder.py", line 402, in _wrap
    return type_dispatch(self, value)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/justinc/Documents/GitHub/torch-onnx/venv/lib/python3.11/site-packages/torch/_dynamo/variables/builder.py", line 1073, in wrap_tensor
    tensor_variable = wrap_fx_proxy(
                      ^^^^^^^^^^^^^^
  File "/Users/justinc/Documents/GitHub/torch-onnx/venv/lib/python3.11/site-packages/torch/_dynamo/variables/builder.py", line 1330, in wrap_fx_proxy
    return wrap_fx_proxy_cls(target_cls=TensorVariable, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/justinc/Documents/GitHub/torch-onnx/venv/lib/python3.11/site-packages/torch/_dynamo/variables/builder.py", line 1440, in wrap_fx_proxy_cls
    example_value = wrap_to_fake_tensor_and_record(
                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/justinc/Documents/GitHub/torch-onnx/venv/lib/python3.11/site-packages/torch/_dynamo/variables/builder.py", line 1880, in wrap_to_fake_tensor_and_record
    fake_e = wrap_fake_exception(
             ^^^^^^^^^^^^^^^^^^^^
  File "/Users/justinc/Documents/GitHub/torch-onnx/venv/lib/python3.11/site-packages/torch/_dynamo/utils.py", line 1196, in wrap_fake_exception
    raise unimplemented(msg) from e
          ^^^^^^^^^^^^^^^^^^
  File "/Users/justinc/Documents/GitHub/torch-onnx/venv/lib/python3.11/site-packages/torch/_dynamo/exc.py", line 190, in unimplemented
    raise Unsupported(msg)
torch._dynamo.exc.Unsupported: Unsupported: quantized nyi in meta tensors with fake tensor propagation.

Set TORCH_LOGS="+dynamo" and TORCHDYNAMO_VERBOSE=1 for more information

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/Users/justinc/Documents/GitHub/torch-onnx/src/torch_onnx/_patch.py", line 182, in _torch_onnx_export_adapter_with_error_report
    torch_onnx_export_adaptor(*args, **kwargs, check=True)
  File "/Users/justinc/Documents/GitHub/torch-onnx/src/torch_onnx/_patch.py", line 129, in torch_onnx_export_adaptor
    raise TorchExportError(
torch_onnx._patch.TorchExportError: Failed to export the model with torch.export. This is step 1/2 of exporting the model to ONNX. Please create an issue in the PyTorch GitHub repository against the *torch.export* component and attach the full error stack as well as reproduction scripts.