pub struct Encoder {
pub config: EncoderConfig,
pub attention: MultiHeadAttention,
pub ffn: FeedForward,
pub norm1: LayerNorm,
pub norm2: LayerNorm,
}Expand description
Transformer encoder layer
Fields§
§config: EncoderConfigConfiguration
attention: MultiHeadAttentionMulti-head attention
ffn: FeedForwardFeed-forward network
norm1: LayerNormFirst layer normalization
norm2: LayerNormSecond layer normalization
Implementations§
Source§impl Encoder
impl Encoder
Sourcepub fn new(config: EncoderConfig) -> Result<Self>
pub fn new(config: EncoderConfig) -> Result<Self>
Create a new encoder layer
Sourcepub fn build_encoder_graph(&self, graph: &mut EinsumGraph) -> Result<Vec<usize>>
pub fn build_encoder_graph(&self, graph: &mut EinsumGraph) -> Result<Vec<usize>>
Build einsum graph for encoder layer
Input tensors:
- 0: x (input) [batch, seq_len, d_model]
- 1-N: weight matrices and parameters for attention, FFN, and layer norms
Output tensors:
- output: [batch, seq_len, d_model]
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Encoder
impl RefUnwindSafe for Encoder
impl Send for Encoder
impl Sync for Encoder
impl Unpin for Encoder
impl UnsafeUnpin for Encoder
impl UnwindSafe for Encoder
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,
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