pub struct MultiModuleMtpHead { /* private fields */ }Expand description
N independent MTP modules, one per draft slot.
Implementations§
Source§impl MultiModuleMtpHead
impl MultiModuleMtpHead
Sourcepub fn new(modules: Vec<MtpHead>) -> Result<Self>
pub fn new(modules: Vec<MtpHead>) -> Result<Self>
Assemble a multi-module proposer from per-module heads.
Callers construct each MtpHead via MtpHead::new with the
MTP weights for that module’s prefix (e.g. model.layers.62..64
for MiniMax M2 with num_hidden_layers=62, num_mtp_modules=3).
Sourcepub fn num_modules(&self) -> usize
pub fn num_modules(&self) -> usize
Number of MTP modules available (caps num_drafts in propose).
Trait Implementations§
Source§impl Debug for MultiModuleMtpHead
impl Debug for MultiModuleMtpHead
Source§impl DraftProposer for MultiModuleMtpHead
impl DraftProposer for MultiModuleMtpHead
Source§fn alloc_state(&self, _gpu: &dyn GpuBackend) -> Result<Box<dyn ProposerState>>
fn alloc_state(&self, _gpu: &dyn GpuBackend) -> Result<Box<dyn ProposerState>>
Allocate per-sequence proposer state.
Source§fn propose(
&self,
last_token: u32,
target_hidden: DevicePtr,
position: usize,
num_drafts: usize,
state: &mut dyn ProposerState,
ctx: &ForwardContext<'_>,
stream: u64,
draft_embed_target: Option<DevicePtr>,
grammar_bitmask: Option<&[i32]>,
_target_hidden_stack: Option<DevicePtr>,
) -> Result<Vec<u32>>
fn propose( &self, last_token: u32, target_hidden: DevicePtr, position: usize, num_drafts: usize, state: &mut dyn ProposerState, ctx: &ForwardContext<'_>, stream: u64, draft_embed_target: Option<DevicePtr>, grammar_bitmask: Option<&[i32]>, _target_hidden_stack: Option<DevicePtr>, ) -> Result<Vec<u32>>
Propose up to
num_drafts tokens autoregressively. Read moreSource§fn read_deferred_draft_token(&self, gpu: &dyn GpuBackend) -> Result<u32>
fn read_deferred_draft_token(&self, gpu: &dyn GpuBackend) -> Result<u32>
Read the draft token ID stored on GPU by the last
propose() call
that used draft_embed_target = Some(...). Returns 0 if not supported.Source§fn after_verify(
&self,
num_accepted: usize,
state: &mut dyn ProposerState,
stream: u64,
) -> Result<()>
fn after_verify( &self, num_accepted: usize, state: &mut dyn ProposerState, stream: u64, ) -> Result<()>
Called after target verification to trim proposer state. Read more
Source§fn free_state(
&self,
_gpu: &dyn GpuBackend,
state: &mut dyn ProposerState,
) -> Result<()>
fn free_state( &self, _gpu: &dyn GpuBackend, state: &mut dyn ProposerState, ) -> Result<()>
Free per-sequence proposer state (KV cache blocks, device buffers, etc.). Read more
Source§fn alloc_state_for(
&self,
gpu: &dyn GpuBackend,
budget_tokens: usize,
) -> Result<Box<dyn ProposerState>>
fn alloc_state_for( &self, gpu: &dyn GpuBackend, budget_tokens: usize, ) -> Result<Box<dyn ProposerState>>
Self::alloc_state with the sequence’s KNOWN token budget
(prompt_len + max_tokens), so a proposer whose per-sequence state
scales with context can size to what this request can actually reach
instead of the global --max-seq-len ceiling. That distinction is what
OOMs a high-concurrency long-context serve: the ceiling is per-sequence
and paid n times, while a typical request needs a fraction of it. Read moreSource§fn block_gamma(&self) -> Option<usize>
fn block_gamma(&self) -> Option<usize>
The proposer’s trained block size γ, when it is a block-diffusion
drafter (DFlash/DFlash2). The serve layer derives num_drafts from
this — the head resolved it from the drafter checkpoint and is the
SSOT.
None = not a block drafter.Source§fn last_confidence(&self) -> Option<f32>
fn last_confidence(&self) -> Option<f32>
Chain confidence of the most recent
propose (min top-1 softmax prob
across its drafts), when the proposer computes it (draft_conf_tau >
0). None = not computed; callers must not gate on it then.Rows this proposer can actually consume from
mtp_prefill_hidden, given
the served --max-seq-len. Read moreSource§fn needs_comm(&self) -> bool
fn needs_comm(&self) -> bool
True when this proposer’s block is SHARDED across ranks and its
forward therefore needs the communicator (a routed-MoE all-reduce and
a row-parallel
o_proj reduce), like any target layer. Read moreTrue when this proposer’s context prefill uses the SHARED forward
scratch (
ctx.buffers), so it must not run from the end-of-prefill
eager hook — only from the first propose, where the target owns
nothing. Read moreSource§fn drafter_rows(&self, _state: &mut dyn ProposerState) -> usize
fn drafter_rows(&self, _state: &mut dyn ProposerState) -> usize
Current drafter KV length (rows), for the catch-up append point.
0 = unknown / not applicable (catch-up is skipped).
Source§fn last_pair_key(&self, _state: &mut dyn ProposerState) -> Option<usize>
fn last_pair_key(&self, _state: &mut dyn ProposerState) -> Option<usize>
Sequence-space pair key of the newest drafter row (
None = untracked;
catch-up is skipped). The drafter row space is compacted, so rows
cannot locate the drafter in the sequence — this can.Source§fn take_drafter_kv(
&self,
_state: &mut dyn ProposerState,
) -> Option<(Vec<u32>, usize, Option<usize>)>
fn take_drafter_kv( &self, _state: &mut dyn ProposerState, ) -> Option<(Vec<u32>, usize, Option<usize>)>
ATLAS_MTP_CARRY_DRAFTER: move this sequence’s drafter KV blocks OUT of
its proposer state, so
free_state releases nothing and the model can
hold them for the next turn. Returns (blocks, rows, last_pair_key);
None = unsupported or nothing to carry. After this call the state
must behave as if freshly allocated.Source§fn install_drafter_kv(
&self,
_state: &mut dyn ProposerState,
_blocks: Vec<u32>,
_rows: usize,
_last_pair_key: Option<usize>,
) -> bool
fn install_drafter_kv( &self, _state: &mut dyn ProposerState, _blocks: Vec<u32>, _rows: usize, _last_pair_key: Option<usize>, ) -> bool
Inverse of
Self::take_drafter_kv: install carried blocks into a fresh
proposer state. Returns false when unsupported (caller must then free
the blocks itself).Source§fn free_drafter_kv(&self, _blocks: &[u32])
fn free_drafter_kv(&self, _blocks: &[u32])
Release drafter KV blocks that no proposer state owns (a carried entry
being replaced or dropped).
Source§fn catchup_drafter(
&self,
_tokens: &[u32],
_hiddens: DevicePtr,
_row_base: usize,
_pos_base: usize,
_state: &mut dyn ProposerState,
_ctx: &ForwardContext<'_>,
_stream: u64,
) -> Result<usize>
fn catchup_drafter( &self, _tokens: &[u32], _hiddens: DevicePtr, _row_base: usize, _pos_base: usize, _state: &mut dyn ProposerState, _ctx: &ForwardContext<'_>, _stream: u64, ) -> Result<usize>
Append drafter rows at KV slots
row_base .. with RoPE positions
pos_base .. from (tokens, hiddens) pairs — the catch-up feed.
Returns rows written (0 = unsupported/no-op).Source§fn propose_batch(
&self,
_last_tokens: &[u32],
_target_hiddens: &[DevicePtr],
_positions: &[usize],
_num_drafts: usize,
_states: &mut [&mut dyn ProposerState],
_ctx: &ForwardContext<'_>,
_stream: u64,
_out_conf: Option<&mut Vec<Vec<f32>>>,
) -> Result<Option<Vec<Vec<u32>>>>
fn propose_batch( &self, _last_tokens: &[u32], _target_hiddens: &[DevicePtr], _positions: &[usize], _num_drafts: usize, _states: &mut [&mut dyn ProposerState], _ctx: &ForwardContext<'_>, _stream: u64, _out_conf: Option<&mut Vec<Vec<f32>>>, ) -> Result<Option<Vec<Vec<u32>>>>
Batched cross-sequence propose: draft
num_drafts tokens for each of
n = last_tokens.len() sequences, reading every drafter weight ONCE
per draft position instead of once per sequence (the measured C=4
serialization: 12 x ~5 ms per-seq drafter forwards per batched verify
step, ~62 ms of the ~180 ms step). Read moreSource§fn propose_batch_max(
&self,
_buffers: &BufferArena,
_config: &ModelConfig,
) -> usize
fn propose_batch_max( &self, _buffers: &BufferArena, _config: &ModelConfig, ) -> usize
The widest batch
Self::propose_batch can carry in ONE drafter
forward per draft position, derived from this proposer’s resolved
kernels and the arena’s row capacities. 1 = per-sequence only. Read moreSource§fn prefill_drafter(
&self,
prompt_tokens: &[u32],
hiddens: DevicePtr,
state: &mut dyn ProposerState,
ctx: &ForwardContext<'_>,
stream: u64,
) -> Result<usize>
fn prefill_drafter( &self, prompt_tokens: &[u32], hiddens: DevicePtr, state: &mut dyn ProposerState, ctx: &ForwardContext<'_>, stream: u64, ) -> Result<usize>
Prefill the drafter’s own context (KV cache) over the prompt, before
the first
propose() of a sequence (ATLAS_MTP_DRAFTER_PREFILL). Read moreAuto Trait Implementations§
impl Freeze for MultiModuleMtpHead
impl !RefUnwindSafe for MultiModuleMtpHead
impl Send for MultiModuleMtpHead
impl Sync for MultiModuleMtpHead
impl Unpin for MultiModuleMtpHead
impl UnwindSafe for MultiModuleMtpHead
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
Mutably borrows from an owned value. Read more