pub struct Gemma4Experts {
pub experts: Vec<Gemma4Expert>,
/* private fields */
}Expand description
Collection of routed Mixture-of-Experts feed-forward networks with sparse dispatch.
Fields§
§experts: Vec<Gemma4Expert>Individual routed experts (len == num_experts).
Implementations§
Source§impl Gemma4Experts
impl Gemma4Experts
Sourcepub fn from_tensors(
prefix: &str,
config: &ModelConfig,
tensors: &HashMap<String, Tensor>,
spec: LinearLoadSpec<'_>,
) -> Result<Self>
pub fn from_tensors( prefix: &str, config: &ModelConfig, tensors: &HashMap<String, Tensor>, spec: LinearLoadSpec<'_>, ) -> Result<Self>
Load experts from either per-expert keys ({prefix}.{e}.gate_up_proj.*) or
Hugging Face fused 3D parameter tensors ({prefix}.gate_up_proj / {prefix}.down_proj).
§Errors
Returns an error if expert weights are missing or shapes do not match config.
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>
Sourcepub fn forward(
&self,
hidden_flat: &Tensor,
dispatch: &RouterDispatch,
) -> Result<Tensor>
pub fn forward( &self, hidden_flat: &Tensor, dispatch: &RouterDispatch, ) -> Result<Tensor>
Execute ONLY the experts selected in dispatch across their assigned tokens.
§Errors
Returns an error if an assigned expert ID is out of bounds or tensor ops fail.
Trait Implementations§
Source§impl Clone for Gemma4Experts
impl Clone for Gemma4Experts
Auto Trait Implementations§
impl !RefUnwindSafe for Gemma4Experts
impl !UnwindSafe for Gemma4Experts
impl Freeze for Gemma4Experts
impl Send for Gemma4Experts
impl Sync for Gemma4Experts
impl Unpin for Gemma4Experts
impl UnsafeUnpin for Gemma4Experts
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