Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master' into partial_value_opt…
Browse files Browse the repository at this point in the history
…imization

Signed-off-by: Evgeniia Nugmanova <[email protected]>
  • Loading branch information
jane-intel committed Dec 24, 2024
2 parents 7c183db + b4c81e0 commit e22d3b6
Show file tree
Hide file tree
Showing 45 changed files with 2,305 additions and 180 deletions.
133 changes: 133 additions & 0 deletions .github/workflows/job_jax_layer_tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
name: JAX Layer Tests

on:
workflow_call:
inputs:
runner:
description: 'Machine on which the tests would run'
type: string
required: true
container:
description: 'JSON to be converted to the value of the "container" configuration for the job'
type: string
required: false
default: '{"image": null}'
affected-components:
description: 'Components that are affected by changes in the commit defined by the Smart CI Action'
type: string
required: true
python-version:
description: 'Python version to setup. E.g., "3.11"'
type: string
required: true

permissions: read-all

env:
PIP_CACHE_PATH_LINUX: /mount/caches/pip/linux
PIP_CACHE_PATH_WIN: "C:\\mount\\caches\\pip\\win"

jobs:
JAX_Layer_Tests:
name: JAX Layer Tests
timeout-minutes: 40
runs-on: ${{ inputs.runner }}
container: ${{ fromJSON(inputs.container) }}
defaults:
run:
shell: ${{ contains(inputs.runner, 'win') && 'pwsh' || 'bash' }}
env:
DEBIAN_FRONTEND: noninteractive # to prevent apt-get from waiting user input
OPENVINO_REPO: ${{ github.workspace }}/openvino
INSTALL_DIR: ${{ github.workspace }}/install
INSTALL_TEST_DIR: ${{ github.workspace }}/install/tests
INSTALL_WHEELS_DIR: ${{ github.workspace }}/install/wheels
LAYER_TESTS_INSTALL_DIR: ${{ github.workspace }}/install/tests/layer_tests
steps:
- name: Download OpenVINO artifacts (tarballs)
uses: actions/download-artifact@fa0a91b85d4f404e444e00e005971372dc801d16 # v4.1.8
with:
pattern: openvino_[tests]*
path: ${{ env.INSTALL_DIR }}
merge-multiple: true

- name: Download OpenVINO artifacts (wheels)
uses: actions/download-artifact@fa0a91b85d4f404e444e00e005971372dc801d16 # v4.1.8
with:
pattern: openvino_[wheels]*
path: ${{ env.INSTALL_WHEELS_DIR }}
merge-multiple: true

# Needed as ${{ github.workspace }} is not working correctly when using Docker
- name: Setup Variables
if: runner.os != 'Windows'
run: |
echo "OPENVINO_REPO=$GITHUB_WORKSPACE/openvino" >> "$GITHUB_ENV"
echo "INSTALL_DIR=$GITHUB_WORKSPACE/install" >> "$GITHUB_ENV"
echo "INSTALL_TEST_DIR=$GITHUB_WORKSPACE/install/tests" >> "$GITHUB_ENV"
echo "INSTALL_WHEELS_DIR=$GITHUB_WORKSPACE/install/wheels" >> "$GITHUB_ENV"
echo "LAYER_TESTS_INSTALL_DIR=$GITHUB_WORKSPACE/install/tests/layer_tests" >> "$GITHUB_ENV"
- name: Install OpenVINO dependencies (mac)
if: runner.os == 'macOS'
run: brew install pigz

- name: Extract OpenVINO packages (Linux, macOS)
if: runner.os != 'Windows'
run: |
pigz -dc openvino_tests.tar.gz | tar -xf - -C ${INSTALL_DIR}
working-directory: ${{ env.INSTALL_DIR }}

- name: Extract OpenVINO artifacts (Windows)
if: runner.os == 'Windows'
run: |
Expand-Archive openvino_tests.zip -DestinationPath ${{ env.INSTALL_DIR }}
working-directory: ${{ env.INSTALL_DIR }}

- name: Fetch setup_python and install wheels actions
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
timeout-minutes: 15
with:
sparse-checkout: |
.github/actions/setup_python/action.yml
.github/actions/install_ov_wheels/action.yml
sparse-checkout-cone-mode: false
path: 'openvino'

- name: Setup Python ${{ inputs.python-version }}
uses: ./openvino/.github/actions/setup_python
with:
version: ${{ inputs.python-version }}
pip-cache-path: ${{ runner.os == 'Linux' && env.PIP_CACHE_PATH_LINUX || env.PIP_CACHE_PATH_WIN }}
should-setup-pip-paths: ${{ runner.os != 'macOS' }}
self-hosted-runner: ${{ runner.os != 'macOS' }}

- name: Install OpenVINO Python wheels
uses: ./openvino/.github/actions/install_ov_wheels
with:
wheels-dir-path: ${{ env.INSTALL_WHEELS_DIR }}
wheels-to-install: 'openvino'

- name: Install JAX Layer tests dependencies
run: |
# jax test requirements
python3 -m pip install -r ${{ env.INSTALL_TEST_DIR }}/requirements_jax
- name: JAX Layer Tests
if: ${{ fromJSON(inputs.affected-components).JAX_FE.test && runner.arch != 'ARM64' }} # Ticket: 126287, 142196
run: python3 -m pytest ${{ env.LAYER_TESTS_INSTALL_DIR }}/jax_tests ${PARALLEL} -m precommit_jax_fe --junitxml=${{ env.INSTALL_TEST_DIR }}/TEST-jax.xml
env:
TEST_DEVICE: CPU
TEST_PRECISION: FP16
JAX_TRACE_MODE: JAXPR
PARALLEL: ${{ runner.os == 'Windows' && ' ' || '-n logical'}}

- name: Upload Test Results
uses: actions/upload-artifact@b4b15b8c7c6ac21ea08fcf65892d2ee8f75cf882 # v4.4.3
if: ${{ !cancelled() }}
with:
name: test-results-python-jax-layers
path: |
${{ env.INSTALL_TEST_DIR }}/TEST*.html
${{ env.INSTALL_TEST_DIR }}/TEST*.xml
if-no-files-found: 'warn'
2 changes: 1 addition & 1 deletion .github/workflows/job_jax_models_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ jobs:

- name: Install JAX tests requirements for precommit
run: |
python3 -m pip install -r ${MODEL_HUB_TESTS_INSTALL_DIR}/jax/requirements.txt
python3 -m pip install -r ${{ env.INSTALL_TEST_DIR }}/requirements_jax
- name: JAX/Flax Models Tests from Hugging Face
if: ${{ inputs.model_scope == 'precommit' || inputs.model_scope == 'nightly' }}
Expand Down
8 changes: 0 additions & 8 deletions .github/workflows/job_python_unit_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -162,14 +162,6 @@ jobs:
export LD_LIBRARY_PATH=${PIP_INSTALL_PATH}/openvino/libs:$LD_LIBRARY_PATH
python3 -m pytest ${LAYER_TESTS_INSTALL_DIR}/py_frontend_tests --junitxml=${INSTALL_TEST_DIR}/TEST-test_py_fontend.xml
- name: JAX Layer Tests - JAX FE
if: ${{ fromJSON(inputs.affected-components).JAX_FE.test && runner.arch != 'ARM64' && runner.os != 'macOS' }}
run: python3 -m pytest ${LAYER_TESTS_INSTALL_DIR}/jax_tests/ -m precommit_jax_fe --junitxml=${INSTALL_TEST_DIR}/TEST-jax_fe.xml
env:
TEST_DEVICE: CPU
TEST_PRECISION: FP16
JAX_TRACE_MODE: JAXPR

- name: TensorFlow Lite Layer Tests - TFL FE
if: fromJSON(inputs.affected-components).TFL_FE.test
run: python3 -m pytest ${LAYER_TESTS_INSTALL_DIR}/tensorflow_lite_tests/ -n logical --junitxml=${INSTALL_TEST_DIR}/TEST-tfl_fe.xml
Expand Down
10 changes: 10 additions & 0 deletions .github/workflows/linux_arm64.yml
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,16 @@ jobs:
affected-components: ${{ needs.smart_ci.outputs.affected_components }}
python-version: '3.11'

JAX_Layer_Tests:
name: JAX Layer Tests
needs: [ Build, Docker, Smart_CI ]
uses: ./.github/workflows/job_jax_layer_tests.yml
with:
runner: 'aks-linux-16-cores-32gb-arm'
container: '{"image": "${{ fromJSON(needs.docker.outputs.images).ov_test.ubuntu_20_04_arm64 }}", "volumes": ["/mount:/mount"]}'
affected-components: ${{ needs.smart_ci.outputs.affected_components }}
python-version: '3.11'

CPU_Functional_Tests:
name: CPU functional tests
if: fromJSON(needs.smart_ci.outputs.affected_components).CPU.test
Expand Down
9 changes: 9 additions & 0 deletions .github/workflows/mac.yml
Original file line number Diff line number Diff line change
Expand Up @@ -356,6 +356,15 @@ jobs:
affected-components: ${{ needs.smart_ci.outputs.affected_components }}
python-version: '3.11'

JAX_Layer_Tests:
name: JAX Layer Tests
needs: [ Build, Smart_CI ]
uses: ./.github/workflows/job_jax_layer_tests.yml
with:
runner: 'macos-13'
affected-components: ${{ needs.smart_ci.outputs.affected_components }}
python-version: '3.11'

CPU_Functional_Tests:
name: CPU functional tests
# if: fromJSON(needs.smart_ci.outputs.affected_components).CPU.test
Expand Down
9 changes: 9 additions & 0 deletions .github/workflows/mac_arm64.yml
Original file line number Diff line number Diff line change
Expand Up @@ -355,6 +355,15 @@ jobs:
affected-components: ${{ needs.smart_ci.outputs.affected_components }}
python-version: '3.11'

JAX_Layer_Tests:
name: JAX Layer Tests
needs: [ Build, Smart_CI ]
uses: ./.github/workflows/job_jax_layer_tests.yml
with:
runner: 'macos-13-xlarge'
affected-components: ${{ needs.smart_ci.outputs.affected_components }}
python-version: '3.11'

CPU_Functional_Tests:
name: CPU functional tests
if: fromJSON(needs.smart_ci.outputs.affected_components).CPU.test
Expand Down
10 changes: 10 additions & 0 deletions .github/workflows/ubuntu_22.yml
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,16 @@ jobs:
affected-components: ${{ needs.smart_ci.outputs.affected_components }}
python-version: '3.11'

JAX_Layer_Tests:
name: JAX Layer Tests
needs: [ Docker, Build, Smart_CI ]
uses: ./.github/workflows/job_jax_layer_tests.yml
with:
runner: 'aks-linux-4-cores-16gb'
container: '{"image": "${{ fromJSON(needs.docker.outputs.images).ov_test.ubuntu_22_04_x64 }}", "volumes": ["/mount:/mount"]}'
affected-components: ${{ needs.smart_ci.outputs.affected_components }}
python-version: '3.11'

CPU_Functional_Tests:
name: CPU functional tests
if: fromJSON(needs.smart_ci.outputs.affected_components).CPU.test
Expand Down
10 changes: 10 additions & 0 deletions .github/workflows/ubuntu_24.yml
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,16 @@ jobs:
affected-components: ${{ needs.smart_ci.outputs.affected_components }}
python-version: '3.12'

JAX_Layer_Tests:
name: JAX Layer Tests
needs: [ Docker, Build, Smart_CI ]
uses: ./.github/workflows/job_jax_layer_tests.yml
with:
runner: 'aks-linux-4-cores-16gb'
container: '{"image": "${{ fromJSON(needs.docker.outputs.images).ov_test.ubuntu_24_04_x64 }}", "volumes": ["/mount:/mount"]}'
affected-components: ${{ needs.smart_ci.outputs.affected_components }}
python-version: '3.12'

TensorFlow_Layer_Tests:
name: TensorFlow Layer Tests
needs: [ Docker, Build, Smart_CI, Openvino_tokenizers ]
Expand Down
9 changes: 9 additions & 0 deletions .github/workflows/windows_vs2019_release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -499,6 +499,15 @@ jobs:
affected-components: ${{ needs.smart_ci.outputs.affected_components }}
python-version: '3.11'

JAX_Layer_Tests:
name: JAX Layer Tests
needs: [ Build, Smart_CI ]
uses: ./.github/workflows/job_jax_layer_tests.yml
with:
runner: 'aks-win-8-cores-16gb'
affected-components: ${{ needs.smart_ci.outputs.affected_components }}
python-version: '3.11'

CXX_Unit_Tests:
name: C++ unit tests
needs: [ Build, Smart_CI ]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,52 @@ Here is an example of how to convert a model obtained with ``torch.export``:
This is an experimental feature. Use it only if you know that you need to. PyTorch version 2.2
is recommended. Dynamic shapes are not supported yet.

Converting a PyTorch Model from Disk
####################################

PyTorch provides the capability to save models in two distinct formats: ``torch.jit.ScriptModule`` and ``torch.export.ExportedProgram``.
Both formats can be saved to disk as standalone files, enabling them to be reloaded independently of the original Python code.

ExportedProgram Format
++++++++++++++++++++++

The ``ExportedProgram`` format is saved on disk using `torch.export.save() <https://pytorch.org/docs/stable/export.html#serialization>`__.
Below is an example of how to convert an ``ExportedProgram`` from disk:

.. tab-set::

.. tab-item:: Python
:sync: py

.. code-block:: py
:force:
import openvino as ov
ov_model = ov.convert_model('exported_program.pt2')
.. tab-item:: CLI
:sync: cli

.. code-block:: sh
ovc exported_program.pt2
ScriptModule Format
+++++++++++++++++++

`torch.jit.save() <https://pytorch.org/docs/stable/generated/torch.jit.save.html>`__ serializes ``ScriptModule`` object on disk.
To convert the serialized ``ScriptModule`` format, run ``convert_model`` function with ``example_input`` parameter as follows:

.. code-block:: py
:force:
from openvino import convert_model
import torch
convert_model(input_model='script_module.pt', example_input=torch.rand(1, 10))
``example_input`` is the required parameter for the conversion because ``torch.jit.ScriptModule`` object is always saved in an untraced state on disk.

Exporting a PyTorch Model to ONNX Format
########################################

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
// Copyright (C) 2024 Intel Corporation
// SPDX-License-Identifier: Apache-2.0
//

#pragma once

#include "openvino/pass/matcher_pass.hpp"
#include "transformations_visibility.hpp"

namespace ov {
namespace pass {

/// This pass transforms the following sub-graph to a single Scaled Dot Product Attention operation.
/// Before:
/// ┌───────┐ ┌───────┐ ┌───────┐
/// │ Q │ │ K │ │ V │
/// └───┬───┘ └───┬───┘ └───┬───┘
/// │ │ │
/// │ │ │
/// ┌───┴───┐ ┌─────┴──────┐ │
/// │ MatMul│<──│ Transpose │ │
/// └───┬───┘ | (Optional) │ │
/// │ └────────────┘ │
/// ┌───┴───┐ ┌─────────────┐ │
/// │ Add │<───│AttentionMask│ │
/// └───┬───┘ | (Optional) │ │
/// │ └─────────────┘ │
/// ┌───┴───┐ │
/// │Softmax│ │
/// └───┬───┘ │
/// │ │
/// ┌───┴───┐ │
/// │ MatMul│<─────────────────────┘
/// └───┬───┘
/// ┌───┴───┐
/// │ Output│
/// └───────┘
///
/// After:
/// ┌───────┐ ┌───────┐ ┌───────┐ ┌─────────────┐
/// │ Q │ │ K │ │ V │ │AttentionMask│
/// └───┬───┘ └───┬───┘ └───┬───┘ └──────┬──────┘
/// │ │ │ │
/// │ │ │ │
/// ┌───┴────────────┴────────────┴───────────────┴─┐
/// │ ScaledDotProductAttention │
/// └────────────────────┬──────────────────────────┘
/// │
/// │
/// ┌────┴────┐
/// │ Output │
/// └─────────┘
class TRANSFORMATIONS_API SDPAFusion : public ov::pass::MatcherPass {
public:
OPENVINO_MATCHER_PASS_RTTI("SDPAFusion", "0");
SDPAFusion();
};

} // namespace pass
} // namespace ov
Loading

0 comments on commit e22d3b6

Please sign in to comment.