Skip to main content

MtmdInputChunk

Struct MtmdInputChunk 

Source
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: bool

Implementations§

Source§

impl MtmdInputChunk

Source

pub fn chunk_type(&self) -> Result<MtmdInputChunkType, MtmdInputChunkTypeError>

Get the type of this chunk

§Errors

Returns an error if the chunk type is unknown.

Source

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.

Source

pub fn n_tokens(&self) -> usize

Get the number of tokens in this chunk

Source

pub fn n_positions(&self) -> i32

Get the number of positions in this chunk.

Source

pub fn id(&self) -> Option<String>

Get chunk ID if available.

Returns None for text chunks, may return an ID for image/audio chunks.

Source

pub fn copy(&self) -> Result<Self, MtmdInputChunkError>

Create a copy of this chunk that you own.

§Errors

Returns MtmdInputChunkError::NullResult if copying fails.

Source

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

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Drop for MtmdInputChunk

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

fn pin_drop(self: Pin<&mut Self>)

🔬This is a nightly-only experimental API. (pin_ergonomics)
Execute the destructor for this type, but different to Drop::drop, it requires self to be pinned. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more