Skip to main content

Tape

Struct Tape 

Source
pub struct Tape { /* private fields */ }

Implementations§

Source§

impl Tape

Source

pub fn new() -> Tape

Source

pub fn leaf(&mut self, t: Tensor) -> TVar

Register a leaf (parameter or input); its gradient is what backward reports.

Source

pub fn add(&mut self, a: &TVar, b: &TVar) -> Result<TVar>

Source

pub fn matmul( &mut self, a: &TVar, b: &TVar, bias: Option<&TVar>, spec: MatmulSpec, ) -> Result<TVar>

Matmul with the specs the training forward uses: trans_a == false, b_rows == None, operands of equal rank (2x2 or batched 3x3).

Source

pub fn gelu(&mut self, x: &TVar) -> Result<TVar>

Source

pub fn layernorm( &mut self, x: &TVar, gamma: &TVar, beta: &TVar, eps: f32, ) -> Result<TVar>

Source

pub fn softmax(&mut self, x: &TVar, causal: bool, off: usize) -> Result<TVar>

Softmax over the last dim (optionally causal). Saves the output for backward; the causal mask needs no bookkeeping there because masked outputs are exact zeros.

Source

pub fn split_heads( &mut self, qkv: &TVar, n_head: usize, ) -> Result<(TVar, TVar, TVar)>

Source

pub fn merge_heads(&mut self, x: &TVar) -> Result<TVar>

Source

pub fn embedding( &mut self, ids: &Tensor, wte: &TVar, wpe: &TVar, pos: usize, ) -> Result<TVar>

Fused token + positional embedding over a single-chunk wte. dwte comes from scatter-add over the token ids; dwpe is the upstream gradient placed at rows pos..pos+t.

Source

pub fn dropout(&mut self, x: &TVar, p: f32, seed: u32) -> Result<TVar>

Inverted dropout; the deterministic counter RNG regenerates the same mask in backward, so nothing is saved.

Source

pub fn backward( &mut self, root: &TVar, seed_grad: Tensor, ) -> Result<Vec<Option<Tensor>>>

Reverse sweep from root seeded with seed_grad (dL/droot). Returns per-node gradients; leaves keep theirs, interior gradients are freed as soon as they have been consumed.

Trait Implementations§

Source§

impl Default for Tape

Source§

fn default() -> Tape

Returns the “default value” for a type. Read more

Auto Trait Implementations§

§

impl !RefUnwindSafe for Tape

§

impl !Send for Tape

§

impl !Sync for Tape

§

impl !UnwindSafe for Tape

§

impl Freeze for Tape

§

impl Unpin for Tape

§

impl UnsafeUnpin for Tape

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<T> for T

Source§

fn downcast(&self) -> &T

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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> 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, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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<T> Upcast<T> for T

Source§

fn upcast(&self) -> Option<&T>

Source§

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

Source§

fn vzip(self) -> V