Hi
I was able to generate an alexnet.onnx graph from Pytorch using this tutorial
https://pytorch.org/docs/stable/onnx.html
I then tried to run this graph with GLOW. I see that in the generated ONNX graph for the Reshape operator, the tensor names are id: 29 for data and id: 36 for shape input. I get this assertion error -
(gdb) bt
assertion=assertion@entry=0x643460 "tensors_.count(name) && \"There is no tensor registered with this name.\"",
file=file@entry=0x643420 "/ml/arch/dmohan/projects/glow/lib/Importer/ProtobufLoader.cpp", line=line@entry=33,
function=function@entry=0x643940 <glow::ProtobufLoader::getTensorByName(llvm::StringRef)::__PRETTY_FUNCTION__> "glow::Tensor* glow::ProtobufLoader::getTensorByName(llvm::StringRef)") at assert.c:92
file=0x643420 "/ml/arch/dmohan/projects/glow/lib/Importer/ProtobufLoader.cpp", line=33,
function=0x643940 <glow::ProtobufLoader::getTensorByName(llvm::StringRef)::__PRETTY_FUNCTION__> "glow::Tensor* glow::ProtobufLoader::getTensorByName(llvm::StringRef)") at assert.c:101
at /ml/arch/dmohan/projects/glow/lib/Importer/ProtobufLoader.cpp:32
dict=std::unordered_map with 0 elements) at /ml/arch/dmohan/projects/glow/include/glow/Importer/CommonOperatorLoader.h:240
typeName=..., op=..., dict=std::unordered_map with 0 elements)
at /ml/arch/dmohan/projects/glow/include/glow/Importer/CommonOperatorLoader.h:429
modelDescFilename="/ml/arch/dmohan/projects/vision/alexnet.onnx", tensorNames=..., tensors=..., F=...)
at /ml/arch/dmohan/projects/glow/lib/Importer/ONNX.cpp:571
(gdb) f 5
dict=std::unordered_map with 0 elements) at /ml/arch/dmohan/projects/glow/include/glow/Importer/CommonOperatorLoader.h:240
240 Tensor *constShapeTensor = getTensorByName(op.input(1));
(gdb) p op.input(1)
$1 = "36"
If you look at the ONNX loader, "shape" comes either from the "shape" attribute or from the input.
It seems like Glow expects input(1) to be statically defined in the net.initializers().
Does that "shape" come from an activation?
It seems the shape parameter in the graph doesn't have a kind:initializer that I see for Reshape nodes in other graphs. I also see the data input to the Reshape node comes from a previous MaxPool node and the shape input comes from a previous Concat layer and hence the concat=>result is becoming the Shape
I've had issues like this and at least in my case the shape info is statically known, but the ONNX exporter decided to export multiple nodes to create the shape vector instead of statically passing it in as member inputs. We would need to do some sort of constant propagation to get the shape, but we don't currently support this. Your options are to implement this constant propagation in Glow, modify the proto manually with the shape info yourself, or ONNX needs to be taught to not do it like this.
"modify the proto manually with the shape info yourself"
Seems a good short-term solution for one off problem.
@dmoham1476 does that work for you? If it does feel free to close the issue.
Ok, I see a similar behavior with the Shape when I converted pytorch sqeezenet to onnx using torch.onnx
Most helpful comment
I've had issues like this and at least in my case the shape info is statically known, but the ONNX exporter decided to export multiple nodes to create the shape vector instead of statically passing it in as member inputs. We would need to do some sort of constant propagation to get the shape, but we don't currently support this. Your options are to implement this constant propagation in Glow, modify the proto manually with the shape info yourself, or ONNX needs to be taught to not do it like this.