From 8993575fad4ce323e33d20e69adaa3625db0b910 Mon Sep 17 00:00:00 2001 From: IlyasMoutawwakil Date: Sun, 27 Oct 2024 14:25:06 +0100 Subject: [PATCH 01/21] clean and clear CI --- .github/workflows/build_pr_documentation.yml | 13 ++-- .github/workflows/check_code_quality.yml | 54 ---------------- .github/workflows/quality.yml | 45 +++++++++++++ .github/workflows/security.yml | 2 +- .github/workflows/test_generation.yml | 45 +++++++------ .github/workflows/test_inc.yml | 47 ++++++-------- .github/workflows/test_ipex.yml | 43 +++++++------ .github/workflows/test_offline.yaml | 19 ++++-- .github/workflows/test_openvino.yml | 43 ++++++++----- .github/workflows/test_openvino_examples.yml | 48 +++++++------- .github/workflows/test_openvino_notebooks.yml | 64 +++++++++---------- ...nvino_basic.yml => test_openvino_slow.yml} | 2 +- setup.py | 1 + ...iffusion.py => test_modeling_diffusion.py} | 0 14 files changed, 221 insertions(+), 205 deletions(-) delete mode 100644 .github/workflows/check_code_quality.yml create mode 100644 .github/workflows/quality.yml rename .github/workflows/{test_openvino_basic.yml => test_openvino_slow.yml} (99%) rename tests/openvino/{test_diffusion.py => test_modeling_diffusion.py} (100%) diff --git a/.github/workflows/build_pr_documentation.yml b/.github/workflows/build_pr_documentation.yml index cab800759..188b90bb1 100644 --- a/.github/workflows/build_pr_documentation.yml +++ b/.github/workflows/build_pr_documentation.yml @@ -2,7 +2,8 @@ name: Build PR documentation on: pull_request: - branches: [ main ] + branches: + - main concurrency: group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }} @@ -18,20 +19,18 @@ jobs: PR_CLONE_URL: ${{ github.event.pull_request.head.repo.clone_url }} steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v4 with: - repository: 'huggingface/doc-builder' + repository: "huggingface/doc-builder" path: doc-builder - - uses: actions/checkout@v2 + - uses: actions/checkout@v4 with: - repository: 'huggingface/optimum-intel' + repository: "huggingface/optimum-intel" path: optimum-intel - name: Setup environment run: | - python -m venv venv-doc - source venv-doc/bin/activate pip uninstall -y doc-builder cd doc-builder git pull origin main diff --git a/.github/workflows/check_code_quality.yml b/.github/workflows/check_code_quality.yml deleted file mode 100644 index c76b6f804..000000000 --- a/.github/workflows/check_code_quality.yml +++ /dev/null @@ -1,54 +0,0 @@ -name: check_code_quality - -on: - push: - branches: [ main ] - paths: - - "optimum/**.py" - - "tests/**.py" - - "examples/**.py" - - pull_request: - branches: [ main ] - paths: - - "optimum/**.py" - - "tests/**.py" - - "examples/**.py" - -concurrency: - group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }} - cancel-in-progress: true - -jobs: - build: - strategy: - fail-fast: false - matrix: - python-version: [3.8] - os: [ubuntu-latest] - - runs-on: ${{ matrix.os }} - steps: - - uses: actions/checkout@v2 - - name: Setup Python ${{ matrix.python-version }} - uses: actions/setup-python@v2 - with: - python-version: ${{ matrix.python-version }} - - name: Create and start a virtual environment - run: | - python -m venv venv - source venv/bin/activate - - name: Install dependencies - run: | - source venv/bin/activate - pip install --upgrade pip - pip install .[quality] - - - name: Check style with black - run: | - source venv/bin/activate - black --check . - - name: Check style with ruff - run: | - source venv/bin/activate - ruff check . diff --git a/.github/workflows/quality.yml b/.github/workflows/quality.yml new file mode 100644 index 000000000..2b9cf49a6 --- /dev/null +++ b/.github/workflows/quality.yml @@ -0,0 +1,45 @@ +name: Code Quality Checks +on: + push: + branches: + - main + + pull_request: + branches: + - main + +concurrency: + group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }} + cancel-in-progress: true + +jobs: + build: + strategy: + fail-fast: false + matrix: + python-version: ["3.9"] + os: [ubuntu-latest] + + runs-on: ${{ matrix.os }} + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Setup Python ${{ matrix.python-version }} + uses: actions/setup-python@v5 + with: + python-version: ${{ matrix.python-version }} + + - name: Install dependencies + run: | + pip install --upgrade pip + # TODO: we should remove the the version pinning at some point + pip install "black~=23.1" "ruff==0.4.4" + + - name: Check style with black + run: | + black --check . + + - name: Check style with ruff + run: | + ruff check . diff --git a/.github/workflows/security.yml b/.github/workflows/security.yml index 3c2dc94da..3fe1c7f6e 100644 --- a/.github/workflows/security.yml +++ b/.github/workflows/security.yml @@ -1,4 +1,4 @@ -name: Security Checks +name: Security Check on: push: diff --git a/.github/workflows/test_generation.yml b/.github/workflows/test_generation.yml index 3c2747318..3bc04e3c6 100644 --- a/.github/workflows/test_generation.yml +++ b/.github/workflows/test_generation.yml @@ -1,12 +1,13 @@ -# This workflow will install Python dependencies, run tests and lint with a variety of Python versions -# For more information see: https://help.github.com/actions/language-and-framework-guides/using-python-with-github-actions -name: Intel Generation Utils - Test +name: Generation Utils - Test on: push: - branches: [ main ] + branches: + - main + - v*-release pull_request: - branches: [ main ] + branches: + - main concurrency: group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }} @@ -17,22 +18,26 @@ jobs: strategy: fail-fast: false matrix: - python-version: [3.8, 3.9] + python-version: [3.9] os: [ubuntu-latest] runs-on: ${{ matrix.os }} + steps: - - uses: actions/checkout@v2 - - name: Setup Python ${{ matrix.python-version }} - uses: actions/setup-python@v2 - with: - python-version: ${{ matrix.python-version }} - - name: Install dependencies - run: | - python -m pip install --upgrade pip - pip install transformers==4.43.* - pip install optimum[exporters] - pip install .[tests] - - name: Test with Pytest - run: | - pytest tests/generation/ + - name: Checkout code + uses: actions/checkout@v4 + + - name: Setup Python ${{ matrix.python-version }} + uses: actions/setup-python@v5 + with: + python-version: ${{ matrix.python-version }} + + - name: Install dependencies + run: | + pip install --upgrade pip + pip install transformers==4.43.* + pip install .[tests] + + - name: Test with Pytest + run: | + pytest tests/generation/ diff --git a/.github/workflows/test_inc.yml b/.github/workflows/test_inc.yml index 6e9992348..6ccfb65c5 100644 --- a/.github/workflows/test_inc.yml +++ b/.github/workflows/test_inc.yml @@ -1,6 +1,4 @@ -# This workflow will install Python dependencies, run tests and lint with a variety of Python versions -# For more information see: https://help.github.com/actions/language-and-framework-guides/using-python-with-github-actions -name: Intel Neural Compressor - Test +name: INC - Test on: push: @@ -20,31 +18,28 @@ jobs: strategy: fail-fast: false matrix: - python-version: [3.8, 3.9] + torch-version: ["2.3.*", "2.4.*"] + python-version: [3.9] os: [ubuntu-latest] runs-on: ${{ matrix.os }} + steps: - - uses: actions/checkout@v2 - - name: Setup Python ${{ matrix.python-version }} - uses: actions/setup-python@v2 - with: - python-version: ${{ matrix.python-version }} - - name: Install dependencies - run: | - python -m pip install --upgrade pip - pip install cmake - pip install py-cpuinfo - pip install torch==2.3.0 torchaudio==2.3.0 torchvision==0.18 --index-url https://download.pytorch.org/whl/cpu - pip install intel-extension-for-pytorch==2.3.0 - pip install datasets==2.19.0 - pip install .[neural-compressor,diffusers,tests] - pip install peft - - - name: Test with Pytest - run: | - pytest tests/neural_compressor/ --ignore tests/neural_compressor/test_ipex.py --durations=0 - - name: Test IPEX - run: | - pytest tests/neural_compressor/test_ipex.py + - name: Checkout code + uses: actions/checkout@v4 + + - name: Setup Python ${{ matrix.python-version }} + uses: actions/setup-python@v5 + with: + python-version: ${{ matrix.python-version }} + + - name: Install dependencies + run: | + pip install --upgrade pip + pip install torch==${{ matrix.torch-version }} torchaudio torchvision --index-url https://download.pytorch.org/whl/cpu + pip install intel-extension-for-pytorch==${{ matrix.torch-version }} + pip install .[neural-compressor,ipex,diffusers,peft,tests] + - name: Test with Pytest + run: | + pytest tests/neural_compressor/ -s -vvvv --durations=0 diff --git a/.github/workflows/test_ipex.yml b/.github/workflows/test_ipex.yml index 4030f7d40..b8ea66387 100644 --- a/.github/workflows/test_ipex.yml +++ b/.github/workflows/test_ipex.yml @@ -1,6 +1,4 @@ -# This workflow will install Python dependencies, run tests and lint with a variety of Python versions -# For more information see: https://help.github.com/actions/language-and-framework-guides/using-python-with-github-actions -name: Intel IPEX - Test +name: IPEX - Test on: push: @@ -17,36 +15,43 @@ concurrency: jobs: build: - runs-on: ubuntu-latest strategy: fail-fast: false matrix: - python-version: [3.9] + torch-version: ["2.2.*", "2.3.*", "2.4.*"] transformers-version: ["4.39.0", "4.44.*"] - ipex-version: ["2.2.0", "2.3.*"] - include: - - python-version: 3.8 - transformers-version: 4.39.0 - ipex-version: 2.2.0 + python-version: [3.9] + os: [ubuntu-latest] + + runs-on: ${{ matrix.os }} steps: - - uses: actions/checkout@v2 + - name: Checkout code + uses: actions/checkout@v4 + - name: Setup Python ${{ matrix.python-version }} - uses: actions/setup-python@v2 + uses: actions/setup-python@v5 with: python-version: ${{ matrix.python-version }} + - name: Install dependencies run: | - python -m pip install --upgrade pip - pip install torch==${{ matrix.ipex-version }} --extra-index-url https://download.pytorch.org/whl/cpu - pip install intel_extension_for_pytorch==${{ matrix.ipex-version }} - pip install Pillow parameterized - pip install transformers[testing]==${{ matrix.transformers-version }} + pip install --upgrade pip + pip install torch==${{ matrix.torch-version }} torchaudio torchvision --extra-index-url https://download.pytorch.org/whl/cpu + pip install intel_extension_for_pytorch==${{ matrix.torch-version }} + pip install transformers==${{ matrix.transformers-version }} pip install .[ipex] - - if: ${{ matrix.ipex-version == '2.2.0' }} + - name: Assert versions + run: | + python -c "import torch; assert torch.__version__.startswith('${{ matrix.torch-version }}'.replace('.*', ''))" + python -c "import transformers; assert transformers.__version__.startswith('${{ matrix.transformers-version }}'.replace('.*', ''))" + python -c "import intel_extension_for_pytorch; assert intel_extension_for_pytorch.__version__.startswith('${{ matrix.torch-version }}'.replace('.*', ''))" + + - if: ${{ matrix.torch-version == '2.2.*' }} + name: Downgrade numpy for torch 2.2.* run: pip install numpy==1.* - name: Test with Pytest run: | - pytest tests/ipex/ + pytest tests/ipex/ -s -vvvv --durations=0 diff --git a/.github/workflows/test_offline.yaml b/.github/workflows/test_offline.yaml index a54ba2076..44589f1f9 100644 --- a/.github/workflows/test_offline.yaml +++ b/.github/workflows/test_offline.yaml @@ -1,10 +1,13 @@ -name: Offline usage / Python - Test +name: Offline - Test on: push: - branches: [main] + branches: + - main + - v*-release pull_request: - branches: [main] + branches: + - main concurrency: group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }} @@ -15,19 +18,23 @@ jobs: strategy: fail-fast: false matrix: - python-version: [3.9] + python-version: ["3.9"] os: [ubuntu-latest] runs-on: ${{ matrix.os }} steps: - - uses: actions/checkout@v3 + - name: Checkout code + uses: actions/checkout@v4 + - name: Setup Python ${{ matrix.python-version }} - uses: actions/setup-python@v3 + uses: actions/setup-python@v5 with: python-version: ${{ matrix.python-version }} + - name: Install dependencies run: | pip install .[tests,openvino] + - name: Test run: | HF_HOME=/tmp/ huggingface-cli download hf-internal-testing/tiny-random-gpt2 diff --git a/.github/workflows/test_openvino.yml b/.github/workflows/test_openvino.yml index 53c210707..9f1caed39 100644 --- a/.github/workflows/test_openvino.yml +++ b/.github/workflows/test_openvino.yml @@ -1,5 +1,3 @@ -# This workflow will install Python dependencies, run tests and lint with a variety of Python versions -# For more information see: https://help.github.com/actions/language-and-framework-guides/using-python-with-github-actions name: OpenVINO - Test on: @@ -20,13 +18,23 @@ jobs: strategy: fail-fast: false matrix: - python-version: ["3.8", "3.12"] + test_pattern: + [ + "test_export*", + "test_modeling*", + "test_quantization*", + "test_training*", + ] transformers-version: ["4.36.0", "4.45.*"] + python-version: ["3.9"] os: [ubuntu-latest] runs-on: ${{ matrix.os }} + steps: - - uses: actions/checkout@v4 + - name: Checkout code + uses: actions/checkout@v4 + - name: Setup Python ${{ matrix.python-version }} uses: actions/setup-python@v5 with: @@ -34,26 +42,29 @@ jobs: - name: Install dependencies run: | - python -m pip install --upgrade pip - # install PyTorch CPU version to avoid installing CUDA packages on GitHub runner without GPU + pip install --upgrade pip pip install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cpu - pip install .[openvino,openvino-tokenizers,tests,diffusers] onnxruntime pip install transformers==${{ matrix.transformers-version }} + pip install .[openvino,openvino-tokenizers,diffusers,tests] + + - name: Assert versions + run: | + python -c "import transformers; assert transformers.__version__.startswith('${{ matrix.transformers-version }}'.replace('.*', ''))" - if: ${{ matrix.transformers-version == '4.36.0' }} run: pip install accelerate==0.* - name: Test with Pytest + run: | + pytest tests/openvino/ -s -vvvv --durations=0 env: HF_HUB_READ_TOKEN: ${{ secrets.HF_HUB_READ_TOKEN }} + + - name: Install nightly OpenVINO run: | - pytest tests/openvino/ --ignore tests/openvino/test_modeling_basic.py --durations=0 - - name: Test basic - run: | - pip uninstall -y nncf - pytest tests/openvino/test_modeling_basic.py - - name: Test openvino-nightly + pip install --upgrade --pre openvino openvino-tokenizers --extra-index-url https://storage.openvinotoolkit.org/simple/wheels/nightly + + - name: Test with Pytest + if: ${{ matrix.test_pattern == 'test_modeling*' }} run: | - pip install -U --pre openvino openvino-tokenizers --extra-index-url https://storage.openvinotoolkit.org/simple/wheels/nightly - python -c "from optimum.intel import OVModelForCausalLM; OVModelForCausalLM.from_pretrained('hf-internal-testing/tiny-random-gpt2', export=True, compile=False)" - optimum-cli export openvino -m hf-internal-testing/tiny-random-gpt2 gpt2-ov + pytest tests/openvino/modeling_basic.py -s -vvvv --durations=0 diff --git a/.github/workflows/test_openvino_examples.yml b/.github/workflows/test_openvino_examples.yml index c76374e9e..0826f1613 100644 --- a/.github/workflows/test_openvino_examples.yml +++ b/.github/workflows/test_openvino_examples.yml @@ -3,15 +3,15 @@ name: OpenVINO - Examples Test on: workflow_dispatch: schedule: - - cron: 0 1 * * 1 # run weekly: every Monday at 1am + - cron: 0 1 * * 1 # run weekly: every Monday at 1am push: paths: - - '.github/workflows/test_openvino_examples.yml' - - 'examples/openvino/**' + - ".github/workflows/test_openvino_examples.yml" + - "examples/openvino/**" pull_request: paths: - - '.github/workflows/test_openvino_examples.yml' - - 'examples/openvino/**' + - ".github/workflows/test_openvino_examples.yml" + - "examples/openvino/**" concurrency: group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }} @@ -22,25 +22,27 @@ jobs: strategy: fail-fast: false matrix: - python-version: ["3.8", "3.12"] + python-version: ["3.9"] runs-on: ubuntu-22.04 steps: - - uses: actions/checkout@v2 - - name: Setup Python ${{ matrix.python-version }} - uses: actions/setup-python@v2 - with: - python-version: ${{ matrix.python-version }} - - - name: Install dependencies - run: | - pip install .[openvino] jstyleson pytest - pip install -r examples/openvino/audio-classification/requirements.txt --extra-index-url https://download.pytorch.org/whl/cpu - pip install -r examples/openvino/image-classification/requirements.txt --extra-index-url https://download.pytorch.org/whl/cpu - pip install -r examples/openvino/question-answering/requirements.txt --extra-index-url https://download.pytorch.org/whl/cpu - pip install -r examples/openvino/text-classification/requirements.txt --extra-index-url https://download.pytorch.org/whl/cpu - - - name: Test examples - run: | - python -m pytest examples/openvino/test_examples.py + - name: Checkout code + uses: actions/checkout@v4 + + - name: Setup Python ${{ matrix.python-version }} + uses: actions/setup-python@v5 + with: + python-version: ${{ matrix.python-version }} + + - name: Install dependencies + run: | + pip install .[openvino] jstyleson pytest + pip install -r examples/openvino/audio-classification/requirements.txt --extra-index-url https://download.pytorch.org/whl/cpu + pip install -r examples/openvino/image-classification/requirements.txt --extra-index-url https://download.pytorch.org/whl/cpu + pip install -r examples/openvino/question-answering/requirements.txt --extra-index-url https://download.pytorch.org/whl/cpu + pip install -r examples/openvino/text-classification/requirements.txt --extra-index-url https://download.pytorch.org/whl/cpu + + - name: Test examples + run: | + pytest examples/openvino/test_examples.py diff --git a/.github/workflows/test_openvino_notebooks.yml b/.github/workflows/test_openvino_notebooks.yml index 26a09012f..2d0f79ffd 100644 --- a/.github/workflows/test_openvino_notebooks.yml +++ b/.github/workflows/test_openvino_notebooks.yml @@ -3,16 +3,15 @@ name: OpenVINO - Notebooks Test on: workflow_dispatch: schedule: - - cron: '14 3 * * 1' # run weekly: every Monday at 3:14 + - cron: "14 3 * * 1" # run weekly: every Monday at 3:14 push: paths: - - '.github/workflows/test_openvino_notebooks.yml' - - 'notebooks/openvino/*' + - ".github/workflows/test_openvino_notebooks.yml" + - "notebooks/openvino/*" pull_request: paths: - - '.github/workflows/test_openvino_notebooks.yml' - - 'notebooks/openvino/*' - + - ".github/workflows/test_openvino_notebooks.yml" + - "notebooks/openvino/*" concurrency: group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }} @@ -23,33 +22,34 @@ jobs: strategy: fail-fast: false matrix: - python-version: ["3.8", "3.12"] + python-version: ["3.9"] runs-on: ubuntu-22.04 steps: - - uses: actions/checkout@v2 - - name: Setup Python ${{ matrix.python-version }} - uses: actions/setup-python@v2 - with: - python-version: ${{ matrix.python-version }} - - - name: Install dependencies - run: | - # Install PyTorch CPU to prevent unnecessary downloading/installing of CUDA packages - # ffmpeg, torchaudio and pillow are required for image classification and audio classification pipelines - sudo apt-get install ffmpeg - pip install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cpu - pip install -r notebooks/openvino/requirements.txt - pip install .[tests,openvino] nbval - - - run: free -h - - run: lscpu - - run: pip freeze - - - name: Test with Pytest - run: | - sed -i 's/NUM_TRAIN_ITEMS = 600/NUM_TRAIN_ITEMS = 10/' notebooks/openvino/question_answering_quantization.ipynb - sed -i 's/# %pip install/%pip install/' notebooks/openvino/optimum_openvino_inference.ipynb - python -m pytest --nbval-lax notebooks/openvino/optimum_openvino_inference.ipynb notebooks/openvino/question_answering_quantization.ipynb - + - name: Checkout code + uses: actions/checkout@v4 + + - name: Setup Python ${{ matrix.python-version }} + uses: actions/setup-python@v5 + with: + python-version: ${{ matrix.python-version }} + + - name: Install dependencies + run: | + # Install PyTorch CPU to prevent unnecessary downloading/installing of CUDA packages + # ffmpeg, torchaudio and pillow are required for image classification and audio classification pipelines + sudo apt-get install ffmpeg + pip install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cpu + pip install -r notebooks/openvino/requirements.txt + pip install .[tests,openvino] nbval + + - run: free -h + - run: lscpu + - run: pip freeze + + - name: Test with Pytest + run: | + sed -i 's/NUM_TRAIN_ITEMS = 600/NUM_TRAIN_ITEMS = 10/' notebooks/openvino/question_answering_quantization.ipynb + sed -i 's/# %pip install/%pip install/' notebooks/openvino/optimum_openvino_inference.ipynb + python -m pytest --nbval-lax notebooks/openvino/optimum_openvino_inference.ipynb notebooks/openvino/question_answering_quantization.ipynb diff --git a/.github/workflows/test_openvino_basic.yml b/.github/workflows/test_openvino_slow.yml similarity index 99% rename from .github/workflows/test_openvino_basic.yml rename to .github/workflows/test_openvino_slow.yml index eefce73ab..8a17db927 100644 --- a/.github/workflows/test_openvino_basic.yml +++ b/.github/workflows/test_openvino_slow.yml @@ -1,4 +1,4 @@ -name: OpenVINO - Basic Test +name: OpenVINO - Slow Test on: workflow_dispatch: diff --git a/setup.py b/setup.py index 7eb40d6c3..95c99af23 100644 --- a/setup.py +++ b/setup.py @@ -71,6 +71,7 @@ "diffusers": ["diffusers"], "quality": QUALITY_REQUIRE, "tests": TESTS_REQUIRE, + "peft": ["peft"], } setup( diff --git a/tests/openvino/test_diffusion.py b/tests/openvino/test_modeling_diffusion.py similarity index 100% rename from tests/openvino/test_diffusion.py rename to tests/openvino/test_modeling_diffusion.py From 43052327af849661ef85f866a94c3084f0bba9e4 Mon Sep 17 00:00:00 2001 From: IlyasMoutawwakil Date: Sun, 27 Oct 2024 14:31:51 +0100 Subject: [PATCH 02/21] fix --- .github/workflows/test_generation.yml | 2 +- .github/workflows/test_ipex.yml | 2 +- setup.py | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/test_generation.yml b/.github/workflows/test_generation.yml index 3bc04e3c6..345a134ae 100644 --- a/.github/workflows/test_generation.yml +++ b/.github/workflows/test_generation.yml @@ -1,4 +1,4 @@ -name: Generation Utils - Test +name: Generation Utils - Test (deprecated) on: push: diff --git a/.github/workflows/test_ipex.yml b/.github/workflows/test_ipex.yml index b8ea66387..48efe9daf 100644 --- a/.github/workflows/test_ipex.yml +++ b/.github/workflows/test_ipex.yml @@ -40,7 +40,7 @@ jobs: pip install torch==${{ matrix.torch-version }} torchaudio torchvision --extra-index-url https://download.pytorch.org/whl/cpu pip install intel_extension_for_pytorch==${{ matrix.torch-version }} pip install transformers==${{ matrix.transformers-version }} - pip install .[ipex] + pip install .[ipex,tests] - name: Assert versions run: | diff --git a/setup.py b/setup.py index 95c99af23..415cd8886 100644 --- a/setup.py +++ b/setup.py @@ -28,7 +28,7 @@ INSTALL_REQUIRE = [ "torch>=1.11", - "transformers>=4.36,<4.46", + "transformers>=4.36.0,<4.46.0", "optimum~=1.23", "datasets>=1.4.0", "sentencepiece", From 60580a1c44ea2d17e7e4ab66838ad48ab484d1ac Mon Sep 17 00:00:00 2001 From: IlyasMoutawwakil Date: Sun, 27 Oct 2024 14:41:48 +0100 Subject: [PATCH 03/21] test --- .github/workflows/quality.yml | 2 +- .github/workflows/security.yml | 2 +- .github/workflows/test_generation.yml | 2 +- .github/workflows/test_inc.yml | 9 +++++++-- .github/workflows/test_ipex.yml | 6 +++--- .github/workflows/test_openvino.yml | 2 +- 6 files changed, 14 insertions(+), 9 deletions(-) diff --git a/.github/workflows/quality.yml b/.github/workflows/quality.yml index 2b9cf49a6..63d525069 100644 --- a/.github/workflows/quality.yml +++ b/.github/workflows/quality.yml @@ -1,4 +1,4 @@ -name: Code Quality Checks +name: Quality Checks on: push: branches: diff --git a/.github/workflows/security.yml b/.github/workflows/security.yml index 3fe1c7f6e..3c2dc94da 100644 --- a/.github/workflows/security.yml +++ b/.github/workflows/security.yml @@ -1,4 +1,4 @@ -name: Security Check +name: Security Checks on: push: diff --git a/.github/workflows/test_generation.yml b/.github/workflows/test_generation.yml index 345a134ae..e95686266 100644 --- a/.github/workflows/test_generation.yml +++ b/.github/workflows/test_generation.yml @@ -18,7 +18,7 @@ jobs: strategy: fail-fast: false matrix: - python-version: [3.9] + python-version: ["3.9"] os: [ubuntu-latest] runs-on: ${{ matrix.os }} diff --git a/.github/workflows/test_inc.yml b/.github/workflows/test_inc.yml index 6ccfb65c5..6f1c3b152 100644 --- a/.github/workflows/test_inc.yml +++ b/.github/workflows/test_inc.yml @@ -18,8 +18,8 @@ jobs: strategy: fail-fast: false matrix: - torch-version: ["2.3.*", "2.4.*"] - python-version: [3.9] + torch-version: ["2.2.0", "2.4.*"] + python-version: ["3.9"] os: [ubuntu-latest] runs-on: ${{ matrix.os }} @@ -40,6 +40,11 @@ jobs: pip install intel-extension-for-pytorch==${{ matrix.torch-version }} pip install .[neural-compressor,ipex,diffusers,peft,tests] + - name: Assert versions + run: | + python -c "import torch; print(torch.__version__); assert torch.__version__.startswith('${{ matrix.torch-version }}'.replace('.*', ''))" + python -c "import intel_extension_for_pytorch; print(intel_extension_for_pytorch.__version__); assert intel_extension_for_pytorch.__version__.startswith('${{ matrix.torch-version }}'.replace('.*', ''))" + - name: Test with Pytest run: | pytest tests/neural_compressor/ -s -vvvv --durations=0 diff --git a/.github/workflows/test_ipex.yml b/.github/workflows/test_ipex.yml index 48efe9daf..ca239267d 100644 --- a/.github/workflows/test_ipex.yml +++ b/.github/workflows/test_ipex.yml @@ -44,9 +44,9 @@ jobs: - name: Assert versions run: | - python -c "import torch; assert torch.__version__.startswith('${{ matrix.torch-version }}'.replace('.*', ''))" - python -c "import transformers; assert transformers.__version__.startswith('${{ matrix.transformers-version }}'.replace('.*', ''))" - python -c "import intel_extension_for_pytorch; assert intel_extension_for_pytorch.__version__.startswith('${{ matrix.torch-version }}'.replace('.*', ''))" + python -c "import torch; print(torch.__version__); assert torch.__version__.startswith('${{ matrix.torch-version }}'.replace('.*', ''))" + python -c "import intel_extension_for_pytorch; print(intel_extension_for_pytorch.__version__); assert intel_extension_for_pytorch.__version__.startswith('${{ matrix.torch-version }}'.replace('.*', ''))" + python -c "import transformers; print(transformers.__version__); assert transformers.__version__.startswith('${{ matrix.transformers-version }}'.replace('.*', ''))" - if: ${{ matrix.torch-version == '2.2.*' }} name: Downgrade numpy for torch 2.2.* diff --git a/.github/workflows/test_openvino.yml b/.github/workflows/test_openvino.yml index 9f1caed39..229db91b0 100644 --- a/.github/workflows/test_openvino.yml +++ b/.github/workflows/test_openvino.yml @@ -49,7 +49,7 @@ jobs: - name: Assert versions run: | - python -c "import transformers; assert transformers.__version__.startswith('${{ matrix.transformers-version }}'.replace('.*', ''))" + python -c "import transformers; print(transformers.__version__); assert transformers.__version__.startswith('${{ matrix.transformers-version }}'.replace('.*', ''))" - if: ${{ matrix.transformers-version == '4.36.0' }} run: pip install accelerate==0.* From 55d00b09223fee48948fb328fd017caff8347c1a Mon Sep 17 00:00:00 2001 From: IlyasMoutawwakil Date: Sun, 27 Oct 2024 14:48:07 +0100 Subject: [PATCH 04/21] fix transformers version installation --- .github/workflows/test_inc.yml | 4 ++++ .github/workflows/test_ipex.yml | 13 ++++++------- .github/workflows/test_openvino.yml | 3 +-- .github/workflows/test_openvino_slow.yml | 3 +-- 4 files changed, 12 insertions(+), 11 deletions(-) diff --git a/.github/workflows/test_inc.yml b/.github/workflows/test_inc.yml index 6f1c3b152..94f327514 100644 --- a/.github/workflows/test_inc.yml +++ b/.github/workflows/test_inc.yml @@ -40,6 +40,10 @@ jobs: pip install intel-extension-for-pytorch==${{ matrix.torch-version }} pip install .[neural-compressor,ipex,diffusers,peft,tests] + - if: ${{ matrix.torch-version == '2.2.0' }} + name: Downgrade Numpy + run: pip install numpy==1.* + - name: Assert versions run: | python -c "import torch; print(torch.__version__); assert torch.__version__.startswith('${{ matrix.torch-version }}'.replace('.*', ''))" diff --git a/.github/workflows/test_ipex.yml b/.github/workflows/test_ipex.yml index ca239267d..2ea8b9321 100644 --- a/.github/workflows/test_ipex.yml +++ b/.github/workflows/test_ipex.yml @@ -18,7 +18,7 @@ jobs: strategy: fail-fast: false matrix: - torch-version: ["2.2.*", "2.3.*", "2.4.*"] + torch-version: ["2.2.0", "2.3.*", "2.4.*"] transformers-version: ["4.39.0", "4.44.*"] python-version: [3.9] os: [ubuntu-latest] @@ -39,8 +39,11 @@ jobs: pip install --upgrade pip pip install torch==${{ matrix.torch-version }} torchaudio torchvision --extra-index-url https://download.pytorch.org/whl/cpu pip install intel_extension_for_pytorch==${{ matrix.torch-version }} - pip install transformers==${{ matrix.transformers-version }} - pip install .[ipex,tests] + pip install .[ipex,tests] transformers==${{ matrix.transformers-version }} + + - if: ${{ matrix.torch-version == '2.2.0' }} + name: Downgrade Numpy + run: pip install numpy==1.* - name: Assert versions run: | @@ -48,10 +51,6 @@ jobs: python -c "import intel_extension_for_pytorch; print(intel_extension_for_pytorch.__version__); assert intel_extension_for_pytorch.__version__.startswith('${{ matrix.torch-version }}'.replace('.*', ''))" python -c "import transformers; print(transformers.__version__); assert transformers.__version__.startswith('${{ matrix.transformers-version }}'.replace('.*', ''))" - - if: ${{ matrix.torch-version == '2.2.*' }} - name: Downgrade numpy for torch 2.2.* - run: pip install numpy==1.* - - name: Test with Pytest run: | pytest tests/ipex/ -s -vvvv --durations=0 diff --git a/.github/workflows/test_openvino.yml b/.github/workflows/test_openvino.yml index 229db91b0..4453706f6 100644 --- a/.github/workflows/test_openvino.yml +++ b/.github/workflows/test_openvino.yml @@ -44,8 +44,7 @@ jobs: run: | pip install --upgrade pip pip install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cpu - pip install transformers==${{ matrix.transformers-version }} - pip install .[openvino,openvino-tokenizers,diffusers,tests] + pip install .[openvino,openvino-tokenizers,diffusers,peft,tests] transformers==${{ matrix.transformers-version }} - name: Assert versions run: | diff --git a/.github/workflows/test_openvino_slow.yml b/.github/workflows/test_openvino_slow.yml index 8a17db927..e72817e75 100644 --- a/.github/workflows/test_openvino_slow.yml +++ b/.github/workflows/test_openvino_slow.yml @@ -61,8 +61,7 @@ jobs: # Install openvino manually to prevent dependency conflicts when .[openvino] pins # optimum or transformers to a specific version pip install ${{ matrix.openvino }} - pip install transformers==${{ matrix.transformers-version }} - pip install .[tests] + pip install .[tests] transformers==${{ matrix.transformers-version }} - name: Pip freeze run: pip freeze From 997b969249c833f356246f5d9411f85c33bb92f7 Mon Sep 17 00:00:00 2001 From: IlyasMoutawwakil Date: Sun, 27 Oct 2024 15:07:46 +0100 Subject: [PATCH 05/21] fix --- .github/workflows/test_generation.yml | 3 +-- .github/workflows/test_inc.yml | 5 ++--- .github/workflows/test_ipex.yml | 3 +-- .github/workflows/test_openvino.yml | 7 ++++--- .github/workflows/test_openvino_slow.yml | 2 +- setup.py | 4 ++-- 6 files changed, 11 insertions(+), 13 deletions(-) diff --git a/.github/workflows/test_generation.yml b/.github/workflows/test_generation.yml index e95686266..bb38d9350 100644 --- a/.github/workflows/test_generation.yml +++ b/.github/workflows/test_generation.yml @@ -35,8 +35,7 @@ jobs: - name: Install dependencies run: | pip install --upgrade pip - pip install transformers==4.43.* - pip install .[tests] + pip install .[tests] transformers[testing]==4.43.* - name: Test with Pytest run: | diff --git a/.github/workflows/test_inc.yml b/.github/workflows/test_inc.yml index 94f327514..7e4600126 100644 --- a/.github/workflows/test_inc.yml +++ b/.github/workflows/test_inc.yml @@ -18,7 +18,7 @@ jobs: strategy: fail-fast: false matrix: - torch-version: ["2.2.0", "2.4.*"] + torch-version: ["2.2.0", "2.3.*", "2.4.*"] python-version: ["3.9"] os: [ubuntu-latest] @@ -37,8 +37,7 @@ jobs: run: | pip install --upgrade pip pip install torch==${{ matrix.torch-version }} torchaudio torchvision --index-url https://download.pytorch.org/whl/cpu - pip install intel-extension-for-pytorch==${{ matrix.torch-version }} - pip install .[neural-compressor,ipex,diffusers,peft,tests] + pip install .[neural-compressor,ipex,diffusers,peft,tests] transformers[testing] intel-extension-for-pytorch==${{ matrix.torch-version }} - if: ${{ matrix.torch-version == '2.2.0' }} name: Downgrade Numpy diff --git a/.github/workflows/test_ipex.yml b/.github/workflows/test_ipex.yml index 2ea8b9321..f501fc4de 100644 --- a/.github/workflows/test_ipex.yml +++ b/.github/workflows/test_ipex.yml @@ -38,8 +38,7 @@ jobs: run: | pip install --upgrade pip pip install torch==${{ matrix.torch-version }} torchaudio torchvision --extra-index-url https://download.pytorch.org/whl/cpu - pip install intel_extension_for_pytorch==${{ matrix.torch-version }} - pip install .[ipex,tests] transformers==${{ matrix.transformers-version }} + pip install .[ipex,tests] transformers[testing]==${{ matrix.transformers-version }} intel_extension_for_pytorch==${{ matrix.torch-version }} - if: ${{ matrix.torch-version == '2.2.0' }} name: Downgrade Numpy diff --git a/.github/workflows/test_openvino.yml b/.github/workflows/test_openvino.yml index 4453706f6..bb66945b1 100644 --- a/.github/workflows/test_openvino.yml +++ b/.github/workflows/test_openvino.yml @@ -44,18 +44,19 @@ jobs: run: | pip install --upgrade pip pip install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cpu - pip install .[openvino,openvino-tokenizers,diffusers,peft,tests] transformers==${{ matrix.transformers-version }} + pip install .[openvino,openvino-tokenizers,diffusers,peft,tests] transformers[testing]==${{ matrix.transformers-version }} - name: Assert versions run: | python -c "import transformers; print(transformers.__version__); assert transformers.__version__.startswith('${{ matrix.transformers-version }}'.replace('.*', ''))" - - if: ${{ matrix.transformers-version == '4.36.0' }} + - name: Downgrade Accelerate + if: ${{ matrix.transformers-version == '4.36.0' }} run: pip install accelerate==0.* - name: Test with Pytest run: | - pytest tests/openvino/ -s -vvvv --durations=0 + pytest tests/openvino/${{ matrix.test_pattern }}.py -s -vvvv --durations=0 env: HF_HUB_READ_TOKEN: ${{ secrets.HF_HUB_READ_TOKEN }} diff --git a/.github/workflows/test_openvino_slow.yml b/.github/workflows/test_openvino_slow.yml index e72817e75..49ffe8d67 100644 --- a/.github/workflows/test_openvino_slow.yml +++ b/.github/workflows/test_openvino_slow.yml @@ -61,7 +61,7 @@ jobs: # Install openvino manually to prevent dependency conflicts when .[openvino] pins # optimum or transformers to a specific version pip install ${{ matrix.openvino }} - pip install .[tests] transformers==${{ matrix.transformers-version }} + pip install .[tests] transformers[testing]==${{ matrix.transformers-version }} - name: Pip freeze run: pip freeze diff --git a/setup.py b/setup.py index 415cd8886..14f2db89c 100644 --- a/setup.py +++ b/setup.py @@ -62,9 +62,9 @@ EXTRAS_REQUIRE = { "neural-compressor": ["neural-compressor[pt]>3.0", "accelerate"], "openvino": [ - "openvino==2024.4.1.dev20240926", "nncf>=2.11.0", - "openvino-tokenizers[transformers]==2024.4.1.0.dev20240926", + "openvino==2024.4.1.dev20240926", + "openvino-tokenizers==2024.4.1.0.dev20240926", ], "nncf": ["nncf>=2.11.0"], "ipex": ["intel-extension-for-pytorch", "transformers>=4.39,<4.45"], From bbd2000d5f97f64234609f8c589b9a9edaed6a59 Mon Sep 17 00:00:00 2001 From: IlyasMoutawwakil Date: Sun, 27 Oct 2024 15:11:39 +0100 Subject: [PATCH 06/21] less verbose --- .github/workflows/test_inc.yml | 2 +- .github/workflows/test_ipex.yml | 2 +- .github/workflows/test_openvino.yml | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/test_inc.yml b/.github/workflows/test_inc.yml index 7e4600126..26a3b59ef 100644 --- a/.github/workflows/test_inc.yml +++ b/.github/workflows/test_inc.yml @@ -50,4 +50,4 @@ jobs: - name: Test with Pytest run: | - pytest tests/neural_compressor/ -s -vvvv --durations=0 + pytest tests/neural_compressor diff --git a/.github/workflows/test_ipex.yml b/.github/workflows/test_ipex.yml index f501fc4de..6d198acf7 100644 --- a/.github/workflows/test_ipex.yml +++ b/.github/workflows/test_ipex.yml @@ -52,4 +52,4 @@ jobs: - name: Test with Pytest run: | - pytest tests/ipex/ -s -vvvv --durations=0 + pytest tests/ipex diff --git a/.github/workflows/test_openvino.yml b/.github/workflows/test_openvino.yml index bb66945b1..aa4d04da5 100644 --- a/.github/workflows/test_openvino.yml +++ b/.github/workflows/test_openvino.yml @@ -56,7 +56,7 @@ jobs: - name: Test with Pytest run: | - pytest tests/openvino/${{ matrix.test_pattern }}.py -s -vvvv --durations=0 + pytest tests/openvino/${{ matrix.test_pattern }}.py env: HF_HUB_READ_TOKEN: ${{ secrets.HF_HUB_READ_TOKEN }} @@ -67,4 +67,4 @@ jobs: - name: Test with Pytest if: ${{ matrix.test_pattern == 'test_modeling*' }} run: | - pytest tests/openvino/modeling_basic.py -s -vvvv --durations=0 + pytest tests/openvino/modeling_basic.py From 81c778af82356c088c8128275a4465c8b72b96e8 Mon Sep 17 00:00:00 2001 From: IlyasMoutawwakil Date: Sun, 27 Oct 2024 16:06:10 +0100 Subject: [PATCH 07/21] faster --- .github/workflows/quality.yml | 2 +- .github/workflows/test_openvino.yml | 15 ++++++---- .github/workflows/test_openvino_examples.yml | 2 +- .github/workflows/test_openvino_notebooks.yml | 7 +---- .github/workflows/test_openvino_slow.yml | 28 ++++++++++++------- 5 files changed, 30 insertions(+), 24 deletions(-) diff --git a/.github/workflows/quality.yml b/.github/workflows/quality.yml index 63d525069..db99106d1 100644 --- a/.github/workflows/quality.yml +++ b/.github/workflows/quality.yml @@ -13,7 +13,7 @@ concurrency: cancel-in-progress: true jobs: - build: + quality: strategy: fail-fast: false matrix: diff --git a/.github/workflows/test_openvino.yml b/.github/workflows/test_openvino.yml index aa4d04da5..b8e1dd46f 100644 --- a/.github/workflows/test_openvino.yml +++ b/.github/workflows/test_openvino.yml @@ -20,10 +20,13 @@ jobs: matrix: test_pattern: [ - "test_export*", - "test_modeling*", + "test_modeling.py", + "test_modeling_basic.py", + "test_modeling_diffusion.py", + "test_modeling_sentence_transformers.py", "test_quantization*", "test_training*", + "test_export*", ] transformers-version: ["4.36.0", "4.45.*"] python-version: ["3.9"] @@ -56,15 +59,15 @@ jobs: - name: Test with Pytest run: | - pytest tests/openvino/${{ matrix.test_pattern }}.py + pytest tests/openvino/${{ matrix.test_pattern }} --duration=0 env: HF_HUB_READ_TOKEN: ${{ secrets.HF_HUB_READ_TOKEN }} - - name: Install nightly OpenVINO + - name: Install dependencies (nightly) run: | pip install --upgrade --pre openvino openvino-tokenizers --extra-index-url https://storage.openvinotoolkit.org/simple/wheels/nightly - - name: Test with Pytest - if: ${{ matrix.test_pattern == 'test_modeling*' }} + - name: Test with Pytest (nightly) + if: ${{ matrix.test_pattern == 'test_modeling_basic.py' }} run: | pytest tests/openvino/modeling_basic.py diff --git a/.github/workflows/test_openvino_examples.yml b/.github/workflows/test_openvino_examples.yml index 0826f1613..a00f3f017 100644 --- a/.github/workflows/test_openvino_examples.yml +++ b/.github/workflows/test_openvino_examples.yml @@ -37,11 +37,11 @@ jobs: - name: Install dependencies run: | - pip install .[openvino] jstyleson pytest pip install -r examples/openvino/audio-classification/requirements.txt --extra-index-url https://download.pytorch.org/whl/cpu pip install -r examples/openvino/image-classification/requirements.txt --extra-index-url https://download.pytorch.org/whl/cpu pip install -r examples/openvino/question-answering/requirements.txt --extra-index-url https://download.pytorch.org/whl/cpu pip install -r examples/openvino/text-classification/requirements.txt --extra-index-url https://download.pytorch.org/whl/cpu + pip install .[openvino] jstyleson pytest - name: Test examples run: | diff --git a/.github/workflows/test_openvino_notebooks.yml b/.github/workflows/test_openvino_notebooks.yml index 2d0f79ffd..d024ad46a 100644 --- a/.github/workflows/test_openvino_notebooks.yml +++ b/.github/workflows/test_openvino_notebooks.yml @@ -37,17 +37,12 @@ jobs: - name: Install dependencies run: | - # Install PyTorch CPU to prevent unnecessary downloading/installing of CUDA packages - # ffmpeg, torchaudio and pillow are required for image classification and audio classification pipelines + # ffmpeg is required for image classification and audio classification pipelines sudo apt-get install ffmpeg pip install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cpu pip install -r notebooks/openvino/requirements.txt pip install .[tests,openvino] nbval - - run: free -h - - run: lscpu - - run: pip freeze - - name: Test with Pytest run: | sed -i 's/NUM_TRAIN_ITEMS = 600/NUM_TRAIN_ITEMS = 10/' notebooks/openvino/question_answering_quantization.ipynb diff --git a/.github/workflows/test_openvino_slow.yml b/.github/workflows/test_openvino_slow.yml index 49ffe8d67..bb193b353 100644 --- a/.github/workflows/test_openvino_slow.yml +++ b/.github/workflows/test_openvino_slow.yml @@ -8,7 +8,11 @@ on: branches: - v*-release pull_request: - types: [opened, synchronize, reopened, labeled] + types: + - opened + - labeled + - reopened + - synchronize concurrency: group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }} @@ -20,6 +24,7 @@ jobs: strategy: fail-fast: false matrix: + # TODO: testong python upper bound seems unnecessary # Testing lower and upper bound of supported Python versions # This also ensures that the test fails if dependencies break for Python 3.7 python-version: ["3.9", "3.12"] @@ -47,7 +52,9 @@ jobs: runs-on: ${{ matrix.os }} steps: - - uses: actions/checkout@v4 + - name: Checkout code + uses: actions/checkout@v4 + - name: Setup Python ${{ matrix.python-version }} uses: actions/setup-python@v5 with: @@ -55,25 +62,26 @@ jobs: - name: Install dependencies run: | - python -m pip install --upgrade pip - # Install PyTorch CPU to prevent unnecessary downloading/installing of CUDA packages + pip install --upgrade pip pip install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cpu - # Install openvino manually to prevent dependency conflicts when .[openvino] pins - # optimum or transformers to a specific version pip install ${{ matrix.openvino }} pip install .[tests] transformers[testing]==${{ matrix.transformers-version }} - - name: Pip freeze - run: pip freeze + - name: Assert versions + run: | + python -c "import transformers; print(transformers.__version__); assert transformers.__version__.startswith('${{ matrix.transformers-version }}'.replace('.*', ''))" - name: Test with Pytest run: | pytest tests/openvino/test_modeling_basic.py - - name: Slow tests + - name: Install dependencies (slow) run: | pip install ${{ matrix.nncf }} - pytest tests/openvino -s -m "run_slow" --durations=0 + + - name: Test with Pytest (slow) + run: | + pytest tests/openvino -m "run_slow" --durations=0 env: RUN_SLOW: 1 HF_HUB_READ_TOKEN: ${{ secrets.HF_HUB_READ_TOKEN }} From 08fd1249a916dde30bfd093066cd9007ca32a65d Mon Sep 17 00:00:00 2001 From: IlyasMoutawwakil Date: Sun, 27 Oct 2024 16:07:21 +0100 Subject: [PATCH 08/21] fix --- .github/workflows/test_openvino.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test_openvino.yml b/.github/workflows/test_openvino.yml index b8e1dd46f..fece6794d 100644 --- a/.github/workflows/test_openvino.yml +++ b/.github/workflows/test_openvino.yml @@ -70,4 +70,4 @@ jobs: - name: Test with Pytest (nightly) if: ${{ matrix.test_pattern == 'test_modeling_basic.py' }} run: | - pytest tests/openvino/modeling_basic.py + pytest tests/openvino/test_modeling_basic.py From 967f4ef4e578469fe99e1adaf423de5373e996ed Mon Sep 17 00:00:00 2001 From: IlyasMoutawwakil Date: Sun, 27 Oct 2024 16:20:05 +0100 Subject: [PATCH 09/21] fix --- .github/workflows/test_openvino.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test_openvino.yml b/.github/workflows/test_openvino.yml index fece6794d..ebdeef4e5 100644 --- a/.github/workflows/test_openvino.yml +++ b/.github/workflows/test_openvino.yml @@ -59,7 +59,7 @@ jobs: - name: Test with Pytest run: | - pytest tests/openvino/${{ matrix.test_pattern }} --duration=0 + pytest tests/openvino/${{ matrix.test_pattern }} --durations=0 env: HF_HUB_READ_TOKEN: ${{ secrets.HF_HUB_READ_TOKEN }} From 96dedd82de179ef79841a7eb71b03e3cfafe45bf Mon Sep 17 00:00:00 2001 From: IlyasMoutawwakil Date: Mon, 28 Oct 2024 11:45:28 +0100 Subject: [PATCH 10/21] reduce --- .github/workflows/test_openvino.yml | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/.github/workflows/test_openvino.yml b/.github/workflows/test_openvino.yml index ebdeef4e5..6305cc3b9 100644 --- a/.github/workflows/test_openvino.yml +++ b/.github/workflows/test_openvino.yml @@ -20,13 +20,12 @@ jobs: matrix: test_pattern: [ - "test_modeling.py", - "test_modeling_basic.py", - "test_modeling_diffusion.py", - "test_modeling_sentence_transformers.py", - "test_quantization*", - "test_training*", - "test_export*", + "*modeling.py", + "*modeling_diffusion.py", + "*modeling_sentence_transformers.py", + "*quantization*", + "*training*", + "*export*", ] transformers-version: ["4.36.0", "4.45.*"] python-version: ["3.9"] @@ -53,11 +52,16 @@ jobs: run: | python -c "import transformers; print(transformers.__version__); assert transformers.__version__.startswith('${{ matrix.transformers-version }}'.replace('.*', ''))" - - name: Downgrade Accelerate - if: ${{ matrix.transformers-version == '4.36.0' }} + - if: ${{ matrix.transformers-version == '4.36.0' }} + name: Downgrade Accelerate run: pip install accelerate==0.* - - name: Test with Pytest + - name: Test with Pytest (basic) + run: | + # catch failures early and quickly + pytest tests/openvino/test_modeling_basic.py --durations=0 + + - name: Test with Pytest (advanced) run: | pytest tests/openvino/${{ matrix.test_pattern }} --durations=0 env: @@ -68,6 +72,5 @@ jobs: pip install --upgrade --pre openvino openvino-tokenizers --extra-index-url https://storage.openvinotoolkit.org/simple/wheels/nightly - name: Test with Pytest (nightly) - if: ${{ matrix.test_pattern == 'test_modeling_basic.py' }} run: | pytest tests/openvino/test_modeling_basic.py From dcb140d90a8891feca22605c8023cdf055475d5a Mon Sep 17 00:00:00 2001 From: IlyasMoutawwakil Date: Mon, 28 Oct 2024 12:08:51 +0100 Subject: [PATCH 11/21] peft in testing --- .github/workflows/test_ipex.yml | 2 +- .github/workflows/test_openvino.yml | 2 +- .github/workflows/test_openvino_slow.yml | 1 - setup.py | 2 +- 4 files changed, 3 insertions(+), 4 deletions(-) diff --git a/.github/workflows/test_ipex.yml b/.github/workflows/test_ipex.yml index 6d198acf7..1c947f76c 100644 --- a/.github/workflows/test_ipex.yml +++ b/.github/workflows/test_ipex.yml @@ -20,7 +20,7 @@ jobs: matrix: torch-version: ["2.2.0", "2.3.*", "2.4.*"] transformers-version: ["4.39.0", "4.44.*"] - python-version: [3.9] + python-version: ["3.9"] os: [ubuntu-latest] runs-on: ${{ matrix.os }} diff --git a/.github/workflows/test_openvino.yml b/.github/workflows/test_openvino.yml index 6305cc3b9..294c7f968 100644 --- a/.github/workflows/test_openvino.yml +++ b/.github/workflows/test_openvino.yml @@ -46,7 +46,7 @@ jobs: run: | pip install --upgrade pip pip install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cpu - pip install .[openvino,openvino-tokenizers,diffusers,peft,tests] transformers[testing]==${{ matrix.transformers-version }} + pip install .[openvino,openvino-tokenizers,diffusers,tests] transformers[testing]==${{ matrix.transformers-version }} - name: Assert versions run: | diff --git a/.github/workflows/test_openvino_slow.yml b/.github/workflows/test_openvino_slow.yml index bb193b353..0ff94fc97 100644 --- a/.github/workflows/test_openvino_slow.yml +++ b/.github/workflows/test_openvino_slow.yml @@ -24,7 +24,6 @@ jobs: strategy: fail-fast: false matrix: - # TODO: testong python upper bound seems unnecessary # Testing lower and upper bound of supported Python versions # This also ensures that the test fails if dependencies break for Python 3.7 python-version: ["3.9", "3.12"] diff --git a/setup.py b/setup.py index 14f2db89c..8f9e489a4 100644 --- a/setup.py +++ b/setup.py @@ -55,6 +55,7 @@ "tiktoken", "sentence-transformers", "open_clip_torch>=2.26.1", + "peft", ] QUALITY_REQUIRE = ["black~=23.1", "ruff==0.4.4"] @@ -71,7 +72,6 @@ "diffusers": ["diffusers"], "quality": QUALITY_REQUIRE, "tests": TESTS_REQUIRE, - "peft": ["peft"], } setup( From 943cb1bee3fda42f32af1751606a1b67a5202693 Mon Sep 17 00:00:00 2001 From: IlyasMoutawwakil Date: Mon, 28 Oct 2024 12:25:24 +0100 Subject: [PATCH 12/21] move ST tests to test_modeling.py since it's a single test --- .github/workflows/test_openvino.yml | 1 - tests/openvino/test_modeling.py | 34 +++++++++ .../test_modeling_sentence_transformers.py | 74 ------------------- tests/openvino/utils_tests.py | 2 + 4 files changed, 36 insertions(+), 75 deletions(-) delete mode 100644 tests/openvino/test_modeling_sentence_transformers.py diff --git a/.github/workflows/test_openvino.yml b/.github/workflows/test_openvino.yml index 294c7f968..4fa203c6d 100644 --- a/.github/workflows/test_openvino.yml +++ b/.github/workflows/test_openvino.yml @@ -22,7 +22,6 @@ jobs: [ "*modeling.py", "*modeling_diffusion.py", - "*modeling_sentence_transformers.py", "*quantization*", "*training*", "*export*", diff --git a/tests/openvino/test_modeling.py b/tests/openvino/test_modeling.py index 119e00403..e9b662134 100644 --- a/tests/openvino/test_modeling.py +++ b/tests/openvino/test_modeling.py @@ -32,6 +32,7 @@ from huggingface_hub import HfApi from parameterized import parameterized from PIL import Image +from sentence_transformers import SentenceTransformer from transformers import ( AutoConfig, AutoFeatureExtractor, @@ -2360,3 +2361,36 @@ def test_functions(self): del model gc.collect() + + +class OVModelForSTFeatureExtractionIntegrationTest(unittest.TestCase): + SUPPORTED_ARCHITECTURES = ("st-bert", "st-mpnet") + + @parameterized.expand(SUPPORTED_ARCHITECTURES) + def test_compare_to_transformers(self, model_arch): + model_id = MODEL_NAMES[model_arch] + set_seed(SEED) + ov_model = OVSentenceTransformer.from_pretrained(model_id, export=True, ov_config=F32_CONFIG) + self.assertIsInstance(ov_model.config, PretrainedConfig) + self.assertTrue(hasattr(ov_model, "encode")) + st_model = SentenceTransformer(model_id) + sentences = ["This is an example sentence", "Each sentence is converted"] + st_embeddings = st_model.encode(sentences) + ov_embeddings = ov_model.encode(sentences) + # Compare tensor outputs + self.assertTrue(np.allclose(ov_embeddings, st_embeddings, atol=1e-4)) + del st_embeddings + del ov_model + gc.collect() + + @parameterized.expand(SUPPORTED_ARCHITECTURES) + def test_sentence_transformers_save_and_infer(self, model_arch): + model_id = MODEL_NAMES[model_arch] + ov_model = OVSentenceTransformer.from_pretrained(model_id, export=True, ov_config=F32_CONFIG) + with TemporaryDirectory() as tmpdirname: + model_save_path = os.path.join(tmpdirname, "sentence_transformers_ov_model") + ov_model.save_pretrained(model_save_path) + model = OVSentenceTransformer.from_pretrained(model_save_path) + sentences = ["This is an example sentence", "Each sentence is converted"] + model.encode(sentences) + gc.collect() diff --git a/tests/openvino/test_modeling_sentence_transformers.py b/tests/openvino/test_modeling_sentence_transformers.py deleted file mode 100644 index 0ddd60ea0..000000000 --- a/tests/openvino/test_modeling_sentence_transformers.py +++ /dev/null @@ -1,74 +0,0 @@ -# Copyright 2021 The HuggingFace Team. All rights reserved. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -import gc -import os -import unittest - -import numpy as np -from parameterized import parameterized -from sentence_transformers import SentenceTransformer -from transformers import ( - PretrainedConfig, - set_seed, -) - -from optimum.intel import OVSentenceTransformer -from optimum.intel.openvino.utils import TemporaryDirectory - - -SEED = 42 - -F32_CONFIG = {"INFERENCE_PRECISION_HINT": "f32"} - -MODEL_NAMES = { - "bert": "sentence-transformers/all-MiniLM-L6-v2", - "mpnet": "sentence-transformers/all-mpnet-base-v2", -} - - -class OVModelForSTFeatureExtractionIntegrationTest(unittest.TestCase): - SUPPORTED_ARCHITECTURES = ( - "bert", - "mpnet", - ) - - @parameterized.expand(SUPPORTED_ARCHITECTURES) - def test_compare_to_transformers(self, model_arch): - model_id = MODEL_NAMES[model_arch] - set_seed(SEED) - ov_model = OVSentenceTransformer.from_pretrained(model_id, export=True, ov_config=F32_CONFIG) - self.assertIsInstance(ov_model.config, PretrainedConfig) - self.assertTrue(hasattr(ov_model, "encode")) - st_model = SentenceTransformer(model_id) - sentences = ["This is an example sentence", "Each sentence is converted"] - st_embeddings = st_model.encode(sentences) - ov_embeddings = ov_model.encode(sentences) - # Compare tensor outputs - self.assertTrue(np.allclose(ov_embeddings, st_embeddings, atol=1e-4)) - del st_embeddings - del ov_model - gc.collect() - - @parameterized.expand(SUPPORTED_ARCHITECTURES) - def test_sentence_transformers_save_and_infer(self, model_arch): - model_id = MODEL_NAMES[model_arch] - ov_model = OVSentenceTransformer.from_pretrained(model_id, export=True, ov_config=F32_CONFIG) - with TemporaryDirectory() as tmpdirname: - model_save_path = os.path.join(tmpdirname, "sentence_transformers_ov_model") - ov_model.save_pretrained(model_save_path) - model = OVSentenceTransformer.from_pretrained(model_save_path) - sentences = ["This is an example sentence", "Each sentence is converted"] - model.encode(sentences) - gc.collect() diff --git a/tests/openvino/utils_tests.py b/tests/openvino/utils_tests.py index e5a9f73a6..e72ec6e7f 100644 --- a/tests/openvino/utils_tests.py +++ b/tests/openvino/utils_tests.py @@ -148,6 +148,8 @@ "glm4": "katuni4ka/tiny-random-glm4", "open-clip": "hf-internal-testing/tiny-open-clip-model", "open-clip-ov": "zofinka/tiny-open-clip-model", + "st-bert": "sentence-transformers/all-MiniLM-L6-v2", + "st-mpnet": "sentence-transformers/all-mpnet-base-v2", } From 47b5ad3621b9f084c641ff3b4b46bcae310e1fd8 Mon Sep 17 00:00:00 2001 From: IlyasMoutawwakil Date: Sun, 3 Nov 2024 12:16:54 +0100 Subject: [PATCH 13/21] resolve convs --- .github/workflows/build_pr_documentation.yml | 6 ++++ .github/workflows/test_openvino.yml | 28 +++++++++---------- setup.py | 1 - ...odeling_diffusion.py => test_diffusion.py} | 0 4 files changed, 19 insertions(+), 16 deletions(-) rename tests/openvino/{test_modeling_diffusion.py => test_diffusion.py} (100%) diff --git a/.github/workflows/build_pr_documentation.yml b/.github/workflows/build_pr_documentation.yml index 188b90bb1..951669f0b 100644 --- a/.github/workflows/build_pr_documentation.yml +++ b/.github/workflows/build_pr_documentation.yml @@ -12,6 +12,7 @@ concurrency: jobs: build_documentation: runs-on: ubuntu-latest + env: COMMIT_SHA: ${{ github.event.pull_request.head.sha }} PR_NUMBER: ${{ github.event.number }} @@ -29,6 +30,11 @@ jobs: repository: "huggingface/optimum-intel" path: optimum-intel + - name: Setup Python + uses: actions/setup-python@v5 + with: + python-version: 3.9 + - name: Setup environment run: | pip uninstall -y doc-builder diff --git a/.github/workflows/test_openvino.yml b/.github/workflows/test_openvino.yml index 4fa203c6d..40b5406fd 100644 --- a/.github/workflows/test_openvino.yml +++ b/.github/workflows/test_openvino.yml @@ -18,10 +18,10 @@ jobs: strategy: fail-fast: false matrix: - test_pattern: + test-pattern: [ - "*modeling.py", - "*modeling_diffusion.py", + "*modeling*", + "*diffusion*", "*quantization*", "*training*", "*export*", @@ -47,29 +47,27 @@ jobs: pip install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cpu pip install .[openvino,openvino-tokenizers,diffusers,tests] transformers[testing]==${{ matrix.transformers-version }} - - name: Assert versions - run: | - python -c "import transformers; print(transformers.__version__); assert transformers.__version__.startswith('${{ matrix.transformers-version }}'.replace('.*', ''))" - - if: ${{ matrix.transformers-version == '4.36.0' }} name: Downgrade Accelerate run: pip install accelerate==0.* - - name: Test with Pytest (basic) + - name: Assert versions run: | - # catch failures early and quickly - pytest tests/openvino/test_modeling_basic.py --durations=0 + python -c "import transformers; print(transformers.__version__); assert transformers.__version__.startswith('${{ matrix.transformers-version }}'.replace('.*', ''))" - - name: Test with Pytest (advanced) + - name: Test with Pytest run: | - pytest tests/openvino/${{ matrix.test_pattern }} --durations=0 + pytest tests/openvino/${{ matrix.test-pattern }} --durations=0 env: HF_HUB_READ_TOKEN: ${{ secrets.HF_HUB_READ_TOKEN }} - - name: Install dependencies (nightly) + - if: ${{ matrix.test-pattern == '*modeling*' }} + name: Install dependencies (nightly) run: | pip install --upgrade --pre openvino openvino-tokenizers --extra-index-url https://storage.openvinotoolkit.org/simple/wheels/nightly + pip uninstall -y nncf - - name: Test with Pytest (nightly) + - if: ${{ matrix.test-pattern == '*modeling*' }} + name: Test with Pytest (nightly) run: | - pytest tests/openvino/test_modeling_basic.py + pytest tests/openvino/test_modeling_basic.py --durations=0 diff --git a/setup.py b/setup.py index 8f9e489a4..e96c22241 100644 --- a/setup.py +++ b/setup.py @@ -89,7 +89,6 @@ "Intended Audience :: Education", "Intended Audience :: Science/Research", "Operating System :: OS Independent", - "Programming Language :: Python :: 3.8", "Programming Language :: Python :: 3.9", "Programming Language :: Python :: 3.10", "Programming Language :: Python :: 3.11", diff --git a/tests/openvino/test_modeling_diffusion.py b/tests/openvino/test_diffusion.py similarity index 100% rename from tests/openvino/test_modeling_diffusion.py rename to tests/openvino/test_diffusion.py From be2a53c406336b309791d55775780837b037706a Mon Sep 17 00:00:00 2001 From: IlyasMoutawwakil Date: Sun, 3 Nov 2024 13:04:23 +0100 Subject: [PATCH 14/21] simple --- .github/workflows/build_pr_documentation.yml | 2 +- .github/workflows/dockerfile_sanity.yml | 52 ++++++++++---------- .github/workflows/quality.yml | 14 ++---- .github/workflows/security.yml | 1 + .github/workflows/test_generation.yml | 12 ++--- .github/workflows/test_inc.yml | 8 ++- .github/workflows/test_ipex.yml | 8 ++- .github/workflows/test_offline.yaml | 11 ++--- .github/workflows/test_openvino.yml | 20 +++----- 9 files changed, 52 insertions(+), 76 deletions(-) diff --git a/.github/workflows/build_pr_documentation.yml b/.github/workflows/build_pr_documentation.yml index 951669f0b..916074ced 100644 --- a/.github/workflows/build_pr_documentation.yml +++ b/.github/workflows/build_pr_documentation.yml @@ -11,7 +11,7 @@ concurrency: jobs: build_documentation: - runs-on: ubuntu-latest + runs-on: ubuntu-22.04 env: COMMIT_SHA: ${{ github.event.pull_request.head.sha }} diff --git a/.github/workflows/dockerfile_sanity.yml b/.github/workflows/dockerfile_sanity.yml index 12be9a5b1..060b80ca4 100644 --- a/.github/workflows/dockerfile_sanity.yml +++ b/.github/workflows/dockerfile_sanity.yml @@ -5,40 +5,40 @@ on: branches: - main paths: - - 'docker/Dockerfile.intel' - + - "docker/Dockerfile.intel" + pull_request: branches: - main paths: - - 'docker/Dockerfile.intel' + - "docker/Dockerfile.intel" jobs: build_and_run: - runs-on: ubuntu-latest + runs-on: ubuntu-22.04 steps: - - name: Checkout code - uses: actions/checkout@v4 + - name: Checkout code + uses: actions/checkout@v4 - - name: Set up Docker Buildx - uses: docker/setup-buildx-action@v3 + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 - - name: Build and Run Docker Image - run: | - IMAGE_NAME="intel_image:latest" - docker build -f docker/Dockerfile.intel -t $IMAGE_NAME . - if [ $? -ne 0 ]; then - echo "Docker image build failed." - exit 1 - fi - CONTAINER_ID=$(docker run -d $IMAGE_NAME tail -f /dev/null) - if docker inspect -f '{{.State.Running}}' $CONTAINER_ID 2>/dev/null | grep -q 'true'; then - echo "Container is running." - else - echo "Container failed to start." - docker logs $CONTAINER_ID 2>/dev/null || echo "No container ID found." - exit 1 - fi - docker stop $CONTAINER_ID - docker rm $CONTAINER_ID \ No newline at end of file + - name: Build and Run Docker Image + run: | + IMAGE_NAME="intel_image:latest" + docker build -f docker/Dockerfile.intel -t $IMAGE_NAME . + if [ $? -ne 0 ]; then + echo "Docker image build failed." + exit 1 + fi + CONTAINER_ID=$(docker run -d $IMAGE_NAME tail -f /dev/null) + if docker inspect -f '{{.State.Running}}' $CONTAINER_ID 2>/dev/null | grep -q 'true'; then + echo "Container is running." + else + echo "Container failed to start." + docker logs $CONTAINER_ID 2>/dev/null || echo "No container ID found." + exit 1 + fi + docker stop $CONTAINER_ID + docker rm $CONTAINER_ID diff --git a/.github/workflows/quality.yml b/.github/workflows/quality.yml index db99106d1..389503820 100644 --- a/.github/workflows/quality.yml +++ b/.github/workflows/quality.yml @@ -3,7 +3,7 @@ on: push: branches: - main - + - v*-release pull_request: branches: - main @@ -14,25 +14,21 @@ concurrency: jobs: quality: - strategy: - fail-fast: false - matrix: - python-version: ["3.9"] - os: [ubuntu-latest] + runs-on: ubuntu-22.04 - runs-on: ${{ matrix.os }} steps: - name: Checkout code uses: actions/checkout@v4 - - name: Setup Python ${{ matrix.python-version }} + - name: Setup Python uses: actions/setup-python@v5 with: - python-version: ${{ matrix.python-version }} + python-version: 3.9 - name: Install dependencies run: | pip install --upgrade pip + # .[quality] installs too many dependencies # TODO: we should remove the the version pinning at some point pip install "black~=23.1" "ruff==0.4.4" diff --git a/.github/workflows/security.yml b/.github/workflows/security.yml index 3c2dc94da..378c78da4 100644 --- a/.github/workflows/security.yml +++ b/.github/workflows/security.yml @@ -9,6 +9,7 @@ permissions: jobs: secrets: runs-on: ubuntu-latest + steps: - shell: bash run: | diff --git a/.github/workflows/test_generation.yml b/.github/workflows/test_generation.yml index 41e0f14ac..cfa3fde40 100644 --- a/.github/workflows/test_generation.yml +++ b/.github/workflows/test_generation.yml @@ -15,22 +15,16 @@ concurrency: jobs: build: - strategy: - fail-fast: false - matrix: - python-version: ["3.9", "3.12"] - os: [ubuntu-latest] - - runs-on: ${{ matrix.os }} + runs-on: ubuntu-22.04 steps: - name: Checkout code uses: actions/checkout@v4 - - name: Setup Python ${{ matrix.python-version }} + - name: Setup Python uses: actions/setup-python@v5 with: - python-version: ${{ matrix.python-version }} + python-version: 3.9 - name: Install dependencies run: | diff --git a/.github/workflows/test_inc.yml b/.github/workflows/test_inc.yml index b5d9c0c45..c1a75a6e3 100644 --- a/.github/workflows/test_inc.yml +++ b/.github/workflows/test_inc.yml @@ -19,19 +19,17 @@ jobs: fail-fast: false matrix: torch-version: ["2.2.0", "2.3.*", "2.4.*"] - python-version: ["3.9", "3.11"] - os: [ubuntu-latest] - runs-on: ${{ matrix.os }} + runs-on: ubuntu-22.04 steps: - name: Checkout code uses: actions/checkout@v4 - - name: Setup Python ${{ matrix.python-version }} + - name: Setup Python uses: actions/setup-python@v5 with: - python-version: ${{ matrix.python-version }} + python-version: 3.9 - name: Install dependencies run: | diff --git a/.github/workflows/test_ipex.yml b/.github/workflows/test_ipex.yml index 1c947f76c..a14fc7337 100644 --- a/.github/workflows/test_ipex.yml +++ b/.github/workflows/test_ipex.yml @@ -20,19 +20,17 @@ jobs: matrix: torch-version: ["2.2.0", "2.3.*", "2.4.*"] transformers-version: ["4.39.0", "4.44.*"] - python-version: ["3.9"] - os: [ubuntu-latest] - runs-on: ${{ matrix.os }} + runs-on: ubuntu-22.04 steps: - name: Checkout code uses: actions/checkout@v4 - - name: Setup Python ${{ matrix.python-version }} + - name: Setup Python uses: actions/setup-python@v5 with: - python-version: ${{ matrix.python-version }} + python-version: 3.9 - name: Install dependencies run: | diff --git a/.github/workflows/test_offline.yaml b/.github/workflows/test_offline.yaml index 44589f1f9..d2599faa5 100644 --- a/.github/workflows/test_offline.yaml +++ b/.github/workflows/test_offline.yaml @@ -15,21 +15,16 @@ concurrency: jobs: build: - strategy: - fail-fast: false - matrix: - python-version: ["3.9"] - os: [ubuntu-latest] + runs-on: ubuntu-22.04 - runs-on: ${{ matrix.os }} steps: - name: Checkout code uses: actions/checkout@v4 - - name: Setup Python ${{ matrix.python-version }} + - name: Setup Python uses: actions/setup-python@v5 with: - python-version: ${{ matrix.python-version }} + python-version: 3.9 - name: Install dependencies run: | diff --git a/.github/workflows/test_openvino.yml b/.github/workflows/test_openvino.yml index 406b71300..cd60c1c94 100644 --- a/.github/workflows/test_openvino.yml +++ b/.github/workflows/test_openvino.yml @@ -26,24 +26,18 @@ jobs: "*training*", "*export*", ] - transformers-version: ["4.36.0", "latest"] - python-version: ["3.9"] - os: [ubuntu-latest] + transformers-version: ["4.36.0", "4.46.*"] - runs-on: ${{ matrix.os }} + runs-on: ubuntu-22.04 steps: - name: Checkout code uses: actions/checkout@v4 - - name: Setup Python ${{ matrix.python-version }} + - name: Setup Python uses: actions/setup-python@v5 with: - python-version: ${{ matrix.python-version }} - - - name: Install lowest compatible transformers version - if: ${{ matrix.transformers-version != 'latest' }} - run: pip install transformers==${{ matrix.transformers-version }} accelerate==0.* + python-version: 3.9 - name: Install dependencies run: | @@ -51,9 +45,9 @@ jobs: pip install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cpu pip install .[openvino,openvino-tokenizers,diffusers,tests] transformers[testing] - - if: ${{ matrix.transformers-version != 'latest' }} - name: Downgrade dependencies - run: pip install transformers==${{ matrix.transformers-version }} accelerate==0.* + - name: Assert versions + run: | + python -c "import transformers; print(transformers.__version__); assert transformers.__version__.startswith('${{ matrix.transformers-version }}'.replace('.*', ''))" - if: ${{ matrix.test-pattern == '*modeling*' }} name: Uninstall NNCF From 183a74fe9e4c6c73ed5fb07d1161b2614a25fd10 Mon Sep 17 00:00:00 2001 From: IlyasMoutawwakil Date: Mon, 4 Nov 2024 09:21:10 +0100 Subject: [PATCH 15/21] use latest --- .github/workflows/test_openvino.yml | 10 +++--- .github/workflows/test_openvino_slow.yml | 39 ++++++++---------------- 2 files changed, 18 insertions(+), 31 deletions(-) diff --git a/.github/workflows/test_openvino.yml b/.github/workflows/test_openvino.yml index cd60c1c94..13ef371ab 100644 --- a/.github/workflows/test_openvino.yml +++ b/.github/workflows/test_openvino.yml @@ -26,7 +26,7 @@ jobs: "*training*", "*export*", ] - transformers-version: ["4.36.0", "4.46.*"] + transformers-version: ["4.36.0", "latest"] runs-on: ubuntu-22.04 @@ -45,13 +45,15 @@ jobs: pip install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cpu pip install .[openvino,openvino-tokenizers,diffusers,tests] transformers[testing] - - name: Assert versions + - if: ${{ matrix.transformers-version != 'latest' }} + name: Downgrade dependencies run: | - python -c "import transformers; print(transformers.__version__); assert transformers.__version__.startswith('${{ matrix.transformers-version }}'.replace('.*', ''))" + pip install transformers==${{ matrix.transformers-version }} accelerate==0.* - if: ${{ matrix.test-pattern == '*modeling*' }} name: Uninstall NNCF - run: pip uninstall -y nncf + run: | + pip uninstall -y nncf - name: Test with Pytest run: | diff --git a/.github/workflows/test_openvino_slow.yml b/.github/workflows/test_openvino_slow.yml index e55105eb3..790699ed5 100644 --- a/.github/workflows/test_openvino_slow.yml +++ b/.github/workflows/test_openvino_slow.yml @@ -24,29 +24,10 @@ jobs: strategy: fail-fast: false matrix: - # Testing lower and upper bound of supported Python versions - # This also ensures that the test fails if dependencies break for Python 3.7 - python-version: ["3.9", "3.12"] - os: ["ubuntu-22.04", "windows-latest"] - transformers-version: ["latest"] - openvino: ["openvino openvino-tokenizers"] - nncf: ["nncf"] - include: - - python-version: "3.12" - os: "ubuntu-22.04" - transformers-version: "4.36.0" - openvino: "openvino openvino-tokenizers" - nncf: "nncf" - - python-version: "3.12" - os: "ubuntu-22.04" - transformers-version: "latest" - openvino: "--pre -U openvino openvino-tokenizers --extra-index-url https://storage.openvinotoolkit.org/simple/wheels/nightly" - nncf: "nncf" - - python-version: "3.12" - os: "ubuntu-22.04" - transformers-version: "latest" - openvino: "--pre -U openvino openvino-tokenizers --extra-index-url https://storage.openvinotoolkit.org/simple/wheels/nightly" - nncf: "git+https://github.com/openvinotoolkit/nncf.git" + os: ["ubuntu-22.04", "windows-2019"] + openvino-version: ["stable", "nightly"] + transformers-version: ["4.36.0", "latest"] + nncf: ["nncf", "git+https://github.com/openvinotoolkit/nncf.git"] runs-on: ${{ matrix.os }} @@ -54,23 +35,27 @@ jobs: - name: Checkout code uses: actions/checkout@v4 - - name: Setup Python ${{ matrix.python-version }} + - name: Setup Python uses: actions/setup-python@v5 with: - python-version: ${{ matrix.python-version }} + python-version: 3.9 - name: Install dependencies run: | pip install --upgrade pip pip install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cpu - pip install ${{ matrix.openvino }} + if [ "${{ matrix.openvino-version }}" == "stable" ]; then + pip install openvino openvino-tokenizers + else + pip install openvino openvino-tokenizers --pre --upgrade --extra-index-url https://storage.openvinotoolkit.org/simple/wheels/nightly" + fi pip install .[tests] transformers[testing] - if: ${{ matrix.transformers-version != 'latest' }} name: Downgrade dependencies run: pip install transformers==${{ matrix.transformers-version }} accelerate==0.* - - name: Test with Pytest + - name: Test with Pytest (basic) run: | pytest tests/openvino/test_modeling_basic.py From 0bdc53b68f4ea85085e22e071958629e2480875f Mon Sep 17 00:00:00 2001 From: IlyasMoutawwakil Date: Mon, 4 Nov 2024 09:23:28 +0100 Subject: [PATCH 16/21] fix --- .github/workflows/test_openvino_slow.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test_openvino_slow.yml b/.github/workflows/test_openvino_slow.yml index 790699ed5..bab5a7b0b 100644 --- a/.github/workflows/test_openvino_slow.yml +++ b/.github/workflows/test_openvino_slow.yml @@ -47,7 +47,7 @@ jobs: if [ "${{ matrix.openvino-version }}" == "stable" ]; then pip install openvino openvino-tokenizers else - pip install openvino openvino-tokenizers --pre --upgrade --extra-index-url https://storage.openvinotoolkit.org/simple/wheels/nightly" + pip install openvino openvino-tokenizers --pre --upgrade --extra-index-url https://storage.openvinotoolkit.org/simple/wheels/nightly fi pip install .[tests] transformers[testing] From fa6ca3e6bd63b172a8afa6afdef255351aa12b11 Mon Sep 17 00:00:00 2001 From: IlyasMoutawwakil Date: Mon, 4 Nov 2024 09:27:40 +0100 Subject: [PATCH 17/21] fix --- .github/workflows/test_openvino.yml | 2 +- .github/workflows/test_openvino_slow.yml | 17 +++++++++++------ 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/.github/workflows/test_openvino.yml b/.github/workflows/test_openvino.yml index 13ef371ab..e2889cb4e 100644 --- a/.github/workflows/test_openvino.yml +++ b/.github/workflows/test_openvino.yml @@ -46,7 +46,7 @@ jobs: pip install .[openvino,openvino-tokenizers,diffusers,tests] transformers[testing] - if: ${{ matrix.transformers-version != 'latest' }} - name: Downgrade dependencies + name: Downgrade Transformers and Accelerate run: | pip install transformers==${{ matrix.transformers-version }} accelerate==0.* diff --git a/.github/workflows/test_openvino_slow.yml b/.github/workflows/test_openvino_slow.yml index bab5a7b0b..d136a9dfa 100644 --- a/.github/workflows/test_openvino_slow.yml +++ b/.github/workflows/test_openvino_slow.yml @@ -44,15 +44,20 @@ jobs: run: | pip install --upgrade pip pip install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cpu - if [ "${{ matrix.openvino-version }}" == "stable" ]; then - pip install openvino openvino-tokenizers - else - pip install openvino openvino-tokenizers --pre --upgrade --extra-index-url https://storage.openvinotoolkit.org/simple/wheels/nightly - fi pip install .[tests] transformers[testing] + - if: ${{ matrix.openvino-version == 'stable' }} + name: Install stable OpenVINO + run: | + pip install openvino openvino-tokenizers + + - if: ${{ matrix.openvino-version == 'nightly' }} + name: Install nightly OpenVINO + run: | + pip install openvino openvino-tokenizers --pre --upgrade --extra-index-url https://storage.openvinotoolkit.org/simple/wheels/nightly + - if: ${{ matrix.transformers-version != 'latest' }} - name: Downgrade dependencies + name: Downgrade Transformers and Accelerate run: pip install transformers==${{ matrix.transformers-version }} accelerate==0.* - name: Test with Pytest (basic) From 96a57870b0657d3d1e5c26910c1c4937d88002da Mon Sep 17 00:00:00 2001 From: IlyasMoutawwakil Date: Mon, 4 Nov 2024 11:23:37 +0100 Subject: [PATCH 18/21] safety checker not a submodel --- optimum/intel/openvino/modeling_diffusion.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/optimum/intel/openvino/modeling_diffusion.py b/optimum/intel/openvino/modeling_diffusion.py index 18d8a7506..d96a98f15 100644 --- a/optimum/intel/openvino/modeling_diffusion.py +++ b/optimum/intel/openvino/modeling_diffusion.py @@ -409,11 +409,9 @@ def _from_pretrained( "tokenizer_2": None, "tokenizer_3": None, "feature_extractor": None, - "image_encoder": None, - "safety_checker": None, } for name in submodels.keys(): - if kwargs.get(name) is not None: + if name in kwargs: submodels[name] = kwargs.pop(name) elif config.get(name, (None, None))[0] is not None: library_name, library_classes = config.get(name) From 361a56a8522f53546220abead1ed292ade849985 Mon Sep 17 00:00:00 2001 From: IlyasMoutawwakil Date: Mon, 4 Nov 2024 11:55:41 +0100 Subject: [PATCH 19/21] fix for pipeline modules --- optimum/intel/openvino/modeling_diffusion.py | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/optimum/intel/openvino/modeling_diffusion.py b/optimum/intel/openvino/modeling_diffusion.py index d96a98f15..afe8271d4 100644 --- a/optimum/intel/openvino/modeling_diffusion.py +++ b/optimum/intel/openvino/modeling_diffusion.py @@ -28,7 +28,7 @@ import openvino import torch from diffusers.configuration_utils import ConfigMixin -from diffusers.pipelines import ( +from diffusers import ( AutoPipelineForImage2Image, AutoPipelineForInpainting, AutoPipelineForText2Image, @@ -60,7 +60,7 @@ DIFFUSION_MODEL_VAE_DECODER_SUBFOLDER, DIFFUSION_MODEL_VAE_ENCODER_SUBFOLDER, ) - +from diffusers import pipelines from ...exporters.openvino import main_export from ..utils.import_utils import is_diffusers_version from .configuration import OVConfig, OVQuantizationMethod, OVWeightQuantizationConfig @@ -409,14 +409,19 @@ def _from_pretrained( "tokenizer_2": None, "tokenizer_3": None, "feature_extractor": None, + "safety_checker": None, + "image_encoder": None, } for name in submodels.keys(): if name in kwargs: submodels[name] = kwargs.pop(name) elif config.get(name, (None, None))[0] is not None: - library_name, library_classes = config.get(name) - library = importlib.import_module(library_name) - class_obj = getattr(library, library_classes) + module_name, module_class = config.get(name) + if hasattr(pipelines, module_name): + module = getattr(pipelines, module_name) + else: + module = importlib.import_module(module_name) + class_obj = getattr(module, module_class) load_method = getattr(class_obj, "from_pretrained") # Check if the module is in a subdirectory if (model_save_path / name).is_dir(): From 20d4225387966f4823ae961cb9e126958e23f8fe Mon Sep 17 00:00:00 2001 From: IlyasMoutawwakil Date: Mon, 4 Nov 2024 12:00:50 +0100 Subject: [PATCH 20/21] style --- optimum/intel/openvino/modeling_diffusion.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/optimum/intel/openvino/modeling_diffusion.py b/optimum/intel/openvino/modeling_diffusion.py index afe8271d4..51041a2fb 100644 --- a/optimum/intel/openvino/modeling_diffusion.py +++ b/optimum/intel/openvino/modeling_diffusion.py @@ -27,7 +27,6 @@ import numpy as np import openvino import torch -from diffusers.configuration_utils import ConfigMixin from diffusers import ( AutoPipelineForImage2Image, AutoPipelineForInpainting, @@ -41,7 +40,9 @@ StableDiffusionXLImg2ImgPipeline, StableDiffusionXLInpaintPipeline, StableDiffusionXLPipeline, + pipelines, ) +from diffusers.configuration_utils import ConfigMixin from diffusers.schedulers import SchedulerMixin from diffusers.schedulers.scheduling_utils import SCHEDULER_CONFIG_NAME from diffusers.utils.constants import CONFIG_NAME @@ -60,7 +61,7 @@ DIFFUSION_MODEL_VAE_DECODER_SUBFOLDER, DIFFUSION_MODEL_VAE_ENCODER_SUBFOLDER, ) -from diffusers import pipelines + from ...exporters.openvino import main_export from ..utils.import_utils import is_diffusers_version from .configuration import OVConfig, OVQuantizationMethod, OVWeightQuantizationConfig From 97d5ded49443429da7b8184ba8851639a420c6f6 Mon Sep 17 00:00:00 2001 From: IlyasMoutawwakil Date: Tue, 5 Nov 2024 11:42:19 +0100 Subject: [PATCH 21/21] added pip freeze --- .github/workflows/test_openvino_slow.yml | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/.github/workflows/test_openvino_slow.yml b/.github/workflows/test_openvino_slow.yml index d136a9dfa..bf52413a7 100644 --- a/.github/workflows/test_openvino_slow.yml +++ b/.github/workflows/test_openvino_slow.yml @@ -44,12 +44,8 @@ jobs: run: | pip install --upgrade pip pip install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cpu - pip install .[tests] transformers[testing] - - - if: ${{ matrix.openvino-version == 'stable' }} - name: Install stable OpenVINO - run: | - pip install openvino openvino-tokenizers + pip install .[openvino,tests] transformers[testing] + pip uninstall -y nncf - if: ${{ matrix.openvino-version == 'nightly' }} name: Install nightly OpenVINO @@ -60,6 +56,9 @@ jobs: name: Downgrade Transformers and Accelerate run: pip install transformers==${{ matrix.transformers-version }} accelerate==0.* + - name: Pip freeze + run: pip freeze + - name: Test with Pytest (basic) run: | pytest tests/openvino/test_modeling_basic.py