A tool for ONNX model:Rapid shape inference; Profile model; Compute Graph and Shape Engine; OPs fusion;Quantized models and sparse models are supported.
Project description
onnx-tool
A tool for ONNX model:
- Rapid shape inference.
- Profile model.
- Compute Graph and Shape Engine.
- OPs fusion.
- Quantized models and sparse models are supported.
Supported Models:
- NLP: BERT, T5, GPT
- Diffusion: Stable Diffusion(TextEncoder, VAE, UNET)
- CV: Resnet, MobileNet, YOLO, ...
- Audio: LPCNet
Shape inference
how to use: data/Profile.md.
pytorch usage: data/PytorchUsage.md.
tensorflow
usage: data/TensorflowUsage.md.
samples: benchmark/samples.py.
Profile Model
Float MultipleAdd Count(1 MAC=2 FLOPs), Memory Usage(in bytes), Parameters(elements number)
Sparse Pattern, Sparse Block Ratio, Sparse Element Ratio
how to use: data/Profile.md.
pytorch usage: data/PytorchUsage.md.
tensorflow
usage: data/TensorflowUsage.md.
samples: benchmark/samples.py.
Compute Graph with Shape Engine
Remove shape calculation layers(created by ONNX export) to get a Compute Graph. Use Shape Engine to update tensor
shapes at runtime.
Samples: benchmark/shape_regress.py.
benchmark/samples.py.
Integrate Compute Graph and Shape Engine into a cpp inference
engine: data/inference_engine.md
Inplace op fusion
MHA and Layernorm Fusion for Transformers
Resnet18 fusion
how to use: data/Subgraph.md.
BERT samples: benchmark/samples.py.
Extract subgraph from ONNX model
how to use: data/Subgraph.md.
Tensor operations
- Export weight tensors to files
- Simplify tensor and node names, convert name from a long string to a short string
- Remove unused tensors, models like vgg19-7.onnx set its static weight tensors as its input tensors
- Set custom input and output tensors' name and dimension, change model from fixed input to dynamic input
how to use: data/Tensors.md.
How to install
pip install onnx-tool
OR
pip install --upgrade git+https://github.com/ThanatosShinji/onnx-tool.git
python>=3.6
If pip install onnx-tool
failed by onnx's installation, you may try pip install onnx==1.8.1
(a lower version like this) first.
Then pip install onnx-tool
again.
Known Issues
- Loop op is not supported
Results of ONNX Model Zoo and SOTA models
Some models have dynamic input shapes. The MACs varies from input shapes. The input shapes used in these results are writen to data/public/config.py. These onnx models with all tensors' shape can be downloaded: baidu drive(code: p91k) google drive
|
|
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for onnx_tool-0.6.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 13be4b58aa7dff5ce4db73e9e8de983d4db2f64805caf835c2a4a25ef8aa2526 |
|
MD5 | 8b55f2bdd1d5f17d105a8f83870aad30 |
|
BLAKE2b-256 | 87001f1b43d9b2f11523f8f6f4f7bc9569eee1ef7dc09e266150680d47c6eed9 |