license: gemma
datasets:
- BUAADreamer/llava-en-zh-300k
language:
- en
- zh
library_name: transformers
pipeline_tag: image-text-to-text
base_model: google/paligemma-3b-mix-448
inference: false
tags:
- paligemma
- llama-factory
- mllm
- vlm
PaliGemma-3B-Chat-v0.2
该模型基于google/paligemma-3b-mix-448微调,专为多轮对话场景优化。
在线演示体验:https://huggingface.co/spaces/llamafactory/PaliGemma-3B-Chat-v0.2

使用方式
import requests
import torch
from PIL import Image
from transformers import AutoModelForVision2Seq, AutoProcessor, AutoTokenizer, TextStreamer
model_id = "BUAADreamer/PaliGemma-3B-Chat-v0.2"
tokenizer = AutoTokenizer.from_pretrained(model_id)
processor = AutoProcessor.from_pretrained(model_id)
model = AutoModelForVision2Seq.from_pretrained(model_id, torch_dtype="auto", device_map="auto")
streamer = TextStreamer(tokenizer, skip_prompt=True, skip_special_tokens=True)
url = "https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/transformers/tasks/car.jpg?download=true"
image = Image.open(requests.get(url, stream=True).raw)
pixel_values = processor(images=[image], return_tensors="pt").to(model.device)["pixel_values"]
messages = [
{"role": "user", "content": "这张图片里有什么?"}
]
input_ids = tokenizer.apply_chat_template(messages, add_generation_prompt=True, return_tensors="pt")
image_token_id = tokenizer.convert_tokens_to_ids("<image>")
image_prefix = torch.empty((1, getattr(processor, "image_seq_length")), dtype=input_ids.dtype).fill_(image_token_id)
input_ids = torch.cat((image_prefix, input_ids), dim=-1).to(model.device)
generate_ids = model.generate(input_ids, pixel_values=pixel_values, streamer=streamer, max_new_tokens=50)
训练流程
我们使用LLaMA Factory进行模型微调。训练过程中冻结了视觉编码器,仅调整语言模型和投影层的参数。
训练超参数
关键训练配置:
- 学习率:0.000003
- 训练轮次:2.0
- 批次大小:4
- 梯度累积步数:16
- 总训练批次:64
- 随机种子:42
- 学习率调度器:余弦退火
- 混合精度训练:bf16
展开查看Llama Factory配置
model_name_or_path: google/paligemma-3b-mix-448
visual_inputs: true
stage: sft
do_train: true
finetuning_type: full
ddp_timeout: 180000000
deepspeed: examples/deepspeed/ds_z3_config.json
dataset: identity,llava_150k_en,llava_150k_zh
template: gemma
cutoff_len: 1536
overwrite_cache: true
preprocessing_num_workers: 16
tokenized_path: cache/paligemma-identity-llava-zh-en-300k
output_dir: models/paligemma-3b-chat-v0.2
logging_steps: 10
save_steps: 1000
plot_loss: true
per_device_train_batch_size: 1
gradient_accumulation_steps: 16
learning_rate: 0.000003
num_train_epochs: 2.0
lr_scheduler_type: cosine
warmup_steps: 50
bf16: true
do_eval: false
框架版本
- Pytorch 2.3.0
- Transformers 4.41.0
评估结果
模型 |
MMMU验证集 |
CMMMU验证集 |
Yi-VL-6B |
36.8 |
32.2 |
Paligemma-3B-Chat-v0.2 |
33.0 |
29.0 |