apepkuss79 commited on
Commit
1e57684
1 Parent(s): b33aeae

Update models

Browse files
Files changed (3) hide show
  1. README.md +38 -87
  2. main.py +247 -0
  3. requirements.txt +26 -0
README.md CHANGED
@@ -1,87 +1,38 @@
1
- ---
2
- base_model: Qwen/Qwen2.5-3B-Instruct
3
- license: other
4
- license_name: qwen-research
5
- license_link: https://huggingface.co/Qwen/Qwen2.5-3B-Instruct/blob/main/LICENSEE
6
- model_creator: Qwen
7
- model_name: QQwen2.5-3B-Instruct
8
- quantized_by: Second State Inc.
9
- language:
10
- - en
11
- pipeline_tag: text-generation
12
- tags:
13
- - chat
14
- ---
15
-
16
- <!-- header start -->
17
- <!-- 200823 -->
18
- <div style="width: auto; margin-left: auto; margin-right: auto">
19
- <img src="https://github.com/LlamaEdge/LlamaEdge/raw/dev/assets/logo.svg" style="width: 100%; min-width: 400px; display: block; margin: auto;">
20
- </div>
21
- <hr style="margin-top: 1.0em; margin-bottom: 1.0em;">
22
- <!-- header end -->
23
-
24
- # QQwen2.5-3B-Instruct-GGUF
25
-
26
- ## Original Model
27
-
28
- [Qwen/Qwen2.5-3B-Instruct](https://huggingface.co/Qwen/Qwen2.5-3B-Instruct)
29
-
30
- ## Run with LlamaEdge
31
-
32
- - LlamaEdge version: [v0.14.3](https://github.com/LlamaEdge/LlamaEdge/releases/tag/0.14.3) and above
33
-
34
- - Prompt template
35
-
36
- - Prompt type: `chatml`
37
-
38
- - Prompt string
39
-
40
- ```text
41
- <|im_start|>system
42
- {system_message}<|im_end|>
43
- <|im_start|>user
44
- {prompt}<|im_end|>
45
- <|im_start|>assistant
46
- ```
47
-
48
- - Context size: `32000`
49
-
50
- - Run as LlamaEdge service
51
-
52
- ```bash
53
- wasmedge --dir .:. --nn-preload default:GGML:AUTO:QQwen2.5-3B-Instruct-Q5_K_M.gguf \
54
- llama-api-server.wasm \
55
- --model-name QQwen2.5-3B-Instruct \
56
- --prompt-template chatml \
57
- --ctx-size 32000
58
- ```
59
-
60
- - Run as LlamaEdge command app
61
-
62
- ```bash
63
- wasmedge --dir .:. --nn-preload default:GGML:AUTO:QQwen2.5-3B-Instruct-Q5_K_M.gguf \
64
- llama-chat.wasm \
65
- --prompt-template chatml \
66
- --ctx-size 32000
67
- ```
68
-
69
- ## Quantized GGUF Models
70
-
71
- | Name | Quant method | Bits | Size | Use case |
72
- | ---- | ---- | ---- | ---- | ----- |
73
- | [QQwen2.5-3B-Instruct-Q2_K.gguf](https://huggingface.co/second-state/QQwen2.5-3B-Instruct-GGUF/blob/main/QQwen2.5-3B-Instruct-Q2_K.gguf) | Q2_K | 2 | 676 MB| smallest, significant quality loss - not recommended for most purposes |
74
- | [QQwen2.5-3B-Instruct-Q3_K_L.gguf](https://huggingface.co/second-state/QQwen2.5-3B-Instruct-GGUF/blob/main/QQwen2.5-3B-Instruct-Q3_K_L.gguf) | Q3_K_L | 3 | 880 MB| small, substantial quality loss |
75
- | [QQwen2.5-3B-Instruct-Q3_K_M.gguf](https://huggingface.co/second-state/QQwen2.5-3B-Instruct-GGUF/blob/main/QQwen2.5-3B-Instruct-Q3_K_M.gguf) | Q3_K_M | 3 | 824 MB| very small, high quality loss |
76
- | [QQwen2.5-3B-Instruct-Q3_K_S.gguf](https://huggingface.co/second-state/QQwen2.5-3B-Instruct-GGUF/blob/main/QQwen2.5-3B-Instruct-Q3_K_S.gguf) | Q3_K_S | 3 | 761 MB| very small, high quality loss |
77
- | [QQwen2.5-3B-Instruct-Q4_0.gguf](https://huggingface.co/second-state/QQwen2.5-3B-Instruct-GGUF/blob/main/QQwen2.5-3B-Instruct-Q4_0.gguf) | Q4_0 | 4 | 935 MB| legacy; small, very high quality loss - prefer using Q3_K_M |
78
- | [QQwen2.5-3B-Instruct-Q4_K_M.gguf](https://huggingface.co/second-state/QQwen2.5-3B-Instruct-GGUF/blob/main/QQwen2.5-3B-Instruct-Q4_K_M.gguf) | Q4_K_M | 4 | 986 MB| medium, balanced quality - recommended |
79
- | [QQwen2.5-3B-Instruct-Q4_K_S.gguf](https://huggingface.co/second-state/QQwen2.5-3B-Instruct-GGUF/blob/main/QQwen2.5-3B-Instruct-Q4_K_S.gguf) | Q4_K_S | 4 | 940 MB| small, greater quality loss |
80
- | [QQwen2.5-3B-Instruct-Q5_0.gguf](https://huggingface.co/second-state/QQwen2.5-3B-Instruct-GGUF/blob/main/QQwen2.5-3B-Instruct-Q5_0.gguf) | Q5_0 | 5 | 1.1 GB| legacy; medium, balanced quality - prefer using Q4_K_M |
81
- | [QQwen2.5-3B-Instruct-Q5_K_M.gguf](https://huggingface.co/second-state/QQwen2.5-3B-Instruct-GGUF/blob/main/QQwen2.5-3B-Instruct-Q5_K_M.gguf) | Q5_K_M | 5 | 1.13 GB| large, very low quality loss - recommended |
82
- | [QQwen2.5-3B-Instruct-Q5_K_S.gguf](https://huggingface.co/second-state/QQwen2.5-3B-Instruct-GGUF/blob/main/QQwen2.5-3B-Instruct-Q5_K_S.gguf) | Q5_K_S | 5 | 1.1 GB| large, low quality loss - recommended |
83
- | [QQwen2.5-3B-Instruct-Q6_K.gguf](https://huggingface.co/second-state/QQwen2.5-3B-Instruct-GGUF/blob/main/QQwen2.5-3B-Instruct-Q6_K.gguf) | Q6_K | 6 | 1.27 GB| very large, extremely low quality loss |
84
- | [QQwen2.5-3B-Instruct-Q8_0.gguf](https://huggingface.co/second-state/QQwen2.5-3B-Instruct-GGUF/blob/main/QQwen2.5-3B-Instruct-Q8_0.gguf) | Q8_0 | 8 | 1.65 GB| very large, extremely low quality loss - not recommended |
85
- | [QQwen2.5-3B-Instruct-f16.gguf](https://huggingface.co/second-state/QQwen2.5-3B-Instruct-GGUF/blob/main/QQwen2.5-3B-Instruct-f16.gguf) | f16 | 16 | 3.09 GB| |
86
-
87
- *Quantized with llama.cpp b3751*
 
1
+ # FACET
2
+
3
+ ## How to run
4
+
5
+ ```bash
6
+ python main.py --full-name <hf-account-name/hf-model-name> -s <target-directory-to-save-git-clone> --enable-converter -c <path-to-python-convert-script> --enable-quantizer -q <path-to-llamacpp-quantizer> -t q4_0
7
+ ```
8
+
9
+ For example,
10
+
11
+ ```bash
12
+ python main.py --full-name baichuan-inc/Baichuan2-13B-Chat -s /home/ubuntu/workspace/models/ --enable-converter -c /home/ubuntu/workspace/llama.cpp/convert.py --enable-quantizer -q llama-cpp-quantizer -t Q5_K_M
13
+ ```
14
+
15
+ ## Allowed quantization types
16
+
17
+ ```text
18
+ 2 or Q4_0 : 3.56G, +0.2166 ppl @ LLaMA-v1-7B
19
+ 3 or Q4_1 : 3.90G, +0.1585 ppl @ LLaMA-v1-7B
20
+ 8 or Q5_0 : 4.33G, +0.0683 ppl @ LLaMA-v1-7B
21
+ 9 or Q5_1 : 4.70G, +0.0349 ppl @ LLaMA-v1-7B
22
+ 10 or Q2_K : 2.63G, +0.6717 ppl @ LLaMA-v1-7B
23
+ 12 or Q3_K : alias for Q3_K_M
24
+ 11 or Q3_K_S : 2.75G, +0.5551 ppl @ LLaMA-v1-7B
25
+ 12 or Q3_K_M : 3.07G, +0.2496 ppl @ LLaMA-v1-7B
26
+ 13 or Q3_K_L : 3.35G, +0.1764 ppl @ LLaMA-v1-7B
27
+ 15 or Q4_K : alias for Q4_K_M
28
+ 14 or Q4_K_S : 3.59G, +0.0992 ppl @ LLaMA-v1-7B
29
+ 15 or Q4_K_M : 3.80G, +0.0532 ppl @ LLaMA-v1-7B
30
+ 17 or Q5_K : alias for Q5_K_M
31
+ 16 or Q5_K_S : 4.33G, +0.0400 ppl @ LLaMA-v1-7B
32
+ 17 or Q5_K_M : 4.45G, +0.0122 ppl @ LLaMA-v1-7B
33
+ 18 or Q6_K : 5.15G, -0.0008 ppl @ LLaMA-v1-7B
34
+ 7 or Q8_0 : 6.70G, +0.0004 ppl @ LLaMA-v1-7B
35
+ 1 or F16 : 13.00G @ 7B
36
+ 0 or F32 : 26.00G @ 7B
37
+ COPY : only copy tensors, no quantizing
38
+ ```
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
main.py ADDED
@@ -0,0 +1,247 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import argparse
2
+ import os
3
+ import shutil
4
+ import subprocess
5
+ import time
6
+ from pathlib import Path
7
+
8
+ from git import Repo
9
+
10
+
11
+ def clone_hf_with_git(username: str, model_name: str, saved_dir: str):
12
+ full_model_name = f"{username}/{model_name}"
13
+ url = f"https://huggingface.co/{full_model_name}"
14
+ saved = f"{saved_dir}/{model_name}"
15
+
16
+ # perform `git lfs install`
17
+ subprocess.run(["git", "lfs", "install"])
18
+
19
+ print(f"[INFO] Cloning {model_name} from {url} ...")
20
+ Repo.clone_from(url, saved)
21
+
22
+
23
+ def download_hf_with_git(full_name: str, saved_dir: str):
24
+ model_name = full_name.split("/")[1]
25
+ url = f"git@hf.co:{full_name}"
26
+ saved = f"{saved_dir}/{model_name}"
27
+
28
+ # perform `git lfs install`
29
+ subprocess.run(["git", "lfs", "install"])
30
+
31
+ print(f"Cloning {model_name} from {url} ...")
32
+ subprocess.run(["git", "clone", "--progress", url, saved])
33
+
34
+
35
+ def convert_hf_to_gguf(
36
+ script_path: str,
37
+ dir_raw_model: str,
38
+ gguf_model_path: str,
39
+ pad_vocab: bool = False,
40
+ ):
41
+ if pad_vocab is True:
42
+ args = [
43
+ "--outfile",
44
+ gguf_model_path,
45
+ # "--vocab-type",
46
+ # "bpe",
47
+ "--pad-vocab",
48
+ dir_raw_model,
49
+ ]
50
+ else:
51
+ args = ["--outfile", gguf_model_path, dir_raw_model]
52
+ # convert.py for llama-3
53
+ # args = ["--outfile", gguf_model_path, "--vocab-type", "bpe", dir_raw_model]
54
+ res = subprocess.run(["python", script_path] + args)
55
+ print(res)
56
+
57
+
58
+ def quantize_model(
59
+ quantizer: str,
60
+ f16_gguf_model_path: str,
61
+ quantized_gguf_model_path: str,
62
+ quant_type: str = "q4_0",
63
+ ):
64
+ print(f"[INFO] quantizer: {quantizer}")
65
+ print(f"[INFO] quant_type: {quant_type}")
66
+ print(f"[INFO] f16_gguf_model_path: {f16_gguf_model_path}")
67
+ print(f"[INFO] quantized_model_filename: {quantized_gguf_model_path}")
68
+ subprocess.run(
69
+ [
70
+ quantizer,
71
+ f16_gguf_model_path,
72
+ quantized_gguf_model_path,
73
+ quant_type,
74
+ ]
75
+ )
76
+
77
+
78
+ def main():
79
+ parser = argparse.ArgumentParser(description="Convert and quantize gguf models.")
80
+ parser.add_argument(
81
+ "--full-name",
82
+ type=str,
83
+ help="Huggingface model full name. e.g. `username/model_name`",
84
+ )
85
+ parser.add_argument(
86
+ "-s",
87
+ "--saved-dir",
88
+ type=str,
89
+ default="models",
90
+ help="The directory to save the model.",
91
+ )
92
+ parser.add_argument(
93
+ "--enable-converter",
94
+ action="store_true",
95
+ help="Enable the converter. Notice that `--converter` must be specified.",
96
+ )
97
+ parser.add_argument(
98
+ "-c",
99
+ "--converter",
100
+ type=str,
101
+ help="The path to the converter. Notice that `--enable-converter` must be specified if use this option.",
102
+ )
103
+ parser.add_argument(
104
+ "--pad-vocab",
105
+ action="store_true",
106
+ help="Enable adding pad tokens when model vocab expects more than tokenizer metadata provides. Notice that `--enable-converter` must be specified.",
107
+ )
108
+ parser.add_argument(
109
+ "--enable-quantizer",
110
+ action="store_true",
111
+ help="Enable the quantizer. Notice that `--quantizer` must be specified.",
112
+ )
113
+ parser.add_argument(
114
+ "-q",
115
+ "--quantizer",
116
+ type=str,
117
+ help="The path to the quantizer. Notice that `--enable-quantizer` must be specified if use this option.",
118
+ )
119
+ parser.add_argument(
120
+ "-t",
121
+ "--quant-type",
122
+ type=str,
123
+ default=None,
124
+ help="The quantization type. Notice that `--enable-quantizer` must be specified if use this option.",
125
+ )
126
+
127
+ args = parser.parse_args()
128
+
129
+ print(args)
130
+
131
+ print("Download model ...")
132
+ full_name = args.full_name
133
+ username, model_name = full_name.split("/")
134
+ saved_dir = args.saved_dir
135
+ # try:
136
+ # download_hf_with_git(full_name, saved_dir)
137
+ # print(f"The raw model is saved in {saved_dir}.")
138
+
139
+ # except Exception as e:
140
+ # print(f"Failed to download model. {e}")
141
+ # return
142
+
143
+ if args.enable_converter is True:
144
+ print("[CONVERTER] Convert model ...")
145
+ converter = args.converter
146
+
147
+ raw_model_dir = f"{saved_dir}/{model_name}"
148
+ print(f"[CONVERTER] raw_model_dir: {raw_model_dir}")
149
+
150
+ gguf_model_dir = Path(raw_model_dir).parent / f"{model_name}-gguf"
151
+ if not gguf_model_dir.exists():
152
+ gguf_model_dir.mkdir()
153
+ f16_gguf_model_path = gguf_model_dir / f"{model_name}-f16.gguf"
154
+
155
+ print(f"[CONVERTER] f16_gguf_model_path: {f16_gguf_model_path}")
156
+
157
+ # try:
158
+ # convert_hf_to_gguf(
159
+ # converter,
160
+ # raw_model_dir,
161
+ # str(f16_gguf_model_path),
162
+ # args.pad_vocab,
163
+ # )
164
+ # print(f"The converted gguf model is saved in {f16_gguf_model_path}.")
165
+
166
+ # except Exception as e:
167
+ # print(f"Failed to convert model. {e}")
168
+ # return
169
+
170
+ if args.enable_quantizer is True:
171
+ print("[QUANTIZER] Quantize model ...")
172
+ quantizer = args.quantizer
173
+ print(f"[QUANTIZER] quantizer: {quantizer}")
174
+
175
+ if args.quant_type is not None:
176
+ quant_type = args.quant_type
177
+ quantized_gguf_model_path = (
178
+ gguf_model_dir / f"{model_name}-{quant_type}.gguf"
179
+ )
180
+
181
+ print(f"[QUANTIZER] quant_type: {quant_type}")
182
+ print(f"[QUANTIZER] quantized_model_filename: {quantized_gguf_model_path}")
183
+
184
+ try:
185
+ quantize_model(
186
+ quantizer,
187
+ str(f16_gguf_model_path),
188
+ str(quantized_gguf_model_path),
189
+ quant_type,
190
+ )
191
+ print(
192
+ f"The quantized gguf model is saved in {quantized_gguf_model_path}."
193
+ )
194
+
195
+ except Exception as e:
196
+ print(e)
197
+ print("Failed to quantize model.")
198
+ return
199
+ else:
200
+ for quant_type in [
201
+ # "Q2_K",
202
+ # "Q3_K_L",
203
+ # "Q3_K_M",
204
+ # "Q3_K_S",
205
+ # "Q4_0",
206
+ # "Q4_K_M",
207
+ # "Q4_K_S",
208
+ # "Q5_0",
209
+ "Q5_K_M",
210
+ # "Q5_K_S",
211
+ "Q6_K",
212
+ "Q8_0",
213
+ ]:
214
+ quantized_gguf_model_path = (
215
+ gguf_model_dir / f"{model_name}-{quant_type}.gguf"
216
+ )
217
+
218
+ print(f"[QUANTIZER] quant_type: {quant_type}")
219
+ print(
220
+ f"[QUANTIZER] quantized_model_filename: {quantized_gguf_model_path}"
221
+ )
222
+
223
+ try:
224
+ quantize_model(
225
+ quantizer,
226
+ str(f16_gguf_model_path),
227
+ str(quantized_gguf_model_path),
228
+ quant_type,
229
+ )
230
+ print(
231
+ f"The quantized gguf model is saved in {quantized_gguf_model_path}."
232
+ )
233
+
234
+ except Exception as e:
235
+ print(e)
236
+ print("Failed to quantize model.")
237
+ return
238
+
239
+ # # remove the raw model dir for saving space
240
+ # print(f"The quantization is done. Remove {raw_model_dir}")
241
+ # shutil.rmtree(raw_model_dir)
242
+
243
+ print("Done.")
244
+
245
+
246
+ if __name__ == "__main__":
247
+ main()
requirements.txt ADDED
@@ -0,0 +1,26 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ certifi==2023.7.22
2
+ charset-normalizer==3.3.2
3
+ filelock==3.13.1
4
+ fsspec==2023.10.0
5
+ idna==3.4
6
+ Jinja2==3.1.2
7
+ MarkupSafe==2.1.3
8
+ mpmath==1.3.0
9
+ networkx==3.2.1
10
+ numpy==1.26.2
11
+ packaging==23.2
12
+ protobuf==4.25.0
13
+ PyYAML==6.0.1
14
+ regex==2023.10.3
15
+ requests==2.31.0
16
+ safetensors==0.4.0
17
+ sympy==1.12
18
+ tokenizers==0.14.1
19
+ torch==2.1.0
20
+ tqdm==4.66.1
21
+ transformers==4.35.0
22
+ typing_extensions==4.8.0
23
+ urllib3==2.1.0
24
+ sentencepiece==0.1.99
25
+ GitPython==3.1.40
26
+ tiktoken==0.5.2