| 1 | name: pnnx |
| 2 | on: |
| 3 | push: |
| 4 | branches: [master] |
| 5 | paths: |
| 6 | - '.ci/pnnx.yml' |
| 7 | - 'src/layer/*' |
| 8 | - 'tools/pnnx/**' |
| 9 | - '!tools/pnnx/README.md' |
| 10 | mr: |
| 11 | target-branches: [master] |
| 12 | paths: |
| 13 | - '.ci/pnnx.yml' |
| 14 | - 'src/layer/*' |
| 15 | - 'tools/pnnx/**' |
| 16 | - '!tools/pnnx/README.md' |
| 17 | concurrency: |
| 18 | group: pnnx-${{ ci.head_ref }} |
| 19 | |
| 20 | variables: |
| 21 | protobuf_version: 21.12 |
| 22 | libtorch_version: 2.4.0 |
| 23 | libtorchvision_version: 0.19.0 |
| 24 | onnxruntime_version: 1.18.1 |
| 25 | cache_date: 20240804 |
| 26 | |
| 27 | jobs: |
| 28 | ubuntu: |
| 29 | strategy: |
| 30 | matrix: |
| 31 | include: |
| 32 | - torch-version: 1.8.1 |
| 33 | torchvision-version: 0.9.1 |
| 34 | |
| 35 | - torch-version: 1.9.1 |
| 36 | torchvision-version: 0.10.1 |
| 37 | |
| 38 | - torch-version: 1.10.0 |
| 39 | torchvision-version: 0.11.1 |
| 40 | |
| 41 | - torch-version: 1.11.0 |
| 42 | torchvision-version: 0.12.0 |
| 43 | |
| 44 | - torch-version: 1.12.0 |
| 45 | torchvision-version: 0.13.0 |
| 46 | |
| 47 | - torch-version: 1.13.0 |
| 48 | torchvision-version: 0.14.0 |
| 49 | |
| 50 | - torch-version: 2.0.0 |
| 51 | torchvision-version: 0.15.1 |
| 52 | |
| 53 | - torch-version: 2.1.0 |
| 54 | torchvision-version: 0.16.0 |
| 55 | |
| 56 | - torch-version: 2.2.1 |
| 57 | torchvision-version: 0.17.1 |
| 58 | |
| 59 | - torch-version: 2.3.0 |
| 60 | torchvision-version: 0.18.0 |
| 61 | |
| 62 | - torch-version: 2.4.0 |
| 63 | torchvision-version: 0.19.0 |
| 64 | |
| 65 | runs-on: |
| 66 | pool-name: docker |
| 67 | container: |
| 68 | image: bkci/ci:ubuntu |
| 69 | steps: |
| 70 | - name: checkout |
| 71 | checkout: self |
| 72 | with: |
| 73 | strategy: FRESH_CHECKOUT |
| 74 | enableGitLfs: false |
| 75 | |
| 76 | - name: install-deps |
| 77 | run: | |
| 78 | apt-get update |
| 79 | apt-get install -y python3-pip libjpeg-dev libpng-dev |
| 80 | python3 -m pip install --upgrade pip |
| 81 | apt-get remove -y python3-setuptools |
| 82 | pip3 install -U setuptools==69.5.1 |
| 83 | pip3 install -U pytest wheel twine requests einops numpy==1.26.4 |
| 84 | cd ${{ci.workspace}} |
| 85 | wget -q https://github.com/Kitware/CMake/releases/download/v3.29.3/cmake-3.29.3-linux-x86_64.tar.gz |
| 86 | tar -xf cmake-3.29.3-linux-x86_64.tar.gz |
| 87 | |
| 88 | - name: cache-pnnx-deps-torch |
| 89 | id: cache-pnnx-deps-torch |
| 90 | uses: cache@1.* |
| 91 | with: |
| 92 | cachePaths: pnnx-deps-torch-install |
| 93 | cacheKey: pnnx-deps-torch-linux-install-${{variables.cache_date}} |
| 94 | |
| 95 | - name: cache-pnnx-deps-onnx |
| 96 | id: cache-pnnx-deps-onnx |
| 97 | uses: cache@1.* |
| 98 | with: |
| 99 | cachePaths: pnnx-deps-onnx-install |
| 100 | cacheKey: pnnx-deps-onnx-linux-install-${{variables.cache_date}} |
| 101 | |
| 102 | - name: checkout-pnnx-patches |
| 103 | if: steps.cache-pnnx-deps-torch.outputs.cacheHit != 'true' || steps.cache-pnnx-deps-onnx.outputs.cacheHit != 'true' |
| 104 | checkout: https://github.com/pnnx/pnnx.git |
| 105 | with: |
| 106 | refName: main |
| 107 | localPath: pnnx-patches |
| 108 | enableSubmodule: false |
| 109 | enableGitLfs: false |
| 110 | |
| 111 | - name: pnnx-deps-torch-libtorch |
| 112 | if: steps.cache-pnnx-deps-torch.outputs.cacheHit != 'true' |
| 113 | run: | |
| 114 | export PATH=${{ci.workspace}}/cmake-3.29.3-linux-x86_64/bin:$PATH |
| 115 | wget -q https://github.com/pytorch/pytorch/releases/download/v${{variables.libtorch_version}}/pytorch-v${{variables.libtorch_version}}.tar.gz |
| 116 | tar -xf pytorch-v${{variables.libtorch_version}}.tar.gz |
| 117 | cd pytorch-v${{variables.libtorch_version}} |
| 118 | pip3 install -r requirements.txt |
| 119 | patch -p1 -i ${{ci.workspace}}/pnnx-patches/pytorch-v${{variables.libtorch_version}}-fix-mobile-build.patch |
| 120 | patch -p1 -i ${{ci.workspace}}/pnnx-patches/pytorch-v${{variables.libtorch_version}}-no-link-system-lib.patch |
| 121 | patch -p1 -i ${{ci.workspace}}/pnnx-patches/pytorch-v${{variables.libtorch_version}}-fix-pocketfft-build.patch |
| 122 | mkdir -p build && cd build |
| 123 | cmake -DCMAKE_INSTALL_PREFIX=${{ci.workspace}}/pnnx-deps-torch-install -DCMAKE_BUILD_TYPE=MinSizeRel -DBUILD_SHARED_LIBS=OFF -DBUILD_CAFFE2_OPS=OFF -DBUILD_CUSTOM_PROTOBUF=OFF -DBUILD_LITE_INTERPRETER=OFF -DBUILD_PYTHON=OFF -DINTERN_BUILD_MOBILE=ON -DINTERN_DISABLE_AUTOGRAD=ON -DINTERN_DISABLE_ONNX=ON -DUSE_CUDA=OFF -DUSE_DISTRIBUTED=OFF -DUSE_ITT=OFF -DUSE_KINETO=OFF -DUSE_LITE_INTERPRETER_PROFILER=OFF -DUSE_MKLDNN=OFF -DUSE_MPS=OFF -DUSE_NUMPY=OFF -DUSE_OPENMP=OFF -DUSE_SOURCE_DEBUG_ON_MOBILE=OFF -DUSE_XNNPACK=OFF .. |
| 124 | cmake --build . -j $(nproc) |
| 125 | cmake --build . -j $(nproc) --target install/strip |
| 126 | - name: pnnx-deps-torch-libtorchvision |
| 127 | if: steps.cache-pnnx-deps-torch.outputs.cacheHit != 'true' |
| 128 | run: | |
| 129 | export PATH=${{ci.workspace}}/cmake-3.29.3-linux-x86_64/bin:$PATH |
| 130 | wget -q https://github.com/pytorch/vision/archive/v${{variables.libtorchvision_version}}.zip -O vision-${{variables.libtorchvision_version}}.zip |
| 131 | unzip -q vision-${{variables.libtorchvision_version}}.zip |
| 132 | cd vision-${{variables.libtorchvision_version}} |
| 133 | patch -p1 -i ${{ci.workspace}}/pnnx-patches/vision-${{variables.libtorchvision_version}}-ops-only.patch |
| 134 | patch -p1 -i ${{ci.workspace}}/pnnx-patches/vision-${{variables.libtorchvision_version}}-no-cuda-version.patch |
| 135 | mkdir -p build && cd build |
| 136 | cmake -DCMAKE_INSTALL_PREFIX=${{ci.workspace}}/pnnx-deps-torch-install -DTorch_DIR=${{ci.workspace}}/pnnx-deps-torch-install/share/cmake/Torch -DCMAKE_BUILD_TYPE=MinSizeRel -DWITH_PNG=OFF -DWITH_JPEG=OFF .. |
| 137 | cmake --build . -j $(nproc) |
| 138 | cmake --build . -j $(nproc) --target install/strip |
| 139 | |
| 140 | - name: pnnx-deps-onnx-protobuf |
| 141 | if: steps.cache-pnnx-deps-onnx.outputs.cacheHit != 'true' |
| 142 | run: | |
| 143 | export PATH=${{ci.workspace}}/cmake-3.29.3-linux-x86_64/bin:$PATH |
| 144 | wget -q https://github.com/protocolbuffers/protobuf/archive/v${{variables.protobuf_version}}.zip -O protobuf-${{variables.protobuf_version}}.zip |
| 145 | unzip -q protobuf-${{variables.protobuf_version}}.zip |
| 146 | cd protobuf-${{variables.protobuf_version}} |
| 147 | mkdir -p build2 && cd build2 |
| 148 | cmake -DCMAKE_INSTALL_PREFIX=${{ci.workspace}}/pnnx-deps-onnx-install -Dprotobuf_BUILD_TESTS=OFF -DCMAKE_BUILD_TYPE=MinSizeRel -DCMAKE_POSITION_INDEPENDENT_CODE=ON .. |
| 149 | cmake --build . -j $(nproc) |
| 150 | cmake --build . --target install/strip |
| 151 | - name: pnnx-deps-onnx-onnxruntime |
| 152 | if: steps.cache-pnnx-deps-onnx.outputs.cacheHit != 'true' |
| 153 | run: | |
| 154 | export PATH=${{ci.workspace}}/cmake-3.29.3-linux-x86_64/bin:$PATH |
| 155 | wget -q https://github.com/microsoft/onnxruntime/archive/v${{variables.onnxruntime_version}}.zip -O onnxruntime-${{variables.onnxruntime_version}}.zip |
| 156 | unzip -q onnxruntime-${{variables.onnxruntime_version}}.zip |
| 157 | cd onnxruntime-${{variables.onnxruntime_version}} |
| 158 | patch -p1 -i ${{ci.workspace}}/pnnx-patches/onnxruntime-${{variables.onnxruntime_version}}-less-mlas-features.patch |
| 159 | patch -p1 -i ${{ci.workspace}}/pnnx-patches/onnxruntime-${{variables.onnxruntime_version}}-monolithic-static-library.patch |
| 160 | mkdir -p build && cd build |
| 161 | cmake -DCMAKE_INSTALL_PREFIX=${{ci.workspace}}/pnnx-deps-onnx-install -DCMAKE_BUILD_TYPE=MinSizeRel -Donnxruntime_USE_FULL_PROTOBUF=ON -Donnxruntime_BUILD_SHARED_LIB=ON -Donnxruntime_BUILD_UNIT_TESTS=OFF -Donnxruntime_ENABLE_CPUINFO=OFF -Donnxruntime_DISABLE_CONTRIB_OPS=ON -Donnxruntime_DISABLE_ML_OPS=ON -Donnxruntime_DISABLE_SPARSE_TENSORS=ON --compile-no-warning-as-error ../cmake |
| 162 | cmake --build . -j $(nproc) |
| 163 | cmake --build . -j $(nproc) --target install/strip |
| 164 | |
| 165 | - name: setup-pytorch |
| 166 | run: | |
| 167 | export PYTHONUSERBASE=${{ci.workspace}}/torch-${{matrix.torch-version}} |
| 168 | pip3 install --user torch==${{matrix.torch-version}}+cpu torchvision==${{matrix.torchvision-version}}+cpu --index-url https://download.pytorch.org/whl/cpu |
| 169 | pip3 install --user onnx |
| 170 | pip3 install --user onnxscript |
| 171 | |
| 172 | - name: build-ncnn |
| 173 | run: | |
| 174 | export PATH=${{ci.workspace}}/cmake-3.29.3-linux-x86_64/bin:$PATH |
| 175 | export PYTHONUSERBASE=${{ci.workspace}}/torch-${{matrix.torch-version}} |
| 176 | mkdir build && cd build |
| 177 | cmake -DCMAKE_BUILD_TYPE=Release -DNCNN_PYTHON=ON -DNCNN_BUILD_TOOLS=OFF -DNCNN_BUILD_EXAMPLES=OFF .. |
| 178 | cmake --build . -j 16 |
| 179 | cd .. |
| 180 | export CMAKE_BUILD_PARALLEL_LEVEL=16 |
| 181 | pip3 install --user . |
| 182 | |
| 183 | - name: build-pnnx |
| 184 | run: | |
| 185 | export PATH=${{ci.workspace}}/cmake-3.29.3-linux-x86_64/bin:$PATH |
| 186 | export PYTHONUSERBASE=${{ci.workspace}}/torch-${{matrix.torch-version}} |
| 187 | cd tools/pnnx |
| 188 | mkdir build && cd build |
| 189 | cmake -DCMAKE_BUILD_TYPE=Release -DTorch_INSTALL_DIR=${{ci.workspace}}/pnnx-deps-torch-install -DTorchVision_INSTALL_DIR=${{ci.workspace}}/pnnx-deps-torch-install -Donnxruntime_INSTALL_DIR=${{ci.workspace}}/pnnx-deps-onnx-install -Dprotobuf_DIR=${{ci.workspace}}/pnnx-deps-onnx-install/lib/cmake/protobuf .. |
| 190 | cmake --build . -j 16 --verbose |
| 191 | |
| 192 | - name: test |
| 193 | run: | |
| 194 | export PATH=${{ci.workspace}}/cmake-3.29.3-linux-x86_64/bin:$PATH |
| 195 | export PYTHONUSERBASE=${{ci.workspace}}/torch-${{matrix.torch-version}} |
| 196 | export OMP_NUM_THREADS=1 |
| 197 | export MKL_NUM_THREADS=1 |
| 198 | export MKL_ENABLE_INSTRUCTIONS=SSE4_2 |
| 199 | cd tools/pnnx |
| 200 | cd build && ctest --output-on-failure -j 16 |
| 201 | |
| 202 | - name: python-pnnx |
| 203 | run: | |
| 204 | export PYTHONUSERBASE=${{ci.workspace}}/torch-${{matrix.torch-version}} |
| 205 | export PNNX_WHEEL_WITHOUT_BUILD=ON |
| 206 | cd tools/pnnx/python |
| 207 | cp ../build/src/pnnx pnnx/ |
| 208 | python3 setup.py install --user |
| 209 | pytest tests |