Qwen 2 Audio Instruct Dynamic Fp8
Qwen2-Audio是Qwen大音频语言模型系列的最新版本,能够接收多种音频信号输入,并根据语音指令执行音频分析或直接生成文本响应。
下载量 24
发布时间 : 4/24/2025
模型简介
Qwen2-Audio支持语音聊天和音频分析两种交互模式,能够处理音频输入并生成文本响应,适用于多种音频理解任务。
模型特点
多模式交互
支持语音聊天和音频分析两种交互模式,用户可以通过语音或文本指令与模型交互。
音频理解
能够处理多种音频信号输入,包括语音、环境音等,并进行理解和分析。
文本生成
根据音频输入生成自然语言文本响应,适用于对话和问答场景。
模型能力
音频理解
文本生成
语音交互
音频分析
使用案例
语音交互
语音聊天
用户无需输入文本,即可与模型进行自由语音交互。
生成自然语言文本响应
音频分析
音频内容理解
用户提供音频和文本指令,模型进行分析并生成响应。
识别音频内容并生成描述
🚀 通义千问/Qwen2-Audio-7B-Instruct-FP8
通义千问2-Audio(Qwen2-Audio)是全新系列的大型音频语言模型,能够接收多种音频信号输入,并根据语音指令进行音频分析或直接给出文本回复。本项目提供了语音聊天和音频分析两种不同的音频交互模式,同时发布了预训练模型通义千问2-Audio-7B和聊天模型通义千问2-Audio-7B-Instruct。
🚀 快速开始
若要在 vllm 中启动,请运行以下命令:
vllm serve mlinmg/Qwen-2-Audio-Instruct-dynamic-fp8
✨ 主要特性
通义千问2-Audio 具备以下两种音频交互模式:
- 语音聊天:用户无需输入文本,即可与通义千问2-Audio 自由进行语音交互。
- 音频分析:用户在交互过程中可提供音频和文本指令进行分析。
📦 安装指南
通义千问2-Audio 的代码已集成在最新的 Hugging face transformers 中,建议使用以下命令从源代码进行构建,否则可能会遇到 KeyError: 'qwen2-audio'
错误:
pip install git+https://github.com/huggingface/transformers
💻 使用示例
基础用法
语音聊天推理
在语音聊天模式下,用户无需输入文本,即可与通义千问2-Audio 自由进行语音交互:
from io import BytesIO
from urllib.request import urlopen
import librosa
from transformers import Qwen2AudioForConditionalGeneration, AutoProcessor
processor = AutoProcessor.from_pretrained("Qwen/Qwen2-Audio-7B-Instruct")
model = Qwen2AudioForConditionalGeneration.from_pretrained("Qwen/Qwen2-Audio-7B-Instruct", device_map="auto")
conversation = [
{"role": "user", "content": [
{"type": "audio", "audio_url": "https://qianwen-res.oss-cn-beijing.aliyuncs.com/Qwen2-Audio/audio/guess_age_gender.wav"},
]},
{"role": "assistant", "content": "Yes, the speaker is female and in her twenties."},
{"role": "user", "content": [
{"type": "audio", "audio_url": "https://qianwen-res.oss-cn-beijing.aliyuncs.com/Qwen2-Audio/audio/translate_to_chinese.wav"},
]},
]
text = processor.apply_chat_template(conversation, add_generation_prompt=True, tokenize=False)
audios = []
for message in conversation:
if isinstance(message["content"], list):
for ele in message["content"]:
if ele["type"] == "audio":
audios.append(librosa.load(
BytesIO(urlopen(ele['audio_url']).read()),
sr=processor.feature_extractor.sampling_rate)[0]
)
inputs = processor(text=text, audios=audios, return_tensors="pt", padding=True)
inputs.input_ids = inputs.input_ids.to("cuda")
generate_ids = model.generate(**inputs, max_length=256)
generate_ids = generate_ids[:, inputs.input_ids.size(1):]
response = processor.batch_decode(generate_ids, skip_special_tokens=True, clean_up_tokenization_spaces=False)[0]
音频分析推理
在音频分析模式下,用户可提供音频和文本指令进行分析:
from io import BytesIO
from urllib.request import urlopen
import librosa
from transformers import Qwen2AudioForConditionalGeneration, AutoProcessor
processor = AutoProcessor.from_pretrained("Qwen/Qwen2-Audio-7B-Instruct")
model = Qwen2AudioForConditionalGeneration.from_pretrained("Qwen/Qwen2-Audio-7B-Instruct", device_map="auto")
conversation = [
{'role': 'system', 'content': 'You are a helpful assistant.'},
{"role": "user", "content": [
{"type": "audio", "audio_url": "https://qianwen-res.oss-cn-beijing.aliyuncs.com/Qwen2-Audio/audio/glass-breaking-151256.mp3"},
{"type": "text", "text": "What's that sound?"},
]},
{"role": "assistant", "content": "It is the sound of glass shattering."},
{"role": "user", "content": [
{"type": "text", "text": "What can you do when you hear that?"},
]},
{"role": "assistant", "content": "Stay alert and cautious, and check if anyone is hurt or if there is any damage to property."},
{"role": "user", "content": [
{"type": "audio", "audio_url": "https://qianwen-res.oss-cn-beijing.aliyuncs.com/Qwen2-Audio/audio/1272-128104-0000.flac"},
{"type": "text", "text": "What does the person say?"},
]},
]
text = processor.apply_chat_template(conversation, add_generation_prompt=True, tokenize=False)
audios = []
for message in conversation:
if isinstance(message["content"], list):
for ele in message["content"]:
if ele["type"] == "audio":
audios.append(
librosa.load(
BytesIO(urlopen(ele['audio_url']).read()),
sr=processor.feature_extractor.sampling_rate)[0]
)
inputs = processor(text=text, audios=audios, return_tensors="pt", padding=True)
inputs.input_ids = inputs.input_ids.to("cuda")
generate_ids = model.generate(**inputs, max_length=256)
generate_ids = generate_ids[:, inputs.input_ids.size(1):]
response = processor.batch_decode(generate_ids, skip_special_tokens=True, clean_up_tokenization_spaces=False)[0]
高级用法
批量推理
本项目还支持批量推理:
from io import BytesIO
from urllib.request import urlopen
import librosa
from transformers import Qwen2AudioForConditionalGeneration, AutoProcessor
processor = AutoProcessor.from_pretrained("Qwen/Qwen2-Audio-7B-Instruct")
model = Qwen2AudioForConditionalGeneration.from_pretrained("Qwen/Qwen2-Audio-7B-Instruct", device_map="auto")
conversation1 = [
{"role": "user", "content": [
{"type": "audio", "audio_url": "https://qianwen-res.oss-cn-beijing.aliyuncs.com/Qwen2-Audio/audio/glass-breaking-151256.mp3"},
{"type": "text", "text": "What's that sound?"},
]},
{"role": "assistant", "content": "It is the sound of glass shattering."},
{"role": "user", "content": [
{"type": "audio", "audio_url": "https://qianwen-res.oss-cn-beijing.aliyuncs.com/Qwen2-Audio/audio/f2641_0_throatclearing.wav"},
{"type": "text", "text": "What can you hear?"},
]}
]
conversation2 = [
{"role": "user", "content": [
{"type": "audio", "audio_url": "https://qianwen-res.oss-cn-beijing.aliyuncs.com/Qwen2-Audio/audio/1272-128104-0000.flac"},
{"type": "text", "text": "What does the person say?"},
]},
]
conversations = [conversation1, conversation2]
text = [processor.apply_chat_template(conversation, add_generation_prompt=True, tokenize=False) for conversation in conversations]
audios = []
for conversation in conversations:
for message in conversation:
if isinstance(message["content"], list):
for ele in message["content"]:
if ele["type"] == "audio":
audios.append(
librosa.load(
BytesIO(urlopen(ele['audio_url']).read()),
sr=processor.feature_extractor.sampling_rate)[0]
)
inputs = processor(text=text, audios=audios, return_tensors="pt", padding=True)
inputs['input_ids'] = inputs['input_ids'].to("cuda")
inputs.input_ids = inputs.input_ids.to("cuda")
generate_ids = model.generate(**inputs, max_length=256)
generate_ids = generate_ids[:, inputs.input_ids.size(1):]
response = processor.batch_decode(generate_ids, skip_special_tokens=True, clean_up_tokenization_spaces=False)
📚 详细文档
如需了解更多详细信息,请参考我们的 博客、GitHub 和 报告。
📄 许可证
本项目采用 Apache-2.0 许可证。
📖 引用
如果您觉得我们的工作有帮助,请引用以下文献:
@article{Qwen2-Audio,
title={Qwen2-Audio Technical Report},
author={Chu, Yunfei and Xu, Jin and Yang, Qian and Wei, Haojie and Wei, Xipin and Guo, Zhifang and Leng, Yichong and Lv, Yuanjun and He, Jinzheng and Lin, Junyang and Zhou, Chang and Zhou, Jingren},
journal={arXiv preprint arXiv:2407.10759},
year={2024}
}
@article{Qwen-Audio,
title={Qwen-Audio: Advancing Universal Audio Understanding via Unified Large-Scale Audio-Language Models},
author={Chu, Yunfei and Xu, Jin and Zhou, Xiaohuan and Yang, Qian and Zhang, Shiliang and Yan, Zhijie and Zhou, Chang and Zhou, Jingren},
journal={arXiv preprint arXiv:2311.07919},
year={2023}
}
Phi 4 Multimodal Instruct
MIT
Phi-4-multimodal-instruct是一款轻量级开源多模态基础模型,融合了Phi-3.5和4.0模型的语言、视觉及语音研究数据。支持文本、图像和音频输入,生成文本输出,并具备128K token的上下文长度。
文本生成音频
Transformers 支持多种语言

P
microsoft
584.02k
1,329
Ultravox V0 5 Llama 3 2 1b
MIT
Ultravox是一个基于Llama3.2-1B和Whisper-large-v3构建的多模态语音大语言模型,能够同时处理语音和文本输入。
文本生成音频
Transformers 支持多种语言

U
fixie-ai
167.25k
21
Seamless M4t V2 Large
SeamlessM4T v2 是 Facebook 发布的大规模多语言多模态机器翻译模型,支持近100种语言的语音和文本翻译。
文本生成音频
Transformers 支持多种语言

S
facebook
64.59k
821
Ultravox V0 3
MIT
Ultravox 是一个基于 Llama3.1-8B-Instruct 和 Whisper-small 构建的多模态语音大语言模型,能够同时处理语音和文本输入。
文本生成音频
Transformers 英语

U
fixie-ai
48.30k
17
Ultravox V0 5 Llama 3 1 8b
MIT
Ultravox是一款基于Llama3.1-8B-Instruct和whisper-large-v3-turbo构建的多模态语音大语言模型,能够同时处理语音和文本输入。
文本生成音频
Transformers 支持多种语言

U
fixie-ai
17.86k
12
Hf Seamless M4t Medium
SeamlessM4T 是一个多语言翻译模型,支持语音和文本的输入输出,实现跨语言交流。
文本生成音频
Transformers

H
facebook
14.74k
30
Granite Speech 3.3 8b
Apache-2.0
专为自动语音识别(ASR)和自动语音翻译(AST)设计的紧凑高效语音语言模型,采用双阶段设计处理音频和文本
文本生成音频
Transformers 英语

G
ibm-granite
5,532
35
Voila Tokenizer
MIT
Voila是一个大型语音-语言基础模型系列,旨在提升人机交互体验,支持多种音频任务和语言。
文本生成音频
Transformers 支持多种语言

V
maitrix-org
4,912
3
Hf Seamless M4t Large
SeamlessM4T 是一个支持多语言语音和文本翻译的统一模型,能够实现语音到语音、语音到文本、文本到语音和文本到文本的翻译任务。
文本生成音频
Transformers

H
facebook
4,648
57
Minicpm O 2 6 Int4
MiniCPM-o 2.6的int4量化版本,显著降低GPU显存占用,支持多模态处理能力。
文本生成音频
Transformers 其他

M
openbmb
4,249
42
精选推荐AI模型
Llama 3 Typhoon V1.5x 8b Instruct
专为泰语设计的80亿参数指令模型,性能媲美GPT-3.5-turbo,优化了应用场景、检索增强生成、受限生成和推理任务
大型语言模型
Transformers 支持多种语言

L
scb10x
3,269
16
Cadet Tiny
Openrail
Cadet-Tiny是一个基于SODA数据集训练的超小型对话模型,专为边缘设备推理设计,体积仅为Cosmo-3B模型的2%左右。
对话系统
Transformers 英语

C
ToddGoldfarb
2,691
6
Roberta Base Chinese Extractive Qa
基于RoBERTa架构的中文抽取式问答模型,适用于从给定文本中提取答案的任务。
问答系统 中文
R
uer
2,694
98