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 Forget for PhiModel
impl Freeze for PhiModelwhere
*const ArcInner<[f32]> is !null: Freeze,
PhantomData<ArcInner<[f32]>>: Freeze,
*const u8 is !null: Freeze,
PhantomData<PhiLayerWeights>: Freeze,
*const ArcInner<[bf16]> is !null: Freeze,
PhantomData<ArcInner<[bf16]>>: Freeze,
*const ArcInner<[u32]> is !null: Freeze,
PhantomData<ArcInner<[u32]>>: Freeze,
*const ArcInner<AwqHostWeight> is !null: Freeze,
PhantomData<ArcInner<AwqHostWeight>>: Freeze,
*const WeightStorage is !null: Freeze,
PhantomData<WeightStorage>: Freeze,
impl Move for PhiModel
impl RefUnwindSafe for PhiModel
impl Send for PhiModel
impl Sync for PhiModel
impl Unpin for PhiModel
impl UnsafeUnpin for PhiModelwhere
*const ArcInner<[f32]> is !null: UnsafeUnpin,
PhantomData<ArcInner<[f32]>>: UnsafeUnpin,
*const u8 is !null: UnsafeUnpin,
PhantomData<PhiLayerWeights>: UnsafeUnpin,
*const ArcInner<[bf16]> is !null: UnsafeUnpin,
PhantomData<ArcInner<[bf16]>>: UnsafeUnpin,
*const ArcInner<[u32]> is !null: UnsafeUnpin,
PhantomData<ArcInner<[u32]>>: UnsafeUnpin,
*const ArcInner<AwqHostWeight> is !null: UnsafeUnpin,
PhantomData<ArcInner<AwqHostWeight>>: UnsafeUnpin,
*const WeightStorage is !null: UnsafeUnpin,
PhantomData<WeightStorage>: UnsafeUnpin,
impl UnwindSafe for PhiModelwhere
Arc<[f32]>: UnwindSafe,
RawVecInner: UnwindSafe,
Arc<[bf16]>: UnwindSafe,
Arc<[u32]>: UnwindSafe,
Arc<AwqHostWeight>: UnwindSafe,
BoxRaw<WeightStorage>: UnwindSafe,
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,
Source§impl<T> DropFlavorWrapper<T> for T
impl<T> DropFlavorWrapper<T> for T
impl<T> ErasedDestructor for Twhere
T: 'static,
Source§impl<T, W> HasTypeWitness<W> for Twhere
W: MakeTypeWitness<Arg = T>,
T: ?Sized,
impl<T, W> HasTypeWitness<W> for Twhere
W: MakeTypeWitness<Arg = T>,
T: ?Sized,
Source§impl<T> Identity for Twhere
T: ?Sized,
impl<T> Identity for Twhere
T: ?Sized,
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