pub struct Gemma4Router {
pub proj: LinearLayer,
/* private fields */
}Expand description
Top-k softmax router for Gemma 4 Mixture-of-Experts blocks.
The router linear projection (proj) always remains unquantized (LinearLayer::Dense)
so top-k routing fidelity is preserved at sub-1-bit expert compression.
Fields§
§proj: LinearLayerUnquantized router linear projection (hidden_size -> num_experts).
Implementations§
Source§impl Gemma4Router
impl Gemma4Router
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 Gemma4Router weights under prefix {layer_prefix}.router.
§Errors
Returns ModelError::MissingWeight if required router parameters 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 random Gemma4Router weights for tests.
§Errors
Returns an error if tensor creation fails.
Sourcepub const fn num_experts(&self) -> usize
pub const fn num_experts(&self) -> usize
Total number of experts supported by this router.
Sourcepub fn forward(&self, hidden_flat: &Tensor) -> Result<RouterDispatch>
pub fn forward(&self, hidden_flat: &Tensor) -> Result<RouterDispatch>
Compute top-k expert assignments and scaled probabilities for hidden_flat (num_tokens, hidden_size).
§Errors
Returns an error if tensor shapes are invalid or projection fails.
Trait Implementations§
Source§impl Clone for Gemma4Router
impl Clone for Gemma4Router
Auto Trait Implementations§
impl !RefUnwindSafe for Gemma4Router
impl !UnwindSafe for Gemma4Router
impl Freeze for Gemma4Router
impl Send for Gemma4Router
impl Sync for Gemma4Router
impl Unpin for Gemma4Router
impl UnsafeUnpin for Gemma4Router
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