onnx / onnx-mlir

Representation and Reference Lowering of ONNX Models in MLIR Compiler Infrastructure
Apache License 2.0
771 stars 322 forks source link

Reuse weight parameter #560

Closed feiyuvl closed 3 years ago

feiyuvl commented 3 years ago

According to the test/numerical/TestConv.cpp, we need to copy weight each time we call the convolution function. Is there any method to set weight once, and avoid copying each time when computing?

caoimhinuibrian commented 3 years ago

Not sure what you're asking. This is a testcase checking numerical accuracy.

feiyuvl commented 3 years ago

When we do inference for a nerual network, for example resnet, we only init weight once, then with different input data. Does onnx-mlir support global variable to store weight parameter?

caoimhinuibrian commented 3 years ago

Yes, the weights are stored in a global constant pool

feiyuvl commented 3 years ago

Thank you. Is there any example?

caoimhinuibrian commented 3 years ago

Not sure what you want to see. Take any trained model, use onnx-mlir to compile it, link it with a driver and run it multiple times with inputs. The weights are saved in the model binary. You do not need to specify them in order to run the inference. For an example use mnist or resnet or something else that is available out there.