Skip to content

Commit

Permalink
[GHA] macos (openvinotoolkit#3110)
Browse files Browse the repository at this point in the history
### Changes

Introduce tests on MacOS in weakly scope
- precommit / common
- precommit / openvino
  • Loading branch information
AlexanderDokuchaev authored Dec 4, 2024
1 parent ba13df4 commit cf950d2
Show file tree
Hide file tree
Showing 4 changed files with 77 additions and 2 deletions.
64 changes: 64 additions & 0 deletions .github/workflows/macos.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
name: MacOS
permissions: read-all

on:
workflow_dispatch:
inputs:
pull_request_number:
description: 'The pull request number'
default: ''
schedule:
- cron: '0 0 * * 0'

jobs:
precommit-common:
runs-on: macos-14
steps:
- uses: actions/checkout@a5ac7e51b41094c92402da3b24376905380afc29 # v4.1.6
with:
lfs: true
fetch-depth: 0 # Fetch full history to allow checking out any branch or PR
- name: Fetch and Checkout the Pull Request Branch
if: ${{ github.event_name == 'workflow_dispatch' && github.event.inputs.pull_request_number != '' }}
run: |
git fetch origin pull/${{ github.event.inputs.pull_request_number }}/head:pr-${{ github.event.inputs.pull_request_number }}
git checkout pr-${{ github.event.inputs.pull_request_number }}
- uses: actions/setup-python@0a5c61591373683505ea898e09a3ea4f39ef2b9c # v5.0.0
with:
python-version: "3.10"
cache: pip
- name: Install dependencies
run: |
pip install .
pip install -r tests/common/requirements.txt
- name: Print installed modules
run: pip list
- name: Run pre-commit
run: pytest -n 2 -ra tests/common

precommit-openvino:
runs-on: macos-14
steps:
- uses: actions/checkout@a5ac7e51b41094c92402da3b24376905380afc29 # v4.1.6
with:
lfs: true
fetch-depth: 0 # Fetch full history to allow checking out any branch or PR
- name: Fetch and Checkout the Pull Request Branch
if: ${{ github.event_name == 'workflow_dispatch' && github.event.inputs.pull_request_number != '' }}
run: |
git fetch origin pull/${{ github.event.inputs.pull_request_number }}/head:pr-${{ github.event.inputs.pull_request_number }}
git checkout pr-${{ github.event.inputs.pull_request_number }}
- uses: actions/setup-python@0a5c61591373683505ea898e09a3ea4f39ef2b9c # v5.0.0
with:
python-version: "3.10"
cache: pip
- name: Install dependencies
run: |
pip install .
pip install -r tests/openvino/requirements.txt
- name: Print installed modules
run: pip list
- name: Run pre-commit
run: pytest -n 3 -ra tests/openvino --dist loadscope
env:
ONEDNN_MAX_CPU_ISA: AVX2
4 changes: 4 additions & 0 deletions nncf/common/utils/os.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ def is_linux() -> bool:
return "linux" in sys.platform


def is_macos() -> bool:
return "darwin" in sys.platform


def get_available_cpu_count(logical: bool = True) -> int:
"""
Return the number of CPUs in the system.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import pytest

from nncf.common.graph.layer_attributes import Dtype
from nncf.common.utils.os import is_macos
from nncf.openvino.statistics.collectors import OVAbsMaxReducer
from nncf.openvino.statistics.collectors import OVAbsQuantileReducer
from nncf.openvino.statistics.collectors import OVBatchMeanReducer
Expand Down Expand Up @@ -88,7 +89,9 @@ def test_mixed_precision_reducers(self, reducer_cls, reduction_axes, ref_value):
compiled_ov_model = ov.compile_model(ov_model)

reducer_output = compiled_ov_model(input_)[0]
assert np.allclose(reducer_output, ref_value)

atol = 1.0e-8 if not is_macos() else 0.3
assert np.allclose(reducer_output, ref_value, atol=atol)

@pytest.mark.parametrize(
"input_", [np.arange(2), np.arange(2 * 4 * 8).reshape(8, 8), np.arange(2 * 4 * 8).reshape(2, 4, 8)]
Expand Down
6 changes: 5 additions & 1 deletion tests/openvino/native/test_fast_bias_correction.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import torch

from nncf.common.factory import NNCFGraphFactory
from nncf.common.utils.os import is_macos
from nncf.openvino.graph.node_utils import get_bias_value
from nncf.openvino.graph.node_utils import is_node_with_bias
from nncf.quantization.algorithms.fast_bias_correction.openvino_backend import OVFastBiasCorrectionAlgoBackend
Expand Down Expand Up @@ -54,12 +55,15 @@ def transform_fn(data_item):
def check_bias(model: ov.Model, ref_bias: list):
ref_bias = np.array(ref_bias)
nncf_graph = NNCFGraphFactory.create(model)

atol = 0.0001 if not is_macos() else 0.01

for node in nncf_graph.get_all_nodes():
if not is_node_with_bias(node, nncf_graph):
continue
bias_value = get_bias_value(node, nncf_graph, model)
bias_value = bias_value.reshape(ref_bias.shape)
assert np.all(np.isclose(bias_value, ref_bias, atol=0.0001)), f"{bias_value} != {ref_bias}"
assert np.all(np.isclose(bias_value, ref_bias, atol=atol)), f"{bias_value} != {ref_bias}"

return
raise ValueError("Not found node with bias")

0 comments on commit cf950d2

Please sign in to comment.