Views
No views yet
Kendamarron/Llama-3.2-11B-Vision-Instruct-Swallow-8B-Merge = Llama-3.2-11B-Vision-Instruct + (Llama-3.1-Swallow-8B-v0.1 - Llama-3.1-8B)1import requests
2import torch
3from PIL import Image
4from transformers import MllamaForConditionalGeneration, AutoProcessor
5
6model_id = "Kendamarron/Llama-3.2-11B-Vision-Instruct-Swallow-8B-LoRA"
7
8model = MllamaForConditionalGeneration.from_pretrained(
9 model_id,
10 torch_dtype=torch.bfloat16,
11 device_map="auto",
12)
13processor = AutoProcessor.from_pretrained(model_id)
14
15url = "https://huggingface.co/datasets/huggingface/documentation-images/resolve/0052a70beed5bf71b92610a43a52df6d286cd5f3/diffusers/rabbit.jpg"
16image = Image.open(requests.get(url, stream=True).raw)
17
18messages = [
19 {"role": "user", "content": [
20 {"type": "image"},
21 {"type": "text", "text": "この画像で一句詠んでください。"}
22 ]}
23]
24input_text = processor.apply_chat_template(messages, add_generation_prompt=True)
25inputs = processor(
26 image,
27 input_text,
28 add_special_tokens=False,
29 return_tensors="pt"
30).to(model.device)
31
32output = model.generate(**inputs, max_new_tokens=30)
33print(processor.decode(output[0]))