Views
No views yet
1import requests
2import torch
3from PIL import Image
4from transformers import MllamaForConditionalGeneration, AutoProcessor
5
6quantized_model_path="OPEA/Llama-3.2V-11B-cot-int4-sym-inc"
7
8model = MllamaForConditionalGeneration.from_pretrained(
9 quantized_model_path,
10 torch_dtype="auto",
11 device_map="auto"
12)
13processor = AutoProcessor.from_pretrained(quantized_model_path)
14image_url = "https://huggingface.co/datasets/huggingface/documentation-images/resolve/0052a70beed5bf71b92610a43a52df6d286cd5f3/diffusers/rabbit.jpg"
15content = "Please write a haiku for this one, it would be: "
16
17messages = [
18 {"role": "user", "content": [
19 {"type": "image"},
20 {"type": "text", "text": content}
21 ]}
22]
23# Preparation for inference
24image = Image.open(requests.get(image_url, stream=True).raw)
25input_text = processor.apply_chat_template(messages, add_generation_prompt=True)
26inputs = processor(
27 image,
28 input_text,
29 add_special_tokens=False,
30 return_tensors="pt"
31).to(model.device)
32
33output = model.generate(**inputs, max_new_tokens=2048)
34print(output)
35##INT4:
36## Blue coat brown vest
37## Stone cottage green hills
38## Peaceful rural scene
39
40##BF16:
41## Rabbit in blue coat
42## Brown vest and stone cottage
43## Peaceful countryside
44
45image_url = "http://images.cocodataset.org/train2017/000000411975.jpg"
46content = "How many people are on the baseball field in the picture?"
47##INT4:
48## There are four people on the baseball field in the picture.
49
50##BF16:
51## There are four people on the baseball field in the picture.
52
53image_url = "https://intelcorp.scene7.com/is/image/intelcorp/processor-overview-framed-badge:1920-1080?wid=480&hei=270"
54content = "Which company does this picture represent?"
55##INT4:
56## This picture represents Intel.
57
58##BF16:
59## Intel1pip install auto-round
2auto-round-mllm \
3--model Xkev/Llama-3.2V-11B-cot \
4--device 0 \
5--group_size 128 \
6--bits 4 \
7--iters 200 \
8--nsample 128 \
9--seqlen 512 \
10--quant_nontext_module \
11--format 'auto_round' \
12--output_dir "./tmp_autoround"