pub struct Embedding { /* private fields */ }Expand description
Trainable FP32 lookup table indexed by an arbitrary-shape U8, U32, or I32 matrix.
Implementations§
Source§impl Embedding
impl Embedding
pub fn new_with_seed( num_embeddings: usize, embedding_dim: usize, seed: u64, ) -> Result<Self>
Sourcepub fn new_with_seed_on(
runtime: &Runtime,
num_embeddings: usize,
embedding_dim: usize,
seed: u64,
) -> Result<Self>
pub fn new_with_seed_on( runtime: &Runtime, num_embeddings: usize, embedding_dim: usize, seed: u64, ) -> Result<Self>
Construct a deterministically initialized embedding table.
§Errors
Returns an error when either dimension is zero, shape arithmetic overflows, or allocation/upload fails.
Sourcepub fn new_from_matrix(weight: Matrix) -> Result<Self>
pub fn new_from_matrix(weight: Matrix) -> Result<Self>
Construct an embedding from an exact FP32 table shaped [V, D].
§Errors
Returns an error unless weight is a nonempty rank-two FP32 matrix.
Sourcepub fn forward(&self, indices: &Matrix) -> Result<Matrix>
pub fn forward(&self, indices: &Matrix) -> Result<Matrix>
Gather one embedding row per U8, U32, or non-negative I32 index.
The output shape is the complete index shape followed by embedding_dim.
Out-of-range indices produce NaN rows without reading outside the table.
§Errors
Returns an error when indices are not U8/U32/I32, the runtimes differ, shape or ABI arithmetic overflows, or runtime recording fails. Negative I32 and other out-of-range indices produce NaN rows without an out-of-bounds read.
pub const fn num_embeddings(&self) -> usize
pub const fn embedding_dim(&self) -> usize
pub fn weight(&self) -> Parameter
pub fn parameters(&self) -> [Parameter; 1]
Trait Implementations§
Source§impl Module for Embedding
impl Module for Embedding
Source§fn forward(&self, input: &Matrix) -> Result<Matrix>
fn forward(&self, input: &Matrix) -> Result<Matrix>
Source§fn registry(&self) -> &ModuleRegistry
fn registry(&self) -> &ModuleRegistry
Source§fn parameters(&self) -> Vec<Parameter>
fn parameters(&self) -> Vec<Parameter>
Source§fn named_parameters(&self) -> Vec<NamedParameter>
fn named_parameters(&self) -> Vec<NamedParameter>
Source§fn named_buffers(&self) -> Vec<NamedBuffer>
fn named_buffers(&self) -> Vec<NamedBuffer>
Source§fn all_parameters(&self) -> Result<Vec<Parameter>>
fn all_parameters(&self) -> Result<Vec<Parameter>>
Source§fn all_named_parameters(&self) -> Result<Vec<NamedParameter>>
fn all_named_parameters(&self) -> Result<Vec<NamedParameter>>
Source§fn all_named_buffers(&self) -> Result<Vec<NamedBuffer>>
fn all_named_buffers(&self) -> Result<Vec<NamedBuffer>>
Source§fn all_named_state_u32(&self) -> Result<Vec<NamedStateU32>>
fn all_named_state_u32(&self) -> Result<Vec<NamedStateU32>>
u32 scalar state in
deterministic depth-first order. Read more