Views
No views yet
pip install auto-adpq1import torch
2from transformers import AutoModelForCausalLM, AutoTokenizer
3
4model_id = "Tfloow/Llama-3.2-3B-adpq-4bit-sim"
5
6model = AutoModelForCausalLM.from_pretrained(
7 model_id,
8 torch_dtype=torch.bfloat16,
9 device_map="auto"
10)
11tokenizer = AutoTokenizer.from_pretrained(model_id)
12
13inputs = tokenizer("Hello, world!", return_tensors="pt").to("cuda")
14output = model.generate(**inputs, max_new_tokens=20)
15print(tokenizer.decode(output[0]))| Model Variant | Quantization Method | PPL (Perplexity) |
|---|---|---|
| meta-llama/Llama-3.1-8B | Baseline | 4.8693 |
| BNB | 5.0733 | |
| AdpQ | 5.3671 | |
| meta-llama/Llama-3.1-8B-Instruct | Baseline | 4.9080 |
| BNB | 4.9993 | |
| AdpQ | 5.0069 | |
| AWQ | 5.0440 | |
| GPTQ | nan | |
| meta-llama/Llama-3.2-1B | Baseline | 6.5546 |
| AdpQ 9% | 6.9491 | |
| BNB | 6.9971 | |
| AdpQ 2% | 7.0380 | |
| meta-llama/Llama-3.2-3B-Instruct | Baseline | 5.7864 |
| AWQ | 5.8339 | |
| AdpQ | 5.9040 |
1
2import torch
3from transformers import AutoModelForCausalLM
4
5from auto_adpq import Auto_AdpQ, AutoAdpQConfig
6
7model_name = "meta-llama/Llama-3.2-3B"
8
9# Setup Auto-AdpQ configuration
10adpq_config = AutoAdpQConfig(
11 group_size=group_size,
12 n_iters=250, # Throw UserWarning if too low
13 alpha=0.05, # The higher, the better the PPL loss but higher overhead
14 device="cpu",
15 q_bit=4,
16 data_packing=False,
17 symmetrical_quantization=True,
18)
19
20user = "Tfloow"
21adpq_model_name = f"{user}/{model_name.split('/')[-1]}-adpq-4bit-sim"
22
23model = AutoModelForCausalLM.from_pretrained(model_name, torch_dtype=torch.bfloat16)
24
25# virtual quantization
26quantized = Auto_AdpQ.apply_quantization(model, adpq_config, multi_threaded=16)
27
28model.push_to_hub(adpq_model_name)