|
| 1 | +name: tests |
| 2 | + |
| 3 | +on: |
| 4 | + # quick tests for pull requests and the releasing branches |
| 5 | + push: |
| 6 | + branches: |
| 7 | + - dev |
| 8 | + - main |
| 9 | + - releasing/* |
| 10 | + paths-ignore: # skip if only docs are modified |
| 11 | + - '**.md' |
| 12 | + - '**.rst' |
| 13 | + - 'docs/**' |
| 14 | + pull_request: |
| 15 | + branches: |
| 16 | + - dev |
| 17 | + - main |
| 18 | + - releasing/* |
| 19 | + paths-ignore: # skip if only docs are modified |
| 20 | + - '**.md' |
| 21 | + - '**.rst' |
| 22 | + - 'docs/**' |
| 23 | + |
| 24 | +concurrency: |
| 25 | + # automatically cancel the previously triggered workflows when there's a newer version |
| 26 | + group: cicd-tests-${{ github.event.pull_request.number || github.ref }} |
| 27 | + cancel-in-progress: true |
| 28 | + |
| 29 | +# Supported versions of Python and PyTorch are listed here for use below and as documentation |
| 30 | +env: |
| 31 | + # supported versions of Python |
| 32 | + PYTHON_VER1: '3.10' |
| 33 | + PYTHON_VER2: '3.11' |
| 34 | + PYTHON_VER3: '3.12' |
| 35 | + PYTHON_VER4: '3.13' |
| 36 | + # PYTHON_VER5: '3.14' # TODO: not compatible with Torchscript, re-enable once Torchscript removed from MONAI |
| 37 | + # supported versions of PyTorch |
| 38 | + PYTORCH_VER1: '2.8.0' |
| 39 | + PYTORCH_VER2: '2.9.1' |
| 40 | + PYTORCH_VER3: '2.10.0' |
| 41 | + PYTORCH_VER4: '2.11.0' |
| 42 | + TORCHVISION_VER1: '0.23.0' # used for testing with lowest PyTorch version (PYTORCH_VER1), update as needed |
| 43 | + |
| 44 | + # versions of PyTorch/Torchvision to use for full-dep Windows tests, needed to get around a gloo bug |
| 45 | + WIN_FULLDEP_VER: '2.11.0' |
| 46 | + WIN_FULLDEP_VISION_VER: '0.26.0' |
| 47 | + |
| 48 | + PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION: python # https://github.com/Project-MONAI/MONAI/issues/4354 |
| 49 | + |
| 50 | +# These jobs run the CICD tests, type checking, and testing packaging. These use the minimum supported versions of |
| 51 | +# Python and PyTorch in many places using the above environment variables but also hard coded where necessary. |
| 52 | +# When support is dropped for a version it is important to update these as appropriate. |
| 53 | + |
| 54 | +jobs: |
| 55 | + static-checks: # Perform static type and other checks using runtests.sh |
| 56 | + runs-on: ubuntu-latest |
| 57 | + strategy: |
| 58 | + matrix: |
| 59 | + opt: ["codeformat", "pytype", "mypy"] |
| 60 | + steps: |
| 61 | + - name: Clean unused tools |
| 62 | + run: | |
| 63 | + find /opt/hostedtoolcache/* -maxdepth 0 ! -name 'Python' -exec rm -rf {} \; |
| 64 | + sudo rm -rf /usr/share/dotnet |
| 65 | + sudo rm -rf /usr/local/lib/android |
| 66 | + sudo rm -rf /opt/ghc /usr/local/.ghcup |
| 67 | + sudo docker system prune -f |
| 68 | +
|
| 69 | + - uses: actions/checkout@v6 |
| 70 | + - name: Set up Python ${{ env.PYTHON_VER1 }} |
| 71 | + uses: actions/setup-python@v6 |
| 72 | + with: |
| 73 | + python-version: ${{ env.PYTHON_VER1 }} |
| 74 | + cache: 'pip' |
| 75 | + - name: Install dependencies |
| 76 | + run: | |
| 77 | + python -m pip install --upgrade pip wheel |
| 78 | + python -m pip install --no-build-isolation -r requirements-dev.txt |
| 79 | + - name: Lint and type check |
| 80 | + run: | |
| 81 | + # clean up temporary files |
| 82 | + $(pwd)/runtests.sh --build --clean |
| 83 | + # Github actions have multiple cores, so parallelize pytype |
| 84 | + $(pwd)/runtests.sh --build --${{ matrix.opt }} -j $(nproc --all) |
| 85 | +
|
| 86 | + min-dep: # Test with minumum dependencies installed for different OS, Python, and PyTorch combinations |
| 87 | + runs-on: ${{ matrix.os }} |
| 88 | + strategy: |
| 89 | + fail-fast: false |
| 90 | + matrix: |
| 91 | + # Base test cases are to test on all three OSes with the lowest versions of Python and PyTorch, other cases are |
| 92 | + # added below as special cases to cover other Python and PyTorch versions under Ubuntu |
| 93 | + os: [windows-latest, macOS-latest, ubuntu-latest] |
| 94 | + python-version: ['3.10'] |
| 95 | + pytorch-version: ['2.8.0'] |
| 96 | + include: |
| 97 | + # Test Python versions under Ubuntu with lowest PyTorch version supported |
| 98 | + - os: ubuntu-latest |
| 99 | + pytorch-version: '2.8.0' |
| 100 | + python-version: '3.11' |
| 101 | + - os: ubuntu-latest |
| 102 | + pytorch-version: '2.8.0' |
| 103 | + python-version: '3.12' |
| 104 | + - os: ubuntu-latest |
| 105 | + pytorch-version: '2.8.0' |
| 106 | + python-version: '3.13' |
| 107 | + # - os: ubuntu-latest |
| 108 | + # pytorch-version: '2.9.1' |
| 109 | + # python-version: '3.14' |
| 110 | + |
| 111 | + # Test PyTorch versions under Ubuntu with lowest Python version supported |
| 112 | + - os: ubuntu-latest |
| 113 | + python-version: '3.10' |
| 114 | + pytorch-version: '2.9.1' |
| 115 | + - os: ubuntu-latest |
| 116 | + python-version: '3.10' |
| 117 | + pytorch-version: '2.10.0' |
| 118 | + - os: ubuntu-latest |
| 119 | + python-version: '3.10' |
| 120 | + pytorch-version: '2.11.0' |
| 121 | + |
| 122 | + timeout-minutes: 40 |
| 123 | + steps: |
| 124 | + - if: runner.os == 'Linux' |
| 125 | + name: Clean unused tools |
| 126 | + run: | |
| 127 | + find /opt/hostedtoolcache/* -maxdepth 0 ! -name 'Python' -exec rm -rf {} \; |
| 128 | + sudo rm -rf /usr/share/dotnet |
| 129 | + sudo rm -rf /usr/local/lib/android |
| 130 | + sudo rm -rf /opt/ghc /usr/local/.ghcup |
| 131 | + sudo docker system prune -f |
| 132 | + - uses: actions/checkout@v6 |
| 133 | + - name: Set up Python ${{ matrix.python-version }} |
| 134 | + uses: actions/setup-python@v6 |
| 135 | + with: |
| 136 | + python-version: ${{ matrix.python-version }} |
| 137 | + cache: 'pip' |
| 138 | + - name: Prepare pip wheel |
| 139 | + run: | |
| 140 | + which python |
| 141 | + python -m pip install --upgrade pip wheel |
| 142 | + python -m pip install --user more-itertools>=8.0 |
| 143 | + - name: Install the minimum dependencies |
| 144 | + run: | |
| 145 | + # min. requirements |
| 146 | + python -m pip install torch==${{ matrix.pytorch-version }} |
| 147 | + python -m pip install -r requirements-min.txt |
| 148 | + python -m pip list |
| 149 | + BUILD_MONAI=0 python setup.py develop # no compile of extensions |
| 150 | + shell: bash |
| 151 | + - if: matrix.os == 'linux-gpu-runner' |
| 152 | + name: Print GPU Info |
| 153 | + run: | |
| 154 | + nvidia-smi |
| 155 | + python -c 'import torch; print(torch.rand(2,2).to("cuda:0"))' |
| 156 | + shell: bash |
| 157 | + - name: Run quick tests |
| 158 | + run: | |
| 159 | + python -c 'import torch; print(torch.__version__); print(torch.rand(5,3))' |
| 160 | + python -c "import monai; monai.config.print_config()" |
| 161 | + ./runtests.sh --min |
| 162 | + shell: bash |
| 163 | + env: |
| 164 | + QUICKTEST: True |
| 165 | + NGC_API_KEY: ${{ secrets.NGC_API_KEY }} |
| 166 | + NGC_ORG: ${{ secrets.NGC_ORG }} |
| 167 | + NGC_TEAM: ${{ secrets.NGC_TEAM }} |
| 168 | + |
| 169 | + full-dep: # Test with full dependencies installed for different OS runners |
| 170 | + runs-on: ${{ matrix.os }} |
| 171 | + strategy: |
| 172 | + fail-fast: false |
| 173 | + matrix: |
| 174 | + os: [windows-latest, macOS-latest, ubuntu-latest] |
| 175 | + timeout-minutes: 120 |
| 176 | + env: |
| 177 | + QUICKTEST: True |
| 178 | + steps: |
| 179 | + - if: runner.os == 'Linux' |
| 180 | + name: Clean unused tools |
| 181 | + run: | |
| 182 | + find /opt/hostedtoolcache/* -maxdepth 0 ! -name 'Python' -exec rm -rf {} \; |
| 183 | + sudo rm -rf /usr/share/dotnet |
| 184 | + sudo rm -rf /usr/local/lib/android |
| 185 | + sudo rm -rf /opt/ghc /usr/local/.ghcup |
| 186 | + sudo docker system prune -f |
| 187 | + - if: runner.os == 'windows' |
| 188 | + name: Config pagefile (Windows only) |
| 189 | + uses: al-cheb/configure-pagefile-action@v1.5 |
| 190 | + with: |
| 191 | + minimum-size: 8GB |
| 192 | + maximum-size: 16GB |
| 193 | + disk-root: "D:" |
| 194 | + - uses: actions/checkout@v6 |
| 195 | + - name: Set up Python ${{ env.PYTHON_VER1 }} |
| 196 | + uses: actions/setup-python@v6 |
| 197 | + with: |
| 198 | + python-version: ${{ env.PYTHON_VER1 }} |
| 199 | + cache: 'pip' |
| 200 | + - name: Prepare pip wheel |
| 201 | + run: | |
| 202 | + which python |
| 203 | + python -m pip install --upgrade pip wheel |
| 204 | + - if: runner.os == 'windows' |
| 205 | + name: Install torch cpu from pytorch.org (Windows only) |
| 206 | + run: | |
| 207 | + python -m pip install torch==${WIN_FULLDEP_VER} torchvision==${WIN_FULLDEP_VISION_VER}+cpu --index-url https://download.pytorch.org/whl/cpu |
| 208 | + shell: bash |
| 209 | + - if: runner.os != 'windows' |
| 210 | + name: Install torch gpu |
| 211 | + run: | |
| 212 | + # install the lowest version of PyTorch supported |
| 213 | + python -m pip install torch==${PYTORCH_VER1} torchvision==${TORCHVISION_VER1} |
| 214 | + shell: bash |
| 215 | + - if: runner.os == 'Linux' |
| 216 | + name: Install itk pre-release (Linux only) |
| 217 | + run: | |
| 218 | + python -m pip install --pre -U itk |
| 219 | + shell: bash |
| 220 | + - name: Install the complete dependencies |
| 221 | + run: | |
| 222 | + python -m pip install --user --upgrade pip wheel pybind11 # TODO: pybind11 added for macOS, may not be needed |
| 223 | + #python -m pip install torch==${PYTORCH_VER1} torchvision==${TORCHVISION_VER1} |
| 224 | + cat "requirements-dev.txt" |
| 225 | + python -m pip install --no-build-isolation -r requirements-dev.txt |
| 226 | + python -m pip list |
| 227 | + python -m pip install -e . # test no compile installation |
| 228 | + shell: bash |
| 229 | + - name: Run compiled (${{ runner.os }}) |
| 230 | + run: | |
| 231 | + python -m pip uninstall -y monai |
| 232 | + BUILD_MONAI=1 python -m pip install -e . # compile the cpp extensions |
| 233 | + shell: bash |
| 234 | + - name: Run quick tests |
| 235 | + run: | |
| 236 | + python -c 'import torch; print(torch.__version__); print(torch.rand(5,3))' |
| 237 | + python -c "import monai; monai.config.print_config()" |
| 238 | + python -m unittest -v |
| 239 | + shell: bash |
| 240 | + |
| 241 | + packaging: # Test package generation |
| 242 | + runs-on: ubuntu-latest |
| 243 | + env: |
| 244 | + QUICKTEST: True |
| 245 | + steps: |
| 246 | + - name: Clean unused tools |
| 247 | + run: | |
| 248 | + find /opt/hostedtoolcache/* -maxdepth 0 ! -name 'Python' -exec rm -rf {} \; |
| 249 | + sudo rm -rf /usr/share/dotnet |
| 250 | + sudo rm -rf /usr/local/lib/android |
| 251 | + sudo rm -rf /opt/ghc /usr/local/.ghcup |
| 252 | + sudo docker system prune -f |
| 253 | + - uses: actions/checkout@v6 |
| 254 | + with: |
| 255 | + fetch-depth: 0 |
| 256 | + - name: Set up Python ${{ env.PYTHON_VER1 }} |
| 257 | + uses: actions/setup-python@v6 |
| 258 | + with: |
| 259 | + python-version: ${{ env.PYTHON_VER1 }} |
| 260 | + cache: 'pip' |
| 261 | + - name: Install dependencies |
| 262 | + run: | |
| 263 | + python -m pip install --user --upgrade pip setuptools wheel twine packaging |
| 264 | + # install the latest pytorch for testing |
| 265 | + # however, "pip install monai*.tar.gz" will build cpp/cuda with an isolated |
| 266 | + # fresh torch installation according to pyproject.toml |
| 267 | + python -m pip install torch==${PYTORCH_VER1} torchvision --extra-index-url https://download.pytorch.org/whl/cpu |
| 268 | + - name: Check packages |
| 269 | + run: | |
| 270 | + pip uninstall monai |
| 271 | + pip list | grep -iv monai |
| 272 | + git fetch --depth=1 origin +refs/tags/*:refs/tags/* |
| 273 | + set -e |
| 274 | +
|
| 275 | + # build tar.gz and wheel |
| 276 | + python setup.py check -m -s |
| 277 | + python setup.py sdist bdist_wheel |
| 278 | + python -m twine check dist/* |
| 279 | + - run: echo "pwd=$PWD" >> $GITHUB_OUTPUT |
| 280 | + id: root |
| 281 | + - run: echo "tmp_dir=$(mktemp -d)" >> $GITHUB_OUTPUT |
| 282 | + id: mktemp |
| 283 | + - name: Move packages |
| 284 | + run: | |
| 285 | + printf ${{ steps.root.outputs.pwd }} |
| 286 | + printf ${{ steps.mktemp.outputs.tmp_dir }} |
| 287 | + # move packages to a temp dir |
| 288 | + cp dist/monai* "${{ steps.mktemp.outputs.tmp_dir }}" |
| 289 | + rm -r build dist monai.egg-info |
| 290 | + cd "${{ steps.mktemp.outputs.tmp_dir }}" |
| 291 | + ls -al |
| 292 | + - name: Install wheel file |
| 293 | + working-directory: ${{ steps.mktemp.outputs.tmp_dir }} |
| 294 | + run: | |
| 295 | + # install from wheel |
| 296 | + python -m pip install monai*.whl --extra-index-url https://download.pytorch.org/whl/cpu |
| 297 | + python -c 'import monai; monai.config.print_config()' 2>&1 | grep -iv "unknown" |
| 298 | + python -c 'import monai; print(monai.__file__)' |
| 299 | + python -m pip uninstall -y monai |
| 300 | + rm monai*.whl |
| 301 | + - name: Install source archive |
| 302 | + working-directory: ${{ steps.mktemp.outputs.tmp_dir }} |
| 303 | + run: | |
| 304 | + for name in *.tar.gz; do break; done |
| 305 | + echo $name |
| 306 | + python -m pip install ${name}[all] --extra-index-url https://download.pytorch.org/whl/cpu |
| 307 | + python -c 'import monai; monai.config.print_config()' 2>&1 | grep -iv "unknown" |
| 308 | + python -c 'import monai; print(monai.__file__)' |
| 309 | + - name: Quick test |
| 310 | + working-directory: ${{ steps.mktemp.outputs.tmp_dir }} |
| 311 | + run: | |
| 312 | + # run min tests |
| 313 | + cp ${{ steps.root.outputs.pwd }}/requirements*.txt . |
| 314 | + cp -r ${{ steps.root.outputs.pwd }}/tests . |
| 315 | + ls -al |
| 316 | + python -m pip install --no-build-isolation -r requirements-dev.txt --extra-index-url https://download.pytorch.org/whl/cpu |
| 317 | + python -m unittest -v |
0 commit comments