Glow: Pytorch generated ONNX graph with GLOW

Created on 4 Sep 2018  路  5Comments  路  Source: pytorch/glow

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 -

3 0x00007ffff6810c82 in __GI___assert_fail (assertion=0x643460 "tensors_.count(name) && \"There is no tensor registered with this name.\"",

(gdb) bt

0 0x00007ffff6818428 in __GI_raise (sig=sig@entry=6) at ../sysdeps/unix/sysv/linux/raise.c:54

1 0x00007ffff681a02a in __GI_abort () at abort.c:89

2 0x00007ffff6810bd7 in __assert_fail_base (fmt=,

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

3 0x00007ffff6810c82 in __GI___assert_fail (assertion=0x643460 "tensors_.count(name) && \"There is no tensor registered with this name.\"",

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

4 0x0000000000424373 in glow::ProtobufLoader::getTensorByName (this=0x959910, name=...)

at /ml/arch/dmohan/projects/glow/lib/Importer/ProtobufLoader.cpp:32

5 0x000000000044ad28 in glow::CommonOperatorLoader::loadReshape (this=0x959910, op=...,

dict=std::unordered_map with 0 elements) at /ml/arch/dmohan/projects/glow/include/glow/Importer/CommonOperatorLoader.h:240

6 0x000000000044654e in glow::CommonOperatorLoader::tryLoadCommonOperator (this=0x959910,

typeName=..., op=..., dict=std::unordered_map with 0 elements)
at /ml/arch/dmohan/projects/glow/include/glow/Importer/CommonOperatorLoader.h:429

7 0x000000000043fece in glow::ONNXModelLoader::loadOperator (this=0x959910, op=...) at /ml/arch/dmohan/projects/glow/lib/Importer/ONNX.cpp:181

8 0x0000000000443dbe in glow::ONNXModelLoader::loadNetwork (this=0x959910, net=...) at /ml/arch/dmohan/projects/glow/lib/Importer/ONNX.cpp:514

9 0x000000000044426f in glow::ONNXModelLoader::ONNXModelLoader (this=0x959910,

modelDescFilename="/ml/arch/dmohan/projects/vision/alexnet.onnx", tensorNames=..., tensors=..., F=...)
at /ml/arch/dmohan/projects/glow/lib/Importer/ONNX.cpp:571

10 0x000000000041b88f in main (argc=4, argv=0x7fffffffe9c8) at /ml/arch/dmohan/projects/glow/tools/loader/ImageClassifier.cpp:197

(gdb) f 5

5 0x000000000044ad28 in glow::CommonOperatorLoader::loadReshape (this=0x959910, op=...,

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"

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.

All 5 comments

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

Was this page helpful?
0 / 5 - 0 ratings

Related issues

georgeokelly picture georgeokelly  路  4Comments

mciprian13 picture mciprian13  路  3Comments

s-peryt picture s-peryt  路  3Comments

pjaaskel picture pjaaskel  路  4Comments

wayneshawn picture wayneshawn  路  3Comments