base_model: Qwen/CodeQwen1.5-7B-Chat
license: other
license_name: tongyi-qianwen
license_link: https://huggingface.co/Qwen/CodeQwen1.5-7B-Chat/blob/main/LICENSE
language:
- en
pipeline_tag: text-generation
tags:
- chat
model_creator: Qwen
model_name: CodeQwen1.5-7B-Chat
model_type: qwen2
datasets:
- m-a-p/CodeFeedback-Filtered-Instruction
quantized_by: CISC
CodeQwen1.5-7B-Chat - SOTA GGUF
- Model creator: Qwen
- Original model: CodeQwen1.5-7B-Chat
Description
This repo contains State Of The Art quantized GGUF format model files for CodeQwen1.5-7B-Chat.
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 dataset.
NOTE: Due to the majority of tensors in Qwen2 models being oddly shaped a consequential portion of the quantization fell back to IQ4_NL instead of the specified method, causing significantly larger (and "smarter"; even IQ1_S is perfectly usable) model files than usual!
Prompt template: ChatML
<|im_start|>system
{system_prompt}<|im_end|>
<|im_start|>user
{prompt}<|im_end|>
<|im_start|>assistant
Compatibility
These quantised GGUFv3 files are compatible with llama.cpp from February 27th 2024 onwards, as of commit 0becb22
They are also compatible with many third party UIs and libraries provided they are built using a recent llama.cpp.
Explanation of quantisation methods
Click to see details
The new methods available are:
- GGML_TYPE_IQ1_S - 1-bit quantization in super-blocks with an importance matrix applied, effectively using 1.56 bits per weight (bpw)
- GGML_TYPE_IQ1_M - 1-bit quantization in super-blocks with an importance matrix applied, effectively using 1.75 bpw
- GGML_TYPE_IQ2_XXS - 2-bit quantization in super-blocks with an importance matrix applied, effectively using 2.06 bpw
- GGML_TYPE_IQ2_XS - 2-bit quantization in super-blocks with an importance matrix applied, effectively using 2.31 bpw
- GGML_TYPE_IQ2_S - 2-bit quantization in super-blocks with an importance matrix applied, effectively using 2.5 bpw
- GGML_TYPE_IQ2_M - 2-bit quantization in super-blocks with an importance matrix applied, effectively using 2.7 bpw
- GGML_TYPE_IQ3_XXS - 3-bit quantization in super-blocks with an importance matrix applied, effectively using 3.06 bpw
- GGML_TYPE_IQ3_XS - 3-bit quantization in super-blocks with an importance matrix applied, effectively using 3.3 bpw
- GGML_TYPE_IQ3_S - 3-bit quantization in super-blocks with an importance matrix applied, effectively using 3.44 bpw
- GGML_TYPE_IQ3_M - 3-bit quantization in super-blocks with an importance matrix applied, effectively using 3.66 bpw
- GGML_TYPE_IQ4_XS - 4-bit quantization in super-blocks with an importance matrix applied, effectively using 4.25 bpw
- GGML_TYPE_IQ4_NL - 4-bit non-linearly mapped quantization with an importance matrix applied, effectively using 4.5 bpw
Refer to the Provided Files table below to see what files use which methods, and how.
Provided files
Name | Quant method | Bits | Size | Max RAM required | Use case |
---|---|---|---|---|---|
CodeQwen1.5-7B-Chat.IQ1_S.gguf | IQ1_S | 1 | 2.2 GB | 2.4 GB | smallest, significant quality loss |
CodeQwen1.5-7B-Chat.IQ1_M.gguf | IQ1_M | 1 | 2.3 GB | 2.5 GB | very small, significant quality loss |
CodeQwen1.5-7B-Chat.IQ2_XXS.gguf | IQ2_XXS | 2 | 2.5 GB | 2.7 GB | very small, high quality loss |
CodeQwen1.5-7B-Chat.IQ2_XS.gguf | IQ2_XS | 2 | 2.6 GB | 2.8 GB | very small, high quality loss |
CodeQwen1.5-7B-Chat.IQ2_S.gguf | IQ2_S | 2 | 2.7 GB | 2.9 GB | small, substantial quality loss |
CodeQwen1.5-7B-Chat.IQ2_M.gguf | IQ2_M | 2 | 2.9 GB | 3.1 GB | small, greater quality loss |
CodeQwen1.5-7B-Chat.IQ3_XXS.gguf | IQ3_XXS | 3 | 3.1 GB | 3.3 GB | very small, high quality loss |
CodeQwen1.5-7B-Chat.IQ3_XS.gguf | IQ3_XS | 3 | 3.2 GB | 3.4 GB | small, substantial quality loss |
CodeQwen1.5-7B-Chat.IQ3_S.gguf | IQ3_S | 3 | 3.3 GB | 3.5 GB | small, greater quality loss |
CodeQwen1.5-7B-Chat.IQ3_M.gguf | IQ3_M | 3 | 3.4 GB | 3.6 GB | medium, balanced quality - recommended |
CodeQwen1.5-7B-Chat.IQ4_NL.gguf | IQ4_NL | 4 | 4.0 GB | 4.2 GB | small, substantial quality loss |
Generated importance matrix file: CodeQwen1.5-7B-Chat.imatrix.dat
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.
Example llama.cpp
command
Make sure you are using llama.cpp
from commit 0becb22 or later.
./main -ngl 33 -m CodeQwen1.5-7B-Chat.IQ2_XS.gguf --color -c 65536 --temp 1.0 --repeat-penalty 1.0 --top-p 0.95 -n -1 -p "<|im_start|>system\nYou are a helpful assistant<|im_end|>\n<|im_start|>\n{prompt}<|im_end|>\n<|im_start|>assistant\n"
Change -ngl 33
to the number of layers to offload to GPU. Remove it if you don't have GPU acceleration.
Change -c 65536
to the desired sequence length.
If you want to have a chat-style conversation, replace the -p <PROMPT>
argument with -i -ins
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).
There is a similar option for V-cache (-ctv
), however that is not working yet.
For other parameters and how to use them, please refer to the llama.cpp documentation
How to run from Python code
You can use GGUF models from Python using the llama-cpp-python module.
How to load this model in Python code, using llama-cpp-python
For full documentation, please see: llama-cpp-python docs.
First install the package
Run one of the following commands, according to your system:
# Prebuilt wheel with basic CPU support
pip install llama-cpp-python --extra-index-url https://abetlen.github.io/llama-cpp-python/whl/cpu
# Prebuilt wheel with NVidia CUDA acceleration
pip install llama-cpp-python --extra-index-url https://abetlen.github.io/llama-cpp-python/whl/cu121 (or cu122 etc.)
# Prebuilt wheel with Metal GPU acceleration
pip install llama-cpp-python --extra-index-url https://abetlen.github.io/llama-cpp-python/whl/metal
# Build base version with no GPU acceleration
pip install llama-cpp-python
# With NVidia CUDA acceleration
CMAKE_ARGS="-DLLAMA_CUDA=on" pip install llama-cpp-python
# Or with OpenBLAS acceleration
CMAKE_ARGS="-DLLAMA_BLAS=ON -DLLAMA_BLAS_VENDOR=OpenBLAS" pip install llama-cpp-python
# Or with CLBLast acceleration
CMAKE_ARGS="-DLLAMA_CLBLAST=on" pip install llama-cpp-python
# Or with AMD ROCm GPU acceleration (Linux only)
CMAKE_ARGS="-DLLAMA_HIPBLAS=on" pip install llama-cpp-python
# Or with Metal GPU acceleration for macOS systems only
CMAKE_ARGS="-DLLAMA_METAL=on" pip install llama-cpp-python
# Or with Vulkan acceleration
CMAKE_ARGS="-DLLAMA_VULKAN=on" pip install llama-cpp-python
# Or with Kompute acceleration
CMAKE_ARGS="-DLLAMA_KOMPUTE=on" pip install llama-cpp-python
# Or with SYCL acceleration
CMAKE_ARGS="-DLLAMA_SYCL=on -DCMAKE_C_COMPILER=icx -DCMAKE_CXX_COMPILER=icpx" pip install llama-cpp-python
# In windows, to set the variables CMAKE_ARGS in PowerShell, follow this format; eg for NVidia CUDA:
$env:CMAKE_ARGS = "-DLLAMA_CUDA=on"
pip install llama-cpp-python
Simple llama-cpp-python example code
from llama_cpp import Llama
# Chat Completion API
llm = Llama(model_path="./CodeQwen1.5-7B-Chat.IQ2_XS.gguf", n_gpu_layers=33, n_ctx=65536)
print(llm.create_chat_completion(
messages = [
{"role": "system", "content": "You are an expert AI coding assistant."},
{
"role": "user",
"content": "Pick a LeetCode challenge and solve it in Python."
}
]
))
CodeQwen1.5-7B-Chat
Introduction
CodeQwen1.5 is the Code-Specific version of Qwen1.5. It is a transformer-based decoder-only language model pretrained on a large amount of data of codes.
- Strong code generation capabilities and competitve performance across a series of benchmarks;
- Supporting long context understanding and generation with the context length of 64K tokens;
- Supporting 92 coding languages
- Excellent performance in text-to-SQL, bug fix, etc.
For more details, please refer to our blog post and GitHub repo.
Model Details
CodeQwen1.5 is based on Qwen1.5, a language model series including decoder language models of different model sizes. It is trained on 3 trillion tokens of data of codes, and it includes group query attention (GQA) for efficient inference.
Requirements
The code of Qwen1.5 has been in the latest Hugging face transformers and we advise you to install transformers>=4.37.0
, or you might encounter the following error:
KeyError: 'qwen2'.
Quickstart
Here provides a code snippet with apply_chat_template
to show you how to load the tokenizer and model and how to generate contents.
from transformers import AutoModelForCausalLM, AutoTokenizer
device = "cuda" # the device to load the model onto
model = AutoModelForCausalLM.from_pretrained(
"Qwen/CodeQwen1.5-7B-Chat",
torch_dtype="auto",
device_map="auto"
)
tokenizer = AutoTokenizer.from_pretrained("Qwen/CodeQwen1.5-7B-Chat")
prompt = "Write a quicksort algorithm in python."
messages = [
{"role": "system", "content": "You are a helpful assistant."},
{"role": "user", "content": prompt}
]
text = tokenizer.apply_chat_template(
messages,
tokenize=False,
add_generation_prompt=True
)
model_inputs = tokenizer([text], return_tensors="pt").to(device)
generated_ids = model.generate(
model_inputs.input_ids,
max_new_tokens=512
)
generated_ids = [
output_ids[len(input_ids):] for input_ids, output_ids in zip(model_inputs.input_ids, generated_ids)
]
response = tokenizer.batch_decode(generated_ids, skip_special_tokens=True)[0]
Tips
- If you encounter code switching or other bad cases, we advise you to use our provided hyper-parameters in
generation_config.json
.
Citation
If you find our work helpful, feel free to give us a cite.
@article{qwen,
title={Qwen Technical Report},
author={Jinze Bai and Shuai Bai and Yunfei Chu and Zeyu Cui and Kai Dang and Xiaodong Deng and Yang Fan and Wenbin Ge and Yu Han and Fei Huang and Binyuan Hui and Luo Ji and Mei Li and Junyang Lin and Runji Lin and Dayiheng Liu and Gao Liu and Chengqiang Lu and Keming Lu and Jianxin Ma and Rui Men and Xingzhang Ren and Xuancheng Ren and Chuanqi Tan and Sinan Tan and Jianhong Tu and Peng Wang and Shijie Wang and Wei Wang and Shengguang Wu and Benfeng Xu and Jin Xu and An Yang and Hao Yang and Jian Yang and Shusheng Yang and Yang Yao and Bowen Yu and Hongyi Yuan and Zheng Yuan and Jianwei Zhang and Xingxuan Zhang and Yichang Zhang and Zhenru Zhang and Chang Zhou and Jingren Zhou and Xiaohuan Zhou and Tianhang Zhu},
journal={arXiv preprint arXiv:2309.16609},
year={2023}
}