pub struct MoELayer {
pub router_weights: Tensor,
pub num_experts: usize,
pub num_experts_per_tok: usize,
pub device: Device,
}Expand description
Mixture of Experts layer Routes tokens to top-k experts and combines their outputs
Fields§
§router_weights: TensorRouter weights: [hidden_size, num_experts]
num_experts: usizeNumber of experts
num_experts_per_tok: usizeNumber of experts per token
device: DeviceDevice
Implementations§
Source§impl MoELayer
impl MoELayer
Sourcepub fn new(
router_weights: Tensor,
num_experts: usize,
num_experts_per_tok: usize,
device: Device,
) -> Self
pub fn new( router_weights: Tensor, num_experts: usize, num_experts_per_tok: usize, device: Device, ) -> Self
Create new MoE layer
Sourcepub fn route(&self, hidden_states: &Tensor) -> Result<(Tensor, Tensor)>
pub fn route(&self, hidden_states: &Tensor) -> Result<(Tensor, Tensor)>
Compute routing weights and indices for each token Returns (routing_weights, expert_indices) where:
- routing_weights: [batch * seq_len, num_experts_per_tok] - normalized weights
- expert_indices: [batch * seq_len, num_experts_per_tok] - expert indices
Trait Implementations§
Auto Trait Implementations§
impl !RefUnwindSafe for MoELayer
impl !UnwindSafe for MoELayer
impl Freeze for MoELayer
impl Send for MoELayer
impl Sync for MoELayer
impl Unpin for MoELayer
impl UnsafeUnpin for MoELayer
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<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>
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