A very simple tool that compresses the overall size of the ONNX model by aggregating duplicate constant values as much as possible. Simple Constant value Shrink for ONNX.
Project description
scs4onnx
A very simple tool that compresses the overall size of the ONNX model by aggregating duplicate constant values as much as possible. Simple Constant value Shrink for ONNX.
Key concept
- If the same constant tensor is found by scanning the entire graph for Constant values, it is aggregated into a single constant tensor.
- Ignore scalar values.
- Ignore variables.
1. Setup
### option
$ echo export PATH="~/.local/bin:$PATH" >> ~/.bashrc \
&& source ~/.bashrc
### run
$ pip install -U onnx \
&& python3 -m pip install -U onnx_graphsurgeon --index-url https://pypi.ngc.nvidia.com \
&& pip install -U scs4onnx
2. Usage
$ scs4onnx -h
usage: scs4onnx [-h] onnx_file_path {shrink,npy}
positional arguments:
onnx_file_path Input onnx file path.
{shrink,npy} Constant Value Compression Mode.
shrink: Share constant values inside the model as much as possible.
The model size is slightly larger because some shared constant values
remain inside the model, but performance is maximized.
npy: Outputs constant values used repeatedly in the model to an external
file .npy. Instead of the smallest model body size, the file loading
overhead is greater.
Default: shrink
optional arguments:
-h, --help show this help message and exit
3. Execution
$ scs4onnx input.onnx shrink
4. Sample
4-1. shrink
mode sample
-
297.8MB -> 67.4MB
4-2. npy
mode sample
-
297.8MB -> 21.3MB
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
scs4onnx-1.0.1.tar.gz
(5.1 kB
view details)
Built Distribution
File details
Details for the file scs4onnx-1.0.1.tar.gz
.
File metadata
- Download URL: scs4onnx-1.0.1.tar.gz
- Upload date:
- Size: 5.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.0 CPython/3.10.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9c98bf2f52979fa8a82f2f171c96421aa50e1a08746bfa604abeb1e986e00157 |
|
MD5 | a6eff5ee2526264ec2bd298c6f5622a1 |
|
BLAKE2b-256 | 0ba22ed1b074c3d90275e23355b163e0641001e6a581234ca9033a17b76910b1 |
File details
Details for the file scs4onnx-1.0.1-py3-none-any.whl
.
File metadata
- Download URL: scs4onnx-1.0.1-py3-none-any.whl
- Upload date:
- Size: 5.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.0 CPython/3.10.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9da209520d5d79b398f5af31c3531fd29efe923481bf508fa05c93ad31352aa6 |
|
MD5 | 646754b498ab87b56c9d27fd5549a520 |
|
BLAKE2b-256 | 29a1dd49d04f5a2daa2b7970695e4fed0cd745545a7f880e0cde128c7648fe0a |