N2D2 is an open source CAD framework for Deep Neural Network simulation and full DNN-based applications building.
We are delighted to annonce the new release of N2D2, this version introduces the addition of the SAT method and the STM32 export to the open-source version of N2D2 as well as some bug fixes in the Python API. We would like to thank everyone who contributed to this release!
The rate of the update on N2D2 is decreasing as we are working on an exciting complete refont of the software. :muscle:
More news coming soon ! ๐ค
n2d2.deepnet.associate_provider_to_deepnet
to reduce code redundancy in export.py
and quantization.py
;dataprovider
contains data, otherwise prints a warning;data_augmentation.py
example with a data_path
parameter;converter.from_N2D2
to support conversion of C++ transformation to python;DataProvider.get_transformations
method;DataProvider.normalize_stimuli
to normalize stimuli between [0,1];Reshape
transformation to the Python API.SATCell
object to quantize your layers with the SAT method;PruneCell
object to prune the weights in the associated layer;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!
Moreover, more features are already planned to be added in the next releases like other QAT techniques (the SAT technique for example). So don't go too far !
Interface
instances can now be used as an input for a cell without coming from another cell themselves.CPP_Quantization
n2d2.global_variables.cuda_compiled
has been renamed to cuda_available
CPP export
, to avoid conflict with N2D2 when using both N2D2 and the CPP export.CPP export
, to avoid conflict with the ONNX constant in N2D2../bin/run_export
Makefile
or cpp_utils.cpp
.Here an example of what summary can do with a small network.
--------------------------------------------------------------------------------------------------------------
Layer (type) Output Shape Param # MAC # Connected to Extra Grad
==============================================================================================================
Image1 (input) (1, 3, 256, 256) 0 0k -
Conv_0 (Conv 3x3) (1, 64, 256, 256) 1,792 112,657k Image1 Act: ReLu True
Pool_0 (Pool) (1, 64, 129, 129) 0 0k Conv_0 size: 2x2, pad: 1 -
Conv_1 (PointWise) (1, 128, 131, 131) 8,320 136,323k Pool_0 Act: ReLu True
Fc_0 (Fc) (1, 100, 1, 1) 0 219,660k Conv_1 True
Fc_1 (Fc) (1, 10, 1, 1) 0 1k Fc_0 True
Softmax_0 (Softmax) (1, 10, 1, 1) 0 0k Fc_1 -
Features (output) (1, 10, 1, 1) 0 0k Softmax_0 -
==============================================================================================================
Total params: 10,112
Total computing: 468,642,326 MAC
list_exportable_cell
function to the PythonAPI export module.
Usage example :>>> import n2d2
>>> n2d2.export.list_exportable_cell("CPP_TensorRT")
+----------------+-----------+
| Cell Name | Available |
+================+===========+
| Activation | Yes |
+----------------+-----------+
| BatchNorm2d | Yes |
+----------------+-----------+
| Conv | Yes |
+----------------+-----------+
| Deconv | Yes |
+----------------+-----------+
| Dropout | No |
+----------------+-----------+
| ElemWise | Yes |
+----------------+-----------+
| Fc | Yes |
+----------------+-----------+
| Padding | Yes |
+----------------+-----------+
| Pool | Yes |
+----------------+-----------+
| Reshape | Yes |
+----------------+-----------+
| Resize | Yes |
+----------------+-----------+
| Scaling | Yes |
+----------------+-----------+
| Softmax | Yes |
+----------------+-----------+
| Transformation | No |
+----------------+-----------+
| Transpose | Yes |
+----------------+-----------+
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!
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 !
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.
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)
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.
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.
Default_model
not set up anymoreThe 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.
The following python modules have been splitted to improve the code readibility
transformation
database
filler
activation
cell
Before, an error was raised if the batch provided by Pytorch was incomplete. Now N2D2 can handle different batch sizes with the same model.
deepnet_234213 -> deepnet_0
Before the provider needed to load data from the dataset in order to provide the data size which was not necessary.
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.
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
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:
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 !
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")
We decided to use tiny ml networks to test our framework, interoperabilities and exports.
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.
In order to improve the Python API code quality, we added a linter in our Continious Integration tests.
We added multiple examples of the SAT quantization technique with the Python API.
We improved our examples in the Python API:
N2D2 has been on Github since 2017 and we are grateful for the support and the time that have been given by our contributors and the users to develop and enrich N2D2.
But this is not the time for the adventure to end, quite the contrary! :rocket:
We set up a release system to keep you regularly informed of the latest additions of features, bug fixes, changes, ...
If you have any question or problem with the framework, feel free to open an issue on Github. We will answer it as soon as possible :wink:
Currently to use N2D2, you can work with INI files to design, build, simulate and export your network. We are also working to propose the same experience with our Python API with the same features and even more. You can test right now the Python API of N2D2 and tell us your feedback about it.
You can find some explanations on our documentation about the installation of the Python API and how use it. We are open to any kind of relevant improvement of the framework and everyone can express his/her opinion.