OpenVINO™ is an open source toolkit for optimizing and deploying AI inference
C++ aicomputer-visiondeep-learningdeploy-aidiffusion-modelsgenerative-aigood-first-issueinferencellm-inferencenatural-language-processingnlpopenvinooptimize-aiperformance-boostrecommendation-systemspeech-recognitionstable-diffusiontransformersyolo
[CI] [GHA] Use `snapshot_download` to load HF models (#32458)
Andrei Kashchikhin6e4cc94c9788
diff --git a/.github/workflows/job_jax_layer_tests.yml b/.github/workflows/job_jax_layer_tests.ymlindex 07605a80bf0..758bc0fd0d1 100644--- a/.github/workflows/job_jax_layer_tests.yml+++ b/.github/workflows/job_jax_layer_tests.yml@@ -48,6 +48,8 @@ jobs:INSTALL_DIR: ${{ github.workspace }}/installINSTALL_TEST_DIR: ${{ github.workspace }}/install/testsUSE_SYSTEM_CACHE: False # Using remote HuggingFace cache+ HF_HUB_VERBOSITY: debug+ TRANSFORMERS_VERBOSITY: debugsteps:# checkout action cleans up the workspace and have to be the first step- name: Fetch custom actions@@ -75,7 +77,6 @@ jobs:run: |echo "HF_HUB_CACHE=${{ runner.os == 'Linux' && env.HF_HUB_CACHE_LIN || env.HF_HUB_CACHE_WIN }}" >> "$GITHUB_ENV"echo "HUGGINGFACE_HUB_CACHE=${{ runner.os == 'Linux' && env.HF_HUB_CACHE_LIN || env.HF_HUB_CACHE_WIN }}" >> "$GITHUB_ENV"- echo "HF_HUB_OFFLINE=1" >> "$GITHUB_ENV"- name: Install OpenVINO dependencies (mac)if: runner.os == 'macOS'diff --git a/.github/workflows/job_jax_models_tests.yml b/.github/workflows/job_jax_models_tests.ymlindex fa91d63f628..4784daada4f 100644--- a/.github/workflows/job_jax_models_tests.yml+++ b/.github/workflows/job_jax_models_tests.yml@@ -44,6 +44,8 @@ jobs:INSTALL_TEST_DIR: ${{ github.workspace }}/install/testsMODEL_HUB_TESTS_INSTALL_DIR: ${{ github.workspace }}/install/tests/model_hub_testsUSE_SYSTEM_CACHE: False # Using remote HuggingFace cache+ HF_HUB_VERBOSITY: debug+ TRANSFORMERS_VERBOSITY: debugsteps:# checkout action cleans up the workspace and have to be the first step- name: Fetch custom actions@@ -77,7 +79,6 @@ jobs:run: |echo "HF_HUB_CACHE=${{ runner.os == 'Linux' && env.HF_HUB_CACHE_LIN || env.HF_HUB_CACHE_WIN }}" >> "$GITHUB_ENV"echo "HUGGINGFACE_HUB_CACHE=${{ runner.os == 'Linux' && env.HF_HUB_CACHE_LIN || env.HF_HUB_CACHE_WIN }}" >> "$GITHUB_ENV"- echo "HF_HUB_OFFLINE=1" >> "$GITHUB_ENV"- name: Extract OpenVINO packages and testsrun: pigz -dc openvino_tests.tar.gz | tar -xf - -vdiff --git a/.github/workflows/job_onnx_models_tests.yml b/.github/workflows/job_onnx_models_tests.ymlindex 207d6b40223..ef55a438253 100644--- a/.github/workflows/job_onnx_models_tests.yml+++ b/.github/workflows/job_onnx_models_tests.yml@@ -46,6 +46,8 @@ jobs:ONNX_MODEL_ZOO_SHA: "5faef4c33eba0395177850e1e31c4a6a9e634c82"USE_SYSTEM_CACHE: False # Using remote HuggingFace cacheLOGS_FOLDER: ${{ github.workspace }}/onnx_models_tests_logs"+ HF_HUB_VERBOSITY: debug+ TRANSFORMERS_VERBOSITY: debugif: ${{ github.event_name != 'merge_group' }}steps:# checkout action cleans up the workspace and have to be the first step@@ -78,7 +80,6 @@ jobs:run: |echo "HF_HUB_CACHE=${{ runner.os == 'Linux' && env.HF_HUB_CACHE_LIN || env.HF_HUB_CACHE_WIN }}" >> "$GITHUB_ENV"echo "HUGGINGFACE_HUB_CACHE=$HF_HUB_CACHE" >> "$GITHUB_ENV"- echo "HF_HUB_OFFLINE=1" >> "$GITHUB_ENV"echo "MODELS_SHARE_PATH=/mount/testdata$((GITHUB_RUN_NUMBER % NUMBER_OF_REPLICAS))" >> "$GITHUB_ENV"# Issue 148922diff --git a/.github/workflows/job_pytorch_fx_layer_tests.yml b/.github/workflows/job_pytorch_fx_layer_tests.ymlindex f2a8407ead2..8719c816bfa 100644--- a/.github/workflows/job_pytorch_fx_layer_tests.yml+++ b/.github/workflows/job_pytorch_fx_layer_tests.yml@@ -47,6 +47,8 @@ jobs:INSTALL_DIR: ${{ github.workspace }}/installINSTALL_TEST_DIR: ${{ github.workspace }}/install/testsUSE_SYSTEM_CACHE: False # Using remote HuggingFace cache+ HF_HUB_VERBOSITY: debug+ TRANSFORMERS_VERBOSITY: debugsteps:- name: Fetch setup_python and install wheels actionsuses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2@@ -74,7 +76,6 @@ jobs:run: |Add-Content -Path $env:GITHUB_ENV -Value "HF_HUB_CACHE=C:\\mount\\caches\\huggingface"Add-Content -Path $env:GITHUB_ENV -Value "HUGGINGFACE_HUB_CACHE=C:\\mount\\caches\\huggingface"- Add-Content -Path $env:GITHUB_ENV -Value "HF_HUB_OFFLINE=1"- name: Install OpenVINO dependencies (mac)if: runner.os == 'macOS'diff --git a/.github/workflows/job_pytorch_layer_tests.yml b/.github/workflows/job_pytorch_layer_tests.ymlindex 58814cec9e3..650bbcbcf48 100644--- a/.github/workflows/job_pytorch_layer_tests.yml+++ b/.github/workflows/job_pytorch_layer_tests.yml@@ -49,6 +49,8 @@ jobs:INSTALL_TEST_DIR: ${{ github.workspace }}/install/testsLAYER_TESTS_INSTALL_DIR: ${{ github.workspace }}/install/tests/layer_testsUSE_SYSTEM_CACHE: False # Using remote HuggingFace cache+ HF_HUB_VERBOSITY: debug+ TRANSFORMERS_VERBOSITY: debugsteps:- name: Fetch setup_python and install wheels actionsuses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2@@ -75,7 +77,7 @@ jobs:run: |echo "HF_HUB_CACHE=${{ runner.os == 'Linux' && env.HF_HUB_CACHE_LIN || env.HF_HUB_CACHE_WIN }}" >> "$GITHUB_ENV"echo "HUGGINGFACE_HUB_CACHE=${{ runner.os == 'Linux' && env.HF_HUB_CACHE_LIN || env.HF_HUB_CACHE_WIN }}" >> "$GITHUB_ENV"- echo "HF_HUB_OFFLINE=1" >> "$GITHUB_ENV"+- name: Install OpenVINO dependencies (mac)if: runner.os == 'macOS'run: brew install pigzdiff --git a/.github/workflows/job_pytorch_models_tests.yml b/.github/workflows/job_pytorch_models_tests.ymlindex be0af3c8dfa..ca25451feda 100644--- a/.github/workflows/job_pytorch_models_tests.yml+++ b/.github/workflows/job_pytorch_models_tests.yml@@ -43,6 +43,8 @@ jobs:INSTALL_TEST_DIR: ${{ github.workspace }}/install/testsMODEL_HUB_TESTS_INSTALL_DIR: ${{ github.workspace }}/install/tests/model_hub_testsUSE_SYSTEM_CACHE: False # Using remote HuggingFace cache+ HF_HUB_VERBOSITY: debug+ TRANSFORMERS_VERBOSITY: debugsteps:- name: Fetch setup_python and install wheels actionsuses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2@@ -75,7 +77,6 @@ jobs:run: |echo "HF_HUB_CACHE=${{ runner.os == 'Linux' && env.HF_HUB_CACHE_LIN || env.HF_HUB_CACHE_WIN }}" >> "$GITHUB_ENV"echo "HUGGINGFACE_HUB_CACHE=${{ runner.os == 'Linux' && env.HF_HUB_CACHE_LIN || env.HF_HUB_CACHE_WIN }}" >> "$GITHUB_ENV"- echo "HF_HUB_OFFLINE=1" >> "$GITHUB_ENV"- name: Extract OpenVINO artifactsrun: pigz -dc openvino_tests.tar.gz | tar -xf - -v@@ -119,7 +120,6 @@ jobs:TYPE: ${{ inputs.model_scope == 'precommit' && 'precommit' || 'nightly' }}TEST_DEVICE: CPUOP_REPORT_FILE: ${{ env.INSTALL_TEST_DIR }}/TEST-torch_unsupported_ops.log- HF_HUB_OFFLINE: 0 # Can't use offline mode - these tests use `model_info` call, which can't be cached- name: PagedAttention Testif: ${{ inputs.model_scope == 'precommit' }}@@ -128,7 +128,6 @@ jobs: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 2env:TEST_DEVICE: CPU- HF_HUB_OFFLINE: 0- name: RoPE Testif: ${{ inputs.model_scope == 'precommit' }}diff --git a/.github/workflows/job_tensorflow_layer_tests.yml b/.github/workflows/job_tensorflow_layer_tests.ymlindex 367aab22f14..82dd8854c23 100644--- a/.github/workflows/job_tensorflow_layer_tests.yml+++ b/.github/workflows/job_tensorflow_layer_tests.yml@@ -48,6 +48,8 @@ jobs:INSTALL_DIR: ${{ github.workspace }}/installINSTALL_TEST_DIR: ${{ github.workspace }}/install/testsUSE_SYSTEM_CACHE: False # Using remote HuggingFace cache+ HF_HUB_VERBOSITY: debug+ TRANSFORMERS_VERBOSITY: debugsteps:- name: Fetch custom actionsuses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2@@ -80,7 +82,6 @@ jobs:run: |echo "HF_HUB_CACHE=${{ runner.os == 'Linux' && env.HF_HUB_CACHE_LIN || env.HF_HUB_CACHE_WIN }}" >> "$GITHUB_ENV"echo "HUGGINGFACE_HUB_CACHE=${{ runner.os == 'Linux' && env.HF_HUB_CACHE_LIN || env.HF_HUB_CACHE_WIN }}" >> "$GITHUB_ENV"- echo "HF_HUB_OFFLINE=1" >> "$GITHUB_ENV"- name: Install OpenVINO dependencies (mac)if: ${{ runner.os == 'macOS' }}diff --git a/.github/workflows/job_tensorflow_models_tests.yml b/.github/workflows/job_tensorflow_models_tests.ymlindex 83c135d857c..1671e1653f0 100644--- a/.github/workflows/job_tensorflow_models_tests.yml+++ b/.github/workflows/job_tensorflow_models_tests.yml@@ -43,6 +43,8 @@ jobs:INSTALL_TEST_DIR: ${{ github.workspace }}/install/testsNUMBER_OF_REPLICAS: 2USE_SYSTEM_CACHE: False # Using remote HuggingFace cache+ HF_HUB_VERBOSITY: debug+ TRANSFORMERS_VERBOSITY: debugsteps:- name: Fetch custom actionsuses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2@@ -76,7 +78,6 @@ jobs:echo "HF_HUB_CACHE=${{ runner.os == 'Linux' && env.HF_HUB_CACHE_LIN || env.HF_HUB_CACHE_WIN }}" >> "$GITHUB_ENV"echo "HUGGINGFACE_HUB_CACHE=${{ runner.os == 'Linux' && env.HF_HUB_CACHE_LIN || env.HF_HUB_CACHE_WIN }}" >> "$GITHUB_ENV"echo "TFHUB_CACHE_DIR=/mount/testdata$((GITHUB_RUN_NUMBER % NUMBER_OF_REPLICAS))/tfhub_models" >> "$GITHUB_ENV"- echo "HF_HUB_OFFLINE=1" >> "$GITHUB_ENV"- name: Extract OpenVINO artifacts (Linux and macOS)run: pigz -dc openvino_tests.tar.gz | tar -xf - -vdiff --git a/tests/e2e_tests/test_utils/pytorch_loaders.py b/tests/e2e_tests/test_utils/pytorch_loaders.pyindex f1f4cfefbef..cad7b0e30e3 100644--- a/tests/e2e_tests/test_utils/pytorch_loaders.py+++ b/tests/e2e_tests/test_utils/pytorch_loaders.py@@ -6,6 +6,7 @@ import osimport sysimport torch+from huggingface_hub import snapshot_downloadclass LoadPyTorchModel:@@ -70,7 +71,8 @@ def load_cadene_model(module, args):def load_hugging_face_model(module, args):module = importlib.import_module(module)- model = module.AutoModel.from_pretrained(args['model-name'], torchscript=True)+ model_cached = snapshot_download(args['model-name']) # required to avoid HF rate limits+ model = module.AutoModel.from_pretrained(model_cached, torchscript=True)return modeldiff --git a/tests/llm/accuracy_conformance.py b/tests/llm/accuracy_conformance.pyindex 141bccaeecb..0d84cf127b8 100644--- a/tests/llm/accuracy_conformance.py+++ b/tests/llm/accuracy_conformance.py@@ -5,6 +5,7 @@ import shutilimport tempfileimport pytest+from huggingface_hub import snapshot_downloadfrom optimum.intel.openvino import (OVModelForCausalLM,OVWeightQuantizationConfig)from transformers import AutoModelForCausalLM, AutoTokenizer, set_seed@@ -100,8 +101,9 @@ def setup_model(model_id):logger.info(f"Setting up model: {model_id}")# Download original model- model = AutoModelForCausalLM.from_pretrained(model_id)- tokenizer = AutoTokenizer.from_pretrained(model_id)+ model_cached = snapshot_download(model_id) # required to avoid HF rate limits+ model = AutoModelForCausalLM.from_pretrained(model_cached)+ tokenizer = AutoTokenizer.from_pretrained(model_cached)# Save original modelmodel_path = get_model_path(model_id, "org")diff --git a/tests/model_hub_tests/jax/test_hf_transformers.py b/tests/model_hub_tests/jax/test_hf_transformers.pyindex 57fa1d7ba4b..20a131455ee 100644--- a/tests/model_hub_tests/jax/test_hf_transformers.py+++ b/tests/model_hub_tests/jax/test_hf_transformers.py@@ -5,6 +5,7 @@ import openvino as ovimport osimport pytestimport requests+from huggingface_hub import snapshot_downloadfrom PIL import Imagefrom models_hub_common.constants import hf_cache_dir, clean_hf_cache_dirfrom models_hub_common.utils import cleanup_dir, get_models_list, retry@@ -22,17 +23,18 @@ from jax_utils import TestJaxConvertModelclass TestTransformersModel(TestJaxConvertModel):@retry(3, exceptions=(OSError,), delay=1)def load_model(self, model_name, _):- model = FlaxAutoModel.from_pretrained(model_name)+ model_cached = snapshot_download(model_name) # required to avoid HF rate limits+ model = FlaxAutoModel.from_pretrained(model_cached)if model_name in ['google/vit-base-patch16-224-in21k']:url = "http://images.cocodataset.org/val2017/000000039769.jpg"image = Image.open(requests.get(url, stream=True).raw)- image_processor = AutoImageProcessor.from_pretrained(model_name)+ image_processor = AutoImageProcessor.from_pretrained(model_cached)self.example = image_processor(images=image, return_tensors="np")elif model_name in ['albert/albert-base-v2', 'facebook/bart-base', 'ksmcg/Mistral-tiny']:- tokenizer = AutoTokenizer.from_pretrained(model_name)+ tokenizer = AutoTokenizer.from_pretrained(model_cached)self.example = tokenizer("Hello, my dog is cute", return_tensors="np")elif model_name in ['openai/clip-vit-base-patch32']:- processor = AutoProcessor.from_pretrained(model_name)+ processor = AutoProcessor.from_pretrained(model_cached)url = "http://images.cocodataset.org/val2017/000000039769.jpg"image = Image.open(requests.get(url, stream=True).raw)self.example = processor(text=["a photo of a cat", "a photo of a dog"],diff --git a/tests/model_hub_tests/pytorch/test_edsr.py b/tests/model_hub_tests/pytorch/test_edsr.pyindex 844c43985f8..d158d5a98b7 100644--- a/tests/model_hub_tests/pytorch/test_edsr.py+++ b/tests/model_hub_tests/pytorch/test_edsr.py@@ -6,6 +6,7 @@ import osimport pytestimport randomimport torch+from huggingface_hub import snapshot_downloadfrom models_hub_common.constants import hf_cache_dir, clean_hf_cache_dirfrom models_hub_common.utils import cleanup_dir@@ -44,8 +45,9 @@ class TestEdsrConvertModel(TestTorchConvertModel):image = Image.open(requests.get(url, stream=True).raw)assert model_name in name_to_class, "Unexpected model name"print(f"scale: {self.scale}")+ model_cached = snapshot_download(f'eugenesiow/{model_name}') # required to avoid HF rate limitsmodel = name_to_class[model_name].from_pretrained(- f'eugenesiow/{model_name}', scale=self.scale)+ model_cached, scale=self.scale)inputs = ImageLoader.load_image(image)self.example = (torch.randn_like(inputs),)self.inputs = (inputs,)diff --git a/tests/model_hub_tests/pytorch/test_hf_transformers.py b/tests/model_hub_tests/pytorch/test_hf_transformers.pyindex 30fd450347b..89fde03a35d 100644--- a/tests/model_hub_tests/pytorch/test_hf_transformers.py+++ b/tests/model_hub_tests/pytorch/test_hf_transformers.py@@ -4,7 +4,7 @@import osfrom datasets import Audio, load_dataset-from huggingface_hub import hf_hub_download, model_info+from huggingface_hub import hf_hub_download, model_info, snapshot_downloadfrom PIL import Imageimport pytestimport torch@@ -59,12 +59,13 @@ class TestTransformersModel(TestTorchConvertModel):def load_model(self, name, type):name, _, name_suffix = name.partition(':')+ model_cached = snapshot_download(name) # required to avoid HF rate limitsmi = model_info(name)auto_processor = Nonemodel = Noneexample = Nonetry:- config = AutoConfig.from_pretrained(name)+ config = AutoConfig.from_pretrained(model_cached)except Exception:config = {}model_kwargs = {"torchscript": True}@@ -77,31 +78,31 @@ class TestTransformersModel(TestTorchConvertModel):except:auto_model = Noneif "clip_vision_model" in mi.tags:- preprocessor = CLIPFeatureExtractor.from_pretrained(name)+ preprocessor = CLIPFeatureExtractor.from_pretrained(model_cached)encoded_input = preprocessor(self.image, return_tensors='pt')example = dict(encoded_input)elif 'xclip' in mi.tags:- model = XCLIPVisionModel.from_pretrained(name, **model_kwargs)+ model = XCLIPVisionModel.from_pretrained(model_cached, **model_kwargs)example = {'pixel_values': torch.randn(16, 3, 224, 224)}elif 'audio-spectrogram-transformer' in mi.tags:example = {'input_values': torch.randn(1, 1024, 128)}elif 'mega' in mi.tags:- model = AutoModel.from_pretrained(name, **model_kwargs)+ model = AutoModel.from_pretrained(model_cached, **model_kwargs)model.config.output_attentions = Truemodel.config.output_hidden_states = Truemodel.config.return_dict = Trueexample = dict(model.dummy_inputs)elif 'bros' in mi.tags:- processor = AutoProcessor.from_pretrained(name)+ processor = AutoProcessor.from_pretrained(model_cached)encoding = processor("to the moon!", return_tensors="pt")bbox = torch.randn([1, 6, 8])example = dict(input_ids=encoding["input_ids"], bbox=bbox, attention_mask=encoding["attention_mask"])elif 'upernet' in mi.tags:- processor = AutoProcessor.from_pretrained(name)+ processor = AutoProcessor.from_pretrained(model_cached)example = dict(processor(images=self.image, return_tensors="pt"))elif 'deformable_detr' in mi.tags or 'oneformer' in mi.tags:- processor = AutoProcessor.from_pretrained(name)+ processor = AutoProcessor.from_pretrained(model_cached)example = dict(processor(images=self.image, task_inputs=["semantic"], return_tensors="pt"))elif 'clap' in mi.tags:@@ -111,11 +112,11 @@ class TestTransformersModel(TestTorchConvertModel):}example = example_inputs_map[name_suffix]elif 'git' in mi.tags:- processor = AutoProcessor.from_pretrained(name)+ processor = AutoProcessor.from_pretrained(model_cached)example = {'pixel_values': torch.randn(1, 3, 224, 224),'input_ids': torch.randint(1, 100, size=(1, 13), dtype=torch.int64)}elif 'blip-2' in mi.tags:- processor = AutoProcessor.from_pretrained(name)+ processor = AutoProcessor.from_pretrained(model_cached)example = dict(processor(images=self.image, return_tensors="pt"))example_inputs_map = {'vision_model': {'pixel_values': torch.randn([1, 3, 224, 224])},@@ -126,7 +127,7 @@ class TestTransformersModel(TestTorchConvertModel):}example = example_inputs_map[name_suffix]elif "t5" in mi.tags:- tokenizer = T5Tokenizer.from_pretrained(name)+ tokenizer = T5Tokenizer.from_pretrained(model_cached)encoder = tokenizer("Studies have been shown that owning a dog is good for you", return_tensors="pt")decoder = tokenizer("Studies show that", return_tensors="pt")@@ -137,8 +138,8 @@ class TestTransformersModel(TestTorchConvertModel):example = (wav_input_16khz,)elif "vit-gpt2" in name:model = VisionEncoderDecoderModel.from_pretrained(- name, **model_kwargs)- feature_extractor = ViTImageProcessor.from_pretrained(name)+ model_cached, **model_kwargs)+ feature_extractor = ViTImageProcessor.from_pretrained(model_cached)encoded_input = feature_extractor(images=[self.image], return_tensors="pt")@@ -147,7 +148,7 @@ class TestTransformersModel(TestTorchConvertModel):example["decoder_attention_mask"] = torch.ones([1, 20], dtype=torch.int64)elif 'idefics' in mi.tags:- processor = AutoProcessor.from_pretrained(name)+ processor = AutoProcessor.from_pretrained(model_cached)prompts = [["User: What is in this image?",@@ -167,16 +168,16 @@ class TestTransformersModel(TestTorchConvertModel):prompts, add_end_of_utterance_token=False, return_tensors="pt")example = dict(inputs)elif 'blip' in mi.tags and 'text2text-generation' in mi.tags:- processor = BlipProcessor.from_pretrained(name)+ processor = BlipProcessor.from_pretrained(model_cached)model = BlipForConditionalGeneration.from_pretrained(- name, **model_kwargs)+ model_cached, **model_kwargs)text = "a photography of"inputs = processor(self.image, text, return_tensors="pt")example = dict(inputs)elif 'speecht5' in mi.tags:- processor = SpeechT5Processor.from_pretrained(name)+ processor = SpeechT5Processor.from_pretrained(model_cached)model = SpeechT5ForTextToSpeech.from_pretrained(- name, **model_kwargs)+ model_cached, **model_kwargs)inputs = processor(text="Hello, my dog is cute.",return_tensors="pt")@@ -191,7 +192,7 @@ class TestTransformersModel(TestTorchConvertModel):example['decoder_input_values'] = torch.randn([1, 20, model.config.num_mel_bins])elif 'layoutlmv2' in mi.tags:- processor = LayoutLMv2Processor.from_pretrained(name)+ processor = LayoutLMv2Processor.from_pretrained(model_cached)question = "What's the content of this image?"encoding = processor(@@ -199,8 +200,8 @@ class TestTransformersModel(TestTorchConvertModel):example = dict(encoding)elif 'pix2struct' in mi.tags:model = Pix2StructForConditionalGeneration.from_pretrained(- name, **model_kwargs)- processor = AutoProcessor.from_pretrained(name)+ model_cached, **model_kwargs)+ processor = AutoProcessor.from_pretrained(model_cached)import requestsimage_url = "https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/transformers/tasks/ai2d-demo.jpg"@@ -217,25 +218,25 @@ class TestTransformersModel(TestTorchConvertModel):inputs = image_processor(images=self.image, return_tensors="pt")example = dict(inputs)elif "mms-lid" in name:- processor = AutoFeatureExtractor.from_pretrained(name)+ processor = AutoFeatureExtractor.from_pretrained(model_cached)input_values = processor(torch.randn(16000).numpy(),sampling_rate=16_000,return_tensors="pt")example = {"input_values": input_values.input_values}elif "retribert" in mi.tags:- tokenizer = RetriBertTokenizer.from_pretrained(name)+ tokenizer = RetriBertTokenizer.from_pretrained(model_cached)encoding1 = tokenizer("How many cats are there?", return_tensors="pt")encoding2 = tokenizer("Second text", return_tensors="pt")example = (encoding1.input_ids, encoding1.attention_mask,encoding2.input_ids, encoding2.attention_mask)elif "mgp-str" in mi.tags or "clip_vision_model" in mi.tags:- processor = AutoProcessor.from_pretrained(name)+ processor = AutoProcessor.from_pretrained(model_cached)encoded_input = processor(images=self.image, return_tensors="pt")example = (encoded_input.pixel_values,)elif "flava" in mi.tags:- model = FlavaImageModel.from_pretrained(name, **model_kwargs)- feature_extractor = AutoFeatureExtractor.from_pretrained(name)+ model = FlavaImageModel.from_pretrained(model_cached, **model_kwargs)+ feature_extractor = AutoFeatureExtractor.from_pretrained(model_cached)encoded_input = feature_extractor(images=[self.image],return_tensors="pt")@@ -243,11 +244,11 @@ class TestTransformersModel(TestTorchConvertModel):elif "vivit" in mi.tags:frames = list(torch.randint(0, 255, [32, 3, 224, 224]).to(torch.float32))- processor = VivitImageProcessor.from_pretrained(name)+ processor = VivitImageProcessor.from_pretrained(model_cached)encoded_input = processor(images=frames, return_tensors="pt")example = (encoded_input.pixel_values,)elif "tvlt" in mi.tags:- processor = AutoProcessor.from_pretrained(name)+ processor = AutoProcessor.from_pretrained(model_cached)num_frames = 8images = list(torch.rand(num_frames, 3, 224, 224))audio = list(torch.randn(10000))@@ -255,26 +256,26 @@ class TestTransformersModel(TestTorchConvertModel):images, audio, sampling_rate=44100, return_tensors="pt")example = dict(input_dict)elif "gptsan-japanese" in mi.tags:- processor = AutoTokenizer.from_pretrained(name)+ processor = AutoTokenizer.from_pretrained(model_cached)text = "織田信長は、"encoded_input = processor(text=[text], return_tensors="pt")example = dict(input_ids=encoded_input.input_ids,token_type_ids=encoded_input.token_type_ids)elif "videomae" in mi.tags or "timesformer" in mi.tags:- processor = AutoProcessor.from_pretrained(name)+ processor = AutoProcessor.from_pretrained(model_cached)video = list(torch.randint(0, 255, [16, 3, 224, 224]).to(torch.float32))inputs = processor(video, return_tensors="pt")example = dict(inputs)elif 'text-to-speech' in mi.tags:- tokenizer = AutoTokenizer.from_pretrained(name)+ tokenizer = AutoTokenizer.from_pretrained(model_cached)text = "some example text in the English language"inputs = tokenizer(text, return_tensors="pt")example = dict(inputs)elif 'musicgen' in mi.tags or "musicgen_melody" in mi.tags:- processor = AutoProcessor.from_pretrained(name)+ processor = AutoProcessor.from_pretrained(model_cached)model = AutoModelForTextToWaveform.from_pretrained(- name, **model_kwargs)+ model_cached, **model_kwargs)inputs = processor(text=["80s pop track with bassy drums and synth"],@@ -287,14 +288,14 @@ class TestTransformersModel(TestTorchConvertModel):example["decoder_input_ids"] = torch.ones((inputs.input_ids.shape[0] * model.decoder.num_codebooks, 1), dtype=torch.long) * pad_token_idelif 'kosmos-2' in mi.tags or 'instructblip' in mi.tags:- processor = AutoProcessor.from_pretrained(name)+ processor = AutoProcessor.from_pretrained(model_cached)prompt = "<grounding>An image of"inputs = processor(text=prompt, images=self.image, return_tensors="pt")example = dict(inputs)elif 'vitmatte' in mi.tags:- processor = AutoImageProcessor.from_pretrained(name)+ processor = AutoImageProcessor.from_pretrained(model_cached)filepath = hf_hub_download(repo_id="hf-internal-testing/image-matting-fixtures",filename="image.png",repo_type="dataset")@@ -307,7 +308,7 @@ class TestTransformersModel(TestTorchConvertModel):return_tensors="pt")example = dict(inputs)elif 'sam' in mi.tags:- processor = AutoProcessor.from_pretrained(name)+ processor = AutoProcessor.from_pretrained(model_cached)input_points = [[[450, 600]]]inputs = processor(self.image,input_points=input_points,@@ -318,7 +319,7 @@ class TestTransformersModel(TestTorchConvertModel):if "reshaped_input_sizes" in example:del example["reshaped_input_sizes"]elif 'udop' in mi.tags:- processor = AutoProcessor.from_pretrained(name, apply_ocr=False)+ processor = AutoProcessor.from_pretrained(model_cached, apply_ocr=False)dataset = load_dataset("nielsr/funsd-layoutlmv3", split="train")example = dataset[0]image = example["image"]@@ -335,7 +336,7 @@ class TestTransformersModel(TestTorchConvertModel):ds = ds.cast_column("audio", Audio(sampling_rate=22050))sorted_audio = ds.sort("id").select(range(1))[:1]["audio"][0]_, audio, sr = sorted_audio.values()- processor = AutoProcessor.from_pretrained(name)+ processor = AutoProcessor.from_pretrained(model_cached)inputs = processor(raw_speech=audio, sampling_rate=sr,text=text, return_tensors="pt")example = dict(inputs)@@ -364,7 +365,7 @@ class TestTransformersModel(TestTorchConvertModel):future_time_features=batch["future_time_features"])elif "seg-ment-tation" in mi.tags:- image_processor = AutoImageProcessor.from_pretrained(name)+ image_processor = AutoImageProcessor.from_pretrained(model_cached)inputs = image_processor(images=self.image, return_tensors="pt")example = dict(inputs)elif "lxmert" in mi.tags:@@ -375,24 +376,24 @@ class TestTransformersModel(TestTorchConvertModel):else:try:if auto_model == "AutoModelForCausalLM":- tokenizer = AutoTokenizer.from_pretrained(name)+ tokenizer = AutoTokenizer.from_pretrained(model_cached)text = "Replace me by any text you'd like."encoded_input = tokenizer(text, return_tensors='pt')example = dict(encoded_input)if "facebook/incoder" in name and "token_type_ids" in example:del example["token_type_ids"]elif auto_model == "AutoModelForMaskedLM":- tokenizer = AutoTokenizer.from_pretrained(name)+ tokenizer = AutoTokenizer.from_pretrained(model_cached)text = "Replace me by any text you'd like."encoded_input = tokenizer(text, return_tensors='pt')example = dict(encoded_input)elif auto_model == "AutoModelForImageClassification":- processor = AutoProcessor.from_pretrained(name)+ processor = AutoProcessor.from_pretrained(model_cached)encoded_input = processor(images=self.image, return_tensors="pt")example = dict(encoded_input)elif auto_model == "AutoModelForSeq2SeqLM":- tokenizer = AutoTokenizer.from_pretrained(name)+ tokenizer = AutoTokenizer.from_pretrained(model_cached)inputs = tokenizer("Studies have been shown that owning a dog is good for you", return_tensors="pt")decoder_inputs = tokenizer(@@ -403,19 +404,19 @@ class TestTransformersModel(TestTorchConvertModel):example = dict(input_ids=inputs.input_ids,decoder_input_ids=decoder_inputs.input_ids)elif auto_model == "AutoModelForSpeechSeq2Seq":- processor = AutoProcessor.from_pretrained(name)+ processor = AutoProcessor.from_pretrained(model_cached)inputs = processor(torch.randn(1000).numpy(),sampling_rate=16000,return_tensors="pt")example = dict(inputs)elif auto_model == "AutoModelForCTC":- processor = AutoProcessor.from_pretrained(name)+ processor = AutoProcessor.from_pretrained(model_cached)input_values = processor(torch.randn(1000).numpy(),return_tensors="pt")example = dict(input_values)elif auto_model == "AutoModelForTableQuestionAnswering":import pandas as pd- tokenizer = AutoTokenizer.from_pretrained(name)+ tokenizer = AutoTokenizer.from_pretrained(model_cached)data = {"Actors": ["Brad Pitt", "Leonardo Di Caprio", "George Clooney"],"Number of movies": ["87", "53", "69"]}queries = ["What is the name of the first actor?",@@ -433,11 +434,11 @@ class TestTransformersModel(TestTorchConvertModel):else:text = "Replace me by any text you'd like."if auto_processor is not None and "Tokenizer" not in auto_processor:- processor = AutoProcessor.from_pretrained(name)+ processor = AutoProcessor.from_pretrained(model_cached)encoded_input = processor(text=[text], images=self.image, return_tensors="pt", padding=True)else:- tokenizer = AutoTokenizer.from_pretrained(name)+ tokenizer = AutoTokenizer.from_pretrained(model_cached)encoded_input = tokenizer(text, return_tensors='pt')example = dict(encoded_input)except:@@ -505,6 +506,7 @@ class TestTransformersModel(TestTorchConvertModel):@staticmethoddef load_model_with_default_class(name, **kwargs):+ model_cached = snapshot_download(name) # required to avoid HF rate limitstry:mi = model_info(name)assert len({"owlv2", "owlvit", "vit_mae"}.intersection(@@ -513,9 +515,9 @@ class TestTransformersModel(TestTorchConvertModel):mi.config["architectures"]) == 1class_name = mi.config["architectures"][0]model_class = getattr(transformers, class_name)- return model_class.from_pretrained(name, **kwargs)+ return model_class.from_pretrained(model_cached, **kwargs)except:- return AutoModel.from_pretrained(name, **kwargs)+ return AutoModel.from_pretrained(model_cached, **kwargs)@pytest.mark.parametrize("name,type", [("allenai/led-base-16384", "led"),("bert-base-uncased", "bert"),diff --git a/tests/model_hub_tests/pytorch/test_llm.py b/tests/model_hub_tests/pytorch/test_llm.pyindex 7f3a214636d..376ccf0cd80 100644--- a/tests/model_hub_tests/pytorch/test_llm.py+++ b/tests/model_hub_tests/pytorch/test_llm.py@@ -7,6 +7,7 @@ import inspectimport numpy as npimport pytestimport torch+from huggingface_hub import snapshot_downloadfrom transformers import AutoConfig, AutoTokenizer, AutoModelForCausalLMfrom models_hub_common.utils import retry@@ -142,8 +143,9 @@ class TestLLMModel(TestTorchConvertModel):def load_model(self, name, type):model = Noneexample = None+ model_cached = snapshot_download(name) # required to avoid HF rate limitstry:- config = AutoConfig.from_pretrained(name, trust_remote_code=True)+ config = AutoConfig.from_pretrained(model_cached, trust_remote_code=True)except Exception:config = {}model_kwargs = {"torchscript": True, "trust_remote_code": True}@@ -159,9 +161,9 @@ class TestLLMModel(TestTorchConvertModel):model_kwargs["torch_dtype"] = torch.float16else:model_kwargs["torch_dtype"] = "auto"-- t = AutoTokenizer.from_pretrained(name, trust_remote_code=True)- self.model = AutoModelForCausalLM.from_pretrained(name, **model_kwargs)+ model_cached = snapshot_download(name) # required to avoid HF rate limits+ t = AutoTokenizer.from_pretrained(model_cached, trust_remote_code=True)+ self.model = AutoModelForCausalLM.from_pretrained(model_cached, **model_kwargs)if is_quant:model = self.modelelse:diff --git a/tests/model_hub_tests/tensorflow/test_tf_convert_model.py b/tests/model_hub_tests/tensorflow/test_tf_convert_model.pyindex 5fb1981b418..468712b7e90 100644--- a/tests/model_hub_tests/tensorflow/test_tf_convert_model.py+++ b/tests/model_hub_tests/tensorflow/test_tf_convert_model.py@@ -12,6 +12,7 @@ import tensorflow.compat.v1 as tf_v1import tensorflow_hub as hub# noinspection PyUnresolvedReferencesimport tensorflow_text # do not delete, needed for text models+from huggingface_hub import snapshot_downloadfrom models_hub_common.test_convert_model import TestConvertModelfrom models_hub_common.utils import get_models_listfrom openvino import Core@@ -43,13 +44,14 @@ class TestTFHubConvertModel(TestConvertModel):def load_model(self, model_name, model_link: str):if is_hf_link(model_link):+ model_cached = snapshot_download(model_name) # required to avoid HF rate limitslibrary_type = model_link[3:]if library_type == "transformers":from transformers import TFAutoModel- return TFAutoModel.from_pretrained(model_name)+ return TFAutoModel.from_pretrained(model_cached)elif library_type == "sentence-transformers":from tf_sentence_transformers import SentenceTransformer- return SentenceTransformer.from_pretrained(model_name)+ return SentenceTransformer.from_pretrained(model_cached)elif 'storage.openvinotoolkit.org' in model_link:# this models is from public OpenVINO storagesubprocess.check_call(["wget", "-nv", model_link], cwd=self.model_dir.name)