🚀 nanoLLaVA - 小于10亿参数的视觉语言模型
nanoLLaVA是一款“小而强大”的10亿参数以下视觉语言模型,专为在边缘设备上高效运行而设计。它能在有限资源下实现出色的视觉与语言处理能力,为边缘计算场景提供有力支持。
🚀 快速开始
你可以使用transformers
库,通过以下脚本使用该模型:
pip install -U transformers accelerate flash_attn
import torch
import transformers
from transformers import AutoModelForCausalLM, AutoTokenizer
from PIL import Image
import warnings
transformers.logging.set_verbosity_error()
transformers.logging.disable_progress_bar()
warnings.filterwarnings('ignore')
torch.set_default_device('cuda')
model = AutoModelForCausalLM.from_pretrained(
'qnguyen3/nanoLLaVA',
torch_dtype=torch.float16,
device_map='auto',
trust_remote_code=True)
tokenizer = AutoTokenizer.from_pretrained(
'qnguyen3/nanoLLaVA',
trust_remote_code=True)
prompt = 'Describe this image in detail'
messages = [
{"role": "user", "content": f'<image>\n{prompt}'}
]
text = tokenizer.apply_chat_template(
messages,
tokenize=False,
add_generation_prompt=True
)
print(text)
text_chunks = [tokenizer(chunk).input_ids for chunk in text.split('<image>')]
input_ids = torch.tensor(text_chunks[0] + [-200] + text_chunks[1], dtype=torch.long).unsqueeze(0)
image = Image.open('/path/to/image.png')
image_tensor = model.process_images([image], model.config).to(dtype=model.dtype)
output_ids = model.generate(
input_ids,
images=image_tensor,
max_new_tokens=2048,
use_cache=True)[0]
print(tokenizer.decode(output_ids[input_ids.shape[1]:], skip_special_tokens=True).strip())
✨ 主要特性
- 轻量级高效运行:作为10亿参数以下的模型,能够在边缘设备上高效运行,降低了对硬件资源的要求。
- 多数据集表现出色:在多个视觉问答和多模态任务数据集上取得了不错的成绩,如在VQA v2中得分70.84,POPE中得分84.1等。
📦 安装指南
使用以下命令安装所需依赖:
pip install -U transformers accelerate flash_attn
📚 详细文档
模型信息
模型性能
模型 |
VQA v2 |
TextVQA |
ScienceQA |
POPE |
MMMU (测试集) |
MMMU (评估集) |
GQA |
MM-VET |
得分 |
70.84 |
46.71 |
58.97 |
84.1 |
28.6 |
30.4 |
54.79 |
23.9 |
训练数据
训练数据将在后续发布,因为作者仍在撰写相关论文。预计最终版本会比当前版本更强大。
微调代码
即将推出!
提示格式
该模型遵循ChatML标准,但<|im_end|>
末尾没有\n
:
<|im_start|>system
Answer the question<|im_end|><|im_start|>user
<image>
What is the picture about?<|im_end|><|im_start|>assistant
图片 |
示例 |
 |
图片中的文字说了什么? “Small but mighty”。 文字与图片上下文有什么关联? 文字似乎是对一个小而强大的形象(可能是老鼠或老鼠玩具)拿着杠铃的一种有趣或幽默的表达。 |
📄 许可证
本项目采用Apache 2.0许可证。
⚠️ 重要提示
nanoLLaVA-1.5 已发布,性能有显著提升。请点击此处查看。
模型使用了来自 Bunny 的修改版本进行训练。