Eldar Kurtic commited on
Commit
a7050c3
·
1 Parent(s): e2b34ee
.gitattributes CHANGED
@@ -33,3 +33,4 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
33
  *.zip filter=lfs diff=lfs merge=lfs -text
34
  *.zst filter=lfs diff=lfs merge=lfs -text
35
  *tfevents* filter=lfs diff=lfs merge=lfs -text
 
 
33
  *.zip filter=lfs diff=lfs merge=lfs -text
34
  *.zst filter=lfs diff=lfs merge=lfs -text
35
  *tfevents* filter=lfs diff=lfs merge=lfs -text
36
+ tokenizer.json filter=lfs diff=lfs merge=lfs -text
README.md ADDED
@@ -0,0 +1,207 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ tags:
3
+ - w8a8
4
+ - int8
5
+ - vllm
6
+ license: apache-2.0
7
+ license_link: https://huggingface.co/Qwen/QwQ-32B-Preview/blob/main/LICENSE
8
+ language:
9
+ - en
10
+ base_model: Qwen/Qwen2.5-32B-Instruct
11
+ tags:
12
+ - chat
13
+ library_name: transformers
14
+ ---
15
+
16
+ # QwQ-32B-Preview-quantized.w8a8
17
+
18
+ ## Model Overview
19
+ - **Model Architecture:** QwQ-32B-Preview
20
+ - **Input:** Text
21
+ - **Output:** Text
22
+ - **Model Optimizations:**
23
+ - **Weight quantization:** INT8
24
+ - **Activation quantization:** INT8
25
+ - **Release Date:** 3/1/2025
26
+ - **Version:** 1.0
27
+ - **Model Developers:** Neural Magic
28
+
29
+ Quantized version of [QwQ-32B-Preview](https://huggingface.co/Qwen/QwQ-32B-Preview).
30
+ It achieves an average score of 76.49 on the [OpenLLM](https://huggingface.co/spaces/open-llm-leaderboard/open_llm_leaderboard) benchmark (version 1), whereas the unquantized model achieves 77.20.
31
+
32
+ ### Model Optimizations
33
+
34
+ This model was obtained by quantizing the weights and activations of [QwQ-32B-Preview](https://huggingface.co/Qwen/QwQ-32B-Preview) to INT8 data type, ready for inference with vLLM >= 0.5.2.
35
+ This optimization reduces the number of bits per parameter from 16 to 8, reducing the disk size and GPU memory requirements by approximately 50%. Only the weights and activations of the linear operators within transformers blocks are quantized.
36
+
37
+ ## Deployment
38
+
39
+ ### Use with vLLM
40
+
41
+ This model can be deployed efficiently using the [vLLM](https://docs.vllm.ai/en/latest/) backend, as shown in the example below.
42
+
43
+ ```python
44
+ from transformers import AutoTokenizer
45
+ from vllm import LLM, SamplingParams
46
+
47
+ max_model_len, tp_size = 4096, 1
48
+ model_name = "neuralmagic-ent/QwQ-32B-Preview-quantized.w8a8"
49
+ tokenizer = AutoTokenizer.from_pretrained(model_name)
50
+ llm = LLM(model=model_name, tensor_parallel_size=tp_size, max_model_len=max_model_len, trust_remote_code=True)
51
+ sampling_params = SamplingParams(temperature=0.3, max_tokens=256, stop_token_ids=[tokenizer.eos_token_id])
52
+
53
+ messages_list = [
54
+ [{"role": "user", "content": "Who are you? Please respond in pirate speak!"}],
55
+ ]
56
+
57
+ prompt_token_ids = [tokenizer.apply_chat_template(messages, add_generation_prompt=True) for messages in messages_list]
58
+
59
+ outputs = llm.generate(prompt_token_ids=prompt_token_ids, sampling_params=sampling_params)
60
+
61
+ generated_text = [output.outputs[0].text for output in outputs]
62
+ print(generated_text)
63
+ ```
64
+
65
+ vLLM also supports OpenAI-compatible serving. See the [documentation](https://docs.vllm.ai/en/latest/) for more details.
66
+
67
+ ## Creation
68
+
69
+ This model was created with [llm-compressor](https://github.com/vllm-project/llm-compressor) by running the code snippet below with the following arguments:
70
+
71
+
72
+ ```bash
73
+ python quantize.py --model_path Qwen/QwQ-32B-Preview --quant_path "output_dir/QwQ-32B-Preview-quantized.w8a8" --calib_size 1024 --dampening_frac 0.1 --observer mse
74
+ ```
75
+
76
+
77
+ ```python
78
+ from datasets import load_dataset
79
+ from transformers import AutoTokenizer
80
+ from llmcompressor.modifiers.quantization import GPTQModifier
81
+ from llmcompressor.transformers import SparseAutoModelForCausalLM, oneshot, apply
82
+ import argparse
83
+ from compressed_tensors.quantization import QuantizationScheme, QuantizationArgs, QuantizationType, QuantizationStrategy
84
+
85
+
86
+ parser = argparse.ArgumentParser()
87
+ parser.add_argument('--model_path', type=str)
88
+ parser.add_argument('--quant_path', type=str)
89
+ parser.add_argument('--calib_size', type=int, default=256)
90
+ parser.add_argument('--dampening_frac', type=float, default=0.1)
91
+ parser.add_argument('--observer', type=str, default="minmax")
92
+ args = parser.parse_args()
93
+
94
+ model = SparseAutoModelForCausalLM.from_pretrained(
95
+ args.model_path,
96
+ device_map="auto",
97
+ torch_dtype="auto",
98
+ use_cache=False,
99
+ trust_remote_code=True,
100
+ )
101
+ tokenizer = AutoTokenizer.from_pretrained(args.model_path)
102
+
103
+ NUM_CALIBRATION_SAMPLES = args.calib_size
104
+ DATASET_ID = "garage-bAInd/Open-Platypus"
105
+ DATASET_SPLIT = "train"
106
+ ds = load_dataset(DATASET_ID, split=DATASET_SPLIT)
107
+ ds = ds.shuffle(seed=42).select(range(NUM_CALIBRATION_SAMPLES))
108
+
109
+ def preprocess(example):
110
+ concat_txt = example["instruction"] + "\n" + example["output"]
111
+ return {"text": concat_txt}
112
+
113
+ ds = ds.map(preprocess)
114
+
115
+ def tokenize(sample):
116
+ return tokenizer(
117
+ sample["text"],
118
+ padding=False,
119
+ truncation=False,
120
+ add_special_tokens=True,
121
+ )
122
+
123
+
124
+ ds = ds.map(tokenize, remove_columns=ds.column_names)
125
+
126
+ recipe = [
127
+ GPTQModifier(
128
+ targets=["Linear"],
129
+ ignore=["lm_head"],
130
+ scheme="W8A8",
131
+ dampening_frac=args.dampening_frac,
132
+ observer=args.observer,
133
+ )
134
+ ]
135
+ oneshot(
136
+ model=model,
137
+ dataset=ds,
138
+ recipe=recipe,
139
+ num_calibration_samples=args.calib_size,
140
+ max_seq_length=8192,
141
+ )
142
+
143
+ # Save to disk compressed.
144
+ SAVE_DIR = args.quant_path
145
+ model.save_pretrained(SAVE_DIR, save_compressed=True)
146
+ tokenizer.save_pretrained(SAVE_DIR)
147
+ ```
148
+
149
+ ## Evaluation
150
+
151
+ The model was evaluated on OpenLLM Leaderboard [V1](https://huggingface.co/spaces/open-llm-leaderboard-old/open_llm_leaderboard) and [V2](https://huggingface.co/spaces/open-llm-leaderboard/open_llm_leaderboard#/), using the following commands:
152
+
153
+ OpenLLM Leaderboard V1:
154
+ ```
155
+ lm_eval \
156
+ --model vllm \
157
+ --model_args pretrained="neuralmagic-ent/QwQ-32B-Preview-quantized.w8a8",dtype=auto,add_bos_token=True,max_model_len=4096,tensor_parallel_size=1,gpu_memory_utilization=0.8,enable_chunked_prefill=True,trust_remote_code=True \
158
+ --tasks openllm \
159
+ --write_out \
160
+ --batch_size auto \
161
+ --output_path output_dir \
162
+ --show_config
163
+ ```
164
+
165
+ OpenLLM Leaderboard V2:
166
+ ```
167
+ lm_eval \
168
+ --model vllm \
169
+ --model_args pretrained="neuralmagic-ent/QwQ-32B-Preview-quantized.w8a8",dtype=auto,add_bos_token=False,max_model_len=4096,tensor_parallel_size=1,gpu_memory_utilization=0.8,enable_chunked_prefill=True,trust_remote_code=True \
170
+ --apply_chat_template \
171
+ --fewshot_as_multiturn \
172
+ --tasks leaderboard \
173
+ --write_out \
174
+ --batch_size auto \
175
+ --output_path output_dir \
176
+ --show_config
177
+
178
+ ```
179
+
180
+ ### Accuracy
181
+
182
+ #### OpenLLM Leaderboard V1 evaluation scores
183
+
184
+ | Metric | Qwen/QwQ-32B-Preview | neuralmagic-ent/QwQ-32B-Preview-quantized.w8a8 |
185
+ |-----------------------------------------|:---------------------------------:|:-------------------------------------------:|
186
+ | ARC-Challenge (Acc-Norm, 25-shot) | 70.73 | 70.73 |
187
+ | GSM8K (Strict-Match, 5-shot) | 83.09 | 79.91 |
188
+ | HellaSwag (Acc-Norm, 10-shot) | 85.77 | 85.75 |
189
+ | MMLU (Acc, 5-shot) | 82.67 | 82.24 |
190
+ | TruthfulQA (MC2, 0-shot) | 60.88 | 59.18 |
191
+ | Winogrande (Acc, 5-shot) | 80.03 | 81.14 |
192
+ | **Average Score** | **77.20** | **76.49** |
193
+ | **Recovery** | **100.00** | **99.08** |
194
+
195
+ #### OpenLLM Leaderboard V2 evaluation scores
196
+
197
+ | Metric | Qwen/QwQ-32B-Preview | neuralmagic-ent/QwQ-32B-Preview-quantized.w8a8 |
198
+ |---------------------------------------------------------|:---------------------------------:|:-------------------------------------------:|
199
+ | IFEval (Inst-and-Prompt Level Strict Acc, 0-shot) | 42.34 | 43.49 |
200
+ | BBH (Acc-Norm, 3-shot) | 53.03 | 52.95 |
201
+ | Math-Hard (Exact-Match, 4-shot) | 21.15 | 22.36 |
202
+ | GPQA (Acc-Norm, 0-shot) | 2.97 | 3.5 |
203
+ | MUSR (Acc-Norm, 0-shot) | 9.57 | 10.87 |
204
+ | MMLU-Pro (Acc, 5-shot) | 52.00 | 51.4 |
205
+ | **Average Score** | **30.18** | **30.76** |
206
+ | **Recovery** | **100.00** | **101.92** |
207
+
added_tokens.json ADDED
@@ -0,0 +1,24 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "</tool_call>": 151658,
3
+ "<tool_call>": 151657,
4
+ "<|box_end|>": 151649,
5
+ "<|box_start|>": 151648,
6
+ "<|endoftext|>": 151643,
7
+ "<|file_sep|>": 151664,
8
+ "<|fim_middle|>": 151660,
9
+ "<|fim_pad|>": 151662,
10
+ "<|fim_prefix|>": 151659,
11
+ "<|fim_suffix|>": 151661,
12
+ "<|im_end|>": 151645,
13
+ "<|im_start|>": 151644,
14
+ "<|image_pad|>": 151655,
15
+ "<|object_ref_end|>": 151647,
16
+ "<|object_ref_start|>": 151646,
17
+ "<|quad_end|>": 151651,
18
+ "<|quad_start|>": 151650,
19
+ "<|repo_name|>": 151663,
20
+ "<|video_pad|>": 151656,
21
+ "<|vision_end|>": 151653,
22
+ "<|vision_pad|>": 151654,
23
+ "<|vision_start|>": 151652
24
+ }
config.json ADDED
@@ -0,0 +1,71 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "_name_or_path": "Qwen/QwQ-32B-Preview",
3
+ "architectures": [
4
+ "Qwen2ForCausalLM"
5
+ ],
6
+ "attention_dropout": 0.0,
7
+ "bos_token_id": 151643,
8
+ "eos_token_id": 151645,
9
+ "hidden_act": "silu",
10
+ "hidden_size": 5120,
11
+ "initializer_range": 0.02,
12
+ "intermediate_size": 27648,
13
+ "max_position_embeddings": 32768,
14
+ "max_window_layers": 64,
15
+ "model_type": "qwen2",
16
+ "num_attention_heads": 40,
17
+ "num_hidden_layers": 64,
18
+ "num_key_value_heads": 8,
19
+ "quantization_config": {
20
+ "config_groups": {
21
+ "group_0": {
22
+ "input_activations": {
23
+ "actorder": null,
24
+ "block_structure": null,
25
+ "dynamic": true,
26
+ "group_size": null,
27
+ "num_bits": 8,
28
+ "observer": null,
29
+ "observer_kwargs": {},
30
+ "strategy": "token",
31
+ "symmetric": true,
32
+ "type": "int"
33
+ },
34
+ "output_activations": null,
35
+ "targets": [
36
+ "Linear"
37
+ ],
38
+ "weights": {
39
+ "actorder": null,
40
+ "block_structure": null,
41
+ "dynamic": false,
42
+ "group_size": null,
43
+ "num_bits": 8,
44
+ "observer": "minmax",
45
+ "observer_kwargs": {},
46
+ "strategy": "channel",
47
+ "symmetric": true,
48
+ "type": "int"
49
+ }
50
+ }
51
+ },
52
+ "format": "int-quantized",
53
+ "global_compression_ratio": 1.462761855914978,
54
+ "ignore": [
55
+ "lm_head"
56
+ ],
57
+ "kv_cache_scheme": null,
58
+ "quant_method": "compressed-tensors",
59
+ "quantization_status": "compressed"
60
+ },
61
+ "rms_norm_eps": 1e-05,
62
+ "rope_scaling": null,
63
+ "rope_theta": 1000000.0,
64
+ "sliding_window": null,
65
+ "tie_word_embeddings": false,
66
+ "torch_dtype": "bfloat16",
67
+ "transformers_version": "4.47.1",
68
+ "use_cache": false,
69
+ "use_sliding_window": false,
70
+ "vocab_size": 152064
71
+ }
generation_config.json ADDED
@@ -0,0 +1,13 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "bos_token_id": 151643,
3
+ "do_sample": true,
4
+ "eos_token_id": [
5
+ 151645,
6
+ 151643
7
+ ],
8
+ "pad_token_id": 151643,
9
+ "temperature": 0.7,
10
+ "top_k": 20,
11
+ "top_p": 0.8,
12
+ "transformers_version": "4.47.1"
13
+ }
merges.txt ADDED
The diff for this file is too large to render. See raw diff
 
model-00001-of-00007.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:de0111c56f51428f9beda9d632521bb9ce79a6fac84a67558d32761cb2a412d3
3
+ size 4997762496
model-00002-of-00007.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:cbc72d4ddd26edf5e1a65b28a21589312e881fb6fc4b1bbae7b149965b89cad2
3
+ size 4914421312
model-00003-of-00007.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:7ef88f31d10359ebf3d940b873d271723d5a0d41fcfb23edbbdc4b14d8e978d6
3
+ size 4877701896
model-00004-of-00007.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:8ac4a9378b7116b360ccb67385be46dc0e896c717c0b3bc11a86dad94eaf9c02
3
+ size 4877701896
model-00005-of-00007.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:085323cfeb249569a23ee657411a7d3f48464273decc8d50ae08391bba24329c
3
+ size 4877701896
model-00006-of-00007.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:c3dd932c6e3ef4dbdfd5bdd27c32ae0b9cede00033c5c025c09127aafd14fcf0
3
+ size 4877701896
model-00007-of-00007.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:ea954cbeae92e996cff924211e5c53e13798ed570ced2ac212b417c951f55614
3
+ size 4908582968
model.safetensors.index.json ADDED
The diff for this file is too large to render. See raw diff
 
quant_w8a8.sh ADDED
@@ -0,0 +1,22 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/bin/bash
2
+
3
+ # for DAMPENING_FRAC 0.01 0.1;
4
+ # do
5
+ # for OBSERVER minmax mse;
6
+ # do
7
+ # for ACTORDER False group;
8
+ # do
9
+
10
+ # export DAMPENING_FRAC=0.01
11
+ # export OBSERVER="minmax"
12
+
13
+ export CUDA_VISIBLE_DEVICES=${1}
14
+ export MDL=${2}
15
+ export OBSERVER=${3} # minmax mse
16
+ export DAMPENING_FRAC=${4} # 0.01 0.1
17
+
18
+ for CALIB_SIZE in 128 512 1024;
19
+ do
20
+ python w8a8.py --model_path ${MDL} --quant_path "output_dir_w8a8/${MDL}/calib${CALIB_SIZE}_eosFalse_damp${DAMPENING_FRAC}_obs${OBSERVER}" --calib_size ${CALIB_SIZE} --dampening_frac ${DAMPENING_FRAC} --observer ${OBSERVER}
21
+ done
22
+
recipe.yaml ADDED
@@ -0,0 +1,7 @@
 
 
 
 
 
 
 
 
1
+ DEFAULT_stage:
2
+ DEFAULT_modifiers:
3
+ GPTQModifier:
4
+ targets: [Linear]
5
+ dampening_frac: 0.1
6
+ ignore: [lm_head]
7
+ scheme: W8A8
special_tokens_map.json ADDED
@@ -0,0 +1,31 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "additional_special_tokens": [
3
+ "<|im_start|>",
4
+ "<|im_end|>",
5
+ "<|object_ref_start|>",
6
+ "<|object_ref_end|>",
7
+ "<|box_start|>",
8
+ "<|box_end|>",
9
+ "<|quad_start|>",
10
+ "<|quad_end|>",
11
+ "<|vision_start|>",
12
+ "<|vision_end|>",
13
+ "<|vision_pad|>",
14
+ "<|image_pad|>",
15
+ "<|video_pad|>"
16
+ ],
17
+ "eos_token": {
18
+ "content": "<|im_end|>",
19
+ "lstrip": false,
20
+ "normalized": false,
21
+ "rstrip": false,
22
+ "single_word": false
23
+ },
24
+ "pad_token": {
25
+ "content": "<|endoftext|>",
26
+ "lstrip": false,
27
+ "normalized": false,
28
+ "rstrip": false,
29
+ "single_word": false
30
+ }
31
+ }
tokenizer.json ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:9c5ae00e602b8860cbd784ba82a8aa14e8feecec692e7076590d014d7b7fdafa
3
+ size 11421896
tokenizer_config.json ADDED
@@ -0,0 +1,208 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "add_bos_token": false,
3
+ "add_prefix_space": false,
4
+ "added_tokens_decoder": {
5
+ "151643": {
6
+ "content": "<|endoftext|>",
7
+ "lstrip": false,
8
+ "normalized": false,
9
+ "rstrip": false,
10
+ "single_word": false,
11
+ "special": true
12
+ },
13
+ "151644": {
14
+ "content": "<|im_start|>",
15
+ "lstrip": false,
16
+ "normalized": false,
17
+ "rstrip": false,
18
+ "single_word": false,
19
+ "special": true
20
+ },
21
+ "151645": {
22
+ "content": "<|im_end|>",
23
+ "lstrip": false,
24
+ "normalized": false,
25
+ "rstrip": false,
26
+ "single_word": false,
27
+ "special": true
28
+ },
29
+ "151646": {
30
+ "content": "<|object_ref_start|>",
31
+ "lstrip": false,
32
+ "normalized": false,
33
+ "rstrip": false,
34
+ "single_word": false,
35
+ "special": true
36
+ },
37
+ "151647": {
38
+ "content": "<|object_ref_end|>",
39
+ "lstrip": false,
40
+ "normalized": false,
41
+ "rstrip": false,
42
+ "single_word": false,
43
+ "special": true
44
+ },
45
+ "151648": {
46
+ "content": "<|box_start|>",
47
+ "lstrip": false,
48
+ "normalized": false,
49
+ "rstrip": false,
50
+ "single_word": false,
51
+ "special": true
52
+ },
53
+ "151649": {
54
+ "content": "<|box_end|>",
55
+ "lstrip": false,
56
+ "normalized": false,
57
+ "rstrip": false,
58
+ "single_word": false,
59
+ "special": true
60
+ },
61
+ "151650": {
62
+ "content": "<|quad_start|>",
63
+ "lstrip": false,
64
+ "normalized": false,
65
+ "rstrip": false,
66
+ "single_word": false,
67
+ "special": true
68
+ },
69
+ "151651": {
70
+ "content": "<|quad_end|>",
71
+ "lstrip": false,
72
+ "normalized": false,
73
+ "rstrip": false,
74
+ "single_word": false,
75
+ "special": true
76
+ },
77
+ "151652": {
78
+ "content": "<|vision_start|>",
79
+ "lstrip": false,
80
+ "normalized": false,
81
+ "rstrip": false,
82
+ "single_word": false,
83
+ "special": true
84
+ },
85
+ "151653": {
86
+ "content": "<|vision_end|>",
87
+ "lstrip": false,
88
+ "normalized": false,
89
+ "rstrip": false,
90
+ "single_word": false,
91
+ "special": true
92
+ },
93
+ "151654": {
94
+ "content": "<|vision_pad|>",
95
+ "lstrip": false,
96
+ "normalized": false,
97
+ "rstrip": false,
98
+ "single_word": false,
99
+ "special": true
100
+ },
101
+ "151655": {
102
+ "content": "<|image_pad|>",
103
+ "lstrip": false,
104
+ "normalized": false,
105
+ "rstrip": false,
106
+ "single_word": false,
107
+ "special": true
108
+ },
109
+ "151656": {
110
+ "content": "<|video_pad|>",
111
+ "lstrip": false,
112
+ "normalized": false,
113
+ "rstrip": false,
114
+ "single_word": false,
115
+ "special": true
116
+ },
117
+ "151657": {
118
+ "content": "<tool_call>",
119
+ "lstrip": false,
120
+ "normalized": false,
121
+ "rstrip": false,
122
+ "single_word": false,
123
+ "special": false
124
+ },
125
+ "151658": {
126
+ "content": "</tool_call>",
127
+ "lstrip": false,
128
+ "normalized": false,
129
+ "rstrip": false,
130
+ "single_word": false,
131
+ "special": false
132
+ },
133
+ "151659": {
134
+ "content": "<|fim_prefix|>",
135
+ "lstrip": false,
136
+ "normalized": false,
137
+ "rstrip": false,
138
+ "single_word": false,
139
+ "special": false
140
+ },
141
+ "151660": {
142
+ "content": "<|fim_middle|>",
143
+ "lstrip": false,
144
+ "normalized": false,
145
+ "rstrip": false,
146
+ "single_word": false,
147
+ "special": false
148
+ },
149
+ "151661": {
150
+ "content": "<|fim_suffix|>",
151
+ "lstrip": false,
152
+ "normalized": false,
153
+ "rstrip": false,
154
+ "single_word": false,
155
+ "special": false
156
+ },
157
+ "151662": {
158
+ "content": "<|fim_pad|>",
159
+ "lstrip": false,
160
+ "normalized": false,
161
+ "rstrip": false,
162
+ "single_word": false,
163
+ "special": false
164
+ },
165
+ "151663": {
166
+ "content": "<|repo_name|>",
167
+ "lstrip": false,
168
+ "normalized": false,
169
+ "rstrip": false,
170
+ "single_word": false,
171
+ "special": false
172
+ },
173
+ "151664": {
174
+ "content": "<|file_sep|>",
175
+ "lstrip": false,
176
+ "normalized": false,
177
+ "rstrip": false,
178
+ "single_word": false,
179
+ "special": false
180
+ }
181
+ },
182
+ "additional_special_tokens": [
183
+ "<|im_start|>",
184
+ "<|im_end|>",
185
+ "<|object_ref_start|>",
186
+ "<|object_ref_end|>",
187
+ "<|box_start|>",
188
+ "<|box_end|>",
189
+ "<|quad_start|>",
190
+ "<|quad_end|>",
191
+ "<|vision_start|>",
192
+ "<|vision_end|>",
193
+ "<|vision_pad|>",
194
+ "<|image_pad|>",
195
+ "<|video_pad|>"
196
+ ],
197
+ "bos_token": null,
198
+ "chat_template": "{%- if tools %}\n {{- '<|im_start|>system\\n' }}\n {%- if messages[0]['role'] == 'system' %}\n {{- messages[0]['content'] }}\n {%- else %}\n {{- 'You are a helpful and harmless assistant. You are Qwen developed by Alibaba. You should think step-by-step.' }}\n {%- endif %}\n {{- \"\\n\\n# Tools\\n\\nYou may call one or more functions to assist with the user query.\\n\\nYou are provided with function signatures within <tools></tools> XML tags:\\n<tools>\" }}\n {%- for tool in tools %}\n {{- \"\\n\" }}\n {{- tool | tojson }}\n {%- endfor %}\n {{- \"\\n</tools>\\n\\nFor each function call, return a json object with function name and arguments within <tool_call></tool_call> XML tags:\\n<tool_call>\\n{\\\"name\\\": <function-name>, \\\"arguments\\\": <args-json-object>}\\n</tool_call><|im_end|>\\n\" }}\n{%- else %}\n {%- if messages[0]['role'] == 'system' %}\n {{- '<|im_start|>system\\n' + messages[0]['content'] + '<|im_end|>\\n' }}\n {%- else %}\n {{- '<|im_start|>system\\nYou are a helpful and harmless assistant. You are Qwen developed by Alibaba. You should think step-by-step.<|im_end|>\\n' }}\n {%- endif %}\n{%- endif %}\n{%- for message in messages %}\n {%- if (message.role == \"user\") or (message.role == \"system\" and not loop.first) or (message.role == \"assistant\" and not message.tool_calls) %}\n {{- '<|im_start|>' + message.role + '\\n' + message.content + '<|im_end|>' + '\\n' }}\n {%- elif message.role == \"assistant\" %}\n {{- '<|im_start|>' + message.role }}\n {%- if message.content %}\n {{- '\\n' + message.content }}\n {%- endif %}\n {%- for tool_call in message.tool_calls %}\n {%- if tool_call.function is defined %}\n {%- set tool_call = tool_call.function %}\n {%- endif %}\n {{- '\\n<tool_call>\\n{\"name\": \"' }}\n {{- tool_call.name }}\n {{- '\", \"arguments\": ' }}\n {{- tool_call.arguments | tojson }}\n {{- '}\\n</tool_call>' }}\n {%- endfor %}\n {{- '<|im_end|>\\n' }}\n {%- elif message.role == \"tool\" %}\n {%- if (loop.index0 == 0) or (messages[loop.index0 - 1].role != \"tool\") %}\n {{- '<|im_start|>user' }}\n {%- endif %}\n {{- '\\n<tool_response>\\n' }}\n {{- message.content }}\n {{- '\\n</tool_response>' }}\n {%- if loop.last or (messages[loop.index0 + 1].role != \"tool\") %}\n {{- '<|im_end|>\\n' }}\n {%- endif %}\n {%- endif %}\n{%- endfor %}\n{%- if add_generation_prompt %}\n {{- '<|im_start|>assistant\\n' }}\n{%- endif %}\n",
199
+ "clean_up_tokenization_spaces": false,
200
+ "eos_token": "<|im_end|>",
201
+ "errors": "replace",
202
+ "extra_special_tokens": {},
203
+ "model_max_length": 32768,
204
+ "pad_token": "<|endoftext|>",
205
+ "split_special_tokens": false,
206
+ "tokenizer_class": "Qwen2Tokenizer",
207
+ "unk_token": null
208
+ }
vocab.json ADDED
The diff for this file is too large to render. See raw diff
 
w8a8.py ADDED
@@ -0,0 +1,123 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from datasets import load_dataset
2
+ from transformers import AutoTokenizer
3
+ from llmcompressor.modifiers.quantization import GPTQModifier
4
+ from llmcompressor.transformers import SparseAutoModelForCausalLM, oneshot, apply
5
+ import argparse
6
+ from compressed_tensors.quantization import QuantizationScheme, QuantizationArgs, QuantizationType, QuantizationStrategy
7
+
8
+
9
+ parser = argparse.ArgumentParser()
10
+ parser.add_argument('--model_path', type=str, default="/network/eldar/llama31_8b_gsm8k/sparse_transfer/sp2of4_2ep_lr7e-6_bs32_GradClip2_warmup20ba_noKD")
11
+ parser.add_argument('--quant_path', type=str, default="output_dir/quant_test")
12
+
13
+ parser.add_argument('--calib_size', type=int, default=256) # 32 64 128 256 512 1024 2048
14
+ parser.add_argument('--dampening_frac', type=float, default=0.01) # 0.001 0.003 0.005 0.008 0.01 0.03 0.05 0.08 0.1 0.3
15
+ parser.add_argument('--observer', type=str, default="minmax") # mse or minmax
16
+
17
+ # ToDo: add args for SmoothQuant if needed
18
+ args = parser.parse_args()
19
+
20
+ print(f"[DEBUGGING ARGS] {args}")
21
+ # TODO: to ablate on additionally is whether we want to add EOS token to calib data
22
+
23
+
24
+ model = SparseAutoModelForCausalLM.from_pretrained(
25
+ args.model_path,
26
+ device_map="auto",
27
+ torch_dtype="auto",
28
+ use_cache=False,
29
+ trust_remote_code=True,
30
+ )
31
+ tokenizer = AutoTokenizer.from_pretrained(args.model_path)
32
+
33
+
34
+ NUM_CALIBRATION_SAMPLES = args.calib_size
35
+ DATASET_ID = "garage-bAInd/Open-Platypus"
36
+ DATASET_SPLIT = "train"
37
+ ds = load_dataset(DATASET_ID, split=DATASET_SPLIT)
38
+ ds = ds.shuffle(seed=42).select(range(NUM_CALIBRATION_SAMPLES))
39
+
40
+ def preprocess(example):
41
+ concat_txt = example["instruction"] + "\n" + example["output"]
42
+ return {"text": concat_txt}
43
+
44
+ ds = ds.map(preprocess)
45
+ print(f"================================================================================")
46
+ print(f"[For debugging] Calibration data sample is:\n{repr(ds[0]['text'])}")
47
+ print(f"================================================================================")
48
+
49
+ def tokenize(sample):
50
+ return tokenizer(
51
+ sample["text"],
52
+ padding=False,
53
+ truncation=False,
54
+ add_special_tokens=True,
55
+ )
56
+
57
+
58
+ ds = ds.map(tokenize, remove_columns=ds.column_names)
59
+ print(f"================================================================================")
60
+ print(f"[For debugging] Tokenized data sample is:\n{tokenizer.decode(ds[0]['input_ids'])}")
61
+ print(f"================================================================================")
62
+
63
+ # TODO: why do we need to fuck around the calibration data when it's given completely prepared
64
+ # TODO: are recipe_args used to override params?
65
+
66
+ #quant_scheme = QuantizationScheme(
67
+ # targets=["Linear"],
68
+ # weights=QuantizationArgs(
69
+ # num_bits=args.num_bits,
70
+ # type=QuantizationType.INT,
71
+ # symmetric=True,
72
+ # group_size=128,
73
+ # strategy=QuantizationStrategy.GROUP,
74
+ # observer=args.observer,
75
+ # actorder=args.actorder
76
+ # ),
77
+ # input_activations=None,
78
+ # output_activations=None,
79
+ #)
80
+
81
+ recipe = [
82
+ GPTQModifier(
83
+ targets=["Linear"],
84
+ ignore=["lm_head"],
85
+ scheme="W8A8",
86
+ dampening_frac=args.dampening_frac,
87
+ observer=args.observer,
88
+ #config_groups={"group_0": quant_scheme},
89
+ )
90
+ ]
91
+ oneshot(
92
+ model=model,
93
+ dataset=ds,
94
+ # recipe="w4a16_recipe.yaml",
95
+ recipe=recipe,
96
+ # recipe_args={
97
+ # "quant_stage.quant_modifiers.GPTQModifier.dampening_frac": 100,
98
+ # "quant_stage.quant_modifiers.GPTQModifier.sequential_update": args.sequential_update,
99
+ # "quant_stage.quant_modifiers.GPTQModifier.config_groups.group_0.weights.observer": args.observer,
100
+ # "quant_stage.quant_modifiers.GPTQModifier.config_groups.group_0.weights.actorder": args.actorder,
101
+ # },
102
+ num_calibration_samples=args.calib_size,
103
+ max_seq_length=8192,
104
+ )
105
+
106
+
107
+ # apply(
108
+ # recipe=self.recipe,
109
+ # # recipe_stage=None,
110
+ # recipe_args=self.recipe_args,
111
+ # model=self.model,
112
+ # calib_data=calibration_data, # dataloader
113
+ # start=-1,
114
+ # copy_data=False,
115
+ # accelerator=self.accelerator, # some accelerator object
116
+ # min_tokens_per_module=None
117
+ # )
118
+
119
+ # Save to disk compressed.
120
+ SAVE_DIR = args.quant_path
121
+ model.save_pretrained(SAVE_DIR, save_compressed=True)
122
+ tokenizer.save_pretrained(SAVE_DIR)
123
+