🚀 Qwen2-Audio-7B-Instruct 4-bit量化版本模型
本模型是Qwen2-Audio-7B-Instruct的4位量化版本,能有效解决音频文本多模态处理问题,在减少内存使用的同时,提升有限资源硬件上的推理速度。
🚀 快速开始
若要使用此模型,你需要安装transformers
库,以及支持4位量化的bitsandbytes
库。可参考Hugging Face上的Qwen2-Audio-7B-Instruct模型页面获取使用示例和代码片段。
以下是加载和使用该模型的基本示例:
import torch
from io import BytesIO
from urllib.request import urlopen
import librosa
from transformers import Qwen2AudioForConditionalGeneration, AutoProcessor, BitsAndBytesConfig
processor = AutoProcessor.from_pretrained("alicekyting/Qwen2-Audio-7B-Instruct-4bit")
bnb_config = BitsAndBytesConfig(
load_in_4bit=True,
bnb_4bit_compute_dtype=torch.float16
)
model = Qwen2AudioForConditionalGeneration.from_pretrained(
"alicekyting/Qwen2-Audio-7B-Instruct-4bit",
device_map="auto",
quantization_config=bnb_config
)
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,
mono=True
)[0]
)
inputs = processor(text=text, audios=audios, return_tensors="pt", padding=True)
inputs = {k: v.to(model.device) for k, v in inputs.items()}
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]
print(response)
✨ 主要特性
- 低内存占用:4位量化技术显著降低了内存使用,尤其适合资源有限的硬件环境。
- 快速推理:在特定硬件上,量化模型可实现更快的推理速度。
- 多模态处理:作为音频-文本多模态大语言模型,能够同时处理音频和文本信息。
📦 安装指南
使用此模型前,请确保已安装以下库:
transformers
bitsandbytes
可使用以下命令进行安装:
pip install transformers bitsandbytes
📚 详细文档
模型详情
模型描述
这是一个🤗 transformers
模型的模型卡片,已发布到Hugging Face Hub,此卡片由系统自动生成。
- 开发基础:基于阿里云的原始Qwen模型开发。
- 模型类型:音频-文本多模态大语言模型。
模型来源
- 仓库地址:https://huggingface.co/Qwen/Qwen2-Audio-7B-Instruct
模型用途
4位量化允许减少内存使用,并可能加快推理时间,特别是在资源有限的硬件上。不过,与全精度模型相比,性能可能会略有下降。
偏差、风险和限制
运行该模型需要GPU支持。
🔧 技术细节
本模型基于阿里云的Qwen模型开发,采用4位量化技术,在减少内存使用的同时,可能会牺牲一定的性能。在资源有限的硬件上,4位量化模型能够实现更快的推理速度,但与全精度模型相比,其性能可能会略有下降。
📄 许可证
文档未提及相关许可证信息。