Skip to main content

Linear

oa::ml::nn

Struct Linear 

Source
pub struct Linear { /* private fields */ }
Expand description

Trainable FP32 affine projection using [output, input] weight layout.

Implementations§

Source§

impl Linear

Source

pub fn new_with_seed( input_features: usize, output_features: usize, seed: u64, ) -> Result<Self>

Source

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.

Source

pub fn new_with_seed_and_bias( input_features: usize, output_features: usize, trainable_bias: bool, seed: u64, ) -> Result<Self>

Source

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.

Source

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.

Source

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.

Source

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.

Source

pub const fn input_features(&self) -> usize

Return this layer’s input feature count.

Source

pub const fn output_features(&self) -> usize

Return this layer’s output feature count.

Source

pub fn weight(&self) -> Parameter

Return the stable trainable weight handle.

Source

pub fn bias(&self) -> Option<Parameter>

Return the stable trainable bias handle.

Source

pub fn has_bias(&self) -> bool

Return whether this layer owns a trainable bias.

Source

pub fn parameters(&self) -> Vec<Parameter>

Return this layer’s parameters in deterministic weight, optional-bias order.

Trait Implementations§

Source§

impl Module for Linear

Source§

fn forward(&self, input: &Matrix) -> Result<Matrix>

Evaluate one Matrix input without submitting or waiting.
Source§

fn registry(&self) -> &ModuleRegistry

Return this module’s structural registry.
Source§

fn parameters(&self) -> Vec<Parameter>

Return direct parameters only.
Source§

fn named_parameters(&self) -> Vec<NamedParameter>

Return direct parameters with local registration names.
Source§

fn buffers(&self) -> Vec<Matrix>

Return direct non-trainable buffers only.
Source§

fn named_buffers(&self) -> Vec<NamedBuffer>

Return direct buffers with local registration names and persistence flags.
Source§

fn all_parameters(&self) -> Result<Vec<Parameter>>

Return every parameter exactly once in deterministic depth-first order. Read more
Source§

fn all_named_parameters(&self) -> Result<Vec<NamedParameter>>

Return every parameter with its registration-derived dotted path. Read more
Source§

fn all_named_buffers(&self) -> Result<Vec<NamedBuffer>>

Return all direct and recursive buffers in deterministic depth-first order. Read more
Source§

fn all_named_state_u32(&self) -> Result<Vec<NamedStateU32>>

Return all direct and recursive persistent u32 scalar state in deterministic depth-first order. Read more
Source§

fn all_named_rng_states(&self) -> Result<Vec<NamedRngState>>

Return all direct and recursive stochastic RNG streams in deterministic depth-first order. Read more
Source§

fn num_parameters(&self) -> Result<usize>

Return the total number of trainable scalar values. Read more
Source§

fn train(&self, training: bool)

Set train/eval mode recursively.
Source§

fn eval(&self)

Enter evaluation mode recursively.
Source§

fn is_training(&self) -> bool

Return this module’s current train/eval mode.
Source§

fn scoped_eval(&self) -> ScopedEval<'_>

Enter evaluation mode until the returned guard is dropped.

Auto Trait Implementations§

§

impl !Freeze for Linear

§

impl !RefUnwindSafe for Linear

§

impl !Send for Linear

§

impl !Sync for Linear

§

impl !UnwindSafe for Linear

§

impl Forget for Linear

§

impl Move for Linear

§

impl Unpin for Linear
where Rc<RefCell<ParameterState>>: Unpin, Rc<RefCell<RuntimeState>>: Unpin, Rc<StorageInner>: Unpin, *const u8 is !null: Unpin, Rc<MatrixSemantic>: Unpin, Rc<()>: Unpin, Rc<RefCell<Matrix>>: Unpin, Rc<Cell<u32>>: Unpin, Rc<RngStreamState>: Unpin, Rc<dyn Module>: Unpin,

§

impl UnsafeUnpin for Linear
where *const RcInner<RefCell<ParameterState>> is !null: UnsafeUnpin, PhantomData<RcInner<RefCell<ParameterState>>>: UnsafeUnpin, *const RcInner<RefCell<RuntimeState>> is !null: UnsafeUnpin, PhantomData<RcInner<RefCell<RuntimeState>>>: UnsafeUnpin, *const RcInner<StorageInner> is !null: UnsafeUnpin, PhantomData<RcInner<StorageInner>>: UnsafeUnpin, *const u8 is !null: UnsafeUnpin, PhantomData<usize>: UnsafeUnpin, *const RcInner<MatrixSemantic> is !null: UnsafeUnpin, PhantomData<RcInner<MatrixSemantic>>: UnsafeUnpin, PhantomData<Rc<()>>: UnsafeUnpin, PhantomData<ParameterEntry>: UnsafeUnpin, PhantomData<BufferEntry>: UnsafeUnpin, PhantomData<StateU32Entry>: UnsafeUnpin, PhantomData<RngStateEntry>: UnsafeUnpin, PhantomData<ChildEntry>: UnsafeUnpin,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<S, T> Duplex<S> for T
where T: FromSample<S> + ToSample<S>,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<S> FromSample<S> for S

Source§

fn from_sample_(s: S) -> S

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<F, T> IntoSample<T> for F
where T: FromSample<F>,

Source§

fn into_sample(self) -> T

Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> ToSample<U> for T
where U: FromSample<T>,

Source§

fn to_sample_(self) -> U

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.