Views
No views yet
1model_name = "Qwen/Qwen2.5-VL-7B-Instruct"
2config = AutoConfig.from_pretrained(model_name)
3#it cost few minute to load model in float32, although config is to appoint bfloat16
4model = Qwen2_5_VLForConditionalGeneration(config)
5model.to(torch.bfloat16)
6processor = AutoProcessor.from_pretrained(model_name)
7# Apply AWQ
8quantization_config_path = "./weights/AWQ_config.json"
9quantization_weight_path = "./weights/AWQ_weights.pth"
10res = apply_AWQ(model, quantization_config_path, quantization_weight_path=quantization_weight_path)1messages = [
2 {
3 "role": "user",
4 "content": [
5 {
6 "type": "image",
7 "image": "<url id=\"cuq4ml2misdhuceigs30\" type=\"url\" status=\"failed\" title=\"\" wc=\"0\">https://qianwen-res.oss-cn-beijing.aliyuncs.com/Qwen-VL/assets/demo.jpeg</url>",
8 },
9 {"type": "text", "text": "What does this photo show ?"},
10 ],
11 }
12]
13
14# Preparation for inference
15text = processor.apply_chat_template(messages, tokenize=False, add_generation_prompt=True)
16image_inputs, video_inputs = process_vision_info(messages)
17inputs = processor(
18 text=[text],
19 images=image_inputs,
20 videos=video_inputs,
21 padding=True,
22 return_tensors="pt",
23)
24
25# Inference: Generation of the output
26device = "cuda"
27inputs = inputs.to(device)
28model.to(device)
29model.eval()
30generated_ids = model.generate(**inputs, max_new_tokens=128)
31generated_ids_trimmed = [
32 out_ids[len(in_ids):] for in_ids, out_ids in zip(inputs.input_ids, generated_ids)
33]
34output_text = processor.batch_decode(
35 generated_ids_trimmed, skip_special_tokens=True, clean_up_tokenization_spaces=False
36)
37print(output_text)