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
[TESTS][HF] Use snapshot_download() in HF tests (#32282)
Mikhail Ryzhove6264070ff29
diff --git a/tests/model_hub_tests/transformation_tests/generate_ref_diffs.py b/tests/model_hub_tests/transformation_tests/generate_ref_diffs.pyindex 055f55af44e..5a64fc987d3 100644--- a/tests/model_hub_tests/transformation_tests/generate_ref_diffs.py+++ b/tests/model_hub_tests/transformation_tests/generate_ref_diffs.py@@ -38,6 +38,7 @@ for generating the same map, but utilizing cache-eviction.import osimport sys+from huggingface_hub import snapshot_downloadfrom pathlib import Pathimport models_hub_common.utils as utilsfrom openvino._offline_transformations import paged_attention_transformation@@ -92,7 +93,8 @@ def main():for model_id, _, _, _, cls in model_list:# wrapping in try/catch block to continue printing models even if one has failedtry:- model = cls.from_pretrained(model_id, export=True, trust_remote_code=True)+ model_cached = snapshot_download(model_id) # required to avoid HF rate limits+ model = cls.from_pretrained(model_cached, export=True, trust_remote_code=True)except:print(f"Couldn't read {model_id}.")continuediff --git a/tests/model_hub_tests/transformation_tests/test_gptq_torchfx_transformations.py b/tests/model_hub_tests/transformation_tests/test_gptq_torchfx_transformations.pyindex 9e4e2680bc2..5681cbecef8 100644--- a/tests/model_hub_tests/transformation_tests/test_gptq_torchfx_transformations.py+++ b/tests/model_hub_tests/transformation_tests/test_gptq_torchfx_transformations.py@@ -1,6 +1,7 @@# Copyright (C) 2018-2025 Intel Corporation# SPDX-License-Identifier: Apache-2.0+from huggingface_hub import snapshot_downloadfrom transformers import AutoConfig, AutoTokenizer, AutoModelForCausalLM, pipelineimport torchimport hashlib@@ -40,11 +41,12 @@ def patch_gptq(config):return orig_cuda_check, orig_post_init_modeldef run_gptq_torchfx(tmp_path, model_id, model_link, prompt_result_pair):- config = AutoConfig.from_pretrained(model_id, trust_remote_code=True, torch_dtype=torch.float32)+ model_cached = snapshot_download(model_id) # required to avoid HF rate limits+ config = AutoConfig.from_pretrained(model_cached, trust_remote_code=True, torch_dtype=torch.float32)cuda, post_init = patch_gptq(config)- tokenizer = AutoTokenizer.from_pretrained(model_id, trust_remote_code=True, torch_dtype=torch.float32)+ tokenizer = AutoTokenizer.from_pretrained(model_cached, trust_remote_code=True, torch_dtype=torch.float32)model = AutoModelForCausalLM.from_pretrained(- model_id,+ model_cached,trust_remote_code=True,config=config,device_map='cpu',diff --git a/tests/model_hub_tests/transformation_tests/test_pa_transformation.py b/tests/model_hub_tests/transformation_tests/test_pa_transformation.pyindex 39a82342885..2b227389da3 100644--- a/tests/model_hub_tests/transformation_tests/test_pa_transformation.py+++ b/tests/model_hub_tests/transformation_tests/test_pa_transformation.py@@ -1,6 +1,7 @@# Copyright (C) 2018-2025 Intel Corporation# SPDX-License-Identifier: Apache-2.0+from huggingface_hub import snapshot_downloadfrom openvino._offline_transformations import paged_attention_transformationfrom openvino._pyopenvino.op import _PagedAttentionExtensionfrom optimum.intel import OVModelForCausalLM@@ -127,7 +128,9 @@ def run_pa(tmp_path,allow_cache_rotation,allow_xattention,ie_device):- model = cls.from_pretrained(model_id, export=True, trust_remote_code=True)+ model_cached = snapshot_download(model_id) # required to avoid HF rate limits+ model = cls.from_pretrained(model_cached, export=True, trust_remote_code=True)+ov_model = model.model if cls is OVModelForCausalLM else model.lm_modelapply_transformation_and_compare_diffs(ov_model, model_id, use_block_indices_inputs, use_score_outputs, allow_score_aggregation, allow_cache_rotation, allow_xattention, ie_device)diff --git a/tests/model_hub_tests/transformation_tests/test_stateful_to_stateless_transformation.py b/tests/model_hub_tests/transformation_tests/test_stateful_to_stateless_transformation.pyindex d2a37c97f27..372ee9ff85e 100644--- a/tests/model_hub_tests/transformation_tests/test_stateful_to_stateless_transformation.py+++ b/tests/model_hub_tests/transformation_tests/test_stateful_to_stateless_transformation.py@@ -2,6 +2,7 @@# SPDX-License-Identifier: Apache-2.0import openvino as ov+from huggingface_hub import snapshot_downloadfrom openvino._offline_transformations import stateful_to_stateless_transformationfrom optimum.intel import OVModelForCausalLMfrom models_hub_common.utils import retry@@ -51,7 +52,8 @@ def check_result_desc_tensors(expected_tensors, tensors):@retry(3, exceptions=(OSError,), delay=1)def run_stateful_to_stateless_in_runtime(tmp_path, model_id, model_link):- model = OVModelForCausalLM.from_pretrained(model_id, export=True, stateful=True, compile=False)+ model_cached = snapshot_download(model_id) # required to avoid HF rate limits+ model = OVModelForCausalLM.from_pretrained(model_cached, export=True, stateful=True, compile=False)assert len(model.model.get_sinks()), f"Input model is not in the expected stateful form because it doesn't have any sinks."assert len(get_read_value_ops(model.model)), f"Input model is not in the expected stateful form because it doesn't have any ReadValue operations."@@ -62,7 +64,7 @@ def run_stateful_to_stateless_in_runtime(tmp_path, model_id, model_link):assert len(sink_ops) == 0, f"Expected stateless model, but there are sinks found: {sink_ops}"assert len(read_value_ops) == 0, f"Expected stateless model, but there are ReadValue operations found: {read_value_ops}"- stateless_model = OVModelForCausalLM.from_pretrained(model_id, export=True, stateful=False, compile=False)+ stateless_model = OVModelForCausalLM.from_pretrained(model_cached, export=True, stateful=False, compile=False)print(model.model)print(stateless_model.model)diff --git a/tests/model_hub_tests/transformation_tests/test_transformations.py b/tests/model_hub_tests/transformation_tests/test_transformations.pyindex 4f60e488288..13d55548bed 100644--- a/tests/model_hub_tests/transformation_tests/test_transformations.py+++ b/tests/model_hub_tests/transformation_tests/test_transformations.py@@ -1,7 +1,7 @@# Copyright (C) 2018-2025 Intel Corporation# SPDX-License-Identifier: Apache-2.0-+from huggingface_hub import snapshot_downloadfrom optimum.intel import OVModelForCausalLMimport models_hub_common.utils as utilsimport pytest@@ -72,7 +72,8 @@ class EnvVar:def run_test(model_id, ie_device, ts_names, expected_layer_types):- model = OVModelForCausalLM.from_pretrained(model_id, export=True, trust_remote_code=True)+ model_cached = snapshot_download(model_id) # required to avoid HF rate limits+ model = OVModelForCausalLM.from_pretrained(model_cached, export=True, trust_remote_code=True)with tempfile.NamedTemporaryFile(delete=True) as temp_file, \EnvVar({'OV_ENABLE_PROFILE_PASS': temp_file.name}):