Views
No views yet
LlavaForConditionalGeneration class. However, you should use the processor from the base model to ensure correct input preprocessing.1from transformers import AutoProcessor, LlavaForConditionalGeneration
2import torch
3
4model_id = "CrystalRaindropsFall/llava-glu30-heads30"
5base_model_id = "llava-hf/llava-1.5-7b-hf"
6
7# 1. Load the processor from the base model
8processor = AutoProcessor.from_pretrained(base_model_id)
9
10# 2. Load the pruned model
11model = LlavaForConditionalGeneration.from_pretrained(
12 model_id,
13 torch_dtype=torch.float16,
14 device_map="auto"
15)
16
17# Example inference
18from PIL import Image
19import requests
20
21url = "https://github.com/haotian-liu/LLaVA/blob/1a91fc274d7c35a9b50b3cb29c4247ae5837ce39/images/llava_logo.png?raw=true"
22image = Image.open(requests.get(url, stream=True).raw)
23prompt = "USER: <image>\nWhat is shown in this image?\nASSISTANT:"
24
25inputs = processor(images=image, text=prompt, return_tensors="pt").to(model.device, model.dtype)
26
27output = model.generate(**inputs, max_new_tokens=100, do_sample=False)
28print(processor.decode(output[0], skip_special_tokens=True))