CISCai commited on
Commit
f664277
·
verified ·
1 Parent(s): 2c669a0

Upload 13 files

Browse files
.gitattributes CHANGED
@@ -33,3 +33,15 @@ 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
+ Qwen2.5-Coder-7B-Instruct.imatrix.dat filter=lfs diff=lfs merge=lfs -text
37
+ Qwen2.5-Coder-7B-Instruct.IQ1_M.gguf filter=lfs diff=lfs merge=lfs -text
38
+ Qwen2.5-Coder-7B-Instruct.IQ1_S.gguf filter=lfs diff=lfs merge=lfs -text
39
+ Qwen2.5-Coder-7B-Instruct.IQ2_M.gguf filter=lfs diff=lfs merge=lfs -text
40
+ Qwen2.5-Coder-7B-Instruct.IQ2_S.gguf filter=lfs diff=lfs merge=lfs -text
41
+ Qwen2.5-Coder-7B-Instruct.IQ2_XS.gguf filter=lfs diff=lfs merge=lfs -text
42
+ Qwen2.5-Coder-7B-Instruct.IQ2_XXS.gguf filter=lfs diff=lfs merge=lfs -text
43
+ Qwen2.5-Coder-7B-Instruct.IQ3_M.gguf filter=lfs diff=lfs merge=lfs -text
44
+ Qwen2.5-Coder-7B-Instruct.IQ3_S.gguf filter=lfs diff=lfs merge=lfs -text
45
+ Qwen2.5-Coder-7B-Instruct.IQ3_XS.gguf filter=lfs diff=lfs merge=lfs -text
46
+ Qwen2.5-Coder-7B-Instruct.IQ3_XXS.gguf filter=lfs diff=lfs merge=lfs -text
47
+ Qwen2.5-Coder-7B-Instruct.IQ4_XS.gguf filter=lfs diff=lfs merge=lfs -text
Qwen2.5-Coder-7B-Instruct.IQ1_M.gguf ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:001db89be35ca359717cea0e6f7a297f3668bbe8c9e6f7e6604947b8b6017f0e
3
+ size 2042196896
Qwen2.5-Coder-7B-Instruct.IQ1_S.gguf ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:7558c1b93d9bf96d474eabafb9366500356fef12027c3e76518cc5692ba16a31
3
+ size 1903668128
Qwen2.5-Coder-7B-Instruct.IQ2_M.gguf ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:ac4e5412e6a8a2aaaf8a56bf6e8910c5c7bc9d1b4b15f6b46921a760ade63262
3
+ size 2780343200
Qwen2.5-Coder-7B-Instruct.IQ2_S.gguf ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:2aa99c1c940040400b01860584ca27de2479371161e29ff149ee6103ed879991
3
+ size 2595638176
Qwen2.5-Coder-7B-Instruct.IQ2_XS.gguf ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:ff8c48e91b8381908932ed1f23f4cb25e9be9bc69924fa89c1013e35a03d426d
3
+ size 2469022624
Qwen2.5-Coder-7B-Instruct.IQ2_XXS.gguf ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:90fcacf552cc18e12275b96962dcdfd4c6eda368773849149ee055b96f2fdd43
3
+ size 2273078176
Qwen2.5-Coder-7B-Instruct.IQ3_M.gguf ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:ec80ac6c4e0c2d87fed042781d30dc16c02b2503688208fbbbcd5d7e80c13768
3
+ size 3574012832
Qwen2.5-Coder-7B-Instruct.IQ3_S.gguf ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:fce11b34d82ac7e21937d682721df29d5c32d5eb99c872bdd405cdceade7779b
3
+ size 3499193248
Qwen2.5-Coder-7B-Instruct.IQ3_XS.gguf ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:4eaab5ed5dc664022895d0d973dadaf3b5e9b1a7a67908bc374913778f35036c
3
+ size 3346256800
Qwen2.5-Coder-7B-Instruct.IQ3_XXS.gguf ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:d450630df6970afd882afca6e64529384f2b82f1789545644c620af900e2d02a
3
+ size 3114515360
Qwen2.5-Coder-7B-Instruct.IQ4_XS.gguf ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:ec775a1e7a71623e9bcbe180cb93eefcb324653827bdbb0679eca5cc89ae401d
3
+ size 4218473376
Qwen2.5-Coder-7B-Instruct.imatrix.dat ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:4184e2278c8a8be7fcaf819a7a455ee73b53048d0490c3472e9755a45c4dd55b
3
+ size 4536668
README.md CHANGED
@@ -1,3 +1,449 @@
1
- ---
2
- license: apache-2.0
3
- ---
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ license: apache-2.0
3
+ license_link: https://huggingface.co/Qwen/Qwen2.5-Coder-7B-Instruct/blob/main/LICENSE
4
+ language:
5
+ - en
6
+ pipeline_tag: text-generation
7
+ tags:
8
+ - code
9
+ - codeqwen
10
+ - chat
11
+ - qwen
12
+ - qwen-coder
13
+ base_model: Qwen/Qwen2.5-Coder-7B-Instruct
14
+ model_creator: Qwen
15
+ model_name: Qwen2.5-Coder-7B-Instruct
16
+ model_type: qwen2
17
+ datasets:
18
+ - m-a-p/CodeFeedback-Filtered-Instruction
19
+ quantized_by: CISC
20
+ ---
21
+
22
+ # Qwen2.5-Coder-7B-Instruct - SOTA GGUF
23
+ - Model creator: [Qwen](https://huggingface.co/Qwen)
24
+ - Original model: [Qwen2.5-Coder-7B-Instruct](https://huggingface.co/Qwen/Qwen2.5-Coder-7B-Instruct)
25
+
26
+ <!-- description start -->
27
+ ## Description
28
+
29
+ This repo contains State Of The Art quantized GGUF format model files for [Qwen2.5-Coder-7B-Instruct](https://huggingface.co/Qwen/Qwen2.5-Coder-7B-Instruct).
30
+
31
+ Quantization was done with an importance matrix that was trained for ~1M tokens (256 batches of 4096 tokens) of answers from the [CodeFeedback-Filtered-Instruction](https://huggingface.co/datasets/m-a-p/CodeFeedback-Filtered-Instruction) dataset.
32
+
33
+ Fill-in-Middle token metadata has been added, see [example](#simple-llama-cpp-python-example-fill-in-middle-code).
34
+
35
+ <!-- description end -->
36
+
37
+
38
+ <!-- prompt-template start -->
39
+ ## Prompt template: ChatML
40
+
41
+ ```
42
+ <|im_start|>system
43
+ {system_prompt}<|im_end|>
44
+ <|im_start|>user
45
+ {prompt}<|im_end|>
46
+ <|im_start|>assistant
47
+ ```
48
+
49
+ <!-- prompt-template end -->
50
+
51
+
52
+ <!-- compatibility_gguf start -->
53
+ ## Compatibility
54
+
55
+ These quantised GGUFv3 files are compatible with llama.cpp from February 27th 2024 onwards, as of commit [0becb22](https://github.com/ggerganov/llama.cpp/commit/0becb22ac05b6542bd9d5f2235691aa1d3d4d307)
56
+
57
+ They are also compatible with many third party UIs and libraries provided they are built using a recent llama.cpp.
58
+
59
+ ## Explanation of quantisation methods
60
+
61
+ <details>
62
+ <summary>Click to see details</summary>
63
+
64
+ The new methods available are:
65
+
66
+ * GGML_TYPE_IQ1_S - 1-bit quantization in super-blocks with an importance matrix applied, effectively using 1.56 bits per weight (bpw)
67
+ * GGML_TYPE_IQ1_M - 1-bit quantization in super-blocks with an importance matrix applied, effectively using 1.75 bpw
68
+ * GGML_TYPE_IQ2_XXS - 2-bit quantization in super-blocks with an importance matrix applied, effectively using 2.06 bpw
69
+ * GGML_TYPE_IQ2_XS - 2-bit quantization in super-blocks with an importance matrix applied, effectively using 2.31 bpw
70
+ * GGML_TYPE_IQ2_S - 2-bit quantization in super-blocks with an importance matrix applied, effectively using 2.5 bpw
71
+ * GGML_TYPE_IQ2_M - 2-bit quantization in super-blocks with an importance matrix applied, effectively using 2.7 bpw
72
+ * GGML_TYPE_IQ3_XXS - 3-bit quantization in super-blocks with an importance matrix applied, effectively using 3.06 bpw
73
+ * GGML_TYPE_IQ3_XS - 3-bit quantization in super-blocks with an importance matrix applied, effectively using 3.3 bpw
74
+ * GGML_TYPE_IQ3_S - 3-bit quantization in super-blocks with an importance matrix applied, effectively using 3.44 bpw
75
+ * GGML_TYPE_IQ3_M - 3-bit quantization in super-blocks with an importance matrix applied, effectively using 3.66 bpw
76
+ * GGML_TYPE_IQ4_XS - 4-bit quantization in super-blocks with an importance matrix applied, effectively using 4.25 bpw
77
+ * GGML_TYPE_IQ4_NL - 4-bit non-linearly mapped quantization with an importance matrix applied, effectively using 4.5 bpw
78
+
79
+ Refer to the Provided Files table below to see what files use which methods, and how.
80
+ </details>
81
+ <!-- compatibility_gguf end -->
82
+
83
+ <!-- README_GGUF.md-provided-files start -->
84
+ ## Provided files
85
+
86
+ | Name | Quant method | Bits | Size | Max RAM required | Use case |
87
+ | ---- | ---- | ---- | ---- | ---- | ----- |
88
+ | [Qwen2.5-Coder-7B-Instruct.IQ1_S.gguf](https://huggingface.co/CISCai/Qwen2.5-Coder-7B-Instruct-SOTA-GGUF/blob/main/Qwen2.5-Coder-7B-Instruct.IQ1_S.gguf) | IQ1_S | 1 | 1.8 GB| 2.0 GB | smallest, significant quality loss |
89
+ | [Qwen2.5-Coder-7B-Instruct.IQ1_M.gguf](https://huggingface.co/CISCai/Qwen2.5-Coder-7B-Instruct-SOTA-GGUF/blob/main/Qwen2.5-Coder-7B-Instruct.IQ1_M.gguf) | IQ1_M | 1 | 1.9 GB| 2.1 GB | very small, significant quality loss |
90
+ | [Qwen2.5-Coder-7B-Instruct.IQ2_XXS.gguf](https://huggingface.co/CISCai/Qwen2.5-Coder-7B-Instruct-SOTA-GGUF/blob/main/Qwen2.5-Coder-7B-Instruct.IQ2_XXS.gguf) | IQ2_XXS | 2 | 2.1 GB| 2.3 GB | very small, high quality loss |
91
+ | [Qwen2.5-Coder-7B-Instruct.IQ2_XS.gguf](https://huggingface.co/CISCai/Qwen2.5-Coder-7B-Instruct-SOTA-GGUF/blob/main/Qwen2.5-Coder-7B-Instruct.IQ2_XS.gguf) | IQ2_XS | 2 | 2.3 GB| 2.5 GB | very small, high quality loss |
92
+ | [Qwen2.5-Coder-7B-Instruct.IQ2_S.gguf](https://huggingface.co/CISCai/Qwen2.5-Coder-7B-Instruct-SOTA-GGUF/blob/main/Qwen2.5-Coder-7B-Instruct.IQ2_S.gguf) | IQ2_S | 2 | 2.4 GB| 2.6 GB | small, substantial quality loss |
93
+ | [Qwen2.5-Coder-7B-Instruct.IQ2_M.gguf](https://huggingface.co/CISCai/Qwen2.5-Coder-7B-Instruct-SOTA-GGUF/blob/main/Qwen2.5-Coder-7B-Instruct.IQ2_M.gguf) | IQ2_M | 2 | 2.6 GB| 2.8 GB | small, greater quality loss |
94
+ | [Qwen2.5-Coder-7B-Instruct.IQ3_XXS.gguf](https://huggingface.co/CISCai/Qwen2.5-Coder-7B-Instruct-SOTA-GGUF/blob/main/Qwen2.5-Coder-7B-Instruct.IQ3_XXS.gguf) | IQ3_XXS | 3 | 2.9 GB| 3.1 GB | very small, high quality loss |
95
+ | [Qwen2.5-Coder-7B-Instruct.IQ3_XS.gguf](https://huggingface.co/CISCai/Qwen2.5-Coder-7B-Instruct-SOTA-GGUF/blob/main/Qwen2.5-Coder-7B-Instruct.IQ3_XS.gguf) | IQ3_XS | 3 | 3.1 GB| 3.3 GB | small, substantial quality loss |
96
+ | [Qwen2.5-Coder-7B-Instruct.IQ3_S.gguf](https://huggingface.co/CISCai/Qwen2.5-Coder-7B-Instruct-SOTA-GGUF/blob/main/Qwen2.5-Coder-7B-Instruct.IQ3_S.gguf) | IQ3_S | 3 | 3.3 GB| 3.4 GB | small, greater quality loss |
97
+ | [Qwen2.5-Coder-7B-Instruct.IQ3_M.gguf](https://huggingface.co/CISCai/Qwen2.5-Coder-7B-Instruct-SOTA-GGUF/blob/main/Qwen2.5-Coder-7B-Instruct.IQ3_M.gguf) | IQ3_M | 3 | 3.3 GB| 3.5 GB | medium, balanced quality - recommended |
98
+ | [Qwen2.5-Coder-7B-Instruct.IQ4_XS.gguf](https://huggingface.co/CISCai/Qwen2.5-Coder-7B-Instruct-SOTA-GGUF/blob/main/Qwen2.5-Coder-7B-Instruct.IQ4_XS.gguf) | IQ4_XS | 4 | 3.9 GB| 4.1 GB | small, substantial quality loss |
99
+
100
+ Generated importance matrix file: [Qwen2.5-Coder-7B-Instruct.imatrix.dat](https://huggingface.co/CISCai/Qwen2.5-Coder-7B-Instruct-SOTA-GGUF/blob/main/Qwen2.5-Coder-7B-Instruct.imatrix.dat)
101
+
102
+ **Note**: the above RAM figures assume no GPU offloading with 4K context. If layers are offloaded to the GPU, this will reduce RAM usage and use VRAM instead.
103
+
104
+ <!-- README_GGUF.md-provided-files end -->
105
+
106
+ <!-- README_GGUF.md-how-to-run start -->
107
+ ## Example `llama.cpp` command
108
+
109
+ Make sure you are using `llama.cpp` from commit [0becb22](https://github.com/ggerganov/llama.cpp/commit/0becb22ac05b6542bd9d5f2235691aa1d3d4d307) or later.
110
+
111
+ ```shell
112
+ ./llama-cli -ngl 29 -m Qwen2.5-Coder-7B-Instruct.IQ4_XS.gguf --color -c 131072 --temp 0.7 --top-p 0.8 --top-k 20 --repeat-penalty 1.1 -p "<|im_start|>system\nYou are a helpful assistant.<|im_end|>\n<|im_start|>\n{prompt}<|im_end|>\n<|im_start|>assistant\n"
113
+ ```
114
+
115
+ Change `-ngl 29` to the number of layers to offload to GPU. Remove it if you don't have GPU acceleration.
116
+
117
+ Change `-c 131072` to the desired sequence length.
118
+
119
+ If you are low on V/RAM try quantizing the K-cache with `-ctk q8_0` or even `-ctk q4_0` for big memory savings (depending on context size).
120
+ There is a similar option for V-cache (`-ctv`), only available if you enable Flash Attention (`-fa`) as well.
121
+
122
+ For other parameters and how to use them, please refer to [the llama.cpp documentation](https://github.com/ggerganov/llama.cpp/blob/master/examples/main/README.md)
123
+
124
+ ## How to run from Python code
125
+
126
+ You can use GGUF models from Python using the [llama-cpp-python](https://github.com/abetlen/llama-cpp-python) module.
127
+
128
+ ### How to load this model in Python code, using llama-cpp-python
129
+
130
+ For full documentation, please see: [llama-cpp-python docs](https://llama-cpp-python.readthedocs.io/en/latest/).
131
+
132
+ #### First install the package
133
+
134
+ Run one of the following commands, according to your system:
135
+
136
+ ```shell
137
+ # Prebuilt wheel with basic CPU support
138
+ pip install llama-cpp-python --extra-index-url https://abetlen.github.io/llama-cpp-python/whl/cpu
139
+ # Prebuilt wheel with NVidia CUDA acceleration
140
+ pip install llama-cpp-python --extra-index-url https://abetlen.github.io/llama-cpp-python/whl/cu121 (or cu122 etc.)
141
+ # Prebuilt wheel with Metal GPU acceleration
142
+ pip install llama-cpp-python --extra-index-url https://abetlen.github.io/llama-cpp-python/whl/metal
143
+ # Build base version with no GPU acceleration
144
+ pip install llama-cpp-python
145
+ # With NVidia CUDA acceleration
146
+ CMAKE_ARGS="-DGGML_CUDA=on" pip install llama-cpp-python
147
+ # Or with OpenBLAS acceleration
148
+ CMAKE_ARGS="-DGGML_BLAS=ON -DGGML_BLAS_VENDOR=OpenBLAS" pip install llama-cpp-python
149
+ # Or with AMD ROCm GPU acceleration (Linux only)
150
+ CMAKE_ARGS="-DGGML_HIPBLAS=on" pip install llama-cpp-python
151
+ # Or with Metal GPU acceleration for macOS systems only
152
+ CMAKE_ARGS="-DGGML_METAL=on" pip install llama-cpp-python
153
+ # Or with Vulkan acceleration
154
+ CMAKE_ARGS="-DGGML_VULKAN=on" pip install llama-cpp-python
155
+ # Or with SYCL acceleration
156
+ CMAKE_ARGS="-DGGML_SYCL=on -DCMAKE_C_COMPILER=icx -DCMAKE_CXX_COMPILER=icpx" pip install llama-cpp-python
157
+
158
+ # In windows, to set the variables CMAKE_ARGS in PowerShell, follow this format; eg for NVidia CUDA:
159
+ $env:CMAKE_ARGS = "-DGGML_CUDA=on"
160
+ pip install llama-cpp-python
161
+ ```
162
+
163
+ #### Simple llama-cpp-python example code
164
+
165
+ ```python
166
+ from llama_cpp import Llama
167
+
168
+ # Chat Completion API
169
+
170
+ llm = Llama(model_path="./Qwen2.5-Coder-7B-Instruct.IQ4_XS.gguf", n_gpu_layers=29, n_ctx=131072)
171
+ print(llm.create_chat_completion(
172
+ repeat_penalty = 1.1,
173
+ messages = [
174
+ {
175
+ "role": "user",
176
+ "content": "Pick a LeetCode challenge and solve it in Python."
177
+ }
178
+ ]
179
+ ))
180
+ ```
181
+
182
+ #### Simple llama-cpp-python example fill-in-middle code
183
+
184
+ ```python
185
+ from llama_cpp import Llama
186
+
187
+ # Completion API
188
+
189
+ prompt = "def add("
190
+ suffix = "\n return sum\n\n"
191
+
192
+ llm = Llama(model_path="./Qwen2.5-Coder-7B-Instruct.IQ4_XS.gguf", n_gpu_layers=29, n_ctx=131072)
193
+ output = llm.create_completion(
194
+ temperature = 0.0,
195
+ repeat_penalty = 1.0,
196
+ prompt = prompt,
197
+ suffix = suffix
198
+ )
199
+
200
+ # Models sometimes repeat suffix in response, attempt to filter that
201
+ response = output["choices"][0]["text"]
202
+ response_stripped = response.rstrip()
203
+ unwanted_response_suffix = suffix.rstrip()
204
+ unwanted_response_length = len(unwanted_response_suffix)
205
+
206
+ filtered = False
207
+ if unwanted_response_suffix and response_stripped[-unwanted_response_length:] == unwanted_response_suffix:
208
+ response = response_stripped[:-unwanted_response_length]
209
+ filtered = True
210
+
211
+ print(f"Fill-in-Middle completion{' (filtered)' if filtered else ''}:\n\n{prompt}\033[32m{response}\033[{'33' if filtered else '0'}m{suffix}\033[0m")
212
+ ```
213
+
214
+ #### Simple llama-cpp-python example function calling code
215
+
216
+ ```python
217
+ from llama_cpp import Llama
218
+
219
+ # Chat Completion API
220
+
221
+ grammar = LlamaGrammar.from_json_schema(json.dumps({
222
+ "type": "array",
223
+ "items": {
224
+ "type": "object",
225
+ "required": [ "name", "arguments" ],
226
+ "properties": {
227
+ "name": {
228
+ "type": "string"
229
+ },
230
+ "arguments": {
231
+ "type": "object"
232
+ }
233
+ }
234
+ }
235
+ }))
236
+
237
+ llm = Llama(model_path="./Qwen2.5-Coder-7B-Instruct.IQ4_XS.gguf", n_gpu_layers=29, n_ctx=131072)
238
+ response = llm.create_chat_completion(
239
+ temperature = 0.0,
240
+ repeat_penalty = 1.1,
241
+ messages = [
242
+ {
243
+ "role": "user",
244
+ "content": "What's the weather like in Oslo and Stockholm?"
245
+ }
246
+ ],
247
+ tools=[{
248
+ "type": "function",
249
+ "function": {
250
+ "name": "get_current_weather",
251
+ "description": "Get the current weather in a given location",
252
+ "parameters": {
253
+ "type": "object",
254
+ "properties": {
255
+ "location": {
256
+ "type": "string",
257
+ "description": "The city and state, e.g. San Francisco, CA"
258
+ },
259
+ "unit": {
260
+ "type": "string",
261
+ "enum": [ "celsius", "fahrenheit" ]
262
+ }
263
+ },
264
+ "required": [ "location" ]
265
+ }
266
+ }
267
+ }],
268
+ grammar = grammar
269
+ )
270
+ print(json.loads(response["choices"][0]["text"]))
271
+
272
+ print(llm.create_chat_completion(
273
+ temperature = 0.0,
274
+ repeat_penalty = 1.1,
275
+ messages = [
276
+ {
277
+ "role": "user",
278
+ "content": "What's the weather like in Oslo?"
279
+ },
280
+ { # The tool_calls is from the response to the above with tool_choice active
281
+ "role": "assistant",
282
+ "content": None,
283
+ "tool_calls": [
284
+ {
285
+ "id": "call__0_get_current_weather_cmpl-...",
286
+ "type": "function",
287
+ "function": {
288
+ "name": "get_current_weather",
289
+ "arguments": { "location": "Oslo, Norway" , "unit": "celsius" }
290
+ }
291
+ }
292
+ ]
293
+ },
294
+ { # The tool_call_id is from tool_calls and content is the result from the function call you made
295
+ "role": "tool",
296
+ "content": "20",
297
+ "tool_call_id": "call__0_get_current_weather_cmpl-..."
298
+ }
299
+ ],
300
+ tools=[{
301
+ "type": "function",
302
+ "function": {
303
+ "name": "get_current_weather",
304
+ "description": "Get the current weather in a given location",
305
+ "parameters": {
306
+ "type": "object",
307
+ "properties": {
308
+ "location": {
309
+ "type": "string",
310
+ "description": "The city and state, e.g. San Francisco, CA"
311
+ },
312
+ "unit": {
313
+ "type": "string",
314
+ "enum": [ "celsius", "fahrenheit" ]
315
+ }
316
+ },
317
+ "required": [ "location" ]
318
+ }
319
+ }
320
+ }],
321
+ #tool_choice={
322
+ # "type": "function",
323
+ # "function": {
324
+ # "name": "get_current_weather"
325
+ # }
326
+ #}
327
+ ))
328
+ ```
329
+
330
+ <!-- README_GGUF.md-how-to-run end -->
331
+
332
+ <!-- original-model-card start -->
333
+ # Qwen2.5-Coder-7B-Instruct
334
+
335
+ ## Introduction
336
+
337
+ Qwen2.5-Coder is the latest series of Code-Specific Qwen large language models (formerly known as CodeQwen). For Qwen2.5-Coder, we release three base language models and instruction-tuned language models, 1.5, 7 and 32 (coming soon) billion parameters. Qwen2.5-Coder brings the following improvements upon CodeQwen1.5:
338
+
339
+ - Significantly improvements in **code generation**, **code reasoning** and **code fixing**. Base on the strong Qwen2.5, we scale up the training tokens into 5.5 trillion including source code, text-code grounding, Synthetic data, etc.
340
+ - A more comprehensive foundation for real-world applications such as **Code Agents**. Not only enhancing coding capabilities but also maintaining its strengths in mathematics and general competencies.
341
+ - **Long-context Support** up to 128K tokens.
342
+
343
+ **This repo contains the instruction-tuned 7B Qwen2.5-Coder model**, which has the following features:
344
+ - Type: Causal Language Models
345
+ - Training Stage: Pretraining & Post-training
346
+ - Architecture: transformers with RoPE, SwiGLU, RMSNorm, and Attention QKV bias
347
+ - Number of Parameters: 7.61B
348
+ - Number of Paramaters (Non-Embedding): 6.53B
349
+ - Number of Layers: 28
350
+ - Number of Attention Heads (GQA): 28 for Q and 4 for KV
351
+ - Context Length: Full 131,072 tokens
352
+ - Please refer to [this section](#processing-long-texts) for detailed instructions on how to deploy Qwen2.5 for handling long texts.
353
+
354
+ For more details, please refer to our [blog](https://qwenlm.github.io/blog/qwen2.5-coder/), [GitHub](https://github.com/QwenLM/Qwen2.5-Coder), and [Documentation](https://qwen.readthedocs.io/en/latest/).
355
+
356
+ ## Requirements
357
+
358
+ The code of Qwen2.5-Coder has been in the latest Hugging face `transformers` and we advise you to use the latest version of `transformers`.
359
+
360
+ With `transformers<4.37.0`, you will encounter the following error:
361
+ ```
362
+ KeyError: 'qwen2'
363
+ ```
364
+
365
+ ## Quickstart
366
+
367
+ Here provides a code snippet with `apply_chat_template` to show you how to load the tokenizer and model and how to generate contents.
368
+
369
+ ```python
370
+ from transformers import AutoModelForCausalLM, AutoTokenizer
371
+
372
+ model_name = "Qwen/Qwen2.5-Coder-7B-Instruct"
373
+
374
+ model = AutoModelForCausalLM.from_pretrained(
375
+ model_name,
376
+ torch_dtype="auto",
377
+ device_map="auto"
378
+ )
379
+ tokenizer = AutoTokenizer.from_pretrained(model_name)
380
+
381
+ prompt = "write a quick sort algorithm."
382
+ messages = [
383
+ {"role": "system", "content": "You are Qwen, created by Alibaba Cloud. You are a helpful assistant."},
384
+ {"role": "user", "content": prompt}
385
+ ]
386
+ text = tokenizer.apply_chat_template(
387
+ messages,
388
+ tokenize=False,
389
+ add_generation_prompt=True
390
+ )
391
+ model_inputs = tokenizer([text], return_tensors="pt").to(model.device)
392
+
393
+ generated_ids = model.generate(
394
+ **model_inputs,
395
+ max_new_tokens=512
396
+ )
397
+ generated_ids = [
398
+ output_ids[len(input_ids):] for input_ids, output_ids in zip(model_inputs.input_ids, generated_ids)
399
+ ]
400
+
401
+ response = tokenizer.batch_decode(generated_ids, skip_special_tokens=True)[0]
402
+ ```
403
+
404
+ ### Processing Long Texts
405
+
406
+ The current `config.json` is set for context length up to 32,768 tokens.
407
+ To handle extensive inputs exceeding 32,768 tokens, we utilize [YaRN](https://arxiv.org/abs/2309.00071), a technique for enhancing model length extrapolation, ensuring optimal performance on lengthy texts.
408
+
409
+ For supported frameworks, you could add the following to `config.json` to enable YaRN:
410
+ ```json
411
+ {
412
+ ...,
413
+ "rope_scaling": {
414
+ "factor": 4.0,
415
+ "original_max_position_embeddings": 32768,
416
+ "type": "yarn"
417
+ }
418
+ }
419
+ ```
420
+
421
+ For deployment, we recommend using vLLM.
422
+ Please refer to our [Documentation](https://qwen.readthedocs.io/en/latest/deployment/vllm.html) for usage if you are not familar with vLLM.
423
+ Presently, vLLM only supports static YARN, which means the scaling factor remains constant regardless of input length, **potentially impacting performance on shorter texts**.
424
+ We advise adding the `rope_scaling` configuration only when processing long contexts is required.
425
+
426
+ ## Evaluation & Performance
427
+
428
+ Detailed evaluation results are reported in this [📑 blog](https://qwenlm.github.io/blog/qwen2.5-coder/).
429
+
430
+ For requirements on GPU memory and the respective throughput, see results [here](https://qwen.readthedocs.io/en/latest/benchmark/speed_benchmark.html).
431
+
432
+ ## Citation
433
+
434
+ If you find our work helpful, feel free to give us a cite.
435
+
436
+ ```
437
+ @article{qwen25_coder,
438
+ title={Qwen2.5-Coder Technical Report},
439
+ author={Binyuan Hui, Jian Yang, Zeyu Cui, Jiaxi Yang, Dayiheng Liu, Lei Zhang, Tianyu Liu, Jiajun Zhang, Bowen Yu, Kai Dang, An Yang, Rui Men, Fei Huang, Xingzhang Ren, Xuancheng Ren, Jingren Zhou and Junyang Lin},
440
+ journal={arXiv preprint arXiv:2409.12186},
441
+ year={2024}
442
+ }
443
+ @article{qwen2,
444
+ title={Qwen2 Technical Report},
445
+ author={An Yang and Baosong Yang and Binyuan Hui and Bo Zheng and Bowen Yu and Chang Zhou and Chengpeng Li and Chengyuan Li and Dayiheng Liu and Fei Huang and Guanting Dong and Haoran Wei and Huan Lin and Jialong Tang and Jialin Wang and Jian Yang and Jianhong Tu and Jianwei Zhang and Jianxin Ma and Jin Xu and Jingren Zhou and Jinze Bai and Jinzheng He and Junyang Lin and Kai Dang and Keming Lu and Keqin Chen and Kexin Yang and Mei Li and Mingfeng Xue and Na Ni and Pei Zhang and Peng Wang and Ru Peng and Rui Men and Ruize Gao and Runji Lin and Shijie Wang and Shuai Bai and Sinan Tan and Tianhang Zhu and Tianhao Li and Tianyu Liu and Wenbin Ge and Xiaodong Deng and Xiaohuan Zhou and Xingzhang Ren and Xinyu Zhang and Xipin Wei and Xuancheng Ren and Yang Fan and Yang Yao and Yichang Zhang and Yu Wan and Yunfei Chu and Yuqiong Liu and Zeyu Cui and Zhenru Zhang and Zhihao Fan},
446
+ journal={arXiv preprint arXiv:2407.10671},
447
+ year={2024}
448
+ }
449
+ ```