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][LLM] Avoid sporadic library inference failure in llm accuracy (#36799)
Mikhail Ryzhovb34b278ae545
diff --git a/tests/llm/accuracy_conformance.py b/tests/llm/accuracy_conformance.pyindex b332b434d98..2fd46a72680 100644--- a/tests/llm/accuracy_conformance.py+++ b/tests/llm/accuracy_conformance.py@@ -1,3 +1,6 @@+# Copyright (C) 2018-2026 Intel Corporation+# SPDX-License-Identifier: Apache-2.0+import gcimport loggingimport os@@ -100,18 +103,38 @@ def setup_model(model_id):logger.info(f"Setting up model: {model_id}")- # Download original model- model_cached = snapshot_download(model_id) # required to avoid HF rate limits+ # Download original model from a Hugging Face snapshot to get a stable, canonical on-disk layout+ # (once cached, subsequent `from_pretrained(..., local_files_only=True)` calls are fully offline)+ model_cached = snapshot_download(model_id)model = AutoModelForCausalLM.from_pretrained(model_cached, local_files_only=True)tokenizer = AutoTokenizer.from_pretrained(model_cached, local_files_only=True)- # Save original model+ # Cache original model for reuse in repeated test runs and potential future tests+ # This improves efficiency when PYTEST_DO_NOT_CLEANUP is enabledmodel_path = get_model_path(model_id, "org")if not os.path.exists(model_path):- logger.info(f"Saving original model: {model_path}")+ logger.info(f"Caching original model: {model_path}")model.save_pretrained(model_path)tokenizer.save_pretrained(model_path)+ # Prepare ground truth data+ set_seed(42)+ use_chat_template = tokenizer is not None and tokenizer.chat_template is not None+ gt_path = get_gt_path(model_id, use_chat_template)+ if not os.path.exists(gt_path):+ logger.info(f'Creating ground truth data: {gt_path}')+ evaluator = wwb.Evaluator(+ base_model=model,+ tokenizer=tokenizer,+ num_samples=NUMBER_OF_SAMPLES,+ use_chat_template=use_chat_template+ )+ evaluator.dump_gt(gt_path)+ del evaluator++ del model+ gc.collect() # Free large base model before quantization steps+# Convert tokenizer for OpenVINOov_tokenizer, ov_detokenizer = convert_tokenizer(tokenizer, with_detokenizer=True)@@ -119,40 +142,28 @@ def setup_model(model_id):int8_model_path = get_model_path(model_id, PREC_INT8)if not os.path.exists(int8_model_path):logger.info(f'Creating INT8 OpenVINO model: {int8_model_path}')- ov_model = OVModelForCausalLM.from_pretrained(model_path, load_in_8bit=True)+ ov_model = OVModelForCausalLM.from_pretrained(model_cached, local_files_only=True, load_in_8bit=True)ov_model.save_pretrained(int8_model_path)tokenizer.save_pretrained(int8_model_path)del ov_modelsave_model(ov_tokenizer, os.path.join(int8_model_path, "openvino_tokenizer.xml"))save_model(ov_detokenizer, os.path.join(int8_model_path, "openvino_detokenizer.xml"))- gc.collect()# Prepare INT4 modelint4_model_path = get_model_path(model_id, PREC_INT4)if not os.path.exists(int4_model_path):logger.info(f'Creating INT4 OpenVINO model: {int4_model_path}')quantization_config = OVWeightQuantizationConfig(bits=4, ratio=0.8)- quantized_model = OVModelForCausalLM.from_pretrained(model_path, quantization_config=quantization_config)+ quantized_model = OVModelForCausalLM.from_pretrained(+ model_cached,+ local_files_only=True,+ quantization_config=quantization_config,+ )quantized_model.save_pretrained(int4_model_path)tokenizer.save_pretrained(int4_model_path)del quantized_modelsave_model(ov_tokenizer, os.path.join(int4_model_path, "openvino_tokenizer.xml"))save_model(ov_detokenizer, os.path.join(int4_model_path, "openvino_detokenizer.xml"))- gc.collect()-- # Prepare ground truth data- set_seed(42)- use_chat_template = tokenizer is not None and tokenizer.chat_template is not None- gt_path = get_gt_path(model_id, use_chat_template)- if not os.path.exists(gt_path):- logger.info(f'Creating ground truth data: {gt_path}')- evaluator = wwb.Evaluator(- base_model=model,- tokenizer=tokenizer,- num_samples=NUMBER_OF_SAMPLES,- use_chat_template=use_chat_template- )- evaluator.dump_gt(gt_path)# Mark model as downloadedDOWNLOADED_MODELS.add(model_id)