pub struct Linear { /* private fields */ }Expand description
Trainable FP32 affine projection using [output, input] weight layout.
Implementations§
Source§impl Linear
impl Linear
pub fn new_with_seed( input_features: usize, output_features: usize, seed: u64, ) -> Result<Self>
Sourcepub fn new_with_seed_on(
runtime: &Runtime,
input_features: usize,
output_features: usize,
seed: u64,
) -> Result<Self>
pub fn new_with_seed_on( runtime: &Runtime, input_features: usize, output_features: usize, seed: u64, ) -> Result<Self>
Construct a deterministically initialized linear layer.
seed controls an independent SplitMix64 Xavier-uniform initializer.
§Errors
Returns an error when either feature count is zero, shape arithmetic overflows, or parameter allocation/upload fails.
pub fn new_with_seed_and_bias( input_features: usize, output_features: usize, trainable_bias: bool, seed: u64, ) -> Result<Self>
Sourcepub fn new_with_seed_and_bias_on(
runtime: &Runtime,
input_features: usize,
output_features: usize,
trainable_bias: bool,
seed: u64,
) -> Result<Self>
pub fn new_with_seed_and_bias_on( runtime: &Runtime, input_features: usize, output_features: usize, trainable_bias: bool, seed: u64, ) -> Result<Self>
Construct a deterministically initialized linear layer with optional bias.
A bias-free layer retains a private zero vector required by the current physical GEMM ABI, but exposes and registers no fake trainable parameter.
§Errors
Returns an error when either feature count is zero, shape arithmetic overflows, or parameter allocation/upload fails.
Sourcepub fn new_from_matrices(weight: Matrix, bias: Matrix) -> Result<Self>
pub fn new_from_matrices(weight: Matrix, bias: Matrix) -> Result<Self>
Construct a linear layer from exact FP32 weight and bias matrices.
§Errors
Returns an error unless weight has shape [O, I], bias has shape [O],
both are nonempty FP32 matrices, and both belong to the same runtime.
Sourcepub fn new_from_weight(weight: Matrix) -> Result<Self>
pub fn new_from_weight(weight: Matrix) -> Result<Self>
Construct a bias-free linear layer from an exact FP32 weight matrix.
§Errors
Returns an error unless weight is a nonempty FP32 [O, I] matrix or the
private physical zero vector cannot be allocated.
Sourcepub fn forward(&self, input: &Matrix) -> Result<Matrix>
pub fn forward(&self, input: &Matrix) -> Result<Matrix>
Apply this layer to an FP32 Matrix with rank at least two.
Leading dimensions are preserved and the final input-feature dimension is replaced by the configured output-feature dimension.
§Errors
Returns an error when the input contract or runtime recording fails.
Sourcepub const fn input_features(&self) -> usize
pub const fn input_features(&self) -> usize
Return this layer’s input feature count.
Sourcepub const fn output_features(&self) -> usize
pub const fn output_features(&self) -> usize
Return this layer’s output feature count.
Sourcepub fn parameters(&self) -> Vec<Parameter>
pub fn parameters(&self) -> Vec<Parameter>
Return this layer’s parameters in deterministic weight, optional-bias order.
Trait Implementations§
Source§impl Module for Linear
impl Module for Linear
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