justinchuby / torch-onnx

A standalone version of the next PyTorch ONNX exporter
MIT License
3 stars 1 forks source link

Variadic support: Constant input of tuple is unsupported #39

Closed justinchuby closed 2 months ago

justinchuby commented 5 months ago

PyTorch ONNX Conversion Error Report

✅ Obtain model graph with `torch.export.export`
❌ Translate the graph into ONNX
⚪ Run `onnx.checker` on the ONNX model
⚪ Execute the model with ONNX Runtime
⚪ Validate model output accuracy

Error message:

Traceback (most recent call last):
  File "/Users/justinc/Documents/GitHub/torch-onnx/src/torch_onnx/_building.py", line 382, in eval
    outputs = self._call_op(op_signature, named_inputs, named_attrs)
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/justinc/Documents/GitHub/torch-onnx/src/torch_onnx/_building.py", line 340, in _call_op
    converted_named_inputs = _process_python_constants(
                             ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/justinc/Documents/GitHub/torch-onnx/src/torch_onnx/_building.py", line 253, in _process_python_constants
    raise TypeError(
TypeError: Constant input '(SymbolicTensor('anonymous:13290656480', type=None, shape=None, producer=anonymous_node:13278755600, index=0), 0)' of type '<class 'tuple'>' is not supported

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/_building.py", line 453, in eval_function
    return function.function(**named_inputs, **named_attrs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/justinc/Documents/GitHub/onnxscript/onnxscript/function_libs/torch_lib/ops/core.py", line 2582, in _aten_diagonal_onnx
    length = op.Max(op.Min(length, min_dim_size), 0)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/justinc/Documents/GitHub/onnxscript/onnxscript/onnx_opset/_impl/opset13.py", line 1809, in Max
    return op(*self._prepare_inputs(schema, *data_0))
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/justinc/Documents/GitHub/onnxscript/onnxscript/values.py", line 300, in __call__
    return evaluator.default().eval(schema, args, kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/justinc/Documents/GitHub/torch-onnx/src/torch_onnx/_building.py", line 387, in eval
    raise RuntimeError(
RuntimeError: Error calling operator 'Max' with args (SymbolicTensor('anonymous:13290656480', type=None, shape=None, producer=anonymous_node:13278755600, index=0), 0) and kwargs {}.

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/_core.py", line 398, in _handle_call_function_node_with_lowering
    outputs = onnx_function(*onnx_args, **onnx_kwargs)
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/justinc/Documents/GitHub/onnxscript/onnxscript/values.py", line 582, in __call__
    return self.func(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/justinc/Documents/GitHub/onnxscript/onnxscript/function_libs/torch_lib/ops/core.py", line 2534, in aten_diagonal
    return _aten_diagonal_onnx(self, offset, dim1, dim2, perm, axes)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/justinc/Documents/GitHub/onnxscript/onnxscript/values.py", line 528, in __call__
    return evaluator.default().eval_function(self, args, kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/justinc/Documents/GitHub/torch-onnx/src/torch_onnx/_building.py", line 462, in eval_function
    raise RuntimeError(
RuntimeError: Error calling function '_aten_diagonal_onnx' with args (Input('arg0_1', type=Tensor(FLOAT), shape=[3,5,5], producer=None, index=None), 0, 1, 2, [0, 1, 2], [1]) and kwargs {}.

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/_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 400, in _handle_call_function_node_with_lowering
    raise RuntimeError(
RuntimeError: Error when calling function 'TracedOnnxFunction(<function aten_diagonal at 0x16864ce00>)' with args '[Input('arg0_1', type=Tensor(FLOAT), shape=[3,5,5], producer=None, index=None), 0, 1, 2]' and kwargs '{}'

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 222, in _torch_onnx_export
    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 %diagonal : [num_users=1] = call_function[target=torch.ops.aten.diagonal.default](args = (%arg0_1, 0, 1, 2), kwargs = {}). See the stack trace for more information.

Exported program:

ExportedProgram:
    class GraphModule(torch.nn.Module):
        def forward(self, arg0_1: "f32[3, 5, 5]"):
            # File: /Users/justinc/Documents/GitHub/torch-onnx/tests/torch_tests/torch_onnx_test.py:8377 in forward, code: return torch.einsum(eqn, x)
            diagonal: "f32[3, 5]" = torch.ops.aten.diagonal.default(arg0_1, 0, 1, 2);  arg0_1 = None
            permute: "f32[3, 5]" = torch.ops.aten.permute.default(diagonal, [0, 1]);  diagonal = None
            permute_1: "f32[3, 5]" = torch.ops.aten.permute.default(permute, [0, 1]);  permute = None
            return (permute_1,)

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

Analysis

PyTorch ONNX Conversion Analysis

Model Information

The model has 0 parameters and 0 buffers (non-trainable parameters). Number of parameters per dtype:

defaultdict(<class 'int'>, {})

Number of buffers per dtype:

defaultdict(<class 'int'>, {})

Inputs:

Outputs:

The FX graph has 5 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 registered ONNX decompositions.

justinchuby commented 3 months ago

This is variadic