Onnxsim
Context
Add the proptotype of an onnx simplifier, a framework to simplify ONNX graph.
This tool can be used with a CLI:
aidge_sim shuffle_layer.onnx shuffle_layer_sim.onnx
┏━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━┓
┃ ┃ Original Model ┃ Simplified Model ┃
┡━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━┩
│ Concat │ 2 │ 0 │
│ Constant │ 15 │ 0 │
│ Div │ 1 │ 0 │
│ Gather │ 4 │ 0 │
│ Identity │ 1 │ 0 │
│ Reshape │ 2 │ 2 │
│ Shape │ 4 │ 0 │
│ Transpose │ 1 │ 1 │
│ Unsqueeze │ 9 │ 0 │
│ Model Size │ 3.6KiB │ 492.0B │
└────────────┴────────────────┴──────────────────┘
Here are the arguments supported by this tool:
aidge_sim --help
usage: aidge_sim [-h] [-v] [--show_recipes] [--input-shape INPUT_SHAPE [INPUT_SHAPE ...]]
[input_model] [output_model]
positional arguments:
input_model Path to the input ONNX model.
output_model Path to save the simplified ONNX model.
options:
-h, --help show this help message and exit
-v, --verbose Set the verbosity level of the console output. Use -v to increase
verbosity, with the following levels in ascending order: default:
WARN - Only warnings and higher (WARN, ERROR, FATAL) are displayed.
-v: NOTICE - Notices and higher (NOTICE, WARN, ERROR, FATAL) are
displayed. -vv INFO - Informational messages and higher (INFO,
NOTICE, WARN, ERROR, FATAL) are displayed. -vvv: DEBUG - All
messages, including debug information, are displayed. Available
levels in descending order of severity: DEBUG < INFO < NOTICE < WARN
< ERROR < FATAL.
--show_recipes Show available recipes and exit
--input-shape INPUT_SHAPE [INPUT_SHAPE ...]
Overwrite the input shape. The format is
"input_name:dim0,dim1,...,dimN" or simply "dim0,dim1,...,dimN" when
there is only one input. For example, "data:1,3,224,224" or
"1,3,224,224". input_name correspond to the name of the output of
the input node. This convention is due to ONNX name being not
mandatory. If the output name begin by a number, you need to prepend
it with "data_". If one node take multiple input you can add it
multiple time, the order is determined by the order of the arguments
provided. For example, "--input-shape data:1,3 data:1,10". Here the
first input will be of size "1,3" and the second "1,10". Note: you
might want to use some visualization tools like netron to make sure
what the input name and dimension ordering (NCHW or NHWC) is.
TODO:
-
Constant and Shape folding -
Add a better UI to see what has been changed - Add pre-existing aidge recipes:
-
Fuse Batchnorm
-
- Add custom recipies:
-
Remove Identity node
-
-
Package python module so that you can call it as a script (aidge_sim --help)
In future MR
- Allow to skip transformation using the CLI #57 (closed)
- Add a fuse to LayerNorm recipe (tailored to fuse LayerNorm from PyTorch and Keras) aidge_core#248 (closed)
- Create a tutorial to showcase the functionnality aidge#249
Changes
- Add support for ONNX export of Div operator
- Fix the export of the following operators:
- Gather: export failed when indices were attribute instead of producers (+attributes are now scalar for better readabilitiy in netron)
- Squeeze: Typo in attribute name (+attributes are now scalar for better readabilitiy in netron)
- Unsqueeze: Typo in attribute name (+attributes are now scalar for better readabilitiy in netron)
- Shape:
end
attribute was set by default at -1 which did not result in the intended behavior. Corrected this issue by letting it to default (undefined) which is the behavior of aidge value -1 (see comment in code 116aab01 if this explanation is too confusing).
- For ONNX export, ONNX output type is now no longer always FLOAT32 but instead derived from the dtype of the Aidge::Tensor
- Fix small typo in doc...
Edited by Cyril Moineau