Skip to main content

AdaptiveLogSoftmaxWithLoss

oa::ml::nn

Struct AdaptiveLogSoftmaxWithLoss 

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

Two-level output layer: a head linear scores the most frequent classes plus one logit per tail cluster, while each tail cluster owns a projection and output linear that rescore its classes conditioned on the head cluster probability. Matches the nn.AdaptiveLogSoftmaxWithLoss contract: cutoffs partition 0..n_classes into a head range 0..cutoffs[0] and one tail cluster per cutoff, with tail i projecting in_features down to round(in_features / div_value^(i+1)) before its output linear.

Implementations§

Source§

impl AdaptiveLogSoftmaxWithLoss

Source

pub fn new( in_features: usize, n_classes: usize, cutoffs: &[usize], ) -> Result<Self>

Construct on the current runtime with the thread-local seed source.

§Errors

Returns an error when the contract or initialization fails.

Source

pub fn new_with_seed( in_features: usize, n_classes: usize, cutoffs: &[usize], seed: u64, ) -> Result<Self>

Construct on the current runtime with an explicit seed.

Uses div_value 4.0 and a bias-free head, matching the torch defaults.

§Errors

Returns an error when the contract or initialization fails.

Source

pub fn new_with_seed_on( runtime: &Runtime, in_features: usize, n_classes: usize, cutoffs: &[usize], div_value: f64, head_bias: bool, _tail_bias: bool, seed: u64, ) -> Result<Self>

Construct a deterministically initialized adaptive softmax layer.

cutoffs must be a nonempty strictly increasing list below n_classes; each cutoff opens a tail cluster. div_value sets each tail’s projection width and head_bias adds a bias to the head linear.

§Errors

Returns an error when the contract or initialization fails.

Source

pub fn from_parts( in_features: usize, n_classes: usize, cutoffs: &[usize], head: Rc<Linear>, tails: Vec<(Rc<Linear>, Rc<Linear>)>, ) -> Result<Self>

Construct from explicit head and tail linears (deterministic tests and checkpoint assembly).

§Errors

Returns an error when the contract or any linear’s shape is invalid.

Source

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

Return the assembled [N, V] log-probabilities for a rank-two FP32 input, matching AdaptiveLogSoftmaxWithLoss.log_prob.

§Errors

Returns an error when the input contract or runtime recording fails.

Source

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

Compute the assembled log-probabilities and the mean negative log-likelihood for a rank-two FP32 input [N, I] and a rank-one target [N] holding class indices as I32, U32, or FP32.

§Errors

Returns an error when the contract or runtime recording fails.

Source

pub const fn in_features(&self) -> usize

Return the input feature count.

Source

pub const fn n_classes(&self) -> usize

Return the class count.

Trait Implementations§

Source§

impl Module for AdaptiveLogSoftmaxWithLoss

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§

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.