Tvm: [RELAY][Bug] 'name_hint' AttributeError issue when covert tensorflow to TVM

Created on 6 Nov 2019  Â·  19Comments  Â·  Source: apache/tvm

This issue happens when converting tf.tile and tf.transpose with relay.frontend.from_tensorflow

My environment is:
develop: python3.6, tensorflow1.14
convert to TVM: container of tvmai/demo-gpu

Here's the error log for converting code which contains tf.transpose:

Traceback (most recent call last):

  File "read_pb_to_TVM_test.py", line 80, in <module>
    shape=shape_dict)

  File "/usr/tvm/python/tvm/relay/frontend/tensorflow.py", line 2372, in from_tensorflow
    mod, params = g.from_tensorflow(graph, layout, shape, outputs)

  File "/usr/tvm/python/tvm/relay/frontend/tensorflow.py", line 2017, in from_tensorflow
    op = self._convert_operator(node.op, inputs, attr, graph)

  File "/usr/tvm/python/tvm/relay/frontend/tensorflow.py", line 2335, in _convert_operator
    sym = convert_map[op_name](inputs, attrs, self._params)

  File "/usr/tvm/python/tvm/relay/frontend/tensorflow.py", line 932, in _impl
    axes = _get_list_param(params, inputs[1])

  File "/usr/tvm/python/tvm/relay/frontend/tensorflow.py", line 96, in _get_list_param
    return _get_param(params, input_node).tolist()

  File "/usr/tvm/python/tvm/relay/frontend/tensorflow.py", line 90, in _get_param
    return params.pop(input_node.name_hint).asnumpy()

  File "/usr/tvm/python/tvm/_ffi/_ctypes/node.py", line 75, in __getattr__
    "'%s' object has no attribute '%s'" % (str(type(self)), name))

AttributeError: '<class 'tvm.relay.expr.Call'>' object has no attribute 'name_hint'

thanks!

Most helpful comment

We saw the issue these days. @kevinthesun has a fix locally for the similar issue.

All 19 comments

We saw the issue these days. @kevinthesun has a fix locally for the similar issue.

Great!
Thanks for the prompt response. May I ask when will the fixed-version been released?

Having the same issue while reading ONNX model into TVM which was exported from Pytorch.

@kevinthesun does your fix resolve the problem?

@kevinthesun does your fix resolve the problem?

Apparently my problem is caused not by tvm but the way pytorch exported the upsample operator. Pytorch's exporter did not write the "scale" attribute. For now, my hack around is to manually supply the values of the scale operator.

I would say that you could print the operator name thats causing this error to come or is it any operator that causes this problem ?

@FinnWeng @Msabih I met the same problem, have you solved it? someone in TVM forum said that it because of pytorch version, but I changed to 1.0.1 and re-exported the onnx file, still failed

I have the same problem with PyTorch 1.3 and ONNX v4, @Msabih how did you exactly manually supply the values to the scale operator?

@FinnWeng would it be possible to provide a minimal case for this issue?

@Aeroxander It is not related with pytorch or onnx version, it is because of TVM on windows, I used the same pytorch and onnx and TVM on ubuntu, it works well

@anguoyang Not sure, I was already using Ubuntu. Besides that, I think I have figured out why the error is coming, when Pytorch exports to ONNX, it does not write the Upsample operator properly as specified in the ONNX standard (opset version 9). The opset version 11 export works flawlessly from pytorch side but the Upsample has been deprecated and changed to resize which cannot be read by TVM.

Perhaps your error was caused by a different operator and thats why it was solved by switching to Ubuntu ?

@Aeroxander In my case, the model was only using one scaling factor so the quick hack was just to supply the constant. However I would look into a proper solution.

I would try to upload a sample script and snippet for the case.

@Msabih That'd be great, thanks!

Hi @yongwww
I've tried to reproduce the problem with minimum case, but I can't find the right recipes. So sorry for I can't provide it for now.

@yongwww Here's my ONNX (PyTorch) model:
matrixnew.zip
Error happens when I compile the model by following this https://docs.tvm.ai/tutorials/frontend/from_onnx.html

Don't know if I should create a new issue for this as it looks pretty similar.

Haven't found a fix yet as I don't know how to change the ONNX scale parameters in the model.

EDIT:

Someone already brought up the Resize operator missing issue: https://discuss.tvm.ai/t/relay-onnx-frontend-implement-resize-operation/5131/7

With this one fixing it:
https://github.com/apache/incubator-tvm/pull/4536

So this should only fix the PyTorch resize error. If you have ONNX v9 you can just update it through https://github.com/onnx/onnx/blob/master/docs/PythonAPIOverview.md#converting-version-of-an-onnx-model-within-default-domain-aionnx

any update with tf.tile?

@Aeroxander, I am able to reproduce this issue using an ONNX (pytorch) model with the following versions:

pytorch: 1.2.0
onnx: 1.6.0
tvm: 0.7.dev0

Ubuntu 16.04.6 LTS

I can provide the model and code if necessary. Error is happening consistently.

name_hint_issue

Are you getting the same error log?
Have you found a way to fix it?

Regards,
Edgar

@yongwww @kevinthesun Have you found a way to fix it?

I also encountered this problem with tensorflow.

Tensorflow version: 1.15.0 or 1.14.0
tvm version: 0.7.dev0
CentOS Linux release 7.7

If you check the class method _impl_v9 of class Upsample, this is line 778 on tvm 0.7

        assert len(inputs) == 2, "Upsample op take 2 inputs, {} given".format(len(inputs))
        scales = params[inputs[1].name_hint].asnumpy()

The error comes at this line

       scales = params[inputs[1].name_hint].asnumpy()

I found out that there was incompatibility between how pytorch exported upsample operator in onnx and how tvm imported. The fault might be on pytorch's side or tvm's side, I am not sure.

But I got the hack to get my network working because all of its upsample were by a factor of 2. So I manually supplied the scales value as follows

comment the error giving line

        # scales = params[inputs[1].name_hint].asnumpy() 

        # manually supply the scales value
        scales = np.array([1.0, 1.0, 2.0, 2.0])

Could the people having problem with tensorflow verify if manually supplying the scales value gets rid of the error ?

Tensorflow error code:

def _get_param(params, input_node):
    if isinstance(input_node, _expr.Constant):
        return np.atleast_1d(input_node.data.asnumpy())
    # input_node is Call,no name_hint
    return params.pop(input_node.name_hint).asnumpy()

def _get_num_param(params, input_node):
    return _get_param(params, input_node).item()

def _get_list_param(params, input_node):
    return _get_param(params, input_node).tolist()
def _tile():
    def _impl(inputs, attr, params):
        #inputs.pop() -> CallNode( Op(expand_dim),[CallNode(Op(not_equal),[...])],relay.attrs.ExpandDimsAttrs(0x184d9408),[])
        reps = _get_list_param(params, inputs.pop())
        ......

I might need the op that prints the tensorflow model to know what param is needed here。

close for now due to inactive status, feel fre to open another thread on https://discuss.tvm.ai/

Was this page helpful?
0 / 5 - 0 ratings