Xilinx / finn-base

Open Source Compiler Framework using ONNX as Frontend and IR
https://finn-base.readthedocs.io/
BSD 3-Clause "New" or "Revised" License
29 stars 17 forks source link

Can't unset tensor shape, with set_tensor_shape #40

Open heborras opened 3 years ago

heborras commented 3 years ago

It is currently not possible to easily remove the shape from a given tensor.

The attached .zip file contains an QONNX model, which has unset tensors: CNV_2W2A.zip

Running the following:

from finn.core.modelwrapper import ModelWrapper
model = ModelWrapper("CNV_2W2A.onnx")
print(model.get_tensor_shape("55"))
model.set_tensor_shape("55", None)
print(model.get_tensor_shape("55"))

produces:

None
[]

When it should produce:

None
None

Unsetting the tensor shape is in particular useful, when one has changed some up-stream tensor and wants to run shape inference again for the rest of the down-stream tensors. Because as long as the down-stream tensors have wrong or out-dated shapes the shape inference will always fail.

This would require changes to the set_tensor_shape function here: https://github.com/Xilinx/finn-base/blob/92f00196f931b63b08b304c8acac49b078c9c741/src/finn/core/modelwrapper.py#L188 Such that the function will not append a new tensor_value_info, when the argument tensor_shape is None.