Skip to main content

ValueAndGrad

Struct ValueAndGrad 

Source
pub struct ValueAndGrad<F> { /* private fields */ }
Expand description

Implementations§

Source§

impl<F> ValueAndGrad<F>

Source

pub fn call<P, A, O>(&self, params: &P, args: &A) -> (O::On<Native>, P)
where P: Tree<Native>, A: Tree<Native>, O: Tree<Trace>, F: Fn(P::On<Trace>, A::On<Trace>) -> O,

Computes the value and the gradient with the interpreter.

§Panics

Panics if a parameter is not a float, if the first output is not a float scalar, or if a primitive has no differentiation rule.

Source

pub fn call_xla<P, A, O>( &self, params: &P, args: &A, ) -> Result<(O::On<Native>, P), Error>
where P: Tree<Native>, A: Tree<Native>, O: Tree<Trace>, F: Fn(P::On<Trace>, A::On<Trace>) -> O,

Computes the value and the gradient with XLA.

§Errors

Returns an error if no PJRT plugin is configured, or if compiling or running fails.

§Panics

See ValueAndGrad::call.

Source

pub fn call_traced<P, A, O>(&self, params: P, args: A) -> (O, P)
where P: Tree<Trace>, A: Tree<Trace>, O: Tree<Trace>, F: Fn(P, A) -> O,

Computes the value and the gradient inside another trace: the derivative becomes a jit equation of the outer IR. Values that f captures from the outer trace are not differentiated.

§Panics

See ValueAndGrad::call.

Source

pub fn make_ir<P, A, O>(&self, params: &P, args: &A) -> Function
where P: Tree<Native>, A: Tree<Native>, O: Tree<Trace>, F: Fn(P::On<Trace>, A::On<Trace>) -> O,

Returns the IR of the derivative for inputs shaped like params and args: the outputs of f, then the gradient.

§Panics

See ValueAndGrad::call.

Trait Implementations§

Source§

impl<F> Debug for ValueAndGrad<F>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<F> Freeze for ValueAndGrad<F>
where F: Freeze,

§

impl<F> RefUnwindSafe for ValueAndGrad<F>
where F: RefUnwindSafe,

§

impl<F> Send for ValueAndGrad<F>
where F: Send,

§

impl<F> Sync for ValueAndGrad<F>
where F: Sync,

§

impl<F> Unpin for ValueAndGrad<F>
where F: Unpin,

§

impl<F> UnsafeUnpin for ValueAndGrad<F>
where F: UnsafeUnpin,

§

impl<F> UnwindSafe for ValueAndGrad<F>
where F: 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
§

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

§

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

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.

§

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 = !

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.