pub struct Decoder {
pub config: DecoderConfig,
pub self_attention: MultiHeadAttention,
pub cross_attention: MultiHeadAttention,
pub ffn: FeedForward,
pub norm1: LayerNorm,
pub norm2: LayerNorm,
pub norm3: LayerNorm,
}Expand description
Transformer decoder layer
Fields§
§config: DecoderConfigConfiguration
self_attention: MultiHeadAttentionMasked self-attention
cross_attention: MultiHeadAttentionCross-attention
ffn: FeedForwardFeed-forward network
norm1: LayerNormFirst layer normalization (self-attention)
norm2: LayerNormSecond layer normalization (cross-attention)
norm3: LayerNormThird layer normalization (FFN)
Implementations§
Source§impl Decoder
impl Decoder
Sourcepub fn new(config: DecoderConfig) -> Result<Self>
pub fn new(config: DecoderConfig) -> Result<Self>
Create a new decoder layer
Sourcepub fn build_decoder_graph(&self, graph: &mut EinsumGraph) -> Result<Vec<usize>>
pub fn build_decoder_graph(&self, graph: &mut EinsumGraph) -> Result<Vec<usize>>
Build einsum graph for decoder layer
Input tensors:
- 0: x (decoder input) [batch, tgt_len, d_model]
- 1: encoder_output [batch, src_len, d_model]
- 2-N: weight matrices and parameters
Output tensors:
- output: [batch, tgt_len, d_model]
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Decoder
impl RefUnwindSafe for Decoder
impl Send for Decoder
impl Sync for Decoder
impl Unpin for Decoder
impl UnwindSafe for Decoder
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