Skip to main content

OnlineSoftmax

Struct OnlineSoftmax 

Source
pub struct OnlineSoftmax<E: Float> { /* private fields */ }
Expand description

The running max m and sum l of every slice along axis of a score, in the registers of its holder.

The score is cut where its holder keeps it (AxisSlices): a unit’s register block holds whole slices of its own, and a plane’s window of shared memory is the plane’s, every unit of it keeping the state of every slice.

Implementations§

Source§

impl<E: Float> OnlineSoftmax<E>

Source

pub fn along(score: &Tile, axis: Axis) -> OnlineSoftmax<E>

The state of every slice along axis of a score held as score is, before any block is taken in: each unit keeps the slices it holds cells of (Tile::slices_per_unit).

Source

pub fn new(slices: usize, axis: Axis) -> OnlineSoftmax<E>

The state of slices slices along axis before any block is taken in: what a holder opens before the walk that hands it its score, as a cube’s plane does before the cube’s ring.

Source

pub fn step(&mut self, score: &Tile, bias: &Tile, scale: E) -> Array<E> ⓘ

Take one block of score into the slices. The block becomes score · scale + bias, the slices’ max and sum move on, and score is left holding exp(score − max): the block’s probabilities, unnormalized. Returns each slice’s exp(max before − max after), what anything summed against the earlier blocks is multiplied by (AxisSlices::mul).

bias is a procedural tile windowed to the same region as score. A masked cell’s bias is E::min_value(); a slice whose every cell so far is masked holds zeros and a zero sum. On a plane’s window every unit of the plane calls it, and the caller meets the plane before it and before the probabilities are read.

Source

pub fn normalizer(&mut self, plane: &Region) -> Array<E> ⓘ

What this plane’s sum against the values is multiplied by once its last block is taken in: each slice’s 1 / l, or, where the cube’s planes split this axis, each holding part of the same slices, the correction to the merged max times 1 / L of the merged sum, so the planes’ products only remain to be added (PlanesOutput). plane is this plane’s region of the cube; the partitioning it was cut by says how many planes share its slices.

Where planes split the axis it is a meeting of the cube: every unit of every plane calls it, each holding its plane’s state as a plane’s window or fragments keep it, and it meets the cube three times through shared memory. The planes’ values are read in plane order, so the merged sum is the same bits from run to run. A slice every plane masked stays at zero.

Source

pub fn relayed( &mut self, relay: &Relay<'_>, carried_max: &mut Tile, carried_sum: &mut Tile, ) -> RelayedFactors<E>

What this plane’s sum and the carry’s rows are multiplied by in its cube’s turn at relay, where the cubes of the relay split this axis, each holding part of the same slices: the cross-cube normalizer, the carry taking the turns’ partials one at a time.

carried_max and carried_sum are this plane’s window of the slices’ state the relay holds beside its carry: the max and sum every turn before this one merged. This plane merges its own into them and leaves the result there for the next turn. Each factor is a slice’s exp(max − merged max), of this plane’s state for its sum and of the carried one for the carry, both times 1 / L of the merged sum on the last turn, so the carry that turn hands on is the answer. The first turn reads nothing, its drain replacing the carry. A slice every turn masked stays at zero.

Every unit of every plane calls it once its cube has taken the turn; the first unit of each plane writes the state, which the relay publishes with the carry. The caller rescales the carry (Relay::carried) and its sum by the factors, then drains.

Source

pub fn state(&self) -> OnlineSoftmaxState<E>

Every slice’s running max and sum as they stand, copied out: nothing is divided and the state walks on unchanged.

Source

pub fn store_rows(&self, score: &Tile, max: &mut Tile, sum: &mut Tile)

Every slice’s running max and sum as they stand, written into max and sum, a plane’s windows of one cell a slice in slice order: what a holder leaves beside its undivided sum where its slices merge with other holders’ parts of them, and the one way to read out a state taken in from a manual-mma grid, whose units each keep the rows they hold cells of.

score is the tile the state was taken in from (along), which says which unit holds which row: each writes its own, one cell a row. A state every unit holds whole is written by the plane’s first unit. Every unit of the plane calls it, and the caller meets the plane before the windows are read.

Source

pub fn store_logsumexp(&self, score: &Tile, logsumexp: &mut Tile)

Every slice’s logsumexp, m + ln(l), written into logsumexp, a window of one cell a slice in slice order that a unit or a plane holds: what a pass that walks the slices again reads its probabilities back from (AxisSlices::probabilities). A slice whose every cell was masked keeps the minimum value, which reads back as probabilities of zero.

score is the tile the state was taken in from, which says which unit holds which slice, as store_rows reads it. Every unit of the holder calls it.

Source

pub fn recip_l(&self) -> Array<E> ⓘ

Each slice’s 1 / l, what its sum of probabilities times values is normalized by; zero for a slice whose every cell was masked.

Source

pub fn __expand_along( scope: &Scope, score: &<Tile as CubeType>::ExpandType, axis: Axis, ) -> <OnlineSoftmax<E> as CubeType>::ExpandType

The state of every slice along axis of a score held as score is, before any block is taken in: each unit keeps the slices it holds cells of (Tile::slices_per_unit).

Source

pub fn __expand_new( scope: &Scope, slices: usize, axis: Axis, ) -> <OnlineSoftmax<E> as CubeType>::ExpandType

The state of slices slices along axis before any block is taken in: what a holder opens before the walk that hands it its score, as a cube’s plane does before the cube’s ring.

Source

pub fn __expand_step( scope: &Scope, this: &mut <Self as CubeType>::ExpandType, score: &<Tile as CubeType>::ExpandType, bias: &<Tile as CubeType>::ExpandType, scale: <E as CubeType>::ExpandType, ) -> <Array<E> as CubeType>::ExpandType ⓘ

Take one block of score into the slices. The block becomes score · scale + bias, the slices’ max and sum move on, and score is left holding exp(score − max): the block’s probabilities, unnormalized. Returns each slice’s exp(max before − max after), what anything summed against the earlier blocks is multiplied by (AxisSlices::mul).

bias is a procedural tile windowed to the same region as score. A masked cell’s bias is E::min_value(); a slice whose every cell so far is masked holds zeros and a zero sum. On a plane’s window every unit of the plane calls it, and the caller meets the plane before it and before the probabilities are read.

Source

pub fn __expand_normalizer( scope: &Scope, this: &mut <Self as CubeType>::ExpandType, plane: &<Region as CubeType>::ExpandType, ) -> <Array<E> as CubeType>::ExpandType ⓘ

What this plane’s sum against the values is multiplied by once its last block is taken in: each slice’s 1 / l, or, where the cube’s planes split this axis, each holding part of the same slices, the correction to the merged max times 1 / L of the merged sum, so the planes’ products only remain to be added (PlanesOutput). plane is this plane’s region of the cube; the partitioning it was cut by says how many planes share its slices.

Where planes split the axis it is a meeting of the cube: every unit of every plane calls it, each holding its plane’s state as a plane’s window or fragments keep it, and it meets the cube three times through shared memory. The planes’ values are read in plane order, so the merged sum is the same bits from run to run. A slice every plane masked stays at zero.

Source

pub fn __expand_relayed( scope: &Scope, this: &mut <Self as CubeType>::ExpandType, relay: &<Relay<'_> as CubeType>::ExpandType, carried_max: &mut <Tile as CubeType>::ExpandType, carried_sum: &mut <Tile as CubeType>::ExpandType, ) -> <RelayedFactors<E> as CubeType>::ExpandType

What this plane’s sum and the carry’s rows are multiplied by in its cube’s turn at relay, where the cubes of the relay split this axis, each holding part of the same slices: the cross-cube normalizer, the carry taking the turns’ partials one at a time.

carried_max and carried_sum are this plane’s window of the slices’ state the relay holds beside its carry: the max and sum every turn before this one merged. This plane merges its own into them and leaves the result there for the next turn. Each factor is a slice’s exp(max − merged max), of this plane’s state for its sum and of the carried one for the carry, both times 1 / L of the merged sum on the last turn, so the carry that turn hands on is the answer. The first turn reads nothing, its drain replacing the carry. A slice every turn masked stays at zero.

Every unit of every plane calls it once its cube has taken the turn; the first unit of each plane writes the state, which the relay publishes with the carry. The caller rescales the carry (Relay::carried) and its sum by the factors, then drains.

Source

pub fn __expand_state( scope: &Scope, this: &<Self as CubeType>::ExpandType, ) -> <OnlineSoftmaxState<E> as CubeType>::ExpandType

Every slice’s running max and sum as they stand, copied out: nothing is divided and the state walks on unchanged.

Source

pub fn __expand_store_rows( scope: &Scope, this: &<Self as CubeType>::ExpandType, score: &<Tile as CubeType>::ExpandType, max: &mut <Tile as CubeType>::ExpandType, sum: &mut <Tile as CubeType>::ExpandType, )

Every slice’s running max and sum as they stand, written into max and sum, a plane’s windows of one cell a slice in slice order: what a holder leaves beside its undivided sum where its slices merge with other holders’ parts of them, and the one way to read out a state taken in from a manual-mma grid, whose units each keep the rows they hold cells of.

score is the tile the state was taken in from (along), which says which unit holds which row: each writes its own, one cell a row. A state every unit holds whole is written by the plane’s first unit. Every unit of the plane calls it, and the caller meets the plane before the windows are read.

Source

pub fn __expand_store_logsumexp( scope: &Scope, this: &<Self as CubeType>::ExpandType, score: &<Tile as CubeType>::ExpandType, logsumexp: &mut <Tile as CubeType>::ExpandType, )

Every slice’s logsumexp, m + ln(l), written into logsumexp, a window of one cell a slice in slice order that a unit or a plane holds: what a pass that walks the slices again reads its probabilities back from (AxisSlices::probabilities). A slice whose every cell was masked keeps the minimum value, which reads back as probabilities of zero.

score is the tile the state was taken in from, which says which unit holds which slice, as store_rows reads it. Every unit of the holder calls it.

Source

pub fn __expand_recip_l( scope: &Scope, this: &<Self as CubeType>::ExpandType, ) -> <Array<E> as CubeType>::ExpandType ⓘ

Each slice’s 1 / l, what its sum of probabilities times values is normalized by; zero for a slice whose every cell was masked.

Trait Implementations§

Auto Trait Implementations§

§

impl<E> Freeze for OnlineSoftmax<E>
where Array<E>: Freeze,

§

impl<E> RefUnwindSafe for OnlineSoftmax<E>
where Array<E>: RefUnwindSafe,

§

impl<E> Send for OnlineSoftmax<E>
where Array<E>: Send,

§

impl<E> Sync for OnlineSoftmax<E>
where Array<E>: Sync,

§

impl<E> Unpin for OnlineSoftmax<E>
where Array<E>: Unpin,

§

impl<E> UnsafeUnpin for OnlineSoftmax<E>
where Array<E>: UnsafeUnpin,

§

impl<E> UnwindSafe for OnlineSoftmax<E>
where Array<E>: UnwindSafe,

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<T> Downcast for T
where T: Any,

Source§

fn into_any(self: Box<T>) -> Box<dyn Any>

Converts Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>, which can then be downcast into Box<dyn ConcreteType> where ConcreteType implements Trait.
Source§

fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>

Converts Rc<Trait> (where Trait: Downcast) to Rc<Any>, which can then be further downcast into Rc<ConcreteType> where ConcreteType implements Trait.
Source§

fn as_any(&self) -> &(dyn Any + 'static)

Converts &Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &Any’s vtable from &Trait’s.
Source§

fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)

Converts &mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &mut Any’s vtable from &mut Trait’s.
Source§

impl<T> DowncastSend for T
where T: Any + Send,

Source§

fn into_any_send(self: Box<T>) -> Box<dyn Any + Send>

Converts Box<Trait> (where Trait: DowncastSend) to Box<dyn Any + Send>, which can then be downcast into Box<ConcreteType> where ConcreteType implements Trait.
Source§

impl<T> DowncastSync for T
where T: Any + Send + Sync,

Source§

fn into_any_sync(self: Box<T>) -> Box<dyn Any + Send + Sync>

Converts Box<Trait> (where Trait: DowncastSync) to Box<dyn Any + Send + Sync>, which can then be downcast into Box<ConcreteType> where ConcreteType implements Trait.
Source§

fn into_any_arc(self: Arc<T>) -> Arc<dyn Any + Send + Sync> ⓘ

Converts Arc<Trait> (where Trait: DowncastSync) to Arc<Any>, which can then be downcast into Arc<ConcreteType> where ConcreteType implements Trait.
Source§

impl<T> ErasedDestructor for T
where T: 'static,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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<T> IntoComptime for T

Source§

fn comptime(self) -> Self

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
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> 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.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more