Realm

oa::ml::nn::EmbeddingBag

Bag-of-embeddings lookup: embedding lookup followed by a per-bag reduction, covering the nn.EmbeddingBag contract. forward takes the flattened index matrix plus host offsets delimiting bags — the same boundary choice as torch.nn.EmbeddingBag(mode='mean'|'sum'), with offsets kept on the host side of the CPU/GPU contract because bag boundaries are data-shaping metadata, not device state. The bag loop composes slice + sum/mean + concat, so gradients flow through Embedding’s own adjoint into the shared weight — a composed contract, not a fused kernel.

StRust public API

Declaration

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

Public Methods

pub const fn mode(&self) -> EmbeddingBagMode
pub fn embedding(&self) -> &Embedding
pub fn forward(&self, indices: &Matrix, offsets: &[usize]) -> Result<Matrix>
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_on( runtime: &Runtime, num_embeddings: usize, embedding_dim: usize, mode: EmbeddingBagMode, seed: u64, ) -> Result<Self>
pub fn new_with_seed_normal_on( runtime: &Runtime, num_embeddings: usize, embedding_dim: usize, stddev: f32, mode: EmbeddingBagMode, seed: u64, ) -> Result<Self>
pub fn new_from_embedding( embedding: Embedding, mode: EmbeddingBagMode, ) -> Result<Self>
pub fn new_from_matrix(weight: Matrix, mode: EmbeddingBagMode) -> Result<Self>

Public Method Documentation

pub const fn mode( &self ) -> EmbeddingBagMode
No public source comment is attached to this declaration.
pub fn embedding( &self ) -> &Embedding
No public source comment is attached to this declaration.
pub fn forward( &self, indices: &Matrix, offsets: &[usize] ) -> Result<Matrix>
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_on( runtime: &Runtime, num_embeddings: usize, embedding_dim: usize, mode: EmbeddingBagMode, seed: u64 ) -> Result<Self>
No public source comment is attached to this declaration.
pub fn new_with_seed_normal_on( runtime: &Runtime, num_embeddings: usize, embedding_dim: usize, stddev: f32, mode: EmbeddingBagMode, seed: u64 ) -> Result<Self>
No public source comment is attached to this declaration.
pub fn new_from_embedding( embedding: Embedding, mode: EmbeddingBagMode ) -> Result<Self>
No public source comment is attached to this declaration.
pub fn new_from_matrix( weight: Matrix, mode: EmbeddingBagMode ) -> Result<Self>
No public source comment is attached to this declaration.