Views
No views yet
qwen2.5-vl-32b-instruct-abliterated.safetensors - Full precision model weights (63GB, BF16 precision)qwen2.5-vl-32b-instruct-abliterated-f16.gguf - GGUF FP16 format (62GB)qwen2.5-vl-32b-instruct-abliterated-q5-k-m.gguf - GGUF Q5_K_M quantized (22GB)qwen2.5-vl-32b-instruct-abliterated-q4-k-m.gguf - GGUF Q4_K_M quantized (19GB)config.json - Model configurationpreprocessor_config.json - Image/video preprocessing settingstokenizer.json / tokenizer_config.json - Tokenizer filesgeneration_config.json - Text generation parametersprocessor_config.json - Unified processor configuration1# Install from transformers source (recommended)
2pip install git+https://github.com/huggingface/transformers accelerate
3pip install qwen-vl-utils[decord]==0.0.8
4
5# Additional dependencies
6pip install torch torchvision pillow1# Install llama-cpp-python with GPU support
2pip install llama-cpp-python --extra-index-url https://abetlen.github.io/llama-cpp-python/whl/cu121
3
4# Or build llama.cpp from source
5git clone https://github.com/ggerganov/llama.cpp
6cd llama.cpp
7make LLAMA_CUDA=1 # For NVIDIA GPUs
8# or
9make LLAMA_METAL=1 # For Apple Silicon1from transformers import Qwen2_5_VLForConditionalGeneration, AutoProcessor
2from PIL import Image
3import torch
4
5# Load model and processor
6model = Qwen2_5_VLForConditionalGeneration.from_pretrained(
7 "E:/huggingface/qwen2.5-vl-32b-instruct",
8 torch_dtype=torch.bfloat16,
9 device_map="auto"
10)
11processor = AutoProcessor.from_pretrained("E:/huggingface/qwen2.5-vl-32b-instruct")
12
13# Prepare image and text input
14image = Image.open("your_image.jpg")
15messages = [
16 {
17 "role": "user",
18 "content": [
19 {"type": "image", "image": image},
20 {"type": "text", "text": "Describe this image in detail."}
21 ]
22 }
23]
24
25# Process and generate
26text = processor.apply_chat_template(messages, tokenize=False, add_generation_prompt=True)
27inputs = processor(text=[text], images=[image], return_tensors="pt", padding=True)
28inputs = inputs.to("cuda")
29
30# Generate response
31output_ids = model.generate(**inputs, max_new_tokens=512)
32generated_text = processor.batch_decode(output_ids, skip_special_tokens=True)
33print(generated_text[0])1# Multiple images in conversation
2messages = [
3 {
4 "role": "user",
5 "content": [
6 {"type": "image", "image": "image1.jpg"},
7 {"type": "image", "image": "image2.jpg"},
8 {"type": "text", "text": "Compare these two images and identify the differences."}
9 ]
10 }
11]
12
13# Process with multiple images
14images = [Image.open("image1.jpg"), Image.open("image2.jpg")]
15text = processor.apply_chat_template(messages, tokenize=False, add_generation_prompt=True)
16inputs = processor(text=[text], images=images, return_tensors="pt")
17inputs = inputs.to("cuda")
18
19output_ids = model.generate(**inputs, max_new_tokens=1024)
20response = processor.batch_decode(output_ids, skip_special_tokens=True)
21print(response[0])1from qwen_vl_utils import process_vision_info
2
3# Process video input
4messages = [
5 {
6 "role": "user",
7 "content": [
8 {"type": "video", "video": "your_video.mp4", "fps": 1.0},
9 {"type": "text", "text": "Summarize the main events in this video."}
10 ]
11 }
12]
13
14# Process video with configurable FPS
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)
24inputs = inputs.to("cuda")
25
26# Generate video analysis
27output_ids = model.generate(**inputs, max_new_tokens=1024)
28response = processor.batch_decode(output_ids, skip_special_tokens=True)
29print(response[0])1# Enhanced mathematical reasoning
2messages = [
3 {
4 "role": "user",
5 "content": [
6 {"type": "image", "image": "math_diagram.png"},
7 {"type": "text", "text": "Solve this geometry problem step by step."}
8 ]
9 }
10]
11
12# Process with detailed reasoning
13text = processor.apply_chat_template(messages, tokenize=False, add_generation_prompt=True)
14inputs = processor(text=[text], images=[Image.open("math_diagram.png")], return_tensors="pt")
15inputs = inputs.to("cuda")
16
17# Generate detailed solution
18output_ids = model.generate(**inputs, max_new_tokens=2048, do_sample=False)
19solution = processor.batch_decode(output_ids, skip_special_tokens=True)
20print(solution[0])1# Extract structured information from documents
2messages = [
3 {
4 "role": "user",
5 "content": [
6 {"type": "image", "image": "invoice.jpg"},
7 {"type": "text", "text": "Extract all line items from this invoice in JSON format."}
8 ]
9 }
10]
11
12# Process document
13text = processor.apply_chat_template(messages, tokenize=False, add_generation_prompt=True)
14inputs = processor(text=[text], images=[Image.open("invoice.jpg")], return_tensors="pt")
15inputs = inputs.to("cuda")
16
17# Generate structured output
18output_ids = model.generate(**inputs, max_new_tokens=1024, temperature=0.1)
19structured_data = processor.batch_decode(output_ids, skip_special_tokens=True)
20print(structured_data[0])1# Adjust visual token resolution
2processor_config = processor.image_processor
3processor_config.min_pixels = 256 * 256 # Minimum resolution
4processor_config.max_pixels = 2048 * 2048 # Maximum resolution
5
6# Process with custom resolution
7inputs = processor(
8 text=[text],
9 images=[image],
10 return_tensors="pt",
11 resized_height=1024,
12 resized_width=1024
13)1# Efficient batch inference
2batch_messages = [
3 [{"role": "user", "content": [{"type": "image", "image": f"img{i}.jpg"},
4 {"type": "text", "text": "Describe this image."}]}]
5 for i in range(4)
6]
7
8# Process batch
9texts = [processor.apply_chat_template(msg, tokenize=False, add_generation_prompt=True)
10 for msg in batch_messages]
11images_batch = [Image.open(f"img{i}.jpg") for i in range(4)]
12inputs = processor(text=texts, images=images_batch, return_tensors="pt", padding=True)
13inputs = inputs.to("cuda")
14
15# Batch generation
16output_ids = model.generate(**inputs, max_new_tokens=512)
17responses = processor.batch_decode(output_ids, skip_special_tokens=True)
18for i, resp in enumerate(responses):
19 print(f"Image {i}: {resp}")1from llama_cpp import Llama
2from llama_cpp.llama_chat_format import Qwen2VLChatHandler
3
4# Initialize model with vision support
5chat_handler = Qwen2VLChatHandler()
6llm = Llama(
7 model_path="E:/huggingface/qwen2.5-vl-32b-instruct/qwen2.5-vl-32b-instruct-abliterated-q4-k-m.gguf",
8 chat_handler=chat_handler,
9 n_ctx=32768, # Context window
10 n_gpu_layers=50, # Offload layers to GPU (-1 for all)
11 n_batch=512,
12 verbose=False
13)
14
15# Vision-language inference
16response = llm.create_chat_completion(
17 messages=[
18 {
19 "role": "user",
20 "content": [
21 {"type": "image_url", "image_url": {"url": "file:///path/to/image.jpg"}},
22 {"type": "text", "text": "Describe this image in detail."}
23 ]
24 }
25 ],
26 max_tokens=512,
27 temperature=0.7
28)
29
30print(response['choices'][0]['message']['content'])1# GPU-accelerated inference with Q4_K_M
2./llama-cli \
3 -m E:/huggingface/qwen2.5-vl-32b-instruct/qwen2.5-vl-32b-instruct-abliterated-q4-k-m.gguf \
4 --image your_image.jpg \
5 -p "Describe this image in detail." \
6 -n 512 \
7 -ngl 50 \
8 --ctx-size 32768
9
10# CPU-only inference with Q5_K_M
11./llama-cli \
12 -m E:/huggingface/qwen2.5-vl-32b-instruct/qwen2.5-vl-32b-instruct-abliterated-q5-k-m.gguf \
13 --image your_image.jpg \
14 -p "What objects are in this image?" \
15 -n 256 \
16 -t 16 \
17 --ctx-size 8192
18
19# Server mode for API access
20./llama-server \
21 -m E:/huggingface/qwen2.5-vl-32b-instruct/qwen2.5-vl-32b-instruct-abliterated-q4-k-m.gguf \
22 --host 0.0.0.0 \
23 --port 8080 \
24 -ngl 50 \
25 --ctx-size 32768| Model File | Full GPU (ngl) | 24GB GPU (ngl) | 16GB GPU (ngl) | CPU Only (ngl) |
|---|---|---|---|---|
| F16 (62GB) | -1 (all) | ~20 layers | ~10 layers | 0 |
| Q5_K_M (22GB) | -1 (all) | ~40 layers | ~25 layers | 0 |
| Q4_K_M (19GB) | -1 (all) | 50+ layers | ~35 layers | 0 |
| Benchmark | Score | Category |
|---|---|---|
| MMMU | 70.0 | Multimodal Understanding |
| MMMU-Pro | - | Advanced Reasoning |
| MathVista | 74.7 | Mathematical Reasoning |
| DocVQA | 94.8 | Document Understanding |
| Android Control | 69.6/93.3 | Agentic Interaction |
| MMLU | 78.4 | Language Understanding |
| MATH | 82.2 | Mathematical Problem Solving |
| HumanEval | 91.5 | Code Generation |
1model = Qwen2_5_VLForConditionalGeneration.from_pretrained(
2 "E:/huggingface/qwen2.5-vl-32b-instruct",
3 torch_dtype=torch.bfloat16,
4 attn_implementation="flash_attention_2", # 2-3x faster
5 device_map="auto"
6)1# INT8 quantization (requires bitsandbytes)
2from transformers import BitsAndBytesConfig
3
4quantization_config = BitsAndBytesConfig(
5 load_in_8bit=True,
6 llm_int8_threshold=6.0
7)
8
9model = Qwen2_5_VLForConditionalGeneration.from_pretrained(
10 "E:/huggingface/qwen2.5-vl-32b-instruct",
11 quantization_config=quantization_config,
12 device_map="auto"
13)1# For sequences > 32K tokens
2model.config.rope_scaling = {
3 "type": "yarn",
4 "factor": 4.0, # Extend to 128K tokens
5 "original_max_position_embeddings": 32768
6}1# Clear CUDA cache between runs
2import torch
3torch.cuda.empty_cache()
4
5# Gradient checkpointing for fine-tuning
6model.gradient_checkpointing_enable()
7
8# CPU offloading for large batches
9model = Qwen2_5_VLForConditionalGeneration.from_pretrained(
10 "E:/huggingface/qwen2.5-vl-32b-instruct",
11 torch_dtype=torch.bfloat16,
12 device_map="auto",
13 offload_folder="offload",
14 offload_state_dict=True
15)1pip install vllm
2
3python -m vllm.entrypoints.openai.api_server \
4 --model E:/huggingface/qwen2.5-vl-32b-instruct \
5 --dtype bfloat16 \
6 --max-model-len 32768 \
7 --gpu-memory-utilization 0.91docker run --gpus all --shm-size 1g -p 8080:80 \
2 -v E:/huggingface/qwen2.5-vl-32b-instruct:/data \
3 ghcr.io/huggingface/text-generation-inference:latest \
4 --model-id /data --dtype bfloat161from transformers import Trainer, TrainingArguments
2
3training_args = TrainingArguments(
4 output_dir="./qwen-vl-finetuned",
5 per_device_train_batch_size=1,
6 gradient_accumulation_steps=16,
7 learning_rate=2e-5,
8 num_train_epochs=3,
9 bf16=True,
10 logging_steps=10,
11 save_strategy="epoch"
12)
13
14trainer = Trainer(
15 model=model,
16 args=training_args,
17 train_dataset=train_dataset,
18 data_collator=data_collator
19)
20
21trainer.train()Copyright 2025 Alibaba Cloud (base model)
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.1@article{qwen2.5-vl,
2 title={Qwen2.5-VL Technical Report},
3 author={Bai, Jinze and others},
4 journal={arXiv preprint arXiv:2502.13923},
5 year={2025},
6 url={https://arxiv.org/abs/2502.13923}
7}