Skip to content

[Feature] Support for NonZero ONNX operator #4568

@antimora

Description

@antimora

Filing this ticket to request support for NonZero ONNX operator which has been available since version 9 of the default ONNX operator set. Since PyTorch 1.2, ONNX exports with opset 9 as default (And currently Pytorch only exports with 9 and 10 opset versions).

Unless there is some work around this deficiency I cannot use my model with the latest version ( master@e6ff3f701b2bf3e2204709aea392b0abdf6a85d0).

Here is a small model to recreate the issue:
trouble.zip. Zip includes onnx, onnxtxt and graph files.

Here is python code to try with:

import onnx
import numpy as np
import tvm
import tvm.relay as relay

onnx_model = onnx.load('trouble.onnx')

input1 = np.random.rand(1, 192, 100)
input2 = np.random.rand(1)

target = 'llvm'

shape_dict = {'0': input1.shape, '1': input2.shape}
mod, params = relay.frontend.from_onnx(onnx_model, shape_dict)

Here is the error message:

rroot@future:/workspace# /usr/bin/python3 /workspace/trouble_onnx.py
Traceback (most recent call last):

  File "/workspace/trouble_onnx.py", line 15, in <module>
    mod, params = relay.frontend.from_onnx(onnx_model, shape_dict)

  File "/workspace/python/tvm/relay/frontend/onnx.py", line 1601, in from_onnx
    mod, params = g.from_onnx(graph, opset)

  File "/workspace/python/tvm/relay/frontend/onnx.py", line 1406, in from_onnx
    raise tvm.error.OpNotImplemented(msg)

tvm.error.OpNotImplemented: The following operators are not supported for frontend ONNX: NonZero

Please note this onnx model will also fail with missing Expand operator for the tvm 0.6 version but this has been fixed by: #4483

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions