Views
No views yet
1
2from transformers import AutoModelForCausalLM, AutoTokenizer
3
4from llmcompressor import oneshot
5from llmcompressor.modifiers.awq import AWQModifier
6
7MODEL_ID = "Qwen/Qwen3-Coder-30B-A3B-Instruct"
8
9SAVE_DIR = MODEL_ID.split("/")[-1] + "-W4A16-awq"
10
11
12# Configure the quantization algorithm to run.
13recipe = [
14 AWQModifier(
15 duo_scaling=False,
16 ignore=[
17 "lm_head",
18 "re:.*mlp.gate$",
19 "re:.*mlp.shared_expert_gate$",
20 "re:visual.*",
21 ],
22 scheme="W4A16",
23 targets=["Linear"],
24 ),
25]
26
27# Select calibration dataset.
28DATASET_ID = "codeparrot/self-instruct-starcoder"
29DATASET_SPLIT = "curated"
30
31# Select number of samples. 256 samples is a good place to start.
32# Increasing the number of samples can improve accuracy.
33NUM_CALIBRATION_SAMPLES = 256
34MAX_SEQUENCE_LENGTH = 2048
35
36
37def get_calib_dataset(tokenizer):
38 from datasets import load_dataset
39
40 ds = load_dataset(
41 DATASET_ID,
42 split=f"{DATASET_SPLIT}[:{NUM_CALIBRATION_SAMPLES*10}]",
43 )
44
45 def preprocess(example):
46 chat_messages = [
47 {"role": "user", "content": example["instruction"].strip()},
48 {"role": "assistant", "content": example["output"].strip()},
49 ]
50 tokenized_messages = tokenizer.apply_chat_template(
51 chat_messages, tokenize=True
52 )
53 return {"input_ids": tokenized_messages}
54
55 ds = (
56 ds.shuffle(seed=42)
57 .map(preprocess, remove_columns=ds.column_names)
58 .select(range(NUM_CALIBRATION_SAMPLES))
59 )
60
61 return ds
62
63
64if __name__ == "__main__":
65 model = AutoModelForCausalLM.from_pretrained(
66 MODEL_ID, torch_dtype="auto", trust_remote_code=True
67 )
68 tokenizer = AutoTokenizer.from_pretrained(MODEL_ID, trust_remote_code=True)
69
70 ###
71 ### Apply algorithms.
72 ###
73 oneshot(
74 model=model,
75 dataset=get_calib_dataset(tokenizer),
76 recipe=recipe,
77 max_seq_length=MAX_SEQUENCE_LENGTH,
78 num_calibration_samples=NUM_CALIBRATION_SAMPLES,
79 log_dir=None,
80 trust_remote_code_model=True,
81 )
82
83 model.save_pretrained(SAVE_DIR)
84 tokenizer.save_pretrained(SAVE_DIR)1python evalplus/codegen/generate.py --model nm-testing/Qwen3-Coder-30B-A3B-Instruct-W4A16-awq --bs 16 --temperature 0.2 --n_samples 50 --root "./results" --dataset humaneval --backend vllm --dtype auto
2
3python evalplus/evalplus/sanitize.py results/humaneval/nm-testing--Qwen3-Coder-30B-A3B-Instruct-W4A16-awq_vllm_temp_0.2
4
5evalplus.evaluate --dataset humaneval --samples results/humaneval/nm-testing--Qwen3-Coder-30B-A3B-Instruct-W4A16-awq_vllm_temp_0.2-sanitized
6| Metric | Qwen/Qwen3-Coder-30B-A3B-Instruct | nm-testing/Qwen3-Coder-30B-A3B-Instruct-W4A16-awq |
|---|---|---|
| HumanEval pass@1 | 93.0 | 93.7 |
| HumanEval pass@10 | 93.9 | 94.5 |
| HumanEval+ pass@1 | 88.7 | 89.3 |
| HumanEval+ pass@10 | 89.8 | 90.2 |
| Average Score | 91.35 | 91.93 |