🚀 HuggingFaceH4/vsft-llava-1.5-7b-hf-trl
HuggingFaceH4/vsft-llava-1.5-7b-hf-trlは、画像とテキストを組み合わせた多様体言語モデルで、画像からテキストを生成するタスクに特化しています。

デモを試してみましょう! 
🚀 クイックスタート
HuggingFaceH4/vsft-llava-1.5-7b-hf-trlは、ビジョン言語モデルです。このモデルは、llava-hf/llava-1.5-7b-hfモデルに対してVSFTを実行し、HuggingFaceH4/llava-instruct-mix-vsftデータセットから260kの画像と会話のペアを用いて作成されました。
✨ 主な機能
- モデルは、多画像と多プロンプトの生成をサポートしています。つまり、プロンプトに複数の画像を渡すことができます。
- 正しいプロンプトテンプレート (
USER: xxx\nASSISTANT:
) を使用し、画像をクエリしたい場所にトークン <image>
を追加する必要があります。
📚 ドキュメント
モデルの詳細
属性 |
详情 |
モデルタイプ |
LLaVAは、GPT生成のマルチモーダル命令追従データでLLaMA/Vicunaをファインチューニングすることでトレーニングされたオープンソースのチャットボットです。これは、トランスフォーマーアーキテクチャに基づく自己回帰型言語モデルです。 |
モデルの日付 |
モデルは2024年4月11日にトレーニングされました。 |
トレーニングスクリプトの例 |
TRLの例を使って独自にVLMをトレーニングする |
モデルの使用方法
基本的な使用法
from transformers import pipeline
from PIL import Image
import requests
model_id = "HuggingFaceH4/vsft-llava-1.5-7b-hf-trl"
pipe = pipeline("image-to-text", model=model_id)
url = "https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/transformers/tasks/ai2d-demo.jpg"
image = Image.open(requests.get(url, stream=True).raw)
prompt = "A chat between a curious user and an artificial intelligence assistant. The assistant gives helpful, detailed, and polite answers to the user's questions. USER: <image>\nWhat does the label 15 represent? (1) lava (2) core (3) tunnel (4) ash cloud\nASSISTANT:"
outputs = pipe(image, prompt=prompt, generate_kwargs={"max_new_tokens": 200})
print(outputs)
>>> {"generated_text": "\nUSER: What does the label 15 represent? (1) lava (2) core (3) tunnel (4) ash cloud\nASSISTANT: Lava"}
高度な使用法
import requests
from PIL import Image
import torch
from transformers import AutoProcessor, LlavaForConditionalGeneration
model_id = "HuggingFaceH4/vsft-llava-1.5-7b-hf-trl"
prompt = "A chat between a curious user and an artificial intelligence assistant. The assistant gives helpful, detailed, and polite answers to the user's questions. USER: <image>\nWhat are these?\nASSISTANT:"
image_file = "http://images.cocodataset.org/val2017/000000039769.jpg"
model = LlavaForConditionalGeneration.from_pretrained(
model_id,
torch_dtype=torch.float16,
low_cpu_mem_usage=True,
).to(0)
processor = AutoProcessor.from_pretrained(model_id)
raw_image = Image.open(requests.get(image_file, stream=True).raw)
inputs = processor(prompt, raw_image, return_tensors='pt').to(0, torch.float16)
output = model.generate(**inputs, max_new_tokens=200, do_sample=False)
print(processor.decode(output[0][2:], skip_special_tokens=True))
モデルの最適化
bitsandbytes
ライブラリを使用した4ビット量子化
最初に bitsandbytes
をインストールしてください (pip install bitsandbytes
)。CUDA互換のGPUデバイスにアクセスできることを確認してください。上記のスニペットを以下のように変更します。
model = LlavaForConditionalGeneration.from_pretrained(
model_id,
torch_dtype=torch.float16,
low_cpu_mem_usage=True,
+ load_in_4bit=True
)
Flash-Attention 2を使用して生成をさらに高速化する
最初に flash-attn
をインストールしてください。このパッケージのインストールについては、Flash Attentionのオリジナルリポジトリを参照してください。上記のスニペットを以下のように変更します。
model = LlavaForConditionalGeneration.from_pretrained(
model_id,
torch_dtype=torch.float16,
low_cpu_mem_usage=True,
+ use_flash_attention_2=True
).to(0)
📄 ライセンス
Llama 2は、LLAMA 2 Community Licenseの下でライセンスされています。
Copyright (c) Meta Platforms, Inc. All Rights Reserved.
引用
@misc{vonwerra2022trl,
author = {Leandro von Werra and Younes Belkada and Lewis Tunstall and Edward Beeching and Tristan Thrush and Nathan Lambert and Shengyi Huang},
title = {TRL: Transformer Reinforcement Learning},
year = {2020},
publisher = {GitHub},
journal = {GitHub repository},
howpublished = {\url{https://github.com/huggingface/trl}}
}