oa::ml::nn::MultiHeadAttention

Multi-head self-attention over packed [B*S, D] values.

StRust public API

Declaration

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

Public Methods

pub fn forward(&self, input: &Matrix) -> Result<Matrix>
pub fn forward_masked( &self, input: &Matrix, additive_mask: &Matrix, ) -> Result<Matrix>
pub fn set_backend(&self, backend: AttentionBackend)
pub fn backend(&self) -> AttentionBackend
pub fn last_backend(&self) -> AttentionBackend
pub fn set_mode(&self, mode: AttentionMode)
pub fn mode(&self) -> AttentionMode
pub const fn model_width(&self) -> usize
pub const fn num_heads(&self) -> usize
pub fn sequence_length(&self) -> usize
pub fn set_sequence_length(&self, sequence_length: usize) -> Result<()>
pub fn has_bias(&self) -> bool
pub const fn dropout_probability(&self) -> f32
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 with_seed( engine: &Engine, model_width: usize, num_heads: usize, sequence_length: usize, seed: u64, ) -> Result<Self>
pub fn with_seed_and_bias( engine: &Engine, model_width: usize, num_heads: usize, sequence_length: usize, bias: bool, seed: u64, ) -> Result<Self>
pub fn with_seed_and_options( engine: &Engine, model_width: usize, num_heads: usize, sequence_length: usize, dropout_probability: f32, bias: bool, seed: u64, ) -> Result<Self>

Public Method Documentation

pub fn forward( &self, input: &Matrix ) -> Result<Matrix>
No public source comment is attached to this declaration.
pub fn forward_masked( &self, input: &Matrix, additive_mask: &Matrix ) -> Result<Matrix>
No public source comment is attached to this declaration.
pub fn set_backend( &self, backend: AttentionBackend )
No public source comment is attached to this declaration.
pub fn backend( &self ) -> AttentionBackend
No public source comment is attached to this declaration.
pub fn last_backend( &self ) -> AttentionBackend
No public source comment is attached to this declaration.
pub fn set_mode( &self, mode: AttentionMode )
No public source comment is attached to this declaration.
pub fn mode( &self ) -> AttentionMode
No public source comment is attached to this declaration.
pub const fn model_width( &self ) -> usize
Construct four biased projections with causal visibility and automatic backend policy. Errors Returns an error unless dimensions are positive and model_width is divisible by num_heads, or child construction/registration fails.
pub const fn num_heads( &self ) -> usize
Construct four biased projections with causal visibility and automatic backend policy. Errors Returns an error unless dimensions are positive and model_width is divisible by num_heads, or child construction/registration fails.
pub fn sequence_length( &self ) -> usize
Construct four biased projections with causal visibility and automatic backend policy. Errors Returns an error unless dimensions are positive and model_width is divisible by num_heads, or child construction/registration fails.
pub fn set_sequence_length(&self, sequence_length: usize) -> Result<()>
No public source comment is attached to this declaration.
pub fn has_bias( &self ) -> bool
No public source comment is attached to this declaration.
pub const fn dropout_probability( &self ) -> f32
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 with_seed( engine: &Engine, model_width: usize, num_heads: usize, sequence_length: usize, seed: u64 ) -> Result<Self>
No public source comment is attached to this declaration.
pub fn with_seed_and_bias( engine: &Engine, model_width: usize, num_heads: usize, sequence_length: usize, bias: bool, seed: u64 ) -> Result<Self>
No public source comment is attached to this declaration.
pub fn with_seed_and_options( engine: &Engine, model_width: usize, num_heads: usize, sequence_length: usize, dropout_probability: f32, bias: bool, seed: u64 ) -> Result<Self>
No public source comment is attached to this declaration.