Realm

oa::ml::nn::EncoderDecoder

Ready-to-train encoder-decoder Transformer for sequence-to-sequence tasks. Source and target token/position embeddings feed separate block stacks: encoder blocks run bidirectional self-attention, decoder blocks run causal self-attention and bidirectional cross-attention over the encoder output. forward(source, target) returns all-position target logits.

StRust public API

Declaration

pub struct EncoderDecoder { /* private fields */ }
Public Rust declaration.

Public Methods

pub fn encode(&self, tokens: &Matrix) -> Result<Matrix>
pub fn decode(&self, tokens: &Matrix, encoder_output: &Matrix) -> Result<Matrix>
pub fn forward(&self, source: &Matrix, target: &Matrix) -> Result<Matrix>
pub fn encode_masked( &self, tokens: &Matrix, source_mask: &Matrix, ) -> Result<Matrix>
pub fn decode_masked( &self, tokens: &Matrix, encoder_output: &Matrix, cross_mask: &Matrix, ) -> Result<Matrix>
pub fn forward_masked( &self, source: &Matrix, target: &Matrix, source_mask: &Matrix, cross_mask: &Matrix, ) -> Result<Matrix>
pub const fn source_vocab_size(&self) -> usize
pub const fn target_vocab_size(&self) -> usize
pub const fn source_context_length(&self) -> usize
pub const fn target_context_length(&self) -> usize
pub const fn model_width(&self) -> usize
pub const fn hidden_width(&self) -> usize
pub fn num_layers(&self) -> usize
pub const fn num_heads(&self) -> usize
pub fn encoder_block(&self, index: usize) -> Option<&TransformerBlock>
pub fn decoder_block(&self, index: usize) -> Option<&EncoderDecoderBlock>
fn forward(&self, input: &Matrix) -> Result<Matrix>
fn registry(&self) -> &ModuleRegistry
fn parameters(&self) -> Vec<Parameter>
fn named_parameters(&self) -> Vec<NamedParameter>
fn buffers(&self) -> Vec<Matrix>
fn named_buffers(&self) -> Vec<NamedBuffer>
fn all_parameters(&self) -> Result<Vec<Parameter>>
fn all_named_parameters(&self) -> Result<Vec<NamedParameter>>
fn all_named_buffers(&self) -> Result<Vec<NamedBuffer>>
fn all_named_state_u32(&self) -> Result<Vec<NamedStateU32>>
fn num_parameters(&self) -> Result<usize>
fn train(&self, training: bool)
fn eval(&self)
fn is_training(&self) -> bool
fn scoped_eval(&self) -> ScopedEval<'_>

Associated Functions

pub fn new_with_seed( source_vocab_size: usize, target_vocab_size: usize, source_context_length: usize, target_context_length: usize, model_width: usize, hidden_width: usize, num_layers: usize, num_heads: usize, epsilon: f32, seed: u64, ) -> Result<Self>
pub fn new_with_seed_on( runtime: &Runtime, source_vocab_size: usize, target_vocab_size: usize, source_context_length: usize, target_context_length: usize, model_width: usize, hidden_width: usize, num_layers: usize, num_heads: usize, epsilon: f32, seed: u64, ) -> Result<Self>

Public Method Documentation

pub fn encode( &self, tokens: &Matrix ) -> Result<Matrix>
No public source comment is attached to this declaration.
pub fn decode( &self, tokens: &Matrix, encoder_output: &Matrix ) -> Result<Matrix>
No public source comment is attached to this declaration.
pub fn forward( &self, source: &Matrix, target: &Matrix ) -> Result<Matrix>
No public source comment is attached to this declaration.
pub fn encode_masked( &self, tokens: &Matrix, source_mask: &Matrix ) -> Result<Matrix>
No public source comment is attached to this declaration.
pub fn decode_masked( &self, tokens: &Matrix, encoder_output: &Matrix, cross_mask: &Matrix ) -> Result<Matrix>
No public source comment is attached to this declaration.
pub fn forward_masked( &self, source: &Matrix, target: &Matrix, source_mask: &Matrix, cross_mask: &Matrix ) -> Result<Matrix>
No public source comment is attached to this declaration.
pub const fn source_vocab_size( &self ) -> usize
Construct a deterministic encoder-decoder Transformer. Both stacks use num_layers blocks of the same width recipe. Errors Returns an error unless all dimensions are positive, the model width is divisible by the head count, positions fit U32, and every child can be constructed and registered.
pub const fn target_vocab_size( &self ) -> usize
Construct a deterministic encoder-decoder Transformer. Both stacks use num_layers blocks of the same width recipe. Errors Returns an error unless all dimensions are positive, the model width is divisible by the head count, positions fit U32, and every child can be constructed and registered.
pub const fn source_context_length( &self ) -> usize
Construct a deterministic encoder-decoder Transformer. Both stacks use num_layers blocks of the same width recipe. Errors Returns an error unless all dimensions are positive, the model width is divisible by the head count, positions fit U32, and every child can be constructed and registered.
pub const fn target_context_length( &self ) -> usize
Construct a deterministic encoder-decoder Transformer. Both stacks use num_layers blocks of the same width recipe. Errors Returns an error unless all dimensions are positive, the model width is divisible by the head count, positions fit U32, and every child can be constructed and registered.
pub const fn model_width( &self ) -> usize
Construct a deterministic encoder-decoder Transformer. Both stacks use num_layers blocks of the same width recipe. Errors Returns an error unless all dimensions are positive, the model width is divisible by the head count, positions fit U32, and every child can be constructed and registered.
pub const fn hidden_width( &self ) -> usize
Construct a deterministic encoder-decoder Transformer. Both stacks use num_layers blocks of the same width recipe. Errors Returns an error unless all dimensions are positive, the model width is divisible by the head count, positions fit U32, and every child can be constructed and registered.
pub fn num_layers( &self ) -> usize
Construct a deterministic encoder-decoder Transformer. Both stacks use num_layers blocks of the same width recipe. Errors Returns an error unless all dimensions are positive, the model width is divisible by the head count, positions fit U32, and every child can be constructed and registered.
pub const fn num_heads( &self ) -> usize
Construct a deterministic encoder-decoder Transformer. Both stacks use num_layers blocks of the same width recipe. Errors Returns an error unless all dimensions are positive, the model width is divisible by the head count, positions fit U32, and every child can be constructed and registered.
pub fn encoder_block( &self, index: usize ) -> Option<&TransformerBlock>
No public source comment is attached to this declaration.
pub fn decoder_block( &self, index: usize ) -> Option<&EncoderDecoderBlock>
No public source comment is attached to this declaration.
fn forward( &self, input: &Matrix ) -> Result<Matrix>
No public source comment is attached to this declaration.
fn registry( &self ) -> &ModuleRegistry
No public source comment is attached to this declaration.
fn parameters( &self ) -> Vec<Parameter>
No public source comment is attached to this declaration.
fn named_parameters( &self ) -> Vec<NamedParameter>
No public source comment is attached to this declaration.
fn buffers( &self ) -> Vec<Matrix>
No public source comment is attached to this declaration.
fn named_buffers( &self ) -> Vec<NamedBuffer>
No public source comment is attached to this declaration.
fn all_parameters( &self ) -> Result<Vec<Parameter>>
No public source comment is attached to this declaration.
fn all_named_parameters( &self ) -> Result<Vec<NamedParameter>>
No public source comment is attached to this declaration.
fn all_named_buffers( &self ) -> Result<Vec<NamedBuffer>>
No public source comment is attached to this declaration.
fn all_named_state_u32( &self ) -> Result<Vec<NamedStateU32>>
No public source comment is attached to this declaration.
fn num_parameters( &self ) -> Result<usize>
No public source comment is attached to this declaration.
fn train( &self, training: bool )
No public source comment is attached to this declaration.
fn eval( &self )
No public source comment is attached to this declaration.
fn is_training( &self ) -> bool
No public source comment is attached to this declaration.
fn scoped_eval( &self ) -> ScopedEval<'_>
No public source comment is attached to this declaration.
pub fn new_with_seed( source_vocab_size: usize, target_vocab_size: usize, source_context_length: usize, target_context_length: usize, model_width: usize, hidden_width: usize, num_layers: usize, num_heads: usize, epsilon: f32, seed: u64 ) -> Result<Self>
No public source comment is attached to this declaration.
pub fn new_with_seed_on( runtime: &Runtime, source_vocab_size: usize, target_vocab_size: usize, source_context_length: usize, target_context_length: usize, model_width: usize, hidden_width: usize, num_layers: usize, num_heads: usize, epsilon: f32, seed: u64 ) -> Result<Self>
Construct a deterministic encoder-decoder Transformer. Both stacks use num_layers blocks of the same width recipe. Errors Returns an error unless all dimensions are positive, the model width is divisible by the head count, positions fit U32, and every child can be constructed and registered.