Views
No views yet
| Metric | Original | Quantized |
|---|---|---|
| Model Size | 14.5 GB | 4.6 GB |
| VRAM Usage | ~14-15 GB | ~4.5-5.5 GB |
| Vision Quality | 100% | 100% (preserved) |
| Text Layers | FP16 | INT4 |
1import torch
2from transformers import Qwen2_5_VLForConditionalGeneration, AutoProcessor
3from quanto import safe_load, quantize, freeze, qint4
4
5# Load base architecture
6model = Qwen2_5_VLForConditionalGeneration.from_pretrained(
7 "Hadidiz9/UI-S1-7B-Hybrid-W4-Quanto",
8 torch_dtype=torch.bfloat16,
9 device_map="auto",
10 trust_remote_code=True
11)
12
13# Load quantized weights
14state_dict = safe_load("quanto_model.safetensors")
15model.load_state_dict(state_dict, strict=False)
16
17# Requantize (restore quanto layers)
18vision_keywords = ['visual', 'vision', 'image', 'patch', 'merger', 'projector', 'embed_tokens', 'lm_head']
19exclude_modules = []
20for name, module in model.named_modules():
21 if isinstance(module, torch.nn.Linear):
22 if any(k in name.lower() for k in vision_keywords):
23 exclude_modules.append(name)
24
25quantize(model, weights=qint4, exclude=exclude_modules)
26freeze(model)
27model.eval()
28
29processor = AutoProcessor.from_pretrained("Hadidiz9/UI-S1-7B-Hybrid-W4-Quanto", trust_remote_code=True)1from PIL import Image
2from qwen_vl_utils import process_vision_info
3
4# Load image
5image = Image.open("screenshot.png")
6
7# Prepare messages
8messages = [
9 {
10 "role": "user",
11 "content": [
12 {"type": "image", "image": image},
13 {"type": "text", "text": "Describe the UI elements."}
14 ]
15 }
16]
17
18# Process
19text = processor.apply_chat_template(messages, tokenize=False, add_generation_prompt=True)
20image_inputs, video_inputs = process_vision_info(messages)
21
22inputs = processor(
23 text=[text],
24 images=image_inputs,
25 videos=video_inputs,
26 padding=True,
27 return_tensors="pt",
28).to(model.device)
29
30# Generate
31with torch.no_grad():
32 generated_ids = model.generate(**inputs, max_new_tokens=128)
33
34response = processor.batch_decode(
35 [out[len(inp):] for inp, out in zip(inputs.input_ids, generated_ids)],
36 skip_special_tokens=True
37)[0]quanto library for loading1@article{lu2025ui,
2 title={UI-S1: Advancing GUI Automation via Semi-online Reinforcement Learning},
3 author={Lu, Zhengxi and others},
4 journal={arXiv preprint arXiv:2509.11543},
5 year={2025}
6}