Skip to main content

Tape

Struct Tape 

Source
pub struct Tape<'d> { /* private fields */ }
Expand description

Autograd tape. Records forward operations, runs backward to compute gradients.

Implementations§

Source§

impl<'d> Tape<'d>

Source

pub fn new(dev: &'d GpuDevice) -> Self

Source

pub fn leaf(&mut self, data: &[f32]) -> TensorId

Register a leaf tensor (parameter or input data). No backward through this.

Source

pub fn read(&self, id: TensorId) -> Result<Vec<f32>>

Read tensor data back to CPU.

Source

pub fn read_grad(&self, id: TensorId) -> Result<Option<Vec<f32>>>

Read gradient data back to CPU. Returns None if no gradient computed.

Source

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

Source

pub fn sub(&mut self, a: TensorId, b: TensorId) -> Result<TensorId>

Source

pub fn mul(&mut self, a: TensorId, b: TensorId) -> Result<TensorId>

Source

pub fn scale(&mut self, a: TensorId, s: f32) -> Result<TensorId>

Source

pub fn relu(&mut self, a: TensorId) -> Result<TensorId>

Source

pub fn sigmoid(&mut self, a: TensorId) -> Result<TensorId>

Source

pub fn swish(&mut self, a: TensorId) -> Result<TensorId>

Source

pub fn tanh_act(&mut self, a: TensorId) -> Result<TensorId>

Source

pub fn matmul( &mut self, a: TensorId, b: TensorId, m: u32, n: u32, k: u32, ) -> Result<TensorId>

Source

pub fn mse_loss(&mut self, pred: TensorId, target: TensorId) -> Result<TensorId>

Source

pub fn conv2d( &mut self, input: TensorId, weight: TensorId, bias: Option<TensorId>, batch: u32, in_c: u32, in_h: u32, in_w: u32, out_c: u32, kh: u32, kw: u32, stride: (u32, u32), padding: (u32, u32), dilation: (u32, u32), groups: u32, ) -> Result<TensorId>

Source

pub fn backward(&mut self, loss: TensorId) -> Result<()>

Run backward pass from a loss tensor. Computes gradients for all tensors on the tape.

Auto Trait Implementations§

§

impl<'d> Freeze for Tape<'d>

§

impl<'d> !RefUnwindSafe for Tape<'d>

§

impl<'d> Send for Tape<'d>

§

impl<'d> Sync for Tape<'d>

§

impl<'d> Unpin for Tape<'d>

§

impl<'d> UnsafeUnpin for Tape<'d>

§

impl<'d> !UnwindSafe for Tape<'d>

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<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, 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<T> WasmNotSend for T
where T: Send,

Source§

impl<T> WasmNotSendSync for T

Source§

impl<T> WasmNotSync for T
where T: Sync,