Skip to main content

MtpSpeculative

Struct MtpSpeculative 

Source
pub struct MtpSpeculative<'model> { /* private fields */ }
Expand description

RAII owner for a same-model MTP speculative context.

This wrapper currently binds llama.cpp’s speculative state to sequence 0. Batches passed to Self::process must therefore contain only sequence 0.

Implementations§

Source§

impl<'model> MtpSpeculative<'model>

Source

pub fn new( target_context: LlamaContext<'model>, draft_context: LlamaContext<'model>, params: MtpSpeculativeParams, ) -> Result<Self, MtpSpeculativeError>

Create a new MTP speculative helper from a target context and an MTP draft context.

§Errors

Returns an error if parameters are invalid or llama.cpp cannot initialize the speculative implementation for the loaded model.

Source

pub fn target_context(&self) -> &LlamaContext<'model>

Access the target context.

Source

pub fn target_context_mut(&mut self) -> &mut LlamaContext<'model>

Access the target context for decode and cache rollback operations.

Source

pub fn draft_context_mut(&mut self) -> &mut LlamaContext<'model>

Access the draft context for cache rollback operations.

Source

pub fn begin( &mut self, prompt_tokens: &[LlamaToken], ) -> Result<(), MtpSpeculativeError>

Begin a new generation from the given prompt tokens.

§Errors

Returns an error if llama.cpp rejects the call.

Source

pub fn process( &mut self, batch: &LlamaBatch<'_>, ) -> Result<(), MtpSpeculativeError>

Process a batch that was just decoded by the target context.

The batch must contain token input for sequence 0 only.

§Errors

Returns an error if llama.cpp cannot update the MTP draft context.

Source

pub fn draft( &mut self, n_past: i32, id_last: LlamaToken, prompt_tokens: &[LlamaToken], ) -> Result<Vec<LlamaToken>, MtpSpeculativeError>

Generate draft tokens after id_last.

§Errors

Returns an error if llama.cpp rejects the draft operation or emits more draft tokens than requested.

Source

pub fn accept(&mut self, n_accepted: u16) -> Result<(), MtpSpeculativeError>

Notify llama.cpp how many draft tokens the target context accepted.

§Errors

Returns an error if llama.cpp rejects the call.

Trait Implementations§

Source§

impl<'model> Debug for MtpSpeculative<'model>

Source§

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

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

impl Drop for MtpSpeculative<'_>

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<'model> !Send for MtpSpeculative<'model>

§

impl<'model> !Sync for MtpSpeculative<'model>

§

impl<'model> Freeze for MtpSpeculative<'model>

§

impl<'model> RefUnwindSafe for MtpSpeculative<'model>

§

impl<'model> Unpin for MtpSpeculative<'model>

§

impl<'model> UnsafeUnpin for MtpSpeculative<'model>

§

impl<'model> UnwindSafe for MtpSpeculative<'model>

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 = 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