Skip to content
Snippets Groups Projects

[Feat] Add quantized exports for Resnet18 and LeNet

Merged Axel Farrugia requested to merge feat_add_quantized_export into dev

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 the aidge_export_cpp and aidge_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 the aidge_export_cpp module.
  • Add a resnet18.py file describing the different steps to perform an export with the aidge_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 the log_outputs (intermediate tensors generated by the aidge_backend_cpu) as reference and allow data comparison at inference time.
  • Now possible to export quantized LeNet using --dtype int8 while running the lenet.py file.
  • Now possible to export quantized Resnet18 using --dtype int8 while running the resnet18.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

Merge request pipeline #72813 passed

Merge request pipeline passed for 773e5565

Test coverage 65.00% (0.00%) from 1 job
Approval is optional

Merged by Cyril MoineauCyril Moineau 1 month ago (May 14, 2025 2:10pm UTC)

Merge details

  • Changes merged into dev with 773e5565.
  • Deleted the source branch.

Pipeline #72868 passed

Pipeline passed for 773e5565 on dev

Test coverage 65.00% (0.00%) from 1 job

Activity

Filter activity
  • Approvals
  • Assignees & reviewers
  • Comments (from bots)
  • Comments (from users)
  • Commits & branches
  • Edits
  • Labels
  • Lock status
  • Mentions
  • Merge request status
  • Tracking
  • mentioned in merge request aidge_core!369 (merged)

  • Axel Farrugia added 5 commits

    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

    Compare with previous version

  • Axel Farrugia marked the checklist item LeNet Export int8 as completed

    marked the checklist item LeNet Export int8 as completed

  • Axel Farrugia changed the description

    changed the description

  • assigned to @mick94

  • Cyril Moineau mentioned in merge request !24 (closed)

    mentioned in merge request !24 (closed)

  • Axel Farrugia added 19 commits

    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

    Compare with previous version

  • Axel Farrugia added 1 commit

    added 1 commit

    Compare with previous version

  • Cyril Moineau marked the checklist item Resnet18 Export int8 as completed

    marked the checklist item Resnet18 Export int8 as completed

  • Cyril Moineau marked the checklist item Resnet18 Export fp32 as completed

    marked the checklist item Resnet18 Export fp32 as completed

  • Axel Farrugia added 20 commits

    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'

    Compare with previous version

  • Axel Farrugia added 1 commit

    added 1 commit

    • b7e28ee1 - [Chore] Class typo in foc comment

    Compare with previous version

  • Loading
  • Loading
  • Loading
  • Loading
  • Loading
  • Loading
  • Loading
  • Loading
  • Loading
  • Loading
  • Please register or sign in to reply
    Loading