Skip to content

Commit

Permalink
Support torch==2.0.1 (#2465)
Browse files Browse the repository at this point in the history
* Support torch==2.0.1 torchvision==0.15.2 mmcv-full=1.7.0 combination

* Disalbe NNCF & tests for MaskRCNN on torch==2.0.1 temporarily due to Issue#2451

* Upate documents

---------
Signed-off-by: Songki Choi <[email protected]>
  • Loading branch information
goodsong81 authored Sep 20, 2023
1 parent d84d925 commit 6f00907
Show file tree
Hide file tree
Showing 13 changed files with 53 additions and 44 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/pre_merge.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ jobs:
- name: Install dependencies
run: python -m pip install -r requirements/dev.txt
- name: Code quality checks
run: tox -vv -e pre-commit-all-py310
run: tox -vv -e pre-commit-all-py310-pt1
Unit-Test:
runs-on: [self-hosted, linux, x64, dev]
needs: Code-Quality-Checks
Expand Down Expand Up @@ -59,7 +59,7 @@ jobs:
- name: Install dependencies
run: python -m pip install -r requirements/dev.txt
- name: Run unit test
run: tox -vv -e unittest-all-${{ matrix.tox-env }}
run: tox -vv -e unittest-all-${{ matrix.tox-env }}-pt1
- name: Upload coverage artifact
if: ${{ matrix.python-version == '3.8' }}
uses: actions/upload-artifact@v3
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/run_tests_in_tox.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ jobs:
- name: Install dependencies
run: python -m pip install -r requirements/dev.txt
- name: E2E Tests
run: tox -vv -e tests-${{ inputs.toxenv-task }}-${{ inputs.toxenv-pyver }} -- ${{ inputs.tests-dir }}
run: tox -vv -e tests-${{ inputs.toxenv-task }}-${{ inputs.toxenv-pyver }}-pt1 -- ${{ inputs.tests-dir }}
- name: Upload test results
uses: actions/upload-artifact@v3
with:
Expand Down
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,16 @@ All notable changes to this project will be documented in this file.
- Refine input data in-memory caching (<https://github.com/openvinotoolkit/training_extensions/pull/2416>)
- Adapt timeout value of initialization for distributed training (<https://github.com/openvinotoolkit/training_extensions/pull/2422>)
- Optimize data loading by merging load & resize operations w/ caching support for cls/det/iseg/sseg (<https://github.com/openvinotoolkit/training_extensions/pull/2438>, <https://github.com/openvinotoolkit/training_extensions/pull/2453>, <https://github.com/openvinotoolkit/training_extensions/pull/2460>)
- Support torch==2.0.1 (<https://github.com/openvinotoolkit/training_extensions/pull/2465>)

### Bug fixes

- Fix F1 auto-threshold to choose best largest confidence (<https://github.com/openvinotoolkit/training_extensions/pull/2371>)

### Known issues

- OpenVINO(==2023.0) IR inference is not working well on 2-stage models (e.g. Mask-RCNN) exported from torch==1.13.1
- OpenVINO(==2023.0) IR inference is not working well on 2-stage models (e.g. Mask-RCNN) exported from torch>=1.13.1
- NNCF QAT optimization is disabled for MaskRCNN models due to CUDA runtime error in ROIAlign kernel on torch==2.0.1

## \[v1.4.1\]

Expand Down
10 changes: 5 additions & 5 deletions docs/source/guide/get_started/installation.rst
Original file line number Diff line number Diff line change
Expand Up @@ -46,15 +46,15 @@ Refer to the `official installation guide <https://pytorch.org/get-started/previ

.. note::

Currently, only torch==1.13.1 was fully validated, torch==2.x will be supported in the future (Previous versions are not supported due to security issues).
Currently, only torch==1.13.1 ~ 2.0.1 was fully validated. (older versions are not supported due to security issues).

.. code-block::
# install command for torch==1.13.1 for CUDA 11.7:
pip install torch==1.13.1 torchvision==0.14.1 --extra-index-url https://download.pytorch.org/whl/cu117
# Install command for torch==2.0.1 for CUDA 11.7:
pip install torch==2.0.1 torchvision==0.15.2 --extra-index-url https://download.pytorch.org/whl/cu117
# or install command for torch==1.13.1 for CUDA 11.1:
pip install torch==1.13.1 torchvision==0.14.1 --extra-index-url https://download.pytorch.org/whl/cu111
# Or, install command for torch==1.13.1 for CUDA 11.7:
pip install torch==1.13.1 torchvision==0.14.1 --extra-index-url https://download.pytorch.org/whl/cu117
4. Install OpenVINO™ Training Extensions package from either:

Expand Down
2 changes: 1 addition & 1 deletion requirements/action.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ mmcv-full==1.7.0
mmaction2==0.24.1
mmdet==2.28.1
mmdeploy==0.14.0
yapf<0.40.0 # it should be removed after https://github.com/google/yapf/issues/1118 is solved
yapf<0.40.0 # it should be removed after https://github.com/google/yapf/issues/1118 is solved
2 changes: 0 additions & 2 deletions requirements/anomaly.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# Anomaly Requirements.
torchvision<0.15.1
torchtext<0.15.1
anomalib==0.5.1
kornia==0.6.9
2 changes: 1 addition & 1 deletion requirements/classification.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ mmcls==0.25.0
timm==0.6.12
mmdeploy==0.14.0
pytorchcv
yapf<0.40.0 # it should be removed after https://github.com/google/yapf/issues/1118 is solved
yapf<0.40.0 # it should be removed after https://github.com/google/yapf/issues/1118 is solved
2 changes: 1 addition & 1 deletion requirements/detection.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ timm==0.6.12
mmdeploy==0.14.0
mmengine==0.7.4
scikit-image
yapf<0.40.0 # it should be removed after https://github.com/google/yapf/issues/1118 is solved
yapf<0.40.0 # it should be removed after https://github.com/google/yapf/issues/1118 is solved
2 changes: 1 addition & 1 deletion requirements/segmentation.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ mmdeploy==0.14.0
timm==0.6.12
pytorchcv
einops==0.6.1
yapf<0.40.0 # it should be removed after https://github.com/google/yapf/issues/1118 is solved
yapf<0.40.0 # it should be removed after https://github.com/google/yapf/issues/1118 is solved
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,10 @@ def test_nncf_optimize(self, template, tmp_dir_path):
tmp_dir_path = tmp_dir_path / "ins_seg"
if template.entrypoints.nncf is None:
pytest.skip("nncf entrypoint is none")

if torch.__version__.startswith("2.") and template.name.startswith("MaskRCNN"):
pytest.skip(
reason="Issue#2451: Torch2.0 CUDA runtime error during NNCF optimization of ROIAlign MMCV kernel for MaskRCNN"
)
nncf_optimize_testing(template, tmp_dir_path, otx_dir, args)

@e2e_pytest_component
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
"""Tests for OTX Class-Incremental Learning for instance segmentation with OTX CLI"""
# Copyright (C) 2022 Intel Corporation
# Copyright (C) 2022-2023 Intel Corporation
# SPDX-License-Identifier: Apache-2.0
#
import copy
import os

import pytest
import torch

from otx.api.entities.model_template import parse_model_template
from tests.test_suite.e2e_test_system import e2e_pytest_component
Expand Down Expand Up @@ -157,5 +158,8 @@ def test_nncf_optimize(self, template, tmp_dir_path):
tmp_dir_path = tmp_dir_path / "tiling_ins_seg"
if template.entrypoints.nncf is None:
pytest.skip("nncf entrypoint is none")

if torch.__version__.startswith("2.") and template.name.startswith("MaskRCNN"):
pytest.skip(
reason="Issue#2451: Torch2.0 CUDA runtime error during NNCF optimization of ROIAlign MMCV kernel for MaskRCNN"
)
nncf_optimize_testing(template, tmp_dir_path, otx_dir, args)
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,10 @@ def test_call(self, data: dict[str, np.ndarray]) -> None:
def test_repr(self) -> None:
"""Test __repr__ method of ColorJitter."""
transform = ColorJitter(brightness=0.2)
assert str(transform) == "ColorJitter(brightness=[0.8, 1.2], contrast=None, saturation=None, hue=None)"
assert str(transform) in [
"ColorJitter(brightness=[0.8, 1.2], contrast=None, saturation=None, hue=None)",
"ColorJitter(brightness=(0.8, 1.2), contrast=None, saturation=None, hue=None)",
]


class TestRandomGrayscale:
Expand Down
49 changes: 24 additions & 25 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -24,18 +24,22 @@ test_dir =
act: cli/action
visprompt: cli/visual_prompting
deps =
py38: torch @ https://download.pytorch.org/whl/cu117/torch-1.13.1%2Bcu117-cp38-cp38-linux_x86_64.whl
py38: torchvision @ https://download.pytorch.org/whl/cu117/torchvision-0.14.1%2Bcu117-cp38-cp38-linux_x86_64.whl
py38: torchtext @ https://download.pytorch.org/whl/torchtext-0.14.1-cp38-cp38-linux_x86_64.whl
{all,act,cls,det,seg,iseg,iseg_t}-py38: mmcv-full @ https://download.openmmlab.com/mmcv/dist/cu117/torch1.13.0/mmcv_full-1.7.0-cp38-cp38-manylinux1_x86_64.whl
py39: torch @ https://download.pytorch.org/whl/cu117/torch-1.13.1%2Bcu117-cp39-cp39-linux_x86_64.whl
py39: torchvision @ https://download.pytorch.org/whl/cu117/torchvision-0.14.1%2Bcu117-cp39-cp39-linux_x86_64.whl
py39: torchtext @ https://download.pytorch.org/whl/torchtext-0.14.1-cp39-cp39-linux_x86_64.whl
{all,act,cls,det,seg,iseg,iseg_t}-py39: mmcv-full @ https://download.openmmlab.com/mmcv/dist/cu117/torch1.13.0/mmcv_full-1.7.0-cp39-cp39-manylinux1_x86_64.whl
py310: torch @ https://download.pytorch.org/whl/cu117/torch-1.13.1%2Bcu117-cp310-cp310-linux_x86_64.whl
py310: torchvision @ https://download.pytorch.org/whl/cu117/torchvision-0.14.1%2Bcu117-cp310-cp310-linux_x86_64.whl
py310: torchtext @ https://download.pytorch.org/whl/torchtext-0.14.1-cp310-cp310-linux_x86_64.whl
{all,act,cls,det,seg,iseg,iseg_t}-py310: mmcv-full @ https://download.openmmlab.com/mmcv/dist/cu117/torch1.13.0/mmcv_full-1.7.0-cp310-cp310-manylinux1_x86_64.whl
py38-pt1: torch @ https://download.pytorch.org/whl/cu117/torch-1.13.1%2Bcu117-cp38-cp38-linux_x86_64.whl
py38-pt1: torchvision @ https://download.pytorch.org/whl/cu117/torchvision-0.14.1%2Bcu117-cp38-cp38-linux_x86_64.whl
{all,act,cls,det,seg,iseg,iseg_t}-py38-pt1: mmcv-full @ https://download.openmmlab.com/mmcv/dist/cu117/torch1.13.0/mmcv_full-1.7.0-cp38-cp38-manylinux1_x86_64.whl
py39-pt1: torch @ https://download.pytorch.org/whl/cu117/torch-1.13.1%2Bcu117-cp39-cp39-linux_x86_64.whl
py39-pt1: torchvision @ https://download.pytorch.org/whl/cu117/torchvision-0.14.1%2Bcu117-cp39-cp39-linux_x86_64.whl
{all,act,cls,det,seg,iseg,iseg_t}-py39-pt1: mmcv-full @ https://download.openmmlab.com/mmcv/dist/cu117/torch1.13.0/mmcv_full-1.7.0-cp39-cp39-manylinux1_x86_64.whl
py310-pt1: torch @ https://download.pytorch.org/whl/cu117/torch-1.13.1%2Bcu117-cp310-cp310-linux_x86_64.whl
py310-pt1: torchvision @ https://download.pytorch.org/whl/cu117/torchvision-0.14.1%2Bcu117-cp310-cp310-linux_x86_64.whl
{all,act,cls,det,seg,iseg,iseg_t}-py310-pt1: mmcv-full @ https://download.openmmlab.com/mmcv/dist/cu117/torch1.13.0/mmcv_full-1.7.0-cp310-cp310-manylinux1_x86_64.whl

py38-pt2: torch @ https://download.pytorch.org/whl/cu117/torch-2.0.1%2Bcu117-cp38-cp38-linux_x86_64.whl
py38-pt2: torchvision @ https://download.pytorch.org/whl/cu117/torchvision-0.15.2%2Bcu117-cp38-cp38-linux_x86_64.whl
py39-pt2: torch @ https://download.pytorch.org/whl/cu117/torch-2.0.1%2Bcu117-cp39-cp39-linux_x86_64.whl
py39-pt2: torchvision @ https://download.pytorch.org/whl/cu117/torchvision-0.15.2%2Bcu117-cp39-cp39-linux_x86_64.whl
py310-pt2: torch @ https://download.pytorch.org/whl/cu117/torch-2.0.1%2Bcu117-cp310-cp310-linux_x86_64.whl
py310-pt2: torchvision @ https://download.pytorch.org/whl/cu117/torchvision-0.15.2%2Bcu117-cp310-cp310-linux_x86_64.whl
extras =
all: full
ano: anomaly
Expand All @@ -45,7 +49,7 @@ extras =
seg: segmentation
visprompt: visual_prompting

[testenv:pre-commit-all-{py38,py39,py310}]
[testenv:pre-commit-all-{py38,py39,py310}-{pt1,pt2}]
deps =
{[testenv]deps}
-r{toxinidir}/requirements/dev.txt
Expand All @@ -54,15 +58,15 @@ commands =
pre-commit run --all-files


[testenv:tests-{all,ano,cls,det,iseg,iseg_t,seg,act,visprompt}-{py38,py39,py310}]
[testenv:tests-{all,ano,cls,det,iseg,iseg_t,seg,act,visprompt}-{py38,py39,py310}-{pt1,pt2}]
deps =
{[testenv]deps}
-r{toxinidir}/requirements/dev.txt
commands =
python -m pytest -ra --showlocals --csv={toxworkdir}/{envname}.csv {posargs:tests/integration/{[testenv]test_dir}}


[testenv:unittest-all-{py38,py39,py310}]
[testenv:unittest-all-{py38,py39,py310}-{pt1,pt2}]
deps =
{[testenv]deps}
-r{toxinidir}/requirements/dev.txt
Expand All @@ -77,7 +81,7 @@ commands =

[testenv:fuzzing]
deps =
{[testenv:tests-all-py310]deps}
{[testenv:tests-all-py310-pt1]deps}
atheris
commands =
coverage erase
Expand All @@ -88,7 +92,7 @@ commands =

[testenv:build-doc]
deps =
{[testenv:tests-all-py310]deps}
{[testenv:tests-all-py310-pt1]deps}
-r{toxinidir}/requirements/docs.txt
change_dir = {toxinidir}/docs
allowlist_externals =
Expand All @@ -97,16 +101,11 @@ commands =
make html


[testenv:package-py{38,39,310}]
[testenv:package-py{38,39,310}-{pt1,pt2}]
deps =
{[testenv]deps}
build==0.10.0
-r{toxinidir}/requirements/dev.txt
py38: torch @ https://download.pytorch.org/whl/cu117/torch-1.13.1%2Bcu117-cp38-cp38-linux_x86_64.whl
py38: torchvision @ https://download.pytorch.org/whl/cu117/torchvision-0.14.1%2Bcu117-cp38-cp38-linux_x86_64.whl
py39: torch @ https://download.pytorch.org/whl/cu117/torch-1.13.1%2Bcu117-cp39-cp39-linux_x86_64.whl
py39: torchvision @ https://download.pytorch.org/whl/cu117/torchvision-0.14.1%2Bcu117-cp39-cp39-linux_x86_64.whl
py310: torch @ https://download.pytorch.org/whl/cu117/torch-1.13.1%2Bcu117-cp310-cp310-linux_x86_64.whl
py310: torchvision @ https://download.pytorch.org/whl/cu117/torchvision-0.14.1%2Bcu117-cp310-cp310-linux_x86_64.whl
skip_install = true
allowlist_externals =
rm
Expand All @@ -120,7 +119,7 @@ commands =

[testenv:trivy-scan]
deps =
{[testenv:tests-all-py310]deps}
{[testenv:tests-all-py310-pt1]deps}
passenv =
{[testenv]passenv}
TRIVY_DOWNLOAD_URL
Expand Down

0 comments on commit 6f00907

Please sign in to comment.