Views
No views yet
Qwen2.5-1.5B-Instruct model, applying the Optimal Brain Restoration (OBR) framework as presented in the paper Optimal Brain Restoration for Joint Quantization and Sparsification of LLMs. OBR enables aggressive W4A4KV4 quantization with 50% sparsity on existing LLMs, delivering significant speedup and memory reduction.Qwen/Qwen2.5-7B-Instruct. It leverages the Optimal Brain Restoration (OBR) framework, a training-free method that aligns pruning and quantization by error compensation. OBR aims to minimize performance degradation on downstream tasks by using a second-order Hessian objective, reformulated into a tractable problem via surrogate approximation and group error compensation. This specific model instance uses the FlatQuant rotation scheme.Qwen/Qwen2.5-7B-InstructQwen2.5-7B-Instruct model would typically be used, but with significantly reduced computational overhead and memory footprint. It is particularly suitable for environments with limited memory or computational resources, or for deploying LLMs at scale.Qwen/Qwen2.5-7B-Instruct, may carry inherent biases from its training data. Compression techniques like quantization and sparsification, even when carefully applied with OBR, may also introduce minor performance fluctuations compared to the full-precision, dense model.transformers library. To get started, you can load the model using AutoModelForCausalLM and AutoTokenizer.transformers library version is transformers==4.45.0 or newer. You can install it via pip install transformers==4.45.0.1import torch
2from transformers import AutoTokenizer, AutoModelForCausalLM, GenerationConfig
3
4# This model ID is part of the OBR Hugging Face collection, specifically for FlatQuant on Qwen2.5
5model_id = "HangGuo/QWen2.5-7B-FlatQuant-OBR-GPTQ-W4A4KV4S50"
6
7# Load tokenizer and model
8tokenizer = AutoTokenizer.from_pretrained(model_id, trust_remote_code=True)
9model = AutoModelForCausalLM.from_pretrained(
10 model_id,
11 torch_dtype=torch.bfloat16, # Use bfloat16 as indicated in config.json
12 device_map="auto",
13 trust_remote_code=True
14)
15model.eval()
16
17# Load generation configuration from the model's own generation_config.json
18generation_config = GenerationConfig.from_pretrained(model_id)
19
20# Example prompt for an instruct model using Qwen's chat template
21messages = [
22 {"role": "system", "content": "You are Qwen, created by Alibaba Cloud. You are a helpful assistant."},
23 {"role": "user", "content": "Explain the concept of quantum entanglement in simple terms."}
24]
25input_ids = tokenizer.apply_chat_template(messages, tokenize=True, add_generation_prompt=True, return_tensors="pt").to(model.device)
26
27with torch.no_grad():
28 output_ids = model.generate(
29 input_ids,
30 generation_config=generation_config,
31 max_new_tokens=512, # You can override defaults from generation_config.json if needed
32 # Other generation parameters can be passed here or set in generation_config
33 )
34
35generated_text = tokenizer.decode(output_ids[0][input_ids.shape[1]:], skip_special_tokens=True)
36print(f"Prompt: {messages[-1]['content']}
37Generated: {generated_text}")Qwen/Qwen2.5-7B-Instruct, was trained on various datasets. The Optimal Brain Restoration (OBR) method is a post-training compression technique and does not involve additional training data for the compression process itself. However, it relies on a small calibration dataset (e.g., WikiText) to restore performance and optimize quantization/sparsity.1@article{guo2025optimal,
2 title={Optimal Brain Restoration for Joint Quantization and Sparsification of LLMs},
3 author={Hang Guo and Yawei Li and Luca Benini},
4 year={2025},
5 journal={arXiv preprint arXiv:2509.11177},
6 eprint={2509.11177},
7 archivePrefix={arXiv},
8 primaryClass={cs.CL},
9 url={http://arxiv.org/abs/2509.11177},
10}HangGuo/QWen2.5-1.5B-FlatQuant-OBR-GPTQ-W4A4KV4S50), which is compressed using the FlatQuant method, the applicable license is MIT License. Please refer to the FlatQuant GitHub repository for full license details.