Views
No views yet

| Model Name | Description |
|---|---|
| Qwen3-Omni-30B-A3B-Captioner | A downstream audio fine-grained caption model fine-tuned from Qwen3-Omni-30B-A3B-Instruct, which produces detailed, low-hallucination captions for arbitrary audio inputs. It contains the thinker, supporting audio input and text output. For more information, you can refer to the model's cookbook or Hugging Face Demo and ModelScope Demo. |
1# Download through ModelScope (recommended for users in Mainland China)
2pip install -U modelscope
3modelscope download --model Qwen/Qwen3-Omni-30B-A3B-Captioner --local_dir ./Qwen3-Omni-30B-A3B-Captioner
4
5# Download through Hugging Face
6pip install -U "huggingface_hub[cli]"
7huggingface-cli download Qwen/Qwen3-Omni-30B-A3B-Captioner --local-dir ./Qwen3-Omni-30B-A3B-Captioner1# If you already have transformers installed, please uninstall it first, or create a new Python environment
2# pip uninstall transformers
3pip install git+https://github.com/huggingface/transformers
4pip install accelerateffmpeg installed:pip install qwen-omni-utils -Upip install -U flash-attn --no-build-isolationtorch.float16 or torch.bfloat16.transformers and qwen_omni_utils:1import soundfile as sf
2
3from transformers import Qwen3OmniMoeForConditionalGeneration, Qwen3OmniMoeProcessor
4from qwen_omni_utils import process_mm_info
5
6MODEL_PATH = "Qwen/Qwen3-Omni-30B-A3B-Captioner"
7
8model = Qwen3OmniMoeForConditionalGeneration.from_pretrained(
9 MODEL_PATH,
10 dtype="auto",
11 device_map="auto",
12 attn_implementation="flash_attention_2",
13)
14
15processor = Qwen3OmniMoeProcessor.from_pretrained(MODEL_PATH)
16
17conversation = [
18 {
19 "role": "user",
20 "content": [
21 {"type": "audio", "audio": "https://qianwen-res.oss-cn-beijing.aliyuncs.com/Qwen3-Omni/cookbook/caption2.mp3"},
22 ],
23 },
24]
25
26# Preparation for inference
27text = processor.apply_chat_template(conversation, add_generation_prompt=True, tokenize=False)
28audios, _, _ = process_mm_info(conversation, use_audio_in_video=False)
29inputs = processor(text=text,
30 audio=audios,
31 return_tensors="pt",
32 padding=True,
33 use_audio_in_video=False)
34inputs = inputs.to(model.device).to(model.dtype)
35
36# Inference: Generation of the output text and audio
37text_ids, audio = model.generate(**inputs,
38 thinker_return_dict_in_generate=True)
39
40text = processor.batch_decode(text_ids.sequences[:, inputs["input_ids"].shape[1] :],
41 skip_special_tokens=True,
42 clean_up_tokenization_spaces=False)
43print(text)1git clone -b qwen3_omni https://github.com/wangxiongts/vllm.git
2cd vllm
3pip install -r requirements/build.txt
4pip install -r requirements/cuda.txt
5export VLLM_PRECOMPILED_WHEEL_LOCATION=https://wheels.vllm.ai/a5dd03c1ebc5e4f56f3c9d3dc0436e9c582c978f/vllm-0.9.2-cp38-abi3-manylinux1_x86_64.whl
6VLLM_USE_PRECOMPILED=1 pip install -e . -v --no-build-isolation
7# If you meet an "Undefined symbol" error while using VLLM_USE_PRECOMPILED=1, please use "pip install -e . -v" to build from source.
8# Install the Transformers
9pip install git+https://github.com/huggingface/transformers
10pip install accelerate
11pip install qwen-omni-utils -U
12pip install -U flash-attn --no-build-isolation1import os
2import torch
3
4from vllm import LLM, SamplingParams
5from transformers import Qwen3OmniMoeProcessor
6from qwen_omni_utils import process_mm_info
7
8if __name__ == '__main__':
9 # vLLM engine v1 not supported yet
10 os.environ['VLLM_USE_V1'] = '0'
11
12 MODEL_PATH = "Qwen/Qwen3-Omni-30B-A3B-Captioner"
13
14 llm = LLM(
15 model=MODEL_PATH, trust_remote_code=True, gpu_memory_utilization=0.95,
16 tensor_parallel_size=torch.cuda.device_count(),
17 limit_mm_per_prompt={'audio': 1},
18 max_num_seqs=8,
19 max_model_len=32768,
20 seed=1234,
21 )
22
23 sampling_params = SamplingParams(
24 temperature=0.6,
25 top_p=0.95,
26 top_k=20,
27 max_tokens=16384,
28 )
29
30 processor = Qwen3OmniMoeProcessor.from_pretrained(MODEL_PATH)
31
32 messages = [
33 {
34 "role": "user",
35 "content": [
36 {"type": "audio", "audio": "https://qianwen-res.oss-cn-beijing.aliyuncs.com/Qwen3-Omni/cookbook/caption2.mp3"}
37 ],
38 }
39 ]
40
41 text = processor.apply_chat_template(
42 messages,
43 tokenize=False,
44 add_generation_prompt=True,
45 )
46 audios, _, _ = process_mm_info(messages, use_audio_in_video=False)
47
48 inputs = {
49 'prompt': text,
50 'multi_modal_data': {},
51 }
52
53 if audios is not None:
54 inputs['multi_modal_data']['audio'] = audios
55
56 outputs = llm.generate([inputs], sampling_params=sampling_params)
57
58 print(outputs[0].outputs[0].text)1# Qwen3-Omni-30B-A3B-Captioner for single GPU
2vllm serve Qwen/Qwen3-Omni-30B-A3B-Captioner --port 8901 --host 127.0.0.1 --dtype bfloat16 --max-model-len 32768 --allowed-local-media-path / -tp 1
3# Qwen3-Omni-30B-A3B-Captioner for multi-GPU (example on 4 GPUs)
4vllm serve Qwen/Qwen3-Omni-30B-A3B-Captioner --port 8901 --host 127.0.0.1 --dtype bfloat16 --max-model-len 32768 --allowed-local-media-path / -tp 41curl http://localhost:8901/v1/chat/completions \
2 -H "Content-Type: application/json" \
3 -d '{
4 "messages": [
5 {"role": "user", "content": [
6 {"type": "audio_url", "audio_url": {"url": "https://qianwen-res.oss-cn-beijing.aliyuncs.com/Qwen3-Omni/cookbook/caption2.mp3"}}
7 ]}
8 ]
9 }'