[Tensorflow] object has no attribute 'name_hint', max_reduce and reshape

Hi,

I am trying to compile a pb file in TVM. Originally, the pb file was not generated using the “add_shapes=True” flag. But after enabling this I got the following error. It seems is related to the Max reduce operator when getting the name_hint. Any ideas?

Thanks

  File "/home/user/tvm/python/tvm/relay/frontend/tensorflow.py", line 2473, in from_tensorflow
    mod, params = g.from_tensorflow(graph, layout, shape, outputs)
  File "/home/user/tvm/python/tvm/relay/frontend/tensorflow.py", line 2117, in from_tensorflow
    op = self._convert_operator(node.op, inputs, attr, graph)
  File "/home/user/tvm/python/tvm/relay/frontend/tensorflow.py", line 2436, in _convert_operator
    sym = convert_map[op_name](inputs, attrs, self._params)
  File "/home/user/tvm/python/tvm/relay/frontend/tensorflow.py", line 901, in _impl
    axis = params.pop(inputs[1].name_hint).asnumpy()
  File "/home/user/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'

Make sure max_reduce has axis or not (could use Netron tool). If you could make sure there is one condition max_reduce doesn’t have axis. You could do like this:

        axis = params.pop(inputs[1].name_hint).asnumpy()
        axis = tuple(axis)

becomes

        try:
            axis = params.pop(inputs[1].name_hint).asnumpy()
            axis = tuple(axis)
        except (IndexError, KeyError, AttributeError):
            axis = None

Hi,

Thanks for the suggestion. After removing a range operator in the input of the max_reduce, I move forward. But now I am facing a similiar issue with the reshape operator. It seems that the TF frontend is not able to get nor infer the shape

Traceback (most recent call last):
  File "/home/user/tvm/python/tvm/relay/frontend/tensorflow.py", line 722, in _impl
    shape_arg = _get_tuple_param(params, pop_node)
  File "/home/user/tvm/python/tvm/relay/frontend/tensorflow.py", line 258, in _get_tuple_param
    return tuple(_get_param(params, input_node))
  File "/home/user/tvm/python/tvm/relay/frontend/tensorflow.py", line 249, in _get_param
    return params.pop(input_node.name_hint).asnumpy()
  File "/home/user/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'

During handling of the above exception, another exception occurred:

  ....
  File "/home/user/tvm/python/tvm/relay/frontend/tensorflow.py", line 2473, in from_tensorflow
    mod, params = g.from_tensorflow(graph, layout, shape, outputs)
  File "/home/user/tvm/python/tvm/relay/frontend/tensorflow.py", line 2117, in from_tensorflow
    op = self._convert_operator(node.op, inputs, attr, graph)
  File "/home/user/tvm/python/tvm/relay/frontend/tensorflow.py", line 2436, in _convert_operator
    sym = convert_map[op_name](inputs, attrs, self._params)
  File "/home/user/tvm/python/tvm/relay/frontend/tensorflow.py", line 726, in _impl
    params_new = _infer_value(pop_node, params)
  File "/home/user/tvm/python/tvm/relay/frontend/tensorflow.py", line 46, in _infer_value
    graph, lib, params = tvm.relay.build(func, target="llvm", params=params)
  File "/home/user/tvm/python/tvm/relay/build_module.py", line 207, in build
    graph_json, mod, params = bld_mod.build(func, target, target_host, params)
  File "/home/user/tvm/python/tvm/relay/build_module.py", line 108, in build
    self._build(func, target, target_host)
  File "/home/user/tvm/python/tvm/_ffi/_ctypes/function.py", line 210, in __call__
    raise get_last_ffi_error()
tvm._ffi.base.TVMError: Traceback (most recent call last):

Any ideas in this case?

You can try to use _infer_value() to evaluate CallNode to a constant value which can be used as a paramter

The current implementation of reshape in the Tensorflow frontend is as follows. There _infer_value() is already used and it also fails, i.e., both try and except parts failed. Is that what you meant?

def _reshape():
    def _impl(inputs, attr, params):
        pop_node = inputs.pop(1)
        try:
            shape_arg = _get_tuple_param(params, pop_node)
        except AttributeError:
            # Shape operator is already pruned, hence
            # try to infer shape by precompute prune if possible.
            params_new = _infer_value(pop_node, params)
            shape_arg = tuple(params_new.asnumpy().astype('int64').flatten())
        return AttrCvt(
            op_name="reshape",
            extras={'newshape': shape_arg},
            ignores=['Tshape'])(inputs, attr)
    return _impl

Having a shape operator before the reshape in the input[1] helps?. In this case there is a concatenate operator before the reshape, which is this call node I guess. I asking this because in the comments of the code above it says “Shape operator is already pruned”

I didn’t see the log closely…

I think you first need to check the detail information after

tvm._ffi.base.TVMError: Traceback (most recent call last):

It seems that something goes wrong when building module

Yes, I am aware of that. That is what happens when the function _infer_value is called. It tries to infer the value by building a module. However, there it fails. In the network, there is a concat operation preceding the reshape operator. From the concat operator comes the shape value for the Reshape. Is this an issue? normally the shape comes from a constant or from the tf.shape operator.

Any ideas?

Thanks

@srkreddy1238 can you please check this one?

I think I have a problem with a concat operation because all the input tensors are not of the same size. Is this a limitation of Relay?