Skip to content

N2D2 1.1.0

Compare
Choose a tag to compare
@vtemplier vtemplier released this 16 May 16:51
· 428 commits to master since this release

💡 Highlights

We are delighted to annonce the new release of N2D2 with exciting new features and with a little tidying up in the codebase 🧹
We would like to thank everyone who contributed to this release!

  • Improvement of the Python API: our main objective is to improve the user experience with the Python API so we work to make your experience more seamless and close to your needs. Don't hesitate to give us your feedback about it !
  • Learned Stepsize Quantization module implemented in N2D2: this module implements the first QAT method developed in the framework. You can now quantize your network with a precision lower than 8-bit with this QAT method with the Python API or the INI one.
  • Documentation improvement: we added multiple examples to make N2D2 easier to learn.

Moreover, more features are already planned to be added in the upcoming releases like other QAT techniques (the SAT technique for example). So don't go too far !

🐛 Bug Fixes and Other Changes

Cmake

Compile N2D2 without CUDA

You can now compile N2D2 without enabling CUDA, even if the library is installed on your device.
To activate this feature, export the environment variable N2D2_NO_CUDA=1 before compiling N2D2.

Resolved warnings about the Python binding for extra-modules

The CMake warning happens when N2D2 is adding the Binding functions to the compilation. The warning doesn't occur when N2D2 is used in an extra module but happens when N2D2 is not used in an extra module.
The resolution is to include a variable in the extra module CMakeLists.txt of the extra module to import the N2D2 Python binding and performs a test to know if the variable is defined in the CMakeLists.txt of N2D2.

So in the development of the upcoming extra modules using N2D2, don't forget to include at the beginning of your CMakeLists.txt.

set(N2D2_EXTRAMODULE 1)

C++

Removed PYBIND directive

The PYBIND directive has been removed from all files since it is not necessary to add it because pybind is mandatory to compile and use N2D2.

Moved MultiDevice Peer Access function to CudaUtils

To enable Peer Access among devices while the Multi-GPU is used, the function is called from CudaUtils now and not from DeepNet::initialize. This fixed a problem when the deepNet was initialized more than once.

Python API

Default_model not set up anymore

The wrap function of the Keras Interoperability doesn't automatically set the model to Frame_CUDA anymore.
You need to change the global variable default_model in your Python script.

Refactoring/splitting files into classes

The following python modules have been splitted to improve the code readibility

  • transformation
  • database
  • filler
  • activation
  • cell

Fixed incomplete batch in the Pytorch Interoperability

Before, an error was raised if the batch provided by Pytorch was incomplete.
Now N2D2 can handle different batch sizes with the same model.

Change the deepNet name convention (from hashes to incremental indexes)

deepnet_234213 -> deepnet_0

The provider will no longer load data to check data size

Before the provider needed to load data from the dataset in order to provide the data size which was not necessary.

Avoid BatchNorm fuse with tf2onnx framework

The library tf2onnx removes automatically the BatchNorm layer during an ONNX export (fuse it the previous convolutional layer). It is an incompatible behavior with the Keras Interoperability. Therefore, we added a context to temporaly remove this optimization in order to keep the BatchNorm in N2D2.
More details in python/keras_interoperability/keras_interface.py.

Fixed setattr check if N2D2 object is created

Before, setting an attribute on an object which is initialized on call raises an error N2D2 object is not initialized.
Now, the set attribut method checks if N2D2 object is created. Otherwise, it fills tha attribut dictionary

Exports

C++ export

  • Fixed signed outputs display (sign bit badly converted)
  • Fixed output results from the convCellDWPropagate

🚀 Improvements

C++

QAT module added

We added the Quantization Aware-Training module to the framework in order to use QAT techniques.
The first technique is LSQ and is implemented to be used with Activation cells and with Conv/Fc cells.
You can find the functions in Quantizer/QAT. This module is organized as follows:

  • Activation: methods to quantize activations
  • Cell: methods to quantize the cells (essentially the parameters)
  • Kernel: kernels to quantize on CPU and on CUDA

Moreover, several examples are proposed to use LSQ in python/examples.

if isinstance(cell, n2d2.cells.Conv):
        cell.quantizer = LSQCell(
                range = q_range,
                solver=n2d2.solver.SGD(
                        learning_rate_policy = "CosineDecay",
                        learning_rate=lr,
                        momentum=mom,
                        decay=decay,
                        max_iterations=max_iter
        )) 

Warning: LSQ is available for CUDA experiments so far. A CPU implementation is coming soon !

Separation calibration and export

In order to propose Post-Training Quantization techniques without necessarily exporting the model, we decided to separate the PTQ function and the generation of the export. So if you want to use the PTQ and the export, add those lines in your script:

n2d2.quantizer.PTQ(n2d2_net_test.get_deepnet_cell(), 8, provider=provider, act_scaling_mode="SINGLE_SHIFT")

n2d2.export.export_c(n2d2_net_test.get_deepnet_cell(), export_folder_name="test_export") 

Python API

Added tiny ML models to N2D2 tests

We decided to use tiny ml networks to test our framework, interoperabilities and exports.

Decorator for export docstring

We added a decorator to add docstring to the export functions in order to improve the comprehension of our functions.

@n2d2.utils.add_docstring(export_doc_string)
def export_c(deepnet_cell: n2d2.cells.DeepNetCell,
             provider: n2d2.provider.Provider=None,
             **kwargs) -> None:
    """Generate a C export of the neural network.

Added Linter for the Python API

In order to improve the Python API code quality, we added a linter in our Continious Integration tests.

📖 Documentation modifications

SAT QAT method example added

We added multiple examples of the SAT quantization technique with the Python API.

Improve examples with the StimuliProvider

We improved our examples in the Python API:

  • Creation of a StimuliProvider
  • Add a transformation and OnTheFly transformation
  • Creation of N2D2 graph
  • How to access layers and parameters
  • ONNX import