🚀 モデルIDのモデルカード
このモデルは、Qwen2-Audio-7B-Instructの4ビット量子化バージョンです。
(https://huggingface.co/Qwen/Qwen2-Audio-7B-Instruct)
✨ 主な機能
4ビット量子化により、メモリ使用量を削減し、特にリソースが限られたハードウェアでの推論速度を潜在的に向上させることができます。ただし、全精度モデルと比較して、性能が若干低下する可能性があります。
📦 インストール
このモデルを使用するには、transformersライブラリと、4ビット量子化をサポートするbitsandbytesをインストールする必要があります。
💻 使用例
基本的な使用法
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)
📚 ドキュメント
モデルの詳細
モデルの説明
これは、🤗 transformersモデルのモデルカードで、自動生成されたものです。
- 開発元:Alibaba Cloudによる元のQwenモデルをベースに開発
- モデルタイプ:音声-テキストマルチモーダル大規模言語モデル
モデルのソース
- リポジトリ:https://huggingface.co/Qwen/Qwen2-Audio-7B-Instruct
モデルの利用方法
モデルの使用例やコードスニペットについては、Hugging FaceのQwen2-Audio-7B-Instructモデルページを参照してください。
バイアス、リスク、制限事項
このモデルを使用するには、GPUが必要です。