🚀 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位量化模型能夠實現更快的推理速度,但與全精度模型相比,其性能可能會略有下降。
📄 許可證
文檔未提及相關許可證信息。