Views
No views yet

transformers >= 4.35.3.
The model supports multi-image and multi-prompt generation. Meaning that you can pass multiple images in your prompt. Make sure also to follow the correct prompt template (USER: xxx\nASSISTANT:) and add the token <image> to the location where you want to query images:pipeline:"YouLiXiya/tinyllava-v1.0-1.1b-hf" checkpoint.1from transformers import pipeline
2from PIL import Image
3import requests
4
5model_id = "YouLiXiya/tinyllava-v1.0-1.1b-hf"
6pipe = pipeline("image-to-text", model=model_id)
7url = "https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/transformers/tasks/ai2d-demo.jpg"
8
9image = Image.open(requests.get(url, stream=True).raw)
10prompt = "USER: <image>\nWhat does the label 15 represent? (1) lava (2) core (3) tunnel (4) ash cloud\nASSISTANT:"
11
12outputs = pipe(image, prompt=prompt, generate_kwargs={"max_new_tokens": 200})
13print(outputs)
14{'generated_text': 'USER: \nWhat does the label 15 represent? (1) lava (2) core (3) tunnel (4) ash cloud\nASSISTANT: The label 15 represents lava, which is the type of rock that is formed from molten magma. '}transformers:float16 precision on a GPU device:1import requests
2from PIL import Image
3
4import torch
5from transformers import AutoProcessor, LlavaForConditionalGeneration
6
7model_id = "YouLiXiya/tinyllava-v1.0-1.1b-hf"
8
9prompt = "USER: <image>\nWhat are these?\nASSISTANT:"
10image_file = "http://images.cocodataset.org/val2017/000000039769.jpg"
11
12model = LlavaForConditionalGeneration.from_pretrained(
13 model_id,
14 torch_dtype=torch.float16,
15 low_cpu_mem_usage=True,
16).to(0)
17
18processor = AutoProcessor.from_pretrained(model_id)
19
20raw_image = Image.open(requests.get(image_file, stream=True).raw)
21inputs = processor(prompt, raw_image, return_tensors='pt').to(0, torch.float16)
22
23output = model.generate(**inputs, max_new_tokens=200, do_sample=False)
24print(processor.decode(output[0][2:], skip_special_tokens=True))bitsandbytes librarybitsandbytes, pip install bitsandbytes and make sure to have access to a CUDA compatible GPU device. Simply change the snippet above with:1model = LlavaForConditionalGeneration.from_pretrained(
2 model_id,
3 torch_dtype=torch.float16,
4 low_cpu_mem_usage=True,
5+ load_in_4bit=True
6)flash-attn. Refer to the original repository of Flash Attention regarding that package installation. Simply change the snippet above with:1model = LlavaForConditionalGeneration.from_pretrained(
2 model_id,
3 torch_dtype=torch.float16,
4 low_cpu_mem_usage=True,
5+ use_flash_attention_2=True
6).to(0)