This repo contains State Of The Art quantized GGUF format model files for Nxcode-CQ-7B-orpo.
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!
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.
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.
Run one of the following commands, according to your system:
shell
1# Prebuilt wheel with basic CPU support2pip install llama-cpp-python --extra-index-url https://abetlen.github.io/llama-cpp-python/whl/cpu
3# Prebuilt wheel with NVidia CUDA acceleration4pip 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 acceleration6pip install llama-cpp-python --extra-index-url https://abetlen.github.io/llama-cpp-python/whl/metal
7# Build base version with no GPU acceleration8pip install llama-cpp-python
9# With NVidia CUDA acceleration10CMAKE_ARGS="-DLLAMA_CUDA=on" pip install llama-cpp-python
11# Or with OpenBLAS acceleration12CMAKE_ARGS="-DLLAMA_BLAS=ON -DLLAMA_BLAS_VENDOR=OpenBLAS" pip install llama-cpp-python
13# Or with CLBLast acceleration14CMAKE_ARGS="-DLLAMA_CLBLAST=on" pip install llama-cpp-python
15# Or with AMD ROCm GPU acceleration (Linux only)16CMAKE_ARGS="-DLLAMA_HIPBLAS=on" pip install llama-cpp-python
17# Or with Metal GPU acceleration for macOS systems only18CMAKE_ARGS="-DLLAMA_METAL=on" pip install llama-cpp-python
19# Or with Vulkan acceleration20CMAKE_ARGS="-DLLAMA_VULKAN=on" pip install llama-cpp-python
21# Or with Kompute acceleration22CMAKE_ARGS="-DLLAMA_KOMPUTE=on" pip install llama-cpp-python
23# Or with SYCL acceleration24CMAKE_ARGS="-DLLAMA_SYCL=on -DCMAKE_C_COMPILER=icx -DCMAKE_CXX_COMPILER=icpx" pip install llama-cpp-python
2526# In windows, to set the variables CMAKE_ARGS in PowerShell, follow this format; eg for NVidia CUDA:27$env:CMAKE_ARGS ="-DLLAMA_CUDA=on"28pip install llama-cpp-python
Simple llama-cpp-python example code
python
1from llama_cpp import Llama
23# Chat Completion API45llm = Llama(model_path="./Nxcode-CQ-7B-orpo.IQ2_XS.gguf", n_gpu_layers=33, n_ctx=65536)6print(llm.create_chat_completion(7 messages =[8{"role":"system","content":"You are an expert AI coding assistant."},9{10"role":"user",11"content":"Pick a LeetCode challenge and solve it in Python."12}13]14))
Here provides a code snippet with apply_chat_template to show you how to load the tokenizer and model and how to generate contents. You should upgrade the transformers if you receive an error when loading the tokenizer
python
1from transformers import AutoModelForCausalLM, AutoTokenizer
2device ="cuda"# the device to load the model onto34model = AutoModelForCausalLM.from_pretrained(5"NTQAI/Nxcode-CQ-7B-orpo",6 torch_dtype="auto",7 device_map="auto"8)9tokenizer = AutoTokenizer.from_pretrained("NTQAI/Nxcode-CQ-7B-orpo")1011prompt ="""Complete the following Python function:
12from typing import List
131415def has_close_elements(numbers: List[float], threshold: float) -> bool:
16 """ Check ifin given list of numbers, are any two numbers closer to each other than
17 given threshold.18>>> has_close_elements([1.0,2.0,3.0],0.5)19False20>>> has_close_elements([1.0,2.8,3.0,4.0,5.0,2.0],0.3)21True22"""
23"""24messages =[25{"role":"user","content": prompt}26]2728inputs = tokenizer.apply_chat_template(messages, add_generation_prompt=True, return_tensors="pt").to(model.device)29outputs = model.generate(inputs, max_new_tokens=512, do_sample=False, top_k=50, top_p=0.95, num_return_sequences=1, eos_token_id=tokenizer.eos_token_id)30res = tokenizer.decode(outputs[0][len(inputs[0]):], skip_special_tokens=True)31