pub struct EagerTraceCaptureGuard { /* private fields */ }Expand description
Scope guard that keeps semantic-trace recording active for untracked intermediates.
Under active-edge semantics (issue #1665 Def 1), an operation whose inputs are all untracked produces no autograd nodes and drops its semantic trace. Inside this guard, such operations still record their semantic trace, so a later functional JVP/VJP can differentiate with respect to an untracked or detached leaf. This replaces the pre-Def-1 implicit recording.
§Examples
use tenferro_ad::{EagerRuntime, EagerTensor, Tensor};
use tenferro_cpu::CpuBackend;
let ctx = EagerRuntime::with_cpu_backend(CpuBackend::new())?;
let x = EagerTensor::from_tensor_in(
Tensor::from_vec_col_major(vec![2], vec![1.0_f64, 2.0]).unwrap(),
ctx.clone(),
)?;
let (y, x) = {
let _capture = ctx.capture_trace();
let y = x.mul(&x)?;
(y, x)
};
let seed = EagerTensor::from_tensor_in(
Tensor::from_vec_col_major(vec![2], vec![1.0_f64, 1.0]).unwrap(),
ctx.clone(),
)?;
let dx = ctx.vjp(&y, &x, &seed)?;
assert_eq!(dx.value()?.as_slice::<f64>().unwrap(), &[2.0, 4.0]);Trait Implementations§
Source§impl Debug for EagerTraceCaptureGuard
impl Debug for EagerTraceCaptureGuard
Source§impl Drop for EagerTraceCaptureGuard
impl Drop for EagerTraceCaptureGuard
Auto Trait Implementations§
impl !Send for EagerTraceCaptureGuard
impl !Sync for EagerTraceCaptureGuard
impl Freeze for EagerTraceCaptureGuard
impl RefUnwindSafe for EagerTraceCaptureGuard
impl Unpin for EagerTraceCaptureGuard
impl UnsafeUnpin for EagerTraceCaptureGuard
impl UnwindSafe for EagerTraceCaptureGuard
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
impl<T, U> Imply<T> for U
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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