From ffa61e0511e95ce71cc71a0247d7bbc7a7066ee5 Mon Sep 17 00:00:00 2001 From: Pawel Kowalczyk Date: Mon, 24 Aug 2026 14:47:09 +0200 Subject: [PATCH 1/6] Added HFASRPipeline to asr_pipeline_evaluator --- .../asr_pipeline_evaluator.py | 79 +++++++++++++++++++ 1 file changed, 79 insertions(+) diff --git a/tools/accuracy_checker/accuracy_checker/evaluators/custom_evaluators/asr_pipeline_evaluator.py b/tools/accuracy_checker/accuracy_checker/evaluators/custom_evaluators/asr_pipeline_evaluator.py index 3b0680a4575..e69de4e8264 100644 --- a/tools/accuracy_checker/accuracy_checker/evaluators/custom_evaluators/asr_pipeline_evaluator.py +++ b/tools/accuracy_checker/accuracy_checker/evaluators/custom_evaluators/asr_pipeline_evaluator.py @@ -31,6 +31,7 @@ class ASRPipelineEvaluator(BaseCustomEvaluator): VALID_PIPELINE_CLASSES = [ "GenAIASRPipeline", + "HFASRPipeline", "Qwen3ASROptimumPipeline", ] @@ -225,3 +226,81 @@ def parse_asr_output(raw_text): "language": language_match.group(1) if language_match else None, "text": text_match.group(1).strip() if text_match else raw_text.strip(), } + + +class HFASRPipeline(ASRPipeline): + def __init__(self, config): + self.language = config.get("language") + self.max_new_tokens = config.get("max_new_tokens", 1000) + super().__init__(config) + + def _initialize_pipeline(self, config): + model_id = config.get("model_id") + + try: + from qwen_asr import Qwen3ASRModel # pylint: disable=C0415 + except ImportError: + Qwen3ASRModel = None + + if Qwen3ASRModel is not None: + return Qwen3ASRModel.from_pretrained( + model_id, + max_inference_batch_size=1, + max_new_tokens=self.max_new_tokens, + ) + + try: + import torch # pylint: disable=C0415 + except ImportError as import_error: + UnsupportedPackage("torch", import_error.msg).raise_error(self.__class__.__name__) + + try: + from transformers import AutoModelForSpeechSeq2Seq, AutoProcessor # pylint: disable=C0415 + from transformers.pipelines.automatic_speech_recognition import ( # pylint: disable=C0415 + AutomaticSpeechRecognitionPipeline, + ) + except ImportError as import_error: + UnsupportedPackage("transformers", import_error.msg).raise_error( + self.__class__.__name__ + ) + + device = "cpu" + torch_dtype = torch.float16 if torch.cuda.is_available() else torch.float32 + model = AutoModelForSpeechSeq2Seq.from_pretrained( + model_id, torch_dtype=torch_dtype, low_cpu_mem_usage=True + ).to(device) + + processor = AutoProcessor.from_pretrained(model_id) + + pipeline = AutomaticSpeechRecognitionPipeline( + model=model, + tokenizer=processor.tokenizer, + feature_extractor=processor.feature_extractor, + torch_dtype=torch_dtype, + device=device, + ) + return pipeline + + def _get_predictions(self, data, identifiers, input_meta): + sampling_rate = input_meta[0].get("sample_rate") + if hasattr(self.pipeline, "transcribe"): + result = self.pipeline.transcribe( + (data[0], sampling_rate), + context=identifiers[0], + language=self.language, + return_time_stamps=False, + ) + return result[0].text + + sample = { + "path": identifiers[0], + "array": data[0], + "sampling_rate": sampling_rate, + } + return self.pipeline( + sample, + return_timestamps=True, + generate_kwargs={ + "num_beams": 1, + }, + )["text"] From cad02252b1a344d60b3e8b28cbb851655d4933fd Mon Sep 17 00:00:00 2001 From: Pawel Kowalczyk Date: Thu, 27 Aug 2026 14:05:01 +0200 Subject: [PATCH 2/6] Added fix for handling flac files to LibrispeechConverter --- .../annotation_converters/librispeech.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/tools/accuracy_checker/accuracy_checker/annotation_converters/librispeech.py b/tools/accuracy_checker/accuracy_checker/annotation_converters/librispeech.py index b2e5452e447..0edc3a7d194 100644 --- a/tools/accuracy_checker/accuracy_checker/annotation_converters/librispeech.py +++ b/tools/accuracy_checker/accuracy_checker/annotation_converters/librispeech.py @@ -19,6 +19,7 @@ import json import wave import numpy as np +import soundfile as sf from ..representation import CharacterRecognitionAnnotation from ..config import PathField, NumberField, BoolField @@ -74,8 +75,12 @@ def convert(self, check_content=False, **kwargs): continue if self.max_duration > 0 and not self.annotation_file: - with wave.open(str(fname), "rb") as wav: - duration = wav.getnframes() / wav.getframerate() + if self.flac_files: + info = sf.info(str(fname)) + duration = info.frames / info.samplerate + else: + with wave.open(str(fname), "rb") as wav: + duration = wav.getnframes() / wav.getframerate() if duration > self.max_duration: continue From 515d972b604a626feefd42b9fb4a3953ecee58bc Mon Sep 17 00:00:00 2001 From: Pawel Kowalczyk Date: Thu, 27 Aug 2026 16:42:25 +0200 Subject: [PATCH 3/6] Added soundfile to test requirements --- tools/accuracy_checker/requirements-test.in | 1 + 1 file changed, 1 insertion(+) diff --git a/tools/accuracy_checker/requirements-test.in b/tools/accuracy_checker/requirements-test.in index 670b7169839..f4e4019a89e 100644 --- a/tools/accuracy_checker/requirements-test.in +++ b/tools/accuracy_checker/requirements-test.in @@ -11,3 +11,4 @@ opencv-python==4.10.0.84 # So as a workaround, make the atomicwrites dependency unconditional. atomicwrites datasets +soundfile From 4d34b88e095afae4e78763c0a841d8d8ea83b9d6 Mon Sep 17 00:00:00 2001 From: Pawel Kowalczyk Date: Thu, 27 Aug 2026 16:52:08 +0200 Subject: [PATCH 4/6] Fixed param naming in HFASRPipeline --- .../evaluators/custom_evaluators/asr_pipeline_evaluator.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tools/accuracy_checker/accuracy_checker/evaluators/custom_evaluators/asr_pipeline_evaluator.py b/tools/accuracy_checker/accuracy_checker/evaluators/custom_evaluators/asr_pipeline_evaluator.py index e69de4e8264..3d4d5a0dc2e 100644 --- a/tools/accuracy_checker/accuracy_checker/evaluators/custom_evaluators/asr_pipeline_evaluator.py +++ b/tools/accuracy_checker/accuracy_checker/evaluators/custom_evaluators/asr_pipeline_evaluator.py @@ -281,19 +281,19 @@ def _initialize_pipeline(self, config): ) return pipeline - def _get_predictions(self, data, identifiers, input_meta): + def _get_predictions(self, data, identifier, input_meta): sampling_rate = input_meta[0].get("sample_rate") if hasattr(self.pipeline, "transcribe"): result = self.pipeline.transcribe( (data[0], sampling_rate), - context=identifiers[0], + context=identifier, language=self.language, return_time_stamps=False, ) return result[0].text sample = { - "path": identifiers[0], + "path": identifier, "array": data[0], "sampling_rate": sampling_rate, } From eb94729a313d73a052b6b7e8cd479dd7370e57d8 Mon Sep 17 00:00:00 2001 From: Pawel Kowalczyk Date: Thu, 3 Sep 2026 17:15:53 +0200 Subject: [PATCH 5/6] Improved import of soundfile --- .../accuracy_checker/annotation_converters/librispeech.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/tools/accuracy_checker/accuracy_checker/annotation_converters/librispeech.py b/tools/accuracy_checker/accuracy_checker/annotation_converters/librispeech.py index 0edc3a7d194..b2311bb537e 100644 --- a/tools/accuracy_checker/accuracy_checker/annotation_converters/librispeech.py +++ b/tools/accuracy_checker/accuracy_checker/annotation_converters/librispeech.py @@ -19,11 +19,16 @@ import json import wave import numpy as np -import soundfile as sf from ..representation import CharacterRecognitionAnnotation from ..config import PathField, NumberField, BoolField from .format_converter import DirectoryBasedAnnotationConverter, ConverterReturn +from ..utils import UnsupportedPackage + +try: + import soundfile as sf +except (ImportError, OSError) as import_error: + sf = UnsupportedPackage('soundfile', str(import_error)) class LibrispeechConverter(DirectoryBasedAnnotationConverter): From d09ace676bb548233950d872484a11a98fd8ea97 Mon Sep 17 00:00:00 2001 From: Pawel Kowalczyk Date: Fri, 4 Sep 2026 16:34:48 +0200 Subject: [PATCH 6/6] Updated HFASRPipeline to recognize qwen3-asr model type. Added pytests for HFASRPipeline. --- .../asr_pipeline_evaluator.py | 29 ++++++++++--------- .../tests/test_asr_pipeline_evaluator.py | 17 +++++++++++ 2 files changed, 32 insertions(+), 14 deletions(-) diff --git a/tools/accuracy_checker/accuracy_checker/evaluators/custom_evaluators/asr_pipeline_evaluator.py b/tools/accuracy_checker/accuracy_checker/evaluators/custom_evaluators/asr_pipeline_evaluator.py index 3d4d5a0dc2e..1c0b82aac11 100644 --- a/tools/accuracy_checker/accuracy_checker/evaluators/custom_evaluators/asr_pipeline_evaluator.py +++ b/tools/accuracy_checker/accuracy_checker/evaluators/custom_evaluators/asr_pipeline_evaluator.py @@ -237,17 +237,18 @@ def __init__(self, config): def _initialize_pipeline(self, config): model_id = config.get("model_id") - try: - from qwen_asr import Qwen3ASRModel # pylint: disable=C0415 - except ImportError: - Qwen3ASRModel = None - - if Qwen3ASRModel is not None: - return Qwen3ASRModel.from_pretrained( - model_id, - max_inference_batch_size=1, - max_new_tokens=self.max_new_tokens, - ) + if "qwen3" in str(model_id).lower() and "asr" in str(model_id).lower(): + try: + from qwen_asr import Qwen3ASRModel # pylint: disable=C0415 + except ImportError: + Qwen3ASRModel = None + + if Qwen3ASRModel is not None: + return Qwen3ASRModel.from_pretrained( + model_id, + max_inference_batch_size=1, + max_new_tokens=self.max_new_tokens, + ) try: import torch # pylint: disable=C0415 @@ -264,11 +265,11 @@ def _initialize_pipeline(self, config): self.__class__.__name__ ) - device = "cpu" + device = config.get("_device", "cpu") torch_dtype = torch.float16 if torch.cuda.is_available() else torch.float32 model = AutoModelForSpeechSeq2Seq.from_pretrained( model_id, torch_dtype=torch_dtype, low_cpu_mem_usage=True - ).to(device) + ).to(device.lower()) processor = AutoProcessor.from_pretrained(model_id) @@ -277,7 +278,7 @@ def _initialize_pipeline(self, config): tokenizer=processor.tokenizer, feature_extractor=processor.feature_extractor, torch_dtype=torch_dtype, - device=device, + device=device.lower(), ) return pipeline diff --git a/tools/accuracy_checker/tests/test_asr_pipeline_evaluator.py b/tools/accuracy_checker/tests/test_asr_pipeline_evaluator.py index 3dd5b7d4d50..4f0e4d9696c 100644 --- a/tools/accuracy_checker/tests/test_asr_pipeline_evaluator.py +++ b/tools/accuracy_checker/tests/test_asr_pipeline_evaluator.py @@ -20,6 +20,7 @@ from accuracy_checker.evaluators.custom_evaluators.asr_pipeline_evaluator import ( ASRPipelineEvaluator, GenAIASRPipeline, + HFASRPipeline ) from datasets import load_dataset @@ -90,3 +91,19 @@ def test_genai_asr_pipeline(self): result = evaluator.pipe._get_predictions(input_data, identifiers[0], input_meta) assert isinstance(result, str) + + def test_hf_asr_pipeline_qwen3_asr(self): + config = {"_device": "CPU", "model_id": "Qwen/Qwen3-ASR-0.6B"} + pipeline = HFASRPipeline(config) + evaluator = ASRPipelineEvaluator(None, pipeline, None) + + result = evaluator.pipe._get_predictions(input_data, identifiers[0], input_meta) + assert isinstance(result, str) + + def test_hf_asr_pipeline_whisper_tiny(self): + config = {"_device": "CPU", "model_id": "openai/whisper-tiny"} + pipeline = HFASRPipeline(config) + evaluator = ASRPipelineEvaluator(None, pipeline, None) + + result = evaluator.pipe._get_predictions(input_data, identifiers[0], input_meta) + assert isinstance(result, str)