Skip to main content

MtmdBatch

Struct MtmdBatch 

Source
pub struct MtmdBatch<'ctx> { /* private fields */ }
Expand description

Encode several media chunks in one pass.

MtmdContext::encode_chunk handles one chunk at a time; this batches them, which is what you want for a multi-image prompt or a run of video frames — the vision encoder runs once over the whole set instead of once per image.

A batch belongs to the context that created it and borrows it for its lifetime. Chunks are not owned by the batch, so they must outlive it too.

Wraps mtmd_batch_init / mtmd_batch_add_chunk / mtmd_batch_encode.

Implementations§

Source§

impl<'ctx> MtmdBatch<'ctx>

Source

pub fn new(ctx: &'ctx MtmdContext) -> Result<Self>

Start a batch against ctx.

§Errors

Returns MtmdError::BatchCreateFailed if llama.cpp returns null.

Source

pub fn add_chunk(&mut self, chunk: &MtmdInputChunk<'_>) -> Result<()>

Add a media chunk. Text chunks are rejected.

§Errors

Returns MtmdError::BatchAddFailed — code 2 means the batch is full and the chunk was not added (start a new batch), code 3 means it cannot be batched with what is already there (differing image geometry, say).

Source

pub fn encode(&mut self) -> Result<()>

Encode every chunk added so far.

§Errors

Returns MtmdError::EncodeError on failure.

Source

pub fn output_embd( &self, chunk: &MtmdInputChunk<'_>, n_embd: usize, ) -> Option<&[f32]>

Borrow the embeddings produced for chunk by the last Self::encode.

Returns None if the chunk was not part of this batch or encoding has not run. The slice is owned by the batch and is invalidated by the next encode.

§Safety of the returned length

llama.cpp reports only a pointer, so the length is derived from the chunk’s token count and the context’s embedding dimension.

Trait Implementations§

Source§

impl Debug for MtmdBatch<'_>

Source§

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

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

impl Drop for MtmdBatch<'_>

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§

§

impl<'ctx> !Send for MtmdBatch<'ctx>

§

impl<'ctx> !Sync for MtmdBatch<'ctx>

§

impl<'ctx> Freeze for MtmdBatch<'ctx>

§

impl<'ctx> RefUnwindSafe for MtmdBatch<'ctx>

§

impl<'ctx> Unpin for MtmdBatch<'ctx>

§

impl<'ctx> UnsafeUnpin for MtmdBatch<'ctx>

§

impl<'ctx> UnwindSafe for MtmdBatch<'ctx>

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, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

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