pub struct PhiModel { /* private fields */ }Expand description
Causal language model supporting Phi-3 and Phi-4 (model_type = "phi3").
Implementations§
Source§impl PhiModel
impl PhiModel
Sourcepub fn from_tensors(
config: ModelConfig,
tensors: &HashMap<String, Tensor>,
spec: LinearLoadSpec<'_>,
) -> Result<Self>
pub fn from_tensors( config: ModelConfig, tensors: &HashMap<String, Tensor>, spec: LinearLoadSpec<'_>, ) -> Result<Self>
Load a Phi-3 / Phi-4 model from tensors (accepts either fused qkv_proj or split q_proj/k_proj/v_proj).
§Errors
Returns crate::ModelError::MissingWeight if required tensors are absent.
Sourcepub fn new_random(
config: ModelConfig,
dtype: DType,
device: &Device,
rng: &mut ChaCha8Rng,
) -> Result<Self>
pub fn new_random( config: ModelConfig, dtype: DType, device: &Device, rng: &mut ChaCha8Rng, ) -> Result<Self>
Initialize a random Phi-3 / Phi-4 model with fused qkv_proj for testing.
§Errors
Returns an error if tensor creation fails.
Sourcepub fn forward(
&self,
input_ids: &Tensor,
cache: Option<&mut KvCache>,
hidden_mode: HiddenStatesMode,
) -> Result<CausalLmOutput>
pub fn forward( &self, input_ids: &Tensor, cache: Option<&mut KvCache>, hidden_mode: HiddenStatesMode, ) -> Result<CausalLmOutput>
Forward pass returning logits (batch, seq_len, vocab_size) and optional hidden states.
§Errors
Returns an error if layer forward passes fail.
Sourcepub fn layer_qkv_projection(
&self,
layer_idx: usize,
) -> Option<&PhiAttentionProjection>
pub fn layer_qkv_projection( &self, layer_idx: usize, ) -> Option<&PhiAttentionProjection>
Borrow attention projections for verification (e.g., verifying split QKV).
Trait Implementations§
Auto Trait Implementations§
impl !RefUnwindSafe for PhiModel
impl !UnwindSafe for PhiModel
impl Freeze for PhiModel
impl Send for PhiModel
impl Sync for PhiModel
impl Unpin for PhiModel
impl UnsafeUnpin 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
Mutably borrows from an owned value. Read more
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,
§impl<T> Identity for Twhere
T: ?Sized,
impl<T> Identity for Twhere
T: ?Sized,
impl<T, U> Imply<T> for U
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> 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> ⓘ
Converts
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> ⓘ
Converts
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