onnx-simplifier icon indicating copy to clipboard operation
onnx-simplifier copied to clipboard

[BUG] onnx.onnx_cpp2py_export.checker.ValidationError: Field 'type' of 'value_info' is required but missing.

Open yqzhishen opened this issue 1 year ago • 2 comments

Describe the bug

ONNX Simplifier fails to simplify models with optional types.

The following minimum demo:

from typing import Optional

import onnx
import onnxsim
import torch


class MyModule(torch.nn.Module):
    def forward(self, x: Optional[torch.Tensor]):
        return x is not None


module = MyModule()
module = torch.jit.script(module, example_inputs=[(torch.tensor(1),), (None,)])
torch.onnx.export(
    module, (torch.tensor(1),), 'optional.onnx',
    input_names=['x'], output_names=['y'], opset_version=15
)
model = onnx.load('optional.onnx')
model, _ = onnxsim.simplify(model, include_subgraph=True)
onnx.save(model, 'optional.onnx')

will get the following error:

Traceback (most recent call last):
  File "E:\OpenVPI\DiffSinger\optional_test.py", line 20, in <module>
    model, _ = onnxsim.simplify(model, include_subgraph=True)
  File "E:\OpenVPI\DiffSinger\venv\lib\site-packages\onnxsim\onnx_simplifier.py", line 199, in simplify
    model_opt_bytes = C.simplify(
onnx.onnx_cpp2py_export.checker.ValidationError: Field 'type' of 'value_info' is required but missing.

Model

optional.zip

yqzhishen avatar May 18 '23 18:05 yqzhishen

Bug still triged by optional forward arg.

Alicture avatar Apr 11 '24 06:04 Alicture

How to solve the issue? Anyone knows?

philleer avatar Aug 12 '24 03:08 philleer