justinchuby / torch-onnx

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

Expected unbind to output sequence, got %"val_unbind"<?,?> #52

Closed justinchuby closed 1 week ago

justinchuby commented 2 weeks 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/_core.py", line 480, in _add_nodes
    _handle_call_function_node_with_lowering(

  File "/Users/justinc/Documents/GitHub/torch-onnx/src/torch_onnx/_core.py", line 342, in _handle_call_function_node_with_lowering
    _handle_getitem_node(node, node_name_to_values)

  File "/Users/justinc/Documents/GitHub/torch-onnx/src/torch_onnx/_core.py", line 237, in _handle_getitem_node
    assert isinstance(

AssertionError: Expected unbind to output sequence, got %"val_unbind"<?,?>

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 196, 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 619, 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 491, in _add_nodes
    raise errors.OnnxConversionError(

torch_onnx.errors.OnnxConversionError: Error when translating node %getitem_1 : [num_users=1] = call_function[target=operator.getitem](args = (%unbind, 1), kwargs = {}). See the stack trace for more information.

Exported program:

ExportedProgram:
    class GraphModule(torch.nn.Module):
        def forward(self, arg0_1: "f32[3, 4, 5]"):
            # File: /Users/justinc/Documents/GitHub/torch-onnx/tests/torch_tests/torch_onnx_test.py:5444 in forward, code: _, out, _ = input.unbind()
            unbind = torch.ops.aten.unbind.int(arg0_1);  arg0_1 = None
            getitem_1: "f32[4, 5]" = unbind[1];  unbind = None
            return (getitem_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='getitem_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 4 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 1 week ago

python tests/torch_tests/torch_onnx_test.py -k test_unbind