Views
No views yet
<|im_start|>system
{system_prompt}<|im_end|>
<|im_start|>user
{prompt}<|im_end|>
<|im_start|>assistant| Name | Quant method | Bits | Size | Max RAM required | Use case |
|---|---|---|---|---|---|
| Qwen2.5-Coder-32B-Instruct.IQ1_S.gguf (with YaRN) | IQ1_S | 1 | 6.8 GB | 7.8 GB | smallest, significant quality loss |
| Qwen2.5-Coder-32B-Instruct.IQ1_M.gguf (with YaRN) | IQ1_M | 1 | 7.4 GB | 8.4 GB | very small, significant quality loss |
| Qwen2.5-Coder-32B-Instruct.IQ2_XXS.gguf (with YaRN) | IQ2_XXS | 2 | 8.4 GB | 9.4 GB | very small, high quality loss |
| Qwen2.5-Coder-32B-Instruct.IQ2_XS.gguf (with YaRN) | IQ2_XS | 2 | 9.3 GB | 10.3 GB | very small, high quality loss |
| Qwen2.5-Coder-32B-Instruct.IQ2_S.gguf (with YaRN) | IQ2_S | 2 | 9.7 GB | 10.7 GB | small, substantial quality loss |
| Qwen2.5-Coder-32B-Instruct.IQ2_M.gguf (with YaRN) | IQ2_M | 2 | 10.5 GB | 11.5 GB | small, greater quality loss |
| Qwen2.5-Coder-32B-Instruct.IQ3_XXS.gguf (with YaRN) | IQ3_XXS | 3 | 11.9 GB | 12.9 GB | very small, high quality loss |
| Qwen2.5-Coder-32B-Instruct.IQ3_XS.gguf (with YaRN) | IQ3_XS | 3 | 12.8 GB | 13.8 GB | small, substantial quality loss |
| Qwen2.5-Coder-32B-Instruct.IQ3_S.gguf (with YaRN) | IQ3_S | 3 | 13.4 GB | 14.4 GB | small, greater quality loss |
| Qwen2.5-Coder-32B-Instruct.IQ3_M.gguf (with YaRN) | IQ3_M | 3 | 13.8 GB | 14.8 GB | medium, balanced quality - recommended |
| Qwen2.5-Coder-32B-Instruct.IQ4_XS.gguf (with YaRN) | IQ4_XS | 4 | 16.5 GB | 17.5 GB | small, substantial quality loss |
llama.cpp commandllama.cpp from commit 0becb22 or later../llama-cli -ngl 65 -m Qwen2.5-Coder-32B-Instruct.IQ4_XS.gguf --color -c 131072 --temp 0.7 --top-p 0.8 --top-k 20 --repeat-penalty 1.05 -p "<|im_start|>system\nYou are a helpful assistant.<|im_end|>\n<|im_start|>\n{prompt}<|im_end|>\n<|im_start|>assistant\n"-ngl 65 to the number of layers to offload to GPU. Remove it if you don't have GPU acceleration.-c 131072 to the desired sequence length.-ctk q8_0 or even -ctk q4_0 for big memory savings (depending on context size).
There is a similar option for V-cache (-ctv), only available if you enable Flash Attention (-fa) as well.1# Prebuilt wheel with basic CPU support
2pip install llama-cpp-python --extra-index-url https://abetlen.github.io/llama-cpp-python/whl/cpu
3# Prebuilt wheel with NVidia CUDA acceleration
4pip install llama-cpp-python --extra-index-url https://abetlen.github.io/llama-cpp-python/whl/cu121 (or cu122 etc.)
5# Prebuilt wheel with Metal GPU acceleration
6pip install llama-cpp-python --extra-index-url https://abetlen.github.io/llama-cpp-python/whl/metal
7# Build base version with no GPU acceleration
8pip install llama-cpp-python
9# With NVidia CUDA acceleration
10CMAKE_ARGS="-DGGML_CUDA=on" pip install llama-cpp-python
11# Or with OpenBLAS acceleration
12CMAKE_ARGS="-DGGML_BLAS=ON -DGGML_BLAS_VENDOR=OpenBLAS" pip install llama-cpp-python
13# Or with AMD ROCm GPU acceleration (Linux only)
14CMAKE_ARGS="-DGGML_HIPBLAS=on" pip install llama-cpp-python
15# Or with Metal GPU acceleration for macOS systems only
16CMAKE_ARGS="-DGGML_METAL=on" pip install llama-cpp-python
17# Or with Vulkan acceleration
18CMAKE_ARGS="-DGGML_VULKAN=on" pip install llama-cpp-python
19# Or with SYCL acceleration
20CMAKE_ARGS="-DGGML_SYCL=on -DCMAKE_C_COMPILER=icx -DCMAKE_CXX_COMPILER=icpx" pip install llama-cpp-python
21
22# In windows, to set the variables CMAKE_ARGS in PowerShell, follow this format; eg for NVidia CUDA:
23$env:CMAKE_ARGS = "-DGGML_CUDA=on"
24pip install llama-cpp-python1from llama_cpp import Llama
2
3# Chat Completion API
4
5llm = Llama(model_path="./Qwen2.5-Coder-32B-Instruct.IQ4_XS.gguf", n_gpu_layers=65, n_ctx=131072)
6print(llm.create_chat_completion(
7 repeat_penalty = 1.05,
8 messages = [
9 {
10 "role": "user",
11 "content": "Pick a LeetCode challenge and solve it in Python."
12 }
13 ]
14))1from llama_cpp import Llama
2
3# Completion API
4
5prompt = "def add("
6suffix = "\n return sum\n\n"
7
8llm = Llama(model_path="./Qwen2.5-Coder-32B-Instruct.IQ4_XS.gguf", n_gpu_layers=65, n_ctx=131072)
9output = llm.create_completion(
10 temperature = 0.0,
11 repeat_penalty = 1.0,
12 prompt = prompt,
13 suffix = suffix
14)
15
16# Models sometimes repeat suffix in response, attempt to filter that
17response = output["choices"][0]["text"]
18response_stripped = response.rstrip()
19unwanted_response_suffix = suffix.rstrip()
20unwanted_response_length = len(unwanted_response_suffix)
21
22filtered = False
23if unwanted_response_suffix and response_stripped[-unwanted_response_length:] == unwanted_response_suffix:
24 response = response_stripped[:-unwanted_response_length]
25 filtered = True
26
27print(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")1from llama_cpp import Llama
2
3# Chat Completion API
4
5grammar = LlamaGrammar.from_json_schema(json.dumps({
6 "type": "array",
7 "items": {
8 "type": "object",
9 "required": [ "name", "arguments" ],
10 "properties": {
11 "name": {
12 "type": "string"
13 },
14 "arguments": {
15 "type": "object"
16 }
17 }
18 }
19}))
20
21llm = Llama(model_path="./Qwen2.5-Coder-32B-Instruct.IQ4_XS.gguf", n_gpu_layers=65, n_ctx=131072)
22response = llm.create_chat_completion(
23 temperature = 0.0,
24 repeat_penalty = 1.05,
25 messages = [
26 {
27 "role": "user",
28 "content": "What's the weather like in Oslo and Stockholm?"
29 }
30 ],
31 tools=[{
32 "type": "function",
33 "function": {
34 "name": "get_current_weather",
35 "description": "Get the current weather in a given location",
36 "parameters": {
37 "type": "object",
38 "properties": {
39 "location": {
40 "type": "string",
41 "description": "The city and state, e.g. San Francisco, CA"
42 },
43 "unit": {
44 "type": "string",
45 "enum": [ "celsius", "fahrenheit" ]
46 }
47 },
48 "required": [ "location" ]
49 }
50 }
51 }],
52 grammar = grammar
53)
54print(json.loads(response["choices"][0]["text"]))
55
56print(llm.create_chat_completion(
57 temperature = 0.0,
58 repeat_penalty = 1.05,
59 messages = [
60 {
61 "role": "user",
62 "content": "What's the weather like in Oslo?"
63 },
64 { # The tool_calls is from the response to the above with tool_choice active
65 "role": "assistant",
66 "content": None,
67 "tool_calls": [
68 {
69 "id": "call__0_get_current_weather_cmpl-...",
70 "type": "function",
71 "function": {
72 "name": "get_current_weather",
73 "arguments": { "location": "Oslo, Norway" , "unit": "celsius" }
74 }
75 }
76 ]
77 },
78 { # The tool_call_id is from tool_calls and content is the result from the function call you made
79 "role": "tool",
80 "content": "20",
81 "tool_call_id": "call__0_get_current_weather_cmpl-..."
82 }
83 ],
84 tools=[{
85 "type": "function",
86 "function": {
87 "name": "get_current_weather",
88 "description": "Get the current weather in a given location",
89 "parameters": {
90 "type": "object",
91 "properties": {
92 "location": {
93 "type": "string",
94 "description": "The city and state, e.g. San Francisco, CA"
95 },
96 "unit": {
97 "type": "string",
98 "enum": [ "celsius", "fahrenheit" ]
99 }
100 },
101 "required": [ "location" ]
102 }
103 }
104 }],
105 #tool_choice={
106 # "type": "function",
107 # "function": {
108 # "name": "get_current_weather"
109 # }
110 #}
111))transformers and we advise you to use the latest version of transformers.transformers<4.37.0, you will encounter the following error:KeyError: 'qwen2'apply_chat_template to show you how to load the tokenizer and model and how to generate contents.1from transformers import AutoModelForCausalLM, AutoTokenizer
2
3model_name = "Qwen/Qwen2.5-Coder-32B-Instruct"
4
5model = AutoModelForCausalLM.from_pretrained(
6 model_name,
7 torch_dtype="auto",
8 device_map="auto"
9)
10tokenizer = AutoTokenizer.from_pretrained(model_name)
11
12prompt = "write a quick sort algorithm."
13messages = [
14 {"role": "system", "content": "You are Qwen, created by Alibaba Cloud. You are a helpful assistant."},
15 {"role": "user", "content": prompt}
16]
17text = tokenizer.apply_chat_template(
18 messages,
19 tokenize=False,
20 add_generation_prompt=True
21)
22model_inputs = tokenizer([text], return_tensors="pt").to(model.device)
23
24generated_ids = model.generate(
25 **model_inputs,
26 max_new_tokens=512
27)
28generated_ids = [
29 output_ids[len(input_ids):] for input_ids, output_ids in zip(model_inputs.input_ids, generated_ids)
30]
31
32response = tokenizer.batch_decode(generated_ids, skip_special_tokens=True)[0]config.json is set for context length up to 32,768 tokens.
To handle extensive inputs exceeding 32,768 tokens, we utilize YaRN, a technique for enhancing model length extrapolation, ensuring optimal performance on lengthy texts.config.json to enable YaRN:1{
2 ...,
3 "rope_scaling": {
4 "factor": 4.0,
5 "original_max_position_embeddings": 32768,
6 "type": "yarn"
7 }
8}rope_scaling configuration only when processing long contexts is required.@article{hui2024qwen2,
title={Qwen2. 5-Coder Technical Report},
author={Hui, Binyuan and Yang, Jian and Cui, Zeyu and Yang, Jiaxi and Liu, Dayiheng and Zhang, Lei and Liu, Tianyu and Zhang, Jiajun and Yu, Bowen and Dang, Kai and others},
journal={arXiv preprint arXiv:2409.12186},
year={2024}
}
@article{qwen2,
title={Qwen2 Technical Report},
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},
journal={arXiv preprint arXiv:2407.10671},
year={2024}
}