1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
//! Convenience re-exports for typical inference workflows.
//!
//! # Quick start
//!
//! ```
//! use llama_cpp_4::prelude::*;
//! ```
//!
//! Core types are also available at the crate root (`llama_cpp_4::LlamaModel`, …)
//! if you prefer explicit paths over a glob import.
//!
//! # What's included
//!
//! | Category | Re-exported types |
//! |---|---|
//! | Inference | [`LlamaBackend`], [`LlamaModel`], [`LlamaModelParams`], [`LlamaContext`], [`LlamaContextParams`], [`LlamaBatch`], [`LlamaSampler`], [`LlamaSamplerParams`], [`LlamaToken`], [`LlamaTokenDataArray`] |
//! | Tokenising | [`AddBos`], [`Special`] |
//! | Chat | [`LlamaChatMessage`] |
//! | Model introspection | [`LlamaBackendDevice`], [`LlamaBackendDeviceType`] |
//! | Context params | [`LlamaFlashAttnType`], [`LlamaContextType`], [`LlamaAttentionType`], [`RopeScalingType`], [`LlamaPoolingType`], [`ParamsCloneError`] |
//! | KV overrides | [`ParamOverrideValue`] |
//! | Errors | [`Result`], [`LLamaCppError`], [`DecodeError`], [`EncodeError`], [`EmbeddingsError`], [`BatchAddError`], [`ApplyChatTemplateError`], [`NewLlamaChatMessageError`] |
//! | Memory / fit | [`get_device_memory_data`], [`fit_params`], [`FitParams`], [`FitParamsResult`], [`FitParamsError`], [`DeviceMemoryReport`], [`MemoryBreakdownEntry`] |
//! | Tensor capture | [`TensorCapture`], [`CapturedTensor`] |
//! | Speculative | [`MtpSession`], [`MtpSessionConfig`], [`Eagle3Session`], [`Eagle3SessionConfig`] |
//! | Quantization | [`QuantizeParams`], [`TensorTypeOverride`], [`GgmlType`], [`LlamaFtype`], [`model_quantize`], [`attn_rot_disabled`], [`set_attn_rot_disabled`] |
//! | Utilities | [`ggml_time_us`], [`llama_time_us`], [`print_system_info`], [`supports_gpu_offload`], [`max_devices`] |
//!
//! With the `mtmd` feature: [`MtmdContext`], [`MtmdBitmap`], …\
//! With the `rpc` feature: `RpcBackend`, `RpcServer`, and `RpcError` in `llama_cpp_4::rpc`.
//!
//! # Text generation
//!
//! ```no_run
//! use llama_cpp_4::prelude::*;
//! use std::num::NonZeroU32;
//!
//! fn main() {
//! let backend = LlamaBackend::init().unwrap();
//! let model = LlamaModel::load_from_file(
//! &backend,
//! "model.gguf",
//! &LlamaModelParams::default(),
//! )
//! .unwrap();
//! let mut ctx = model
//! .new_context(
//! &backend,
//! LlamaContextParams::default().with_n_ctx(NonZeroU32::new(2048)),
//! )
//! .unwrap();
//!
//! let tokens = model.str_to_token("The answer is", AddBos::Always).unwrap();
//! let n_prompt = tokens.len();
//! let mut batch = LlamaBatch::new(2048, 1);
//! for (i, &tok) in tokens.iter().enumerate() {
//! batch
//! .add(tok, i as i32, &[0], i == n_prompt - 1)
//! .unwrap();
//! }
//! ctx.decode(&mut batch).unwrap();
//!
//! let sampler = LlamaSampler::chain_simple([
//! LlamaSampler::temp(0.8),
//! LlamaSampler::dist(0),
//! ]);
//! let token = sampler.sample(&ctx, 0);
//! let _text = model.token_to_bytes(token, Special::Plaintext).unwrap();
//! }
//! ```
//!
//! # Chat template
//!
//! ```no_run
//! use llama_cpp_4::prelude::*;
//!
//! fn main() {
//! let backend = LlamaBackend::init().unwrap();
//! let model = LlamaModel::load_from_file(
//! &backend,
//! "model.gguf",
//! &LlamaModelParams::default(),
//! )
//! .unwrap();
//!
//! let messages = vec![
//! LlamaChatMessage::new("system".into(), "You are helpful.".into()).unwrap(),
//! LlamaChatMessage::new("user".into(), "What is 2+2?".into()).unwrap(),
//! ];
//! let prompt = model.apply_chat_template(None, &messages, true).unwrap();
//! let _tokens = model.str_to_token(&prompt, AddBos::Always).unwrap();
//! }
//! ```
//!
//! # Embeddings
//!
//! ```no_run
//! use llama_cpp_4::prelude::*;
//! use std::num::NonZeroU32;
//!
//! fn main() {
//! let backend = LlamaBackend::init().unwrap();
//! let model = LlamaModel::load_from_file(
//! &backend,
//! "model.gguf",
//! &LlamaModelParams::default(),
//! )
//! .unwrap();
//! let mut ctx = model
//! .new_context(
//! &backend,
//! LlamaContextParams::default()
//! .with_embeddings(true)
//! .with_n_ctx(NonZeroU32::new(512)),
//! )
//! .unwrap();
//!
//! let tokens = model.str_to_token("Hello", AddBos::Always).unwrap();
//! let mut batch = LlamaBatch::new(512, 1);
//! for (i, &tok) in tokens.iter().enumerate() {
//! batch
//! .add(tok, i as i32, &[0], i == tokens.len() - 1)
//! .unwrap();
//! }
//! ctx.decode(&mut batch).unwrap();
//! let _vec = ctx.embeddings_seq_ith(0).unwrap();
//! }
//! ```
//!
//! # Memory estimation (before loading fully)
//!
//! ```no_run
//! use llama_cpp_4::prelude::*;
//! use std::path::Path;
//!
//! fn main() {
//! let report = get_device_memory_data(
//! Path::new("model.gguf"),
//! &LlamaModelParams::default(),
//! &LlamaContextParams::default(),
//! llama_cpp_sys_4::GGML_LOG_LEVEL_ERROR,
//! )
//! .unwrap();
//! for entry in &report.entries {
//! println!("projected used: {} bytes", entry.used());
//! }
//! }
//! ```
// ── Core inference ────────────────────────────────────────────────────────────
pub use crate;
pub use crate;
pub use crateLlamaBackend;
pub use crate;
pub use crateParamOverrideValue;
pub use crateLlamaModelParams;
pub use crate;
pub use crate;
pub use crateLlamaTokenDataArray;
pub use crateLlamaToken;
// ── Errors & results ────────────────────────────────────────────────────────
pub use crate::;
// ── Memory / fit helpers ────────────────────────────────────────────────────
pub use crate;
// ── Speculative decoding ────────────────────────────────────────────────────
pub use crate;
pub use crate;
// ── Multimodal (feature `mtmd`) ─────────────────────────────────────────────
pub use crate;
// ── Remote backend (feature `rpc`) ──────────────────────────────────────────
pub use crate;
// ── Quantization ────────────────────────────────────────────────────────────
pub use crate;
// ── Utilities ───────────────────────────────────────────────────────────────
pub use crate::;