Skip to content

Commit d92782c

Browse files
akashchimryzhov
andauthored
[CI] [GHA] HuggingFace cache (openvinotoolkit#28481)
The new HuggingFace share was added to the self-hosted runners with the path being `mount/caches/huggingface`. This PR adds this share to workflows that use HF data. ### Tickets: - *159012* - *159010* --------- Co-authored-by: Mikhail Ryzhov <mikhail.ryzhov@intel.com>
1 parent ca47d17 commit d92782c

12 files changed

+61
-30
lines changed

.github/workflows/job_jax_layer_tests.yml

+8-3
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ jobs:
4343
INSTALL_TEST_DIR: ${{ github.workspace }}/install/tests
4444
INSTALL_WHEELS_DIR: ${{ github.workspace }}/install/wheels
4545
LAYER_TESTS_INSTALL_DIR: ${{ github.workspace }}/install/tests/layer_tests
46+
USE_SYSTEM_CACHE: False # Using remote HuggingFace cache
4647
steps:
4748
- name: Download OpenVINO artifacts (tarballs)
4849
uses: actions/download-artifact@fa0a91b85d4f404e444e00e005971372dc801d16 # v4.1.8
@@ -67,7 +68,12 @@ jobs:
6768
echo "INSTALL_TEST_DIR=$GITHUB_WORKSPACE/install/tests" >> "$GITHUB_ENV"
6869
echo "INSTALL_WHEELS_DIR=$GITHUB_WORKSPACE/install/wheels" >> "$GITHUB_ENV"
6970
echo "LAYER_TESTS_INSTALL_DIR=$GITHUB_WORKSPACE/install/tests/layer_tests" >> "$GITHUB_ENV"
70-
71+
echo "HF_HUB_CACHE=/mount/caches/huggingface" >> "$GITHUB_ENV"
72+
73+
- name: Setup HuggingFace Cache Directory (Windows)
74+
if: runner.os == 'Windows'
75+
run: Add-Content -Path $env:GITHUB_ENV -Value "HF_HUB_CACHE=C:\\mount\\caches\\huggingface"
76+
7177
- name: Install OpenVINO dependencies (mac)
7278
if: runner.os == 'macOS'
7379
run: brew install pigz
@@ -80,8 +86,7 @@ jobs:
8086

8187
- name: Extract OpenVINO artifacts (Windows)
8288
if: runner.os == 'Windows'
83-
run: |
84-
Expand-Archive openvino_tests.zip -DestinationPath ${{ env.INSTALL_DIR }}
89+
run: Expand-Archive openvino_tests.zip -DestinationPath ${{ env.INSTALL_DIR }}
8590
working-directory: ${{ env.INSTALL_DIR }}
8691

8792
- name: Fetch setup_python and install wheels actions

.github/workflows/job_jax_models_tests.yml

+7-1
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ jobs:
3535
INSTALL_TEST_DIR: ${{ github.workspace }}/install/tests
3636
INSTALL_WHEELS_DIR: ${{ github.workspace }}/install/wheels
3737
MODEL_HUB_TESTS_INSTALL_DIR: ${{ github.workspace }}/install/tests/model_hub_tests
38+
USE_SYSTEM_CACHE: False # Using remote HuggingFace cache
3839
steps:
3940
- name: Download OpenVINO artifacts (tarballs)
4041
uses: actions/download-artifact@fa0a91b85d4f404e444e00e005971372dc801d16 # v4.1.8
@@ -57,7 +58,12 @@ jobs:
5758
echo "INSTALL_DIR=$GITHUB_WORKSPACE/install" >> "$GITHUB_ENV"
5859
echo "INSTALL_TEST_DIR=$GITHUB_WORKSPACE/install/tests" >> "$GITHUB_ENV"
5960
echo "MODEL_HUB_TESTS_INSTALL_DIR=$GITHUB_WORKSPACE/install/tests/model_hub_tests" >> "$GITHUB_ENV"
60-
61+
echo "HF_HUB_CACHE=/mount/caches/huggingface" >> "$GITHUB_ENV"
62+
63+
- name: Setup HuggingFace Cache Directory (Windows)
64+
if: runner.os == 'Windows'
65+
run: Add-Content -Path $env:GITHUB_ENV -Value "HF_HUB_CACHE=C:\\mount\\caches\\huggingface"
66+
6167
- name: Extract OpenVINO packages and tests
6268
run: |
6369
pigz -dc openvino_tests.tar.gz | tar -xf - -C ${INSTALL_DIR}

.github/workflows/job_onnx_models_tests.yml

+6-1
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ jobs:
3636
# depending on GITHUB_RUN_NUMBER variable
3737
NUMBER_OF_REPLICAS: 2
3838
ONNX_MODEL_ZOO_SHA: "5faef4c33eba0395177850e1e31c4a6a9e634c82"
39+
USE_SYSTEM_CACHE: False # Using remote HuggingFace cache
3940
if: ${{ github.event_name != 'merge_group' }}
4041
steps:
4142
- name: Download OpenVINO artifacts (tests)
@@ -59,8 +60,12 @@ jobs:
5960
echo "INSTALL_DIR=$GITHUB_WORKSPACE/install" >> "$GITHUB_ENV"
6061
echo "INSTALL_TEST_DIR=$GITHUB_WORKSPACE/install/tests" >> "$GITHUB_ENV"
6162
echo "MODELS_SHARE_PATH=/mount/testdata$((GITHUB_RUN_NUMBER % NUMBER_OF_REPLICAS))" >> "$GITHUB_ENV"
62-
echo $MODELS_SHARE_PATH
6363
echo "LOGS_FOLDER=$GITHUB_WORKSPACE/onnx_models_tests_logs" >> "$GITHUB_ENV"
64+
echo "HF_HUB_CACHE=/mount/caches/huggingface" >> "$GITHUB_ENV"
65+
66+
- name: Setup HuggingFace Cache Directory (Windows)
67+
if: runner.os == 'Windows'
68+
run: Add-Content -Path $env:GITHUB_ENV -Value "HF_HUB_CACHE=C:\\mount\\caches\\huggingface"
6469

6570
- name: Extract OpenVINO packages and tests
6671
run: |

.github/workflows/job_pytorch_layer_tests.yml

+6
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ jobs:
4343
INSTALL_TEST_DIR: ${{ github.workspace }}/install/tests
4444
INSTALL_WHEELS_DIR: ${{ github.workspace }}/install/wheels
4545
LAYER_TESTS_INSTALL_DIR: ${{ github.workspace }}/install/tests/layer_tests
46+
USE_SYSTEM_CACHE: False # Using remote HuggingFace cache
4647
steps:
4748
- name: Download OpenVINO artifacts (tarballs)
4849
uses: actions/download-artifact@fa0a91b85d4f404e444e00e005971372dc801d16 # v4.1.8
@@ -67,6 +68,11 @@ jobs:
6768
echo "INSTALL_TEST_DIR=$GITHUB_WORKSPACE/install/tests" >> "$GITHUB_ENV"
6869
echo "INSTALL_WHEELS_DIR=$GITHUB_WORKSPACE/install/wheels" >> "$GITHUB_ENV"
6970
echo "LAYER_TESTS_INSTALL_DIR=$GITHUB_WORKSPACE/install/tests/layer_tests" >> "$GITHUB_ENV"
71+
echo "HF_HUB_CACHE=/mount/caches/huggingface" >> "$GITHUB_ENV"
72+
73+
- name: Setup HuggingFace Cache Directory (Windows)
74+
if: runner.os == 'Windows'
75+
run: Add-Content -Path $env:GITHUB_ENV -Value "HF_HUB_CACHE=C:\\mount\\caches\\huggingface"
7076

7177
- name: Install OpenVINO dependencies (mac)
7278
if: runner.os == 'macOS'

.github/workflows/job_pytorch_models_tests.yml

+7-5
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ jobs:
3535
INSTALL_TEST_DIR: ${{ github.workspace }}/install/tests
3636
INSTALL_WHEELS_DIR: ${{ github.workspace }}/install/wheels
3737
MODEL_HUB_TESTS_INSTALL_DIR: ${{ github.workspace }}/install/tests/model_hub_tests
38+
USE_SYSTEM_CACHE: False # Using remote HuggingFace cache
3839
steps:
3940
- name: Check sudo
4041
if: ${{ runner.os == 'Linux' }}
@@ -65,11 +66,17 @@ jobs:
6566

6667
# Needed as ${{ github.workspace }} is not working correctly when using Docker
6768
- name: Setup Variables
69+
if: ${{ contains(inputs.runner, 'aks') }} # Do not setup variables for GitHub-hosted runners
6870
run: |
6971
echo "OPENVINO_REPO=$GITHUB_WORKSPACE/openvino" >> "$GITHUB_ENV"
7072
echo "INSTALL_DIR=$GITHUB_WORKSPACE/install" >> "$GITHUB_ENV"
7173
echo "INSTALL_TEST_DIR=$GITHUB_WORKSPACE/install/tests" >> "$GITHUB_ENV"
7274
echo "MODEL_HUB_TESTS_INSTALL_DIR=$GITHUB_WORKSPACE/install/tests/model_hub_tests" >> "$GITHUB_ENV"
75+
echo "HF_HUB_CACHE=/mount/caches/huggingface" >> "$GITHUB_ENV"
76+
77+
- name: Setup HuggingFace Cache Directory (Windows)
78+
if: runner.os == 'Windows'
79+
run: Add-Content -Path $env:GITHUB_ENV -Value "HF_HUB_CACHE=C:\\mount\\caches\\huggingface"
7380

7481
- name: Extract OpenVINO artifacts
7582
run: |
@@ -130,7 +137,6 @@ jobs:
130137
env:
131138
TYPE: ${{ inputs.model_scope == 'precommit' && 'precommit' || 'nightly' }}
132139
TEST_DEVICE: CPU
133-
USE_SYSTEM_CACHE: False
134140
OP_REPORT_FILE: ${{ env.INSTALL_TEST_DIR }}/TEST-torch_unsupported_ops.log
135141

136142
- name: PagedAttention Test
@@ -140,7 +146,6 @@ jobs:
140146
python3 -m pytest ${MODEL_HUB_TESTS_INSTALL_DIR}/transformation_tests/test_pa_transformation.py -m precommit --html=${INSTALL_TEST_DIR}/TEST-torch_pagedattention_tests.html --self-contained-html -vvv -s --tb=short -n 2
141147
env:
142148
TEST_DEVICE: CPU
143-
USE_SYSTEM_CACHE: False
144149

145150
- name: RoPE Test
146151
if: ${{ inputs.model_scope == 'precommit' }}
@@ -149,7 +154,6 @@ jobs:
149154
python3 -m pytest ${MODEL_HUB_TESTS_INSTALL_DIR}/transformation_tests/test_transformations.py -m precommit --html=${INSTALL_TEST_DIR}/TEST-torch_rope_tests.html --self-contained-html -v --tb=short -n 2
150155
env:
151156
TEST_DEVICE: CPU
152-
USE_SYSTEM_CACHE: False
153157

154158
- name: StatefulToStateless Test
155159
if: ${{ inputs.model_scope == 'precommit' }}
@@ -158,7 +162,6 @@ jobs:
158162
python3 -m pytest ${MODEL_HUB_TESTS_INSTALL_DIR}/transformation_tests/test_stateful_to_stateless_transformation.py -m precommit --html=${INSTALL_TEST_DIR}/TEST-torch_stateful_to_stateless_tests.html --self-contained-html -v --tb=short
159163
env:
160164
TEST_DEVICE: CPU
161-
USE_SYSTEM_CACHE: False
162165

163166
- name: TorchFX GPTQ Pattern Test
164167
if: ${{ inputs.model_scope == 'precommit' }}
@@ -169,7 +172,6 @@ jobs:
169172
python3 -m pytest ${MODEL_HUB_TESTS_INSTALL_DIR}/transformation_tests/test_gptq_torchfx_transformations.py -m precommit --html=${INSTALL_TEST_DIR}/TEST-torch_gptqpattern_tests.html --self-contained-html -v --tb=short
170173
env:
171174
TEST_DEVICE: CPU
172-
USE_SYSTEM_CACHE: False
173175

174176
- name: Reformat unsupported ops file
175177
if: ${{ inputs.model_scope != 'precommit' && !cancelled()}}

.github/workflows/job_tensorflow_layer_tests.yml

+6
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ jobs:
4343
INSTALL_TEST_DIR: ${{ github.workspace }}/install/tests
4444
INSTALL_WHEELS_DIR: ${{ github.workspace }}/install/wheels
4545
LAYER_TESTS_INSTALL_DIR: ${{ github.workspace }}/install/tests/layer_tests
46+
USE_SYSTEM_CACHE: False # Using remote HuggingFace cache
4647
steps:
4748
- name: Download OpenVINO artifacts (tarballs)
4849
uses: actions/download-artifact@fa0a91b85d4f404e444e00e005971372dc801d16 # v4.1.8
@@ -67,6 +68,11 @@ jobs:
6768
echo "INSTALL_TEST_DIR=$GITHUB_WORKSPACE/install/tests" >> "$GITHUB_ENV"
6869
echo "LAYER_TESTS_INSTALL_DIR=$GITHUB_WORKSPACE/install/tests/layer_tests" >> "$GITHUB_ENV"
6970
echo "INSTALL_WHEELS_DIR=$GITHUB_WORKSPACE/install/wheels" >> "$GITHUB_ENV"
71+
echo "HF_HUB_CACHE=/mount/caches/huggingface" >> "$GITHUB_ENV"
72+
73+
- name: Setup HuggingFace Cache Directory (Windows)
74+
if: runner.os == 'Windows'
75+
run: Add-Content -Path $env:GITHUB_ENV -Value "HF_HUB_CACHE=C:\\mount\\caches\\huggingface"
7076

7177
- name: Install OpenVINO dependencies (mac)
7278
if: runner.os == 'macOS'

.github/workflows/job_tensorflow_models_tests.yml

+7-5
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ jobs:
3636
INSTALL_WHEELS_DIR: ${{ github.workspace }}/install/wheels
3737
MODEL_HUB_TESTS_INSTALL_DIR: ${{ github.workspace }}/install/tests/model_hub_tests
3838
NUMBER_OF_REPLICAS: 2
39+
USE_SYSTEM_CACHE: False # Using remote HuggingFace cache
3940
steps:
4041
- name: Download OpenVINO artifacts (tarballs)
4142
uses: actions/download-artifact@fa0a91b85d4f404e444e00e005971372dc801d16 # v4.1.8
@@ -59,13 +60,14 @@ jobs:
5960
echo "INSTALL_TEST_DIR=$GITHUB_WORKSPACE/install/tests" >> "$GITHUB_ENV"
6061
echo "MODEL_HUB_TESTS_INSTALL_DIR=$GITHUB_WORKSPACE/install/tests/model_hub_tests" >> "$GITHUB_ENV"
6162
echo "TFHUB_CACHE_DIR=/mount/testdata$((GITHUB_RUN_NUMBER % NUMBER_OF_REPLICAS))/tfhub_models" >> "$GITHUB_ENV"
62-
echo $TFHUB_CACHE_DIR
63-
echo "HF_HUB_CACHE=/mount/testdata$((GITHUB_RUN_NUMBER % NUMBER_OF_REPLICAS))/hugging_face" >> "$GITHUB_ENV"
64-
echo $HF_HUB_CACHE
63+
echo "HF_HUB_CACHE=/mount/caches/huggingface" >> "$GITHUB_ENV"
64+
65+
- name: Setup HuggingFace Cache Directory (Windows)
66+
if: runner.os == 'Windows'
67+
run: Add-Content -Path $env:GITHUB_ENV -Value "HF_HUB_CACHE=C:\\mount\\caches\\huggingface"
6568

6669
- name: Extract OpenVINO artifacts (Linux and macOS)
67-
run: |
68-
pigz -dc openvino_tests.tar.gz | tar -xf - -C ${INSTALL_DIR}
70+
run: pigz -dc openvino_tests.tar.gz | tar -xf - -C ${INSTALL_DIR}
6971
working-directory: ${{ env.INSTALL_DIR }}
7072

7173
- name: Fetch setup_python action

tests/model_hub_tests/jax/test_hf_transformers.py

+4-3
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import pytest
77
import requests
88
from PIL import Image
9-
from models_hub_common.constants import hf_hub_cache_dir
9+
from models_hub_common.constants import hf_cache_dir, clean_hf_cache_dir
1010
from models_hub_common.utils import cleanup_dir, get_models_list, retry
1111
from transformers import (
1212
AutoProcessor,
@@ -42,8 +42,9 @@ def load_model(self, model_name, _):
4242
return model
4343

4444
def teardown_method(self):
45-
# remove all downloaded files from cache
46-
cleanup_dir(hf_hub_cache_dir)
45+
if clean_hf_cache_dir:
46+
# remove all downloaded files from cache
47+
cleanup_dir(hf_cache_dir)
4748
super().teardown_method()
4849

4950
def infer_ov_model(self, ov_model, inputs, ie_device):

tests/model_hub_tests/models_hub_common/constants.py

+1-5
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,7 @@
2626
os.environ['TFHUB_CACHE_DIR'] = tf_hub_cache_dir
2727
os.environ['HF_HUB_CACHE'] = hf_cache_dir
2828

29-
no_clean_cache_dir = False
30-
hf_hub_cache_dir = tempfile.gettempdir()
31-
if os.environ.get('USE_SYSTEM_CACHE', 'True') == 'False':
32-
no_clean_cache_dir = True
33-
os.environ['HUGGINGFACE_HUB_CACHE'] = hf_hub_cache_dir
29+
clean_hf_cache_dir = os.environ.get('USE_SYSTEM_CACHE', False) == 'True'
3430

3531
# supported_devices : CPU, GPU
3632
test_device = os.environ.get('TEST_DEVICE', 'CPU;GPU').split(';')

tests/model_hub_tests/performance_tests/test_tf_hub_performance_model.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ def load_model(self, model_name, model_link):
6262
return hub.resolve(model_link)
6363

6464
def teardown_method(self):
65-
if not const.no_clean_cache_dir:
65+
if const.clean_hf_cache_dir:
6666
utils.cleanup_dir(const.tf_hub_cache_dir)
6767
# deallocate memory after each test case
6868
gc.collect()

tests/model_hub_tests/pytorch/test_edsr.py

+4-3
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import pytest
77
import random
88
import torch
9-
from models_hub_common.constants import hf_hub_cache_dir
9+
from models_hub_common.constants import hf_cache_dir, clean_hf_cache_dir
1010
from models_hub_common.utils import cleanup_dir
1111

1212
from torch_utils import TestTorchConvertModel
@@ -52,8 +52,9 @@ def load_model(self, model_name, model_link):
5252
return model
5353

5454
def teardown_method(self):
55-
# remove all downloaded files from cache
56-
cleanup_dir(hf_hub_cache_dir)
55+
if clean_hf_cache_dir:
56+
# remove all downloaded files from cache
57+
cleanup_dir(hf_cache_dir)
5758
super().teardown_method()
5859

5960
@pytest.mark.parametrize("name", ["edsr"])

tests/model_hub_tests/pytorch/test_hf_transformers.py

+4-3
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
VivitImageProcessor, XCLIPVisionModel
2020
)
2121

22-
from models_hub_common.constants import hf_hub_cache_dir
22+
from models_hub_common.constants import hf_cache_dir, clean_hf_cache_dir
2323
from models_hub_common.utils import cleanup_dir, get_models_list, retry
2424
from torch_utils import TestTorchConvertModel
2525

@@ -497,8 +497,9 @@ def load_model(self, name, type):
497497
return model
498498

499499
def teardown_method(self):
500-
# remove all downloaded files from cache
501-
cleanup_dir(hf_hub_cache_dir)
500+
if clean_hf_cache_dir:
501+
# remove all downloaded files from cache
502+
cleanup_dir(hf_cache_dir)
502503

503504
super().teardown_method()
504505

0 commit comments

Comments
 (0)