You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: llama-cpp-2/src/llama_batch.rs
+8-4Lines changed: 8 additions & 4 deletions
Original file line number
Diff line number
Diff line change
@@ -2,17 +2,19 @@
2
2
3
3
usecrate::token::LlamaToken;
4
4
use llama_cpp_sys_2::{llama_batch, llama_batch_free, llama_batch_init, llama_pos, llama_seq_id};
5
+
use std::marker::PhantomData;
5
6
6
7
/// A safe wrapper around `llama_batch`.
7
8
#[derive(Debug)]
8
-
pubstructLlamaBatch{
9
+
pubstructLlamaBatch<'a>{
9
10
/// The number of tokens the batch was allocated with. they are safe to write to - but not necessarily read from as they are not necessarily initialized
10
11
allocated:usize,
11
12
/// The logits that are initialized. Used by [`LlamaContext`] to ensure that only initialized logits are accessed.
12
13
pub(crate)initialized_logits:Vec<i32>,
13
14
#[allow(clippy::doc_markdown)]
14
15
/// The llama_cpp batch. always initialize by `llama_cpp_sys_2::llama_batch_init(allocated, <unknown>, <unknown>)`
15
16
pub(crate)llama_batch:llama_batch,
17
+
phantom:PhantomData<&'a[LlamaToken]>,
16
18
}
17
19
18
20
/// Errors that can occur when adding a token to a batch.
@@ -26,7 +28,7 @@ pub enum BatchAddError {
26
28
EmptyBuffer,
27
29
}
28
30
29
-
implLlamaBatch{
31
+
impl<'a>LlamaBatch<'a>{
30
32
/// Clear the batch. This does not free the memory associated with the batch, but it does reset
31
33
/// the number of tokens to 0.
32
34
pubfnclear(&mutself){
@@ -150,6 +152,7 @@ impl LlamaBatch {
150
152
allocated: n_tokens,
151
153
initialized_logits:vec![],
152
154
llama_batch: batch,
155
+
phantom:PhantomData,
153
156
}
154
157
}
155
158
@@ -163,7 +166,7 @@ impl LlamaBatch {
163
166
///
164
167
/// # Panics
165
168
/// If the number of tokens in ``tokens`` exceeds [`i32::MAX`].
0 commit comments