🚀 LLaVA-Saiga-8b
LLaVA-Saiga-8b是一個基於視覺語言模型(VLM),它依託於IlyaGusev/saiga_llama3_8b
模型,並在原始的LLaVA設置下進行訓練。該模型主要適配俄語,但也支持英語。
🚀 快速開始
LLaVA-Saiga-8b模型可以通過transformers
API輕鬆使用。以下是具體的使用示例:
import requests
from PIL import Image
from transformers import AutoProcessor, AutoTokenizer, LlavaForConditionalGeneration
model_name = "deepvk/llava-saiga-8b"
model = LlavaForConditionalGeneration.from_pretrained(model_name)
processor = AutoProcessor.from_pretrained(model_name)
tokenizer = AutoTokenizer.from_pretrained(model_name)
url = "https://www.ilankelman.org/stopsigns/australia.jpg"
img = Image.open(requests.get(url, stream=True).raw)
messages = [
{"role": "user", "content": "<image>\nОпиши картинку несколькими словами."}
]
text = tokenizer.apply_chat_template(messages, tokenize=False, add_generation_prompt=True)
inputs = processor(images=[img], text=text, return_tensors="pt")
generate_ids = model.generate(**inputs, max_new_tokens=30)
answer = tokenizer.decode(generate_ids[0, inputs.input_ids.shape[1]:], skip_special_tokens=True)
print(answer)
使用時,在文本中使用<image>
標籤指向圖片,並遵循多輪對話的聊天模板。該模型能夠在沒有圖片的情況下進行聊天,也可以在對話中處理多張圖片,但這種情況尚未經過充分測試。
由於該模型的格式,它可以直接在流行的框架中使用。例如,你可以使用lmms-eval來測試模型,具體細節請參閱“結果”部分。
💻 使用示例
基礎用法
import requests
from PIL import Image
from transformers import AutoProcessor, AutoTokenizer, LlavaForConditionalGeneration
model_name = "deepvk/llava-saiga-8b"
model = LlavaForConditionalGeneration.from_pretrained(model_name)
processor = AutoProcessor.from_pretrained(model_name)
tokenizer = AutoTokenizer.from_pretrained(model_name)
url = "https://www.ilankelman.org/stopsigns/australia.jpg"
img = Image.open(requests.get(url, stream=True).raw)
messages = [
{"role": "user", "content": "<image>\nОпиши картинку несколькими словами."}
]
text = tokenizer.apply_chat_template(messages, tokenize=False, add_generation_prompt=True)
inputs = processor(images=[img], text=text, return_tensors="pt")
generate_ids = model.generate(**inputs, max_new_tokens=30)
answer = tokenizer.decode(generate_ids[0, inputs.input_ids.shape[1]:], skip_special_tokens=True)
print(answer)
高級用法
使用時,在文本中使用<image>
標籤指向圖片,並遵循多輪對話的聊天模板。該模型能夠在沒有圖片的情況下進行聊天,也可以在對話中處理多張圖片,但這種情況尚未經過充分測試。
🔧 技術細節
訓練過程
為了訓練這個模型,我們遵循了原始的LLaVA管道,並複用了haotian-liu/LLaVA
框架。
模型的訓練分為兩個階段:
- 使用來自
ShareGPT4V
的預訓練數據來訓練適配器。
- 指令微調包括訓練大語言模型(LLM)和適配器,為此我們使用了以下數據:
整個訓練過程在8個A100 80GB的GPU上進行了3 - 4天。
評估
模型的性能使用lmms-eval
框架進行評估:
accelerate launch -m lmms_eval --model llava_hf --model_args pretrained="deepvk/llava-saiga-8b" \
--tasks gqa-ru,mmbench_ru_dev,gqa,mmbench_en_dev --batch_size 1 \
--log_samples --log_samples_suffix llava-saiga-8b --output_path ./logs/
評估結果
注意:對於MMBench,我們沒有使用OpenAI API來查找生成字符串中的量詞。因此,該分數類似於GQA基準測試中的精確匹配分數。
📄 許可證
本項目採用Apache-2.0許可證。
📚 引用
@misc{liu2023llava,
title={Visual Instruction Tuning},
author={Liu, Haotian and Li, Chunyuan and Wu, Qingyang and Lee, Yong Jae},
publisher={NeurIPS},
year={2023},
}
@misc{deepvk2024llava-saiga-8b,
title={LLaVA-Saiga-8b},
author={Belopolskih, Daniil and Spirin, Egor},
url={https://huggingface.co/deepvk/llava-saiga-8b},
publisher={Hugging Face}
year={2024},
}