Hi. I am starting this topic as a result of #1514 discussion.
The original goal behind the PR was to import a set of TF models from Tensorflow-Examples project. (Link points to a fork containing minor adjustments of the original examples)
Besides missing operations issues, a problem of other kind has appeared: simple_save and other types of TF export functions may generate a graph which has first placeholders nodes placed after first Consts.
Unfortunately, this breaks the required precondition since NNVM treats first constant in a special way. While I have a simple workaround for this problem, one may think about more generic solution which would treat all constants as parameters.
In your opinion, does this task look reasonable at the moment, and what pitfalls are to avoid?
Let me be more specific on one particular issue:
According to the code, nodes have _input_shapes assigned, if they dont have params. Does it means that input_shapes would be defined only for inputs (first const + placeholders)? If so, why do we use this information in operations (e.g. here)? AFAIK it stops some particular models from working.
“According to the code, nodes have _input_shapes assigned, if they dont have params.” : Correction, we pass shapes for non param/constant input nodes as the shape for params can be queried directly from params.
“Does it means that input_shapes would be defined only for inputs (first const + placeholders)?” : A bit confused here. Are you referring to graph level inputs or current node input ?
“_input_shapes” attribute introduction is a work around for situations where a symbol creation depends on the shape of non param/constant input node.
I am planning for some cleanup and maintenance activity for “_input_shapes” this weekend to keep it clean and simplified.
Please refer to the detailed explanation below.
The _input_shapes is an additional attribute we append to each node attributes.
It represents out_shape of input nodes for the current node.
Ex: conv_out = conv(data, weights, bias).
Here the _conv import wrapper receive attribute _input_shapes which contain the shape of (data, weights, bias). Where weights, bias can be params which is straight forward. The catch here is with shape of data.
NNVM process in general contain import and compile steps.
Import just a conversion of nodes+attributes from foreign framework to NNVM (No input/output shapes are inferred here).
Compile takes graph input shapes and infers all the nodes for integrity.
Going back to “The catch here is with shape of data”: Shape of data is required to set attributes for pad operator before convolution.
Finally the workaround for above situation is to enforce “add_shapes=True” while exporting a model in tensorflow and supplying “_input_shapes” attribute to each node in from_tensorfow.
Are you referring to graph level inputs or current node input ?
I’m referring the graph-level inputs here. If I see it correctly, _input_shapes collection doesn’t have entries for non- graph-level inputs. In contrast, graph-level inputs don’t have _params associated with them.
I am planning for some cleanup and maintenance activity for “_input_shapes” this weekend to keep it clean and simplified.
Thanks! Here is a demonstration of what I am talking about: If one swap line 197(in_filter=…) with line 198(in_data=…) of test_forward.py and replaces Const with Const_1 on lines 218 and 221 to continue use the correct nodes as graph-input, the _test_convolution function stops working. The reason is missing _params entry for the very first constant. KeyError: 'Const' is raised by my local copy of tvm.
Meanwhile, I’m going to work on supporting more Tensorflow operations. I need Pack operation to run my model, also I plan to add bindings for Fill, Split, Tanh and Unpack later. It shouldn’t be a big problem.