Views
No views yet
tools parameter and Fill-in-Middle token metadata has been added, see example. NOTE: Mistral's FIM requires support for SPM infill mode![AVAILABLE_TOOLS] [{"name": "function_name", "description": "Description", "parameters": {...}}, ...][/AVAILABLE_TOOLS][INST] {prompt}[/INST]| Name | Quant method | Bits | Size | Max RAM required | Use case |
|---|---|---|---|---|---|
| Codestral-22B-v0.1.IQ1_S.gguf | IQ1_S | 1 | 4.3 GB | 5.3 GB | smallest, significant quality loss - TBD: Waiting for this issue to be resolved |
| Codestral-22B-v0.1.IQ1_M.gguf | IQ1_M | 1 | 4.8 GB | 5.8 GB | very small, significant quality loss |
| Codestral-22B-v0.1.IQ2_XXS.gguf | IQ2_XXS | 2 | 5.4 GB | 6.4 GB | very small, high quality loss |
| Codestral-22B-v0.1.IQ2_XS.gguf | IQ2_XS | 2 | 6.0 GB | 7.0 GB | very small, high quality loss |
| Codestral-22B-v0.1.IQ2_S.gguf | IQ2_S | 2 | 6.4 GB | 7.4 GB | small, substantial quality loss |
| Codestral-22B-v0.1.IQ2_M.gguf | IQ2_M | 2 | 6.9 GB | 7.9 GB | small, greater quality loss |
| Codestral-22B-v0.1.IQ3_XXS.gguf | IQ3_XXS | 3 | 7.9 GB | 8.9 GB | very small, high quality loss |
| Codestral-22B-v0.1.IQ3_XS.gguf | IQ3_XS | 3 | 8.4 GB | 9.4 GB | small, substantial quality loss |
| Codestral-22B-v0.1.IQ3_S.gguf | IQ3_S | 3 | 8.9 GB | 9.9 GB | small, greater quality loss |
| Codestral-22B-v0.1.IQ3_M.gguf | IQ3_M | 3 | 9.2 GB | 10.2 GB | medium, balanced quality - recommended |
| Codestral-22B-v0.1.IQ4_XS.gguf | IQ4_XS | 4 | 11.5 GB | 12.5 GB | small, substantial quality loss |
llama.cpp commandllama.cpp from commit 0becb22 or later../main -ngl 57 -m Codestral-22B-v0.1.IQ4_XS.gguf --color -c 32768 --temp 0 --repeat-penalty 1.1 -p "[AVAILABLE_TOOLS] {tools}[/AVAILABLE_TOOLS][INST] {prompt}[/INST]"-ngl 57 to the number of layers to offload to GPU. Remove it if you don't have GPU acceleration.-c 32768 to the desired sequence length.-p <PROMPT> argument with -i -ins-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.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="-DLLAMA_CUDA=on" pip install llama-cpp-python
11# Or with OpenBLAS acceleration
12CMAKE_ARGS="-DLLAMA_BLAS=ON -DLLAMA_BLAS_VENDOR=OpenBLAS" pip install llama-cpp-python
13# Or with CLBLast acceleration
14CMAKE_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 only
18CMAKE_ARGS="-DLLAMA_METAL=on" pip install llama-cpp-python
19# Or with Vulkan acceleration
20CMAKE_ARGS="-DLLAMA_VULKAN=on" pip install llama-cpp-python
21# Or with Kompute acceleration
22CMAKE_ARGS="-DLLAMA_KOMPUTE=on" pip install llama-cpp-python
23# Or with SYCL acceleration
24CMAKE_ARGS="-DLLAMA_SYCL=on -DCMAKE_C_COMPILER=icx -DCMAKE_CXX_COMPILER=icpx" pip install llama-cpp-python
25
26# 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-python1from llama_cpp import Llama
2
3# Chat Completion API
4
5llm = Llama(model_path="./Codestral-22B-v0.1.IQ4_XS.gguf", n_gpu_layers=57, n_ctx=32768)
6print(llm.create_chat_completion(
7 repeat_penalty = 1.1,
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="./Codestral-22B-v0.1.IQ4_XS.gguf", n_gpu_layers=57, n_ctx=32768, spm_infill=True)
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[0m{suffix}")1from llama_cpp import Llama
2
3# Chat Completion API
4
5llm = Llama(model_path="./Codestral-22B-v0.1.IQ4_XS.gguf", n_gpu_layers=57, n_ctx=32768)
6print(llm.create_chat_completion(
7 temperature = 0.0,
8 repeat_penalty = 1.1,
9 messages = [
10 {
11 "role": "user",
12 "content": "In a physics experiment, you are given an object with a mass of 50 kilograms and a volume of 10 cubic meters. Can you use the 'calculate_density' function to determine the density of this object?"
13 },
14 { # The tool_calls is from the response to the above with tool_choice active
15 "role": "assistant",
16 "content": None,
17 "tool_calls": [
18 {
19 "id": "call__0_calculate_density_cmpl-...",
20 "type": "function",
21 "function": {
22 "name": "calculate_density",
23 "arguments": '{"mass": "50", "volume": "10"}'
24 }
25 }
26 ]
27 },
28 { # The tool_call_id is from tool_calls and content is the result from the function call you made
29 "role": "tool",
30 "content": "5.0",
31 "tool_call_id": "call__0_calculate_density_cmpl-..."
32 }
33 ],
34 tools=[{
35 "type": "function",
36 "function": {
37 "name": "calculate_density",
38 "description": "Calculates the density of an object.",
39 "parameters": {
40 "type": "object",
41 "properties": {
42 "mass": {
43 "type": "integer",
44 "description": "The mass of the object."
45 },
46 "volume": {
47 "type": "integer",
48 "description": "The volume of the object."
49 }
50 },
51 "required": [ "mass", "volume" ]
52 }
53 }
54 }],
55 #tool_choice={
56 # "type": "function",
57 # "function": {
58 # "name": "calculate_density"
59 # }
60 #}
61))mistralai/Codestral-22B-v0.1 with mistral-inference.pip install mistral_inference1from huggingface_hub import snapshot_download
2from pathlib import Path
3
4mistral_models_path = Path.home().joinpath('mistral_models', 'Codestral-22B-v0.1')
5mistral_models_path.mkdir(parents=True, exist_ok=True)
6
7snapshot_download(repo_id="mistralai/Codestral-22B-v0.1", allow_patterns=["params.json", "consolidated.safetensors", "tokenizer.model.v3"], local_dir=mistral_models_path)mistral_inference, a mistral-chat CLI command should be available in your environment.mistral-chat $HOME/mistral_models/Codestral-22B-v0.1 --instruct --max_tokens 256Sure, here's a simple implementation of a function that computes the Fibonacci sequence in Rust. This function takes an integer `n` as an argument and returns the `n`th Fibonacci number.
fn fibonacci(n: u32) -> u32 {
match n {
0 => 0,
1 => 1,
_ => fibonacci(n - 1) + fibonacci(n - 2),
}
}
fn main() {
let n = 10;
println!("The {}th Fibonacci number is: {}", n, fibonacci(n));
}
This function uses recursion to calculate the Fibonacci number. However, it's not the most efficient solution because it performs a lot of redundant calculations. A more efficient solution would use a loop to iteratively calculate the Fibonacci numbers.mistral_inference and running pip install --upgrade mistral_common to make sure to have mistral_common>=1.2 installed:1from mistral_inference.model import Transformer
2from mistral_inference.generate import generate
3from mistral_common.tokens.tokenizers.mistral import MistralTokenizer
4from mistral_common.tokens.instruct.request import FIMRequest
5
6tokenizer = MistralTokenizer.v3()
7model = Transformer.from_folder("~/codestral-22B-240529")
8
9prefix = """def add("""
10suffix = """ return sum"""
11
12request = FIMRequest(prompt=prefix, suffix=suffix)
13
14tokens = tokenizer.encode_fim(request).tokens
15
16out_tokens, _ = generate([tokens], model, max_tokens=256, temperature=0.0, eos_id=tokenizer.instruct_tokenizer.tokenizer.eos_id)
17result = tokenizer.decode(out_tokens[0])
18
19middle = result.split(suffix)[0].strip()
20print(middle)num1, num2):
# Add two numbers
sum = num1 + num2
# return the sumMNLP-0.1 license.