Skip to content

Commit 2a540d5

Browse files
Tests: skip audio model tests when torchaudio or librosa is missing (#50423)
* Tests: skip the Higgs Audio V2 tokenizer tests without torchaudio The model requires the torchaudio backend, so without it every test failed on the missing-backend placeholder instead of skipping. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * Tests: import librosa only when available in the Qwen audio tests Qwen2.5-Omni, Qwen2-Audio and Qwen3-Omni-MoE imported librosa at module level, so without it the whole file failed to collect. Only the integration tests load audio with it: they now require it, and the rest run. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
1 parent 9ae35c1 commit 2a540d5

4 files changed

Lines changed: 20 additions & 4 deletions

File tree

‎tests/models/higgs_audio_v2_tokenizer/test_modeling_higgs_audio_v2_tokenizer.py‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
require_flash_attn,
3030
require_torch,
3131
require_torch_gpu,
32+
require_torchaudio,
3233
slow,
3334
torch_device,
3435
)
@@ -105,6 +106,7 @@ def create_and_check_model_forward(self, config, inputs_dict):
105106

106107

107108
@require_torch
109+
@require_torchaudio
108110
class HiggsAudioV2TokenizerModelTest(ModelTesterMixin, unittest.TestCase):
109111
all_model_classes = (HiggsAudioV2TokenizerModel,) if is_torch_available() else ()
110112
is_encoder_decoder = True

‎tests/models/qwen2_5_omni/test_modeling_qwen2_5_omni.py‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
from io import BytesIO
2020
from urllib.request import urlopen
2121

22-
import librosa
2322
import pytest
2423
import requests
2524

@@ -35,9 +34,11 @@
3534
from transformers.testing_utils import (
3635
Expectations,
3736
cleanup,
37+
is_librosa_available,
3838
require_deterministic_for_accelerator,
3939
require_deterministic_for_xpu,
4040
require_flash_attn,
41+
require_librosa,
4142
require_torch,
4243
require_torch_accelerator,
4344
slow,
@@ -54,6 +55,9 @@
5455
from ...test_pipeline_mixin import PipelineTesterMixin
5556

5657

58+
if is_librosa_available():
59+
import librosa
60+
5761
if is_torch_available():
5862
import torch
5963

@@ -604,6 +608,7 @@ def test_get_rope_index_video_with_audio(self):
604608

605609

606610
@require_torch
611+
@require_librosa
607612
class Qwen2_5OmniModelIntegrationTest(unittest.TestCase):
608613
def setUp(self):
609614
self.processor = AutoProcessor.from_pretrained("Qwen/Qwen2.5-Omni-7B")

‎tests/models/qwen2_audio/test_modeling_qwen2_audio.py‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,6 @@
1717
from io import BytesIO
1818
from urllib.request import urlopen
1919

20-
import librosa
21-
2220
from transformers import (
2321
AutoProcessor,
2422
Qwen2AudioConfig,
@@ -28,6 +26,8 @@
2826
)
2927
from transformers.testing_utils import (
3028
cleanup,
29+
is_librosa_available,
30+
require_librosa,
3131
require_torch,
3232
slow,
3333
torch_device,
@@ -36,6 +36,9 @@
3636
from ...alm_tester import ALMModelTest, ALMModelTester
3737

3838

39+
if is_librosa_available():
40+
import librosa
41+
3942
if is_torch_available():
4043
import torch
4144

@@ -79,6 +82,7 @@ def test_inputs_embeds_matches_input_ids(self):
7982

8083

8184
@require_torch
85+
@require_librosa
8286
class Qwen2AudioForConditionalGenerationIntegrationTest(unittest.TestCase):
8387
def setUp(self):
8488
cleanup(torch_device, gc_collect=True)

‎tests/models/qwen3_omni_moe/test_modeling_qwen3_omni_moe.py‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
from io import BytesIO
2020
from urllib.request import urlopen
2121

22-
import librosa
2322
import pytest
2423
import requests
2524

@@ -39,7 +38,9 @@
3938
Expectations,
4039
backend_device_count,
4140
get_cpu_ram_total_gib,
41+
is_librosa_available,
4242
require_flash_attn,
43+
require_librosa,
4344
require_torch,
4445
require_torch_accelerator,
4546
run_first,
@@ -59,6 +60,9 @@
5960
from ...test_tensor_parallel_mixin import TensorParallelTesterMixin
6061

6162

63+
if is_librosa_available():
64+
import librosa
65+
6266
if is_torch_available():
6367
import torch
6468

@@ -691,6 +695,7 @@ def test_code_predictor_config_init(self):
691695

692696

693697
@require_torch
698+
@require_librosa
694699
class Qwen3OmniModelIntegrationTest(MemoryCleanupMixin, unittest.TestCase):
695700
maxDiff = None
696701

0 commit comments

Comments
 (0)