[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.
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 Axel Farrugia
Merge request reports
Activity
Filter activity
Please register or sign in to reply