pub struct MtmdInputChunk {
pub chunk: NonNull<mtmd_input_chunk>,
pub owned: bool,
}Expand description
Safe wrapper around mtmd_input_chunk.
Represents a single chunk of input data, which can be either text tokens, image tokens, or audio tokens. The chunk type determines what kind of data and operations are available.
Fields§
§chunk: NonNull<mtmd_input_chunk>Raw pointer to the underlying mtmd_input_chunk.
owned: boolImplementations§
Source§impl MtmdInputChunk
impl MtmdInputChunk
Sourcepub fn chunk_type(&self) -> Result<MtmdInputChunkType, MtmdInputChunkTypeError>
pub fn chunk_type(&self) -> Result<MtmdInputChunkType, MtmdInputChunkTypeError>
Sourcepub fn text_tokens(&self) -> Option<&[LlamaToken]>
pub fn text_tokens(&self) -> Option<&[LlamaToken]>
Get text tokens from this chunk.
Only valid for text chunks. Returns None for image or audio chunks.
Sourcepub fn n_positions(&self) -> i32
pub fn n_positions(&self) -> i32
Get the number of positions in this chunk.
Sourcepub fn id(&self) -> Option<String>
pub fn id(&self) -> Option<String>
Get chunk ID if available.
Returns None for text chunks, may return an ID for image/audio chunks.
Sourcepub fn copy(&self) -> Result<Self, MtmdInputChunkError>
pub fn copy(&self) -> Result<Self, MtmdInputChunkError>
Create a copy of this chunk that you own.
§Errors
Returns MtmdInputChunkError::ChunkOperationFailed if copying fails.
Sourcepub fn eval_single(
&self,
mtmd_ctx: &MtmdContext,
llama_ctx: &LlamaContext<'_>,
start_position: llama_pos,
seq_id: llama_seq_id,
n_batch: i32,
logits_last: bool,
) -> Result<llama_pos, MtmdEvalError>
pub fn eval_single( &self, mtmd_ctx: &MtmdContext, llama_ctx: &LlamaContext<'_>, start_position: llama_pos, seq_id: llama_seq_id, n_batch: i32, logits_last: bool, ) -> Result<llama_pos, MtmdEvalError>
Evaluate this single chunk through the multimodal helper.
Mirrors MtmdInputChunks::eval_chunks but for one chunk at a time, so
callers can interleave per-chunk decode with per-chunk bookkeeping
(token counting, marker state-machine replay) inside one loop instead
of running the helper-level all-chunks eval and a separate ingest pass.
Image chunks are decoded as one llama_decode call inside the helper,
so their token count must fit in n_batch. When it would not, the
binding refuses the call up front because the C-side
GGML_ASSERT(n_tokens_all <= cparams.n_batch) would otherwise abort
the process.
§Errors
Returns MtmdEvalError::ImageChunkExceedsBatchSize when this is an
image chunk whose token count exceeds n_batch. Returns
[MtmdEvalError::EvalFailure] if the underlying encode or decode step
fails.
Trait Implementations§
Source§impl Debug for MtmdInputChunk
impl Debug for MtmdInputChunk
Source§impl Drop for MtmdInputChunk
impl Drop for MtmdInputChunk
Auto Trait Implementations§
impl Freeze for MtmdInputChunk
impl RefUnwindSafe for MtmdInputChunk
impl !Send for MtmdInputChunk
impl !Sync for MtmdInputChunk
impl Unpin for MtmdInputChunk
impl UnsafeUnpin for MtmdInputChunk
impl UnwindSafe for MtmdInputChunk
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more