[Feat] Add quantized exports for Resnet18 and LeNet
Context
This MR aims to enable the quantized (int8) export of LeNet and Resnet18.
It brings a lot of changes to clean and update the CPP Aidge export with the latest features.
Refactor
- Operators register files are splitted from one global
operators.py
file to several ones, each matching the actual implementation of one given kernel. - Some utils functions are added to simplify the export file :
-
cpp_fuse_to_metaops()
: Fuse the model nodes into the metaoperators corresponding to the operators supported by the export. -
set_nodes_names()
: Rename the newly created nodes based on their type, position in the graph and number of iterations of this specific layer, to ensure readability once exported. -
set_nodes_datatypes()
: Datatypes have to be set manually after the quantization step. -
read_log_file()
: May be useful to compare intermediate results...
-
New features
General improvements
- Now possible to ignore some producers during export phase, as some of them are not relevant (for instance, the producers holding scaling coefficients, which are handled separately).
- Change the
kernels_to_copy
export node system as the old system had some limitations. Indeed, it was not possible to chose a destination path different from the source path. Also the copied kernel would be automatically included in the fwd file, sometime leading to unused includes. The new system is based on a list of dict holding, for each kernel file, the source and destination paths as well as a boolean to indicate if the kernel needs to be included in the forward file. - Add an
aidge_cmp
feature which allows to compare theaidge_export_cpp
andaidge_backend_cpu
intermediate tensor results for the exported model.
New models examples
- Add LeNet generation file (
create_lenet.py
) which create, train and export a LeNet model. - Add a
lenet.py
file describing the different steps to perform an export with theaidge_export_cpp
module. - Add a
resnet18.py
file describing the different steps to perform an export with theaidge_export_cpp
module. - Add these example scripts to the CI
Quantized Export
- Handle the scaling nodes added by the PTQ and transmit the shift and coef parameters to the generated export.
- Add scaling functions (SingleShift and FixedPoint) to the export.
- Add a
aidge_cmp
option which exports thelog_outputs
(intermediate tensors generated by theaidge_backend_cpu
) as reference and allow data comparison at inference time. - Now possible to export quantized LeNet using
--dtype int8
while running thelenet.py
file. - Now possible to export quantized Resnet18 using
--dtype int8
while running theresnet18.py
file.
Related Issues
[ResNet18] Export Cpp INT8 not supported
TODO
-
LeNet Export fp32 -
LeNet Export int8 -
Resnet18 Export fp32 -
Resnet18 Export int8
Edited by Cyril Moineau
Merge request reports
Activity
Filter activity
changed milestone to %aidge v0.6.0
requested review from @cmoineau
assigned to @axelfarr
- Resolved by Cyril Moineau
mentioned in merge request aidge_core!369 (merged)
added 5 commits
- 53ced27c - [Feat] Add int8 support
- c786170b - [Feat] Add the aidge_cmp option and refactor save_outputs function
- c2553503 - [Fix] Remove memory info from arg list for save_outputs function
- a7c84c70 - [Fix] Temporarily generate only layer params for the first input as all inputs...
- 7efbd360 - [Feat] Change the kernels_to_copy system
Toggle commit listassigned to @mick94
mentioned in merge request !24 (closed)
added 19 commits
-
7efbd360...45d12a67 - 2 commits from branch
dev
- 45d12a67...8773a8a3 - 7 earlier commits
- 6c40bd8e - [Chore] Remove unecessary tabulation
- 5eb416c8 - [Chore] Include export_utils file
- 2bf25de0 - [Chore] Temporarily comment the save_outputs generated code
- a6389992 - [Refactor] Reformat transpose jinja
- 73636be9 - [Feat] Add new lenet export and generation files
- b9066014 - [Feat] Add int8 support
- 1ca57eea - [Feat] Add the aidge_cmp option and refactor save_outputs function
- 5e9baa6d - [Fix] Remove memory info from arg list for save_outputs function
- cf68a996 - [Fix] Temporarily generate only layer params for the first input as all inputs...
- ba2b04cc - [Feat] Change the kernels_to_copy system
Toggle commit list-
7efbd360...45d12a67 - 2 commits from branch
- Resolved by Axel Farrugia
- Resolved by Cyril Moineau
added 20 commits
- aad912c8...e4317fd7 - 10 earlier commits
- 7801dc6f - [Feat] Adaptation of the Aidge_cmp function for an integer datatype
- b063bd16 - [Refactor] Change formatting
- 56ecbd41 - [Feat] Add jinja file for forward build
- cea36246 - [Fix] Add #define to enable or disable the OpenMP option for compilation
- cf3509dd - [Feature] Add Python script for ResNet18 export (cpp)
- 1057b2e0 - [Git] Add gitignores
- 55b4d096 - [Fix] Suppress constexpr and simplified the choice of rounding
- 3f58cc01 - [Refactor] Simplify aidge_cmp function to one function for float or interger
- c2cfa8d1 - Fix Add ignore attribute to False by default
- 00890524 - Merge branch 'feat_add_quantized_export' into 'feat_add_quantized_export'
Toggle commit list
Please register or sign in to reply