pub struct PhiModel {
pub config: PhiConfig,
pub weights: PhiWeights,
}Fields§
§config: PhiConfig§weights: PhiWeightsImplementations§
Source§impl PhiModel
impl PhiModel
Sourcepub fn decode_shape_key(&self) -> u64
pub fn decode_shape_key(&self) -> u64
See LlamaModel::decode_shape_key.
Sourcepub fn forward_with_kv_context(
&self,
tokens: &[u32],
cache: &mut KvCache,
ctx: &mut InferenceContext,
) -> Result<Vec<f32>>
pub fn forward_with_kv_context( &self, tokens: &[u32], cache: &mut KvCache, ctx: &mut InferenceContext, ) -> Result<Vec<f32>>
Forward pass using pre-allocated KV-cache buffers and
Op::WriteSlice; returns last-position logits. Mirrors
LlamaModel::forward_with_kv_context — see its docs for the
architectural notes. The cache must have been constructed via
KvCache::with_capacity with n_kv_heads == n_heads (Phi-2
has no GQA).
Sourcepub fn forward_with_kv_context_persistent(
&self,
tokens: &[u32],
cache: &mut KvCache,
ctx: &mut InferenceContext,
session: &mut Option<DecodeSession>,
) -> Result<Vec<f32>>
pub fn forward_with_kv_context_persistent( &self, tokens: &[u32], cache: &mut KvCache, ctx: &mut InferenceContext, session: &mut Option<DecodeSession>, ) -> Result<Vec<f32>>
Phase D · D4 — plan-once persistent decode (the Phi mirror of
LlamaModel::forward_with_kv_context_persistent). Sibling of
Self::forward_with_kv_context that HOLDS the optimized
decode-step graph in session and, on every token after the
first, re-realizes the SAME graph with the D2a prebuilt seam —
skipping the prepare D2H-splice + the optimize_graph
placement DP. The per-token re-plan win comes from not
re-planning. See the LlamaModel sibling for the full control-flow
contract; the Phi version differs only in the model body it
builds (parallel attn+MLP, LayerNorm, partial RoPE, projection
biases, optional output bias).
Byte-identical to the D1 cached path (Self::forward_with_kv_context)
on the same prefix (same plan → same kernels). Bumps
cache.cached_len + per-slot versions exactly as the D1 path does.
Sourcepub fn generate_streaming_with_kv_context(
&self,
prompt_tokens: &[u32],
max_new_tokens: usize,
strategy: SamplingStrategy,
eos_id: Option<u32>,
device: &Device,
dtype: DType,
on_token: impl FnMut(u32),
) -> Result<Vec<u32>>
pub fn generate_streaming_with_kv_context( &self, prompt_tokens: &[u32], max_new_tokens: usize, strategy: SamplingStrategy, eos_id: Option<u32>, device: &Device, dtype: DType, on_token: impl FnMut(u32), ) -> Result<Vec<u32>>
Streaming generation through Self::forward_with_kv_context.
Allocates a pre-allocated KvCache of capacity
prompt_tokens.len() + max_new_tokens on device, then loops
prefill + decode, calling on_token for each generated token.
Mirrors LlamaModel::generate_streaming_with_kv_context.
Sourcepub fn generate_with_kv_context(
&self,
prompt_tokens: &[u32],
max_new_tokens: usize,
strategy: SamplingStrategy,
eos_id: Option<u32>,
device: &Device,
dtype: DType,
) -> Result<Vec<u32>>
pub fn generate_with_kv_context( &self, prompt_tokens: &[u32], max_new_tokens: usize, strategy: SamplingStrategy, eos_id: Option<u32>, device: &Device, dtype: DType, ) -> Result<Vec<u32>>
Non-streaming convenience wrapper around
Self::generate_streaming_with_kv_context.
Trait Implementations§
Source§impl PersistentDecodeModel for PhiModel
impl PersistentDecodeModel for PhiModel
Source§fn build_decode_token_data(
&self,
device: &Device,
cached_len: usize,
tokens: &[u32],
session: &DecodeSession,
_cache: &KvCache,
_rope_inv_freq: Option<&[f64]>,
) -> Result<DecodeTokenData>
fn build_decode_token_data( &self, device: &Device, cached_len: usize, tokens: &[u32], session: &DecodeSession, _cache: &KvCache, _rope_inv_freq: Option<&[f64]>, ) -> Result<DecodeTokenData>
Measured: Phi takes the SymEnv path on CPU/F32 (offset: None), so
there is no device-offset operand and its builder takes no dtype/offset
arguments. rope_inv_freq is ignored: Phi has no LLaMA-3-style RoPE
scaling override, and accepting-then-dropping it here is what lets one
driver serve both without the driver knowing which model it has.
Source§fn decode_n_layers(&self) -> usize
fn decode_n_layers(&self) -> usize
Auto Trait Implementations§
impl Freeze for PhiModel
impl RefUnwindSafe for PhiModel
impl Send for PhiModel
impl Sync for PhiModel
impl Unpin for PhiModel
impl UnsafeUnpin for PhiModel
impl UnwindSafe for PhiModel
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> ErasedDestructor for Twhere
T: 'static,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
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