The ONNX library defines neural network operators and is commonly supported by multiple deep learning libraries in the community. Because the deep learning field is moving extremely fast, it is common that deep learning researchers and engineers will have to contribute to the ONNX library.
In this blog post, I would like to quickly discuss how to contribute to the ONNX library.
Create ONNX Development Dockerfile
Create a development environment is often very difficult for any libraries. Here I have created a Docker file for building and developing the ONNX library.
# Install ONNX development dependencies. RUNcd /tmp && \ wget https://raw.githubusercontent.com/onnx/onnx/main/requirements-dev.txt && \ # Enfore re-install all the requirements even if they already exists. # This is a work-around to make pytest accessible from the $PATH. pip install --upgrade --force-reinstall -r requirements-dev.txt
# Set ONNX build CMake argument. ENV CMAKE_ARGS "-DONNX_USE_LITE_PROTO=ON"
# Install ONNX. # RUN cd /tmp && \ # git clone https://github.com/onnx/onnx.git && \ # cd onnx && \ # git submodule update --init --recursive && \ # # Optional: prefer lite proto # export CMAKE_ARGS=-DONNX_USE_LITE_PROTO=ON && \ # pip install -e .
Build Docker Image
Build the ONNX development Docker image using the following command.
Pull the main branch of the ONNX repository to the host computer and start the Docker container for development.
1 2 3
$ git clone --recurse-submodules https://github.com/onnx/onnx.git $ cd onnx/ $ docker run -it --rm -v $(pwd):/mnt onnx-dev:0.0.1
Build ONNX Library
The ONNX library needs to be built from source in development mode.
$ cd /mnt/ $ pip install -e .
Run Unit Tests
After adding or modifying the code in the ONNX repository from the host, we will have to run unit tests from the ONNX root directory in the Docker container to ensure that the changes we made are correct.
To only test a specific subset, we could use the -k argument for prefix patten matching. For example,
$ pytest -k test_gridsample
Regenerate Documentations and Test Files
For most of the changes related to ONNX scopes and specs, the ONNX documentations and unit test files have to be updated using the following script.
$ bash tools/update_doc.sh
lintrunner is recommended to be performed from the ONNX root directory on the host outside the Docker container.