ik-llama-cpp-2
Safe Rust bindings for ik_llama.cpp — ikawrakow's
SOTA-quantization fork of llama.cpp. Mirrors the API and codestyle of
llama-cpp-2, so most code ports by swapping
use llama_cpp_2 → use ik_llama_cpp_2.
Reach for this instead of llama-cpp-2 when you want ik's SOTA quant runtime (IQ*_K, IQ*_KT,
R4/R8 repacks, BitNet, …) or its Multi-Token-Prediction (NextN) path.
ik-llama-cpp-2— this crate: the safe wrapper.ik-llama-cpp-sys— the low-level FFI (bindgen + CMake build). ik_llama.cpp is vendored, socargo addworks with no submodule step.
ik and stock llama.cpp export the same
llama_*/ggml_*symbols with incompatible ggml ABIs — never link both into one process.
Requirements
The -sys crate builds ik_llama.cpp from source on first build, so you need CMake and a
C/C++ toolchain (plus libclang for bindgen). The initial build is heavy. Linux CPU + CUDA are
exercised in CI/smoke tests.
[]
= "0.1"
Features
cuda, vulkan, openmp, native (host-CPU tuning), common (ik common/ — enables the MTP
speculative driver + json_schema_to_grammar), mtmd (multimodal). Default = CPU core.
Example
use ;
use NonZeroU32;
let backend = init?;
let model = load_from_file?;
let mut ctx = model.new_context?;
let prompt = model.str_to_token?;
let mut batch = new;
batch.add_sequence?;
ctx.decode?;
// chain-object sampler, exactly like llama-cpp-2
let mut sampler = chain_simple;
let mut idx = batch.n_tokens - 1;
let mut decoder = UTF_8.new_decoder;
for _ in 0..32
# Ok::
Structured output / tool calling: json_schema_to_grammar(schema) → LlamaSampler::grammar(...)
(the common feature). MTP (NextN) speculative decoding: MtpSpeculative::new → begin → step
(also common).
License
Licensed under either of Apache-2.0 or MIT at your option.