Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 1 addition & 10 deletions python/tvm/driver/tvmc/frontends.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,16 +161,7 @@ def load(self, path):
# pylint: disable=E1101
model = onnx.load(path)

# pylint: disable=E1101
name = model.graph.input[0].name

# pylint: disable=E1101
proto_shape = model.graph.input[0].type.tensor_type.shape.dim
shape = [d.dim_value for d in proto_shape]

shape_dict = {name: shape}

return relay.frontend.from_onnx(model, shape_dict)
return relay.frontend.from_onnx(model)


class TensorflowFrontend(Frontend):
Expand Down
6 changes: 6 additions & 0 deletions python/tvm/relay/frontend/onnx.py
Original file line number Diff line number Diff line change
Expand Up @@ -2737,6 +2737,12 @@ def from_onnx(model, shape=None, dtype="float32", opset=None, freeze_params=Fals
warnings.warn(str(e))
except ImportError:
pass

# if no explicit input's shape came from user, then initialize shape as it is defined in onnx model
if shape is None:
shape = {}
for i in model.graph.input:
shape[i.name] = [dim.dim_value for dim in i.type.tensor_type.shape.dim]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we need to edit this logic just a little bit. If we have an unspecified input shape in the onnx model, it will show up as a variable, I think we need to identify that case and convert it to relay.Any() here.

For instance, this version of BERT has for one of it's input shapes [input_ids_dynamic_axes_1,384] I believe this would fail on those inputs.

g = GraphProto(shape, dtype)
graph = model.graph
if opset is None:
Expand Down