🚀 纳米语言视觉模型 nanoLLaVA-1.5 - 改进的 10 亿参数以下视觉语言模型
纳米语言视觉模型 nanoLLaVA-1.5 是一款专为边缘设备高效运行而设计的“小而强大”的 10 亿参数视觉语言模型。它是 v1.0 版本 qnguyen3/nanoLLaVA 的升级版。
🚀 快速开始
你可以使用 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_name = 'qnguyen3/nanoLLaVA-1.5'
model = AutoModelForCausalLM.from_pretrained(
model_name,
torch_dtype=torch.float16,
device_map='auto',
trust_remote_code=True)
tokenizer = AutoTokenizer.from_pretrained(
model_name,
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())
✨ 主要特性
- 高效运行:专为边缘设备设计,能够在资源有限的设备上高效运行。
- 模型升级:是 v1.0 版本的升级版,性能可能更优。
📦 安装指南
使用以下命令安装所需的库:
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_name = 'qnguyen3/nanoLLaVA-1.5'
model = AutoModelForCausalLM.from_pretrained(
model_name,
torch_dtype=torch.float16,
device_map='auto',
trust_remote_code=True)
tokenizer = AutoTokenizer.from_pretrained(
model_name,
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())
📚 详细文档
模型信息
模型性能
模型 |
VQA v2 |
TextVQA |
ScienceQA |
POPE |
MMMU (测试集) |
MMMU (评估集) |
GQA |
MM-VET |
nanoLLavA-1.0 |
70.84 |
46.71 |
58.97 |
84.1 |
28.6 |
30.4 |
54.79 |
23.9 |
nanoLLavA-1.5 |
待确定 |
待确定 |
待确定 |
待确定 |
待确定 |
待确定 |
待确定 |
待确定 |
提示格式
该模型遵循 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
训练数据
训练数据将在后续发布,因为作者仍在撰写相关论文。最终版本预计会比当前版本更强大。
微调代码
微调代码即将推出!
模型训练
模型使用 Bunny 的修改版本进行训练。
📄 许可证
本项目采用 Apache-2.0 许可证。