@tduncan / Nvidia-Optimization-Stack-VLLM Mirror · read-only / commits / 7a3a83e3b8
Fork 0

A high-throughput and memory-efficient inference and serving engine for LLMs

Mirrored from https://github.com/tduncan-lum/Nvidia-Optimization-Stack---VLLM.git

Synced Nov 16, 03:15 UTC

[CI/Build] Move model-specific multi-modal processing tests (#11934)

Signed-off-by: DarkLight1337 <tlleungac@connect.ust.hk>

Cyrus Leung committed Jan 11, 2025 at 13:50 UTC 7a3a83e3b87f50fe9c0985a5c5bcc1d4cf2e95cd
13 files changed +251 -240
.buildkite/test-pipeline.yaml
+1
@@ -368,6 +368,7 @@ steps:
368 - tests/models/encoder_decoder/vision_language
369 commands:
370 - pip install git+https://github.com/TIGER-AI-Lab/Mantis.git
371 + - pytest -v -s models/multimodal
372 - pytest -v -s models/decoder_only/audio_language -m 'core_model or quant_model'
373 - pytest -v -s --ignore models/decoder_only/vision_language/test_phi3v.py models/decoder_only/vision_language -m 'core_model or quant_model'
374 - pytest -v -s models/embedding/vision_language -m core_model
tests/models/multimodal/__init__.py renamed
tests/models/multimodal/processing/__init__.py
tests/models/multimodal/processing/test_common.py new
+201
@@ -0,0 +1,201 @@
1 +from functools import partial
2 +
3 +import numpy as np
4 +import pytest
5 +from PIL import Image
6 +
7 +from vllm.config import ModelConfig
8 +from vllm.inputs import InputProcessingContext
9 +from vllm.multimodal import MULTIMODAL_REGISTRY
10 +from vllm.multimodal.processing import ProcessingCache
11 +from vllm.multimodal.utils import cached_get_tokenizer
12 +
13 +from ....multimodal.utils import random_audio, random_image, random_video
14 +
15 +
16 +def _test_processing_correctness(
17 + model_id: str,
18 + modalities: dict[str, bool],
19 + hit_rate: float,
20 + num_batches: int,
21 + simplify_rate: float,
22 +):
23 + if model_id == "TIGER-Lab/Mantis-8B-siglip-llama3":
24 + hf_overrides = {"architectures": ["MantisForConditionalGeneration"]}
25 + else:
26 + hf_overrides = {}
27 +
28 + limit_mm_per_prompt = {
29 + modality: 3 if supports_multi else 1
30 + for modality, supports_multi in modalities.items()
31 + }
32 +
33 + model_config = ModelConfig(
34 + model_id,
35 + task="auto",
36 + tokenizer=model_id,
37 + tokenizer_mode="auto",
38 + trust_remote_code=True,
39 + seed=0,
40 + dtype="float16",
41 + revision=None,
42 + hf_overrides=hf_overrides,
43 + limit_mm_per_prompt=limit_mm_per_prompt,
44 + )
45 +
46 + model_cls = MULTIMODAL_REGISTRY._get_model_cls(model_config)
47 + factories = MULTIMODAL_REGISTRY._processor_factories[model_cls]
48 + ctx = InputProcessingContext(
49 + model_config,
50 + tokenizer=cached_get_tokenizer(model_config.tokenizer),
51 + )
52 + # Ensure that it can fit all of the data
53 + cache = ProcessingCache(capacity=1 << 30)
54 +
55 + baseline_processor = factories.build_processor(ctx, cache=None)
56 + cached_processor = factories.build_processor(ctx, cache=cache)
57 + dummy_inputs = baseline_processor.dummy_inputs
58 + tokenizer = baseline_processor.info.get_tokenizer()
59 +
60 + rng = np.random.RandomState(0)
61 +
62 + input_to_hit = {
63 + "image": Image.new("RGB", size=(128, 128)),
64 + "video": np.zeros((4, 128, 128, 3), dtype=np.uint8),
65 + "audio": (np.zeros((512, )), 16000),
66 + }
67 + input_factory = {
68 + "image":
69 + partial(random_image, rng, min_wh=128, max_wh=256),
70 + "video":
71 + partial(random_video,
72 + rng,
73 + min_frames=2,
74 + max_frames=8,
75 + min_wh=128,
76 + max_wh=256),
77 + "audio":
78 + partial(random_audio, rng, min_len=512, max_len=1024, sr=16000),
79 + }
80 +
81 + for batch_idx in range(num_batches):
82 + mm_data = {
83 + k:
84 + [(input_to_hit[k] if rng.rand() < hit_rate else input_factory[k]())
85 + for _ in range(rng.randint(limit_mm_per_prompt[k]))]
86 + for k in modalities
87 + }
88 +
89 + mm_counts = {k: len(vs) for k, vs in mm_data.items()}
90 + prompt = dummy_inputs.get_dummy_processor_inputs(
91 + model_config.max_model_len,
92 + mm_counts,
93 + ).prompt_text
94 +
95 + # Drop unnecessary keys and test single -> multi conversion
96 + if rng.rand() < simplify_rate:
97 + for k in list(mm_data.keys()):
98 + if not mm_data[k]:
99 + del mm_data[k]
100 + elif len(mm_data[k]) == 1:
101 + mm_data[k] = mm_data[k][0]
102 +
103 + baseline_result = baseline_processor.apply(
104 + prompt,
105 + mm_data=mm_data,
106 + hf_processor_mm_kwargs={},
107 + )
108 + cached_result = cached_processor.apply(
109 + prompt,
110 + mm_data=mm_data,
111 + hf_processor_mm_kwargs={},
112 + )
113 +
114 + assert baseline_result == cached_result, (
115 + f"Failed ({batch_idx=}, {prompt=}, {mm_data=})")
116 +
117 + baseline_tokenized_result = baseline_processor.apply(
118 + tokenizer.encode(prompt),
119 + mm_data=mm_data,
120 + hf_processor_mm_kwargs={},
121 + )
122 +
123 + assert baseline_result == baseline_tokenized_result, (
124 + f"Failed ({batch_idx=}, {prompt=}, {mm_data=})")
125 +
126 + cached_tokenized_result = cached_processor.apply(
127 + tokenizer.encode(prompt),
128 + mm_data=mm_data,
129 + hf_processor_mm_kwargs={},
130 + )
131 +
132 + assert cached_result == cached_tokenized_result, (
133 + f"Failed ({batch_idx=}, {prompt=}, {mm_data=})")
134 +
135 +
136 +# yapf: disable
137 +# True if the model supports multiple data items of the modality per request
138 +@pytest.mark.parametrize(("model_id", "modalities"), [
139 + ("rhymes-ai/Aria", {"image": True}),
140 + ("Salesforce/blip2-opt-2.7b", {"image": False}),
141 + ("facebook/chameleon-7b", {"image": False}),
142 + ("adept/fuyu-8b", {"image": False}),
143 + ("llava-hf/llava-1.5-7b-hf", {"image": True}),
144 + ("llava-hf/llava-v1.6-mistral-7b-hf", {"image": True}),
145 + ("llava-hf/LLaVA-NeXT-Video-7B-hf", {"video": False}),
146 + ("llava-hf/llava-onevision-qwen2-0.5b-ov-hf", {"image": True, "video": True}), # noqa: E501
147 + ("TIGER-Lab/Mantis-8B-siglip-llama3", {"image": True}),
148 + ("mistral-community/pixtral-12b", {"image": True}),
149 + ("Qwen/Qwen2-VL-2B-Instruct", {"image": True, "video": True}),
150 + ("Qwen/Qwen2-Audio-7B-Instruct", {"audio": True}),
151 + ("fixie-ai/ultravox-v0_3", {"audio": True}),
152 +])
153 +@pytest.mark.parametrize("hit_rate", [0.3, 0.5, 1.0])
154 +@pytest.mark.parametrize("num_batches", [32])
155 +@pytest.mark.parametrize("simplify_rate", [1.0])
156 +# yapf: enable
157 +def test_processing_correctness(
158 + model_id: str,
159 + modalities: dict[str, bool],
160 + hit_rate: float,
161 + num_batches: int,
162 + simplify_rate: float,
163 +):
164 + _test_processing_correctness(
165 + model_id,
166 + modalities,
167 + hit_rate=hit_rate,
168 + num_batches=num_batches,
169 + simplify_rate=simplify_rate,
170 + )
171 +
172 +
173 +# yapf: disable
174 +@pytest.mark.parametrize(("model_id", "modalities"), [
175 + ("microsoft/Phi-3-vision-128k-instruct", {"image": True}),
176 +])
177 +@pytest.mark.parametrize("hit_rate", [0.3, 0.5, 1.0])
178 +@pytest.mark.parametrize("num_batches", [32])
179 +@pytest.mark.parametrize("simplify_rate", [1.0])
180 +# yapf: enable
181 +def test_processing_correctness_phi3v(
182 + model_id: str,
183 + modalities: dict[str, bool],
184 + hit_rate: float,
185 + num_batches: int,
186 + simplify_rate: float,
187 +):
188 + # HACK - this is an attempted workaround for the following bug
189 + # https://github.com/huggingface/transformers/issues/34307
190 + from transformers import AutoImageProcessor # noqa: F401
191 + from transformers import AutoProcessor # noqa: F401
192 +
193 + AutoImageProcessor.from_pretrained(model_id, trust_remote_code=True)
194 +
195 + _test_processing_correctness(
196 + model_id,
197 + modalities,
198 + hit_rate=hit_rate,
199 + num_batches=num_batches,
200 + simplify_rate=simplify_rate,
201 + )
tests/models/multimodal/processing/test_idefics3.py renamed
+2 -2
@@ -8,8 +8,8 @@ from transformers import AutoImageProcessor, AutoTokenizer
8 from vllm.inputs import InputContext, token_inputs
9 from vllm.multimodal import MultiModalRegistry
10
11 -from .....conftest import _ImageAssets
12 -from ....utils import build_model_context
11 +from ....conftest import _ImageAssets
12 +from ...utils import build_model_context
13
14 models = ["HuggingFaceM4/Idefics3-8B-Llama3"]
15
tests/models/multimodal/processing/test_internvl.py renamed
+2 -2
@@ -7,8 +7,8 @@ from transformers import AutoTokenizer
7 from vllm.inputs import InputContext, token_inputs
8 from vllm.multimodal import MultiModalRegistry
9
10 -from .....conftest import _ImageAssets
11 -from ....utils import build_model_context
10 +from ....conftest import _ImageAssets
11 +from ...utils import build_model_context
12
13 models = ["OpenGVLab/InternVL2-2B"]
14
tests/models/multimodal/processing/test_llava_next.py renamed
+1 -1
@@ -10,7 +10,7 @@ from vllm.multimodal.parse import ImageSize
10 from vllm.multimodal.processing import BaseMultiModalProcessor
11 from vllm.multimodal.utils import cached_get_tokenizer
12
13 -from ....utils import build_model_context
13 +from ...utils import build_model_context
14
15
16 def _validate_image_prompt_replacements_one(
tests/models/multimodal/processing/test_llava_onevision.py renamed
+1 -1
@@ -10,7 +10,7 @@ from vllm.multimodal.parse import ImageSize
10 from vllm.multimodal.processing import BaseMultiModalProcessor
11 from vllm.multimodal.utils import cached_get_tokenizer
12
13 -from ....utils import build_model_context
13 +from ...utils import build_model_context
14
15
16 def _validate_image_prompt_replacements_one(
tests/models/multimodal/processing/test_phi3v.py renamed
+2 -2
@@ -4,8 +4,8 @@ import pytest
4 from vllm.multimodal import MULTIMODAL_REGISTRY
5 from vllm.multimodal.utils import cached_get_tokenizer
6
7 -from .....conftest import _ImageAssets
8 -from ....utils import build_model_context
7 +from ....conftest import _ImageAssets
8 +from ...utils import build_model_context
9
10
11 @pytest.mark.parametrize("model_id", ["microsoft/Phi-3.5-vision-instruct"])
tests/models/multimodal/processing/test_qwen.py renamed
+2 -2
@@ -9,8 +9,8 @@ from vllm.inputs import InputContext, token_inputs
9 from vllm.multimodal import MultiModalKwargs
10 from vllm.multimodal.utils import cached_get_tokenizer
11
12 -from .....conftest import IMAGE_ASSETS
13 -from ....utils import build_model_context
12 +from ....conftest import IMAGE_ASSETS
13 +from ...utils import build_model_context
14
15 ### Multimodal preprocessing tests
16 SAMPLE_IMAGE = IMAGE_ASSETS[0].pil_image
tests/models/multimodal/processing/test_qwen2_vl.py renamed
+2 -2
@@ -3,8 +3,8 @@ import pytest
3 from vllm.multimodal import MULTIMODAL_REGISTRY
4 from vllm.multimodal.utils import cached_get_tokenizer
5
6 -from .....conftest import _ImageAssets
7 -from ....utils import build_model_context
6 +from ....conftest import _ImageAssets
7 +from ...utils import build_model_context
8
9
10 @pytest.mark.parametrize("model_id", ["Qwen/Qwen2-VL-2B-Instruct"])
tests/multimodal/test_processing.py
+4 -228
@@ -1,30 +1,25 @@
1 from contextlib import nullcontext
2 -from functools import partial
2 from typing import cast
3 from unittest.mock import MagicMock
4
5 import numpy as np
6 import pytest
8 -from PIL import Image
7
8 from vllm.config import ModelConfig
11 -from vllm.inputs import InputProcessingContext
9 from vllm.multimodal import MULTIMODAL_REGISTRY
13 -# yapf conflicts with isort for this block
14 -# yapf: disable
15 -from vllm.multimodal.processing import (PlaceholderInfo, ProcessingCache,
16 - PromptReplacement,
10 +from vllm.multimodal.processing import (PlaceholderInfo, PromptReplacement,
11 find_mm_placeholders,
12 find_text_matches, find_token_matches,
13 iter_token_matches,
14 replace_text_matches,
15 replace_token_matches)
22 -# yapf: enable
16 from vllm.multimodal.profiling import MultiModalProfiler
17 from vllm.multimodal.utils import cached_get_tokenizer
18 from vllm.transformers_utils.tokenizer import AnyTokenizer
19 from vllm.utils import full_groupby
20
21 +from .utils import random_image
22 +
23
24 # yapf: disable
25 @pytest.mark.parametrize(
@@ -531,37 +526,6 @@ def test_find_mm_placeholders(
526 assert result == expected
527
528
534 -def _rand_img(rng: np.random.RandomState, min_wh: int, max_wh: int):
535 - w, h = rng.randint(min_wh, max_wh, size=(2, ))
536 - arr = rng.randint(0, 255, size=(w, h, 3), dtype=np.uint8)
537 - return Image.fromarray(arr)
538 -
539 -
540 -def _rand_video(
541 - rng: np.random.RandomState,
542 - min_frames: int,
543 - max_frames: int,
544 - min_wh: int,
545 - max_wh: int,
546 -):
547 - # Temporary workaround for https://github.com/huggingface/transformers/issues/35412
548 - num_frames = rng.randint(min_frames, max_frames)
549 - num_frames = (num_frames // 2) * 2
550 -
551 - w, h = rng.randint(min_wh, max_wh, size=(2, ))
552 - return rng.randint(0, 255, size=(num_frames, w, h, 3), dtype=np.uint8)
553 -
554 -
555 -def _rand_audio(
556 - rng: np.random.RandomState,
557 - min_len: int,
558 - max_len: int,
559 - sr: int,
560 -):
561 - audio_len = rng.randint(min_len, max_len)
562 - return rng.rand(audio_len), sr
563 -
564 -
529 @pytest.mark.parametrize("model_id", ["llava-hf/llava-v1.6-mistral-7b-hf"])
530 @pytest.mark.parametrize(
531 ("limit", "num_supported", "is_valid"),
@@ -628,7 +592,7 @@ def test_limit_mm_per_prompt_apply(model_id, num_images, limit, is_valid):
592 )
593
594 rng = np.random.RandomState(0)
631 - image = _rand_img(rng, min_wh=128, max_wh=256)
595 + image = random_image(rng, min_wh=128, max_wh=256)
596 if num_images == 0:
597 mm_data = {}
598 elif num_images == 1:
@@ -647,191 +611,3 @@ def test_limit_mm_per_prompt_apply(model_id, num_images, limit, is_valid):
611 mm_data=mm_data,
612 hf_processor_mm_kwargs={},
613 )
650 -
651 -
652 -def _test_processing_correctness(
653 - model_id: str,
654 - modalities: dict[str, bool],
655 - hit_rate: float,
656 - num_batches: int,
657 - simplify_rate: float,
658 -):
659 - if model_id == "TIGER-Lab/Mantis-8B-siglip-llama3":
660 - hf_overrides = {"architectures": ["MantisForConditionalGeneration"]}
661 - else:
662 - hf_overrides = {}
663 -
664 - limit_mm_per_prompt = {
665 - modality: 3 if supports_multi else 1
666 - for modality, supports_multi in modalities.items()
667 - }
668 -
669 - model_config = ModelConfig(
670 - model_id,
671 - task="auto",
672 - tokenizer=model_id,
673 - tokenizer_mode="auto",
674 - trust_remote_code=True,
675 - seed=0,
676 - dtype="float16",
677 - revision=None,
678 - hf_overrides=hf_overrides,
679 - limit_mm_per_prompt=limit_mm_per_prompt,
680 - )
681 -
682 - model_cls = MULTIMODAL_REGISTRY._get_model_cls(model_config)
683 - factories = MULTIMODAL_REGISTRY._processor_factories[model_cls]
684 - ctx = InputProcessingContext(
685 - model_config,
686 - tokenizer=cached_get_tokenizer(model_config.tokenizer),
687 - )
688 - # Ensure that it can fit all of the data
689 - cache = ProcessingCache(capacity=1 << 30)
690 -
691 - baseline_processor = factories.build_processor(ctx, cache=None)
692 - cached_processor = factories.build_processor(ctx, cache=cache)
693 - dummy_inputs = baseline_processor.dummy_inputs
694 - tokenizer = baseline_processor.info.get_tokenizer()
695 -
696 - rng = np.random.RandomState(0)
697 -
698 - input_to_hit = {
699 - "image": Image.new("RGB", size=(128, 128)),
700 - "video": np.zeros((4, 128, 128, 3), dtype=np.uint8),
701 - "audio": (np.zeros((512, )), 16000),
702 - }
703 - input_factory = {
704 - "image":
705 - partial(_rand_img, rng, min_wh=128, max_wh=256),
706 - "video":
707 - partial(_rand_video,
708 - rng,
709 - min_frames=2,
710 - max_frames=8,
711 - min_wh=128,
712 - max_wh=256),
713 - "audio":
714 - partial(_rand_audio, rng, min_len=512, max_len=1024, sr=16000),
715 - }
716 -
717 - for batch_idx in range(num_batches):
718 - mm_data = {
719 - k:
720 - [(input_to_hit[k] if rng.rand() < hit_rate else input_factory[k]())
721 - for _ in range(rng.randint(limit_mm_per_prompt[k]))]
722 - for k in modalities
723 - }
724 -
725 - mm_counts = {k: len(vs) for k, vs in mm_data.items()}
726 - prompt = dummy_inputs.get_dummy_processor_inputs(
727 - model_config.max_model_len,
728 - mm_counts,
729 - ).prompt_text
730 -
731 - # Drop unnecessary keys and test single -> multi conversion
732 - if rng.rand() < simplify_rate:
733 - for k in list(mm_data.keys()):
734 - if not mm_data[k]:
735 - del mm_data[k]
736 - elif len(mm_data[k]) == 1:
737 - mm_data[k] = mm_data[k][0]
738 -
739 - baseline_result = baseline_processor.apply(
740 - prompt,
741 - mm_data=mm_data,
742 - hf_processor_mm_kwargs={},
743 - )
744 - cached_result = cached_processor.apply(
745 - prompt,
746 - mm_data=mm_data,
747 - hf_processor_mm_kwargs={},
748 - )
749 -
750 - assert baseline_result == cached_result, (
751 - f"Failed ({batch_idx=}, {prompt=}, {mm_data=})")
752 -
753 - baseline_tokenized_result = baseline_processor.apply(
754 - tokenizer.encode(prompt),
755 - mm_data=mm_data,
756 - hf_processor_mm_kwargs={},
757 - )
758 -
759 - assert baseline_result == baseline_tokenized_result, (
760 - f"Failed ({batch_idx=}, {prompt=}, {mm_data=})")
761 -
762 - cached_tokenized_result = cached_processor.apply(
763 - tokenizer.encode(prompt),
764 - mm_data=mm_data,
765 - hf_processor_mm_kwargs={},
766 - )
767 -
768 - assert cached_result == cached_tokenized_result, (
769 - f"Failed ({batch_idx=}, {prompt=}, {mm_data=})")
770 -
771 -
772 -# yapf: disable
773 -# True if the model supports multiple data items of the modality per request
774 -@pytest.mark.parametrize(("model_id", "modalities"), [
775 - ("rhymes-ai/Aria", {"image": True}),
776 - ("Salesforce/blip2-opt-2.7b", {"image": False}),
777 - ("facebook/chameleon-7b", {"image": False}),
778 - ("adept/fuyu-8b", {"image": False}),
779 - ("llava-hf/llava-1.5-7b-hf", {"image": True}),
780 - ("llava-hf/llava-v1.6-mistral-7b-hf", {"image": True}),
781 - ("llava-hf/LLaVA-NeXT-Video-7B-hf", {"video": False}),
782 - ("llava-hf/llava-onevision-qwen2-0.5b-ov-hf", {"image": True, "video": True}), # noqa: E501
783 - ("TIGER-Lab/Mantis-8B-siglip-llama3", {"image": True}),
784 - ("mistral-community/pixtral-12b", {"image": True}),
785 - ("Qwen/Qwen2-VL-2B-Instruct", {"image": True, "video": True}),
786 - ("Qwen/Qwen2-Audio-7B-Instruct", {"audio": True}),
787 - ("fixie-ai/ultravox-v0_3", {"audio": True}),
788 -])
789 -@pytest.mark.parametrize("hit_rate", [0.3, 0.5, 1.0])
790 -@pytest.mark.parametrize("num_batches", [32])
791 -@pytest.mark.parametrize("simplify_rate", [1.0])
792 -# yapf: enable
793 -def test_processing_correctness(
794 - model_id: str,
795 - modalities: dict[str, bool],
796 - hit_rate: float,
797 - num_batches: int,
798 - simplify_rate: float,
799 -):
800 - _test_processing_correctness(
801 - model_id,
802 - modalities,
803 - hit_rate=hit_rate,
804 - num_batches=num_batches,
805 - simplify_rate=simplify_rate,
806 - )
807 -
808 -
809 -# yapf: disable
810 -@pytest.mark.parametrize(("model_id", "modalities"), [
811 - ("microsoft/Phi-3-vision-128k-instruct", {"image": True}),
812 -])
813 -@pytest.mark.parametrize("hit_rate", [0.3, 0.5, 1.0])
814 -@pytest.mark.parametrize("num_batches", [32])
815 -@pytest.mark.parametrize("simplify_rate", [1.0])
816 -# yapf: enable
817 -def test_processing_correctness_phi3v(
818 - model_id: str,
819 - modalities: dict[str, bool],
820 - hit_rate: float,
821 - num_batches: int,
822 - simplify_rate: float,
823 -):
824 - # HACK - this is an attempted workaround for the following bug
825 - # https://github.com/huggingface/transformers/issues/34307
826 - from transformers import AutoImageProcessor # noqa: F401
827 - from transformers import AutoProcessor # noqa: F401
828 -
829 - AutoImageProcessor.from_pretrained(model_id, trust_remote_code=True)
830 -
831 - _test_processing_correctness(
832 - model_id,
833 - modalities,
834 - hit_rate=hit_rate,
835 - num_batches=num_batches,
836 - simplify_rate=simplify_rate,
837 - )
tests/multimodal/utils.py new
+33
@@ -0,0 +1,33 @@
1 +import numpy as np
2 +from PIL import Image
3 +
4 +
5 +def random_image(rng: np.random.RandomState, min_wh: int, max_wh: int):
6 + w, h = rng.randint(min_wh, max_wh, size=(2, ))
7 + arr = rng.randint(0, 255, size=(w, h, 3), dtype=np.uint8)
8 + return Image.fromarray(arr)
9 +
10 +
11 +def random_video(
12 + rng: np.random.RandomState,
13 + min_frames: int,
14 + max_frames: int,
15 + min_wh: int,
16 + max_wh: int,
17 +):
18 + # Temporary workaround for https://github.com/huggingface/transformers/issues/35412
19 + num_frames = rng.randint(min_frames, max_frames)
20 + num_frames = (num_frames // 2) * 2
21 +
22 + w, h = rng.randint(min_wh, max_wh, size=(2, ))
23 + return rng.randint(0, 255, size=(num_frames, w, h, 3), dtype=np.uint8)
24 +
25 +
26 +def random_audio(
27 + rng: np.random.RandomState,
28 + min_len: int,
29 + max_len: int,
30 + sr: int,
31 +):
32 + audio_len = rng.randint(min_len, max_len)
33 + return rng.rand(audio_len), sr