🚀 Llama-3.2-11B-Vision-Instruct-nf4模型
本项目基于meta-llama/Llama-3.2-11B-Vision-Instruct
模型转换而来,使用了BitsAndBytes
库进行NF4(4位)量化,未使用双重量化。它可用于图像文本到文本的转换任务,能为图像生成描述性文字。
🚀 快速开始
本模型由 meta-llama/Llama-3.2-11B-Vision-Instruct 转换而来,使用了 BitsAndBytes 进行 NF4(4 位)量化,不使用双重量化。加载该模型需要 bitsandbytes
库。
📦 安装指南
加载此模型需要安装 bitsandbytes
库,你可以使用以下命令进行安装:
pip install bitsandbytes
💻 使用示例
基础用法
以下是一个图像描述生成的示例代码:
from transformers import MllamaForConditionalGeneration, AutoProcessor, BitsAndBytesConfig
from PIL import Image
import time
model_id = "SeanScripts/Llama-3.2-11B-Vision-Instruct-nf4"
model = MllamaForConditionalGeneration.from_pretrained(
model_id,
use_safetensors=True,
device_map="cuda:0"
)
processor = AutoProcessor.from_pretrained(model_id)
IMAGE = Image.open("test.png").convert("RGB")
PROMPT = """<|begin_of_text|><|start_header_id|>user<|end_header_id|>
Caption this image:
<|image|><|eot_id|><|start_header_id|>assistant<|end_header_id|>
"""
inputs = processor(IMAGE, PROMPT, return_tensors="pt").to(model.device)
prompt_tokens = len(inputs['input_ids'][0])
print(f"Prompt tokens: {prompt_tokens}")
t0 = time.time()
generate_ids = model.generate(**inputs, max_new_tokens=256)
t1 = time.time()
total_time = t1 - t0
generated_tokens = len(generate_ids[0]) - prompt_tokens
time_per_token = generated_tokens/total_time
print(f"Generated {generated_tokens} tokens in {total_time:.3f} s ({time_per_token:.3f} tok/s)")
output = processor.decode(generate_ids[0][prompt_tokens:]).replace('<|eot_id|>', '')
print(output)
高级用法
你可以从以下链接获取一组用于运行此模型的 ComfyUI 自定义节点:
https://github.com/SeanScripts/ComfyUI-PixtralLlamaVision
📄 许可证
本项目使用的许可证为 llama3.2。
属性 |
详情 |
模型类型 |
图像文本到文本转换模型 |
基础模型 |
meta-llama/Llama-3.2-11B-Vision-Instruct |
库名称 |
transformers |