hiyouga's picture
Update README.md
4d97e30 verified
|
raw
history blame
2.18 kB
metadata
license: gemma
datasets:
  - BUAADreamer/llava-en-zh-2k
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.1

This model is fine-tuned from google/paligemma-3b-mix-448 using LLaMA Factory.

examples

Usage

import requests
import torch
from PIL import Image
from transformers import AutoModelForVision2Seq, AutoProcessor, AutoTokenizer, TextStreamer


model_id = "hiyouga/PaliGemma-3B-Chat-v0.1"
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": "What is in this image?"}
]
input_ids = tokenizer.apply_chat_template(messages, tokenize=True, 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)

Training procedure

Training hyperparameters

The following hyperparameters were used during training:

  • learning_rate: 0.00001
  • num_train_epochs: 3.0
  • train_batch_size: 1
  • gradient_accumulation_steps: 8
  • total_train_batch_size: 16
  • seed: 42
  • lr_scheduler_type: cosine
  • mixed_precision_training: bf16

Framework versions

  • Pytorch 2.3.0
  • Transformers 4.41.0