Skip to main content

Crate tenferro_ad

Crate tenferro_ad 

Source
Expand description

Automatic differentiation APIs for tenferro.

This crate is the explicit opt-in boundary for traced and eager automatic differentiation. Primal graph construction and execution live in tenferro-runtime; tensor storage lives in tenferro-tensor, and CPU execution lives in tenferro-cpu.

Use EagerRuntime and EagerTensor for PyTorch-style immediate execution where tracked variables accumulate gradients after backward(). Use TracedTensorAdExt or AdContext for JAX-style graph transforms such as grad, vjp, and jvp on tenferro_runtime::TracedTensor values. AdContext is the explicit place to add extension AD rule sets for operation-family crates such as tenferro-linalg.

User-facing guides live at https://tensor4all.org/tenferro-rs/guides/autodiff.html and https://tensor4all.org/tenferro-rs/guides/choosing-an-api.html.

§Examples

use tenferro_ad::AdContext;
use tenferro_runtime::TracedTensor;

let ad = AdContext::builder().build().unwrap();
let x = TracedTensor::from_vec_col_major(vec![], vec![3.0_f64]).unwrap();
let loss = (&x * &x).unwrap();
let dx = ad.grad(&loss, &x).unwrap();
assert_eq!(dx.rank, 0);

Re-exports§

pub use traced::TracedTensorAdExt;

Modules§

error
extension
Eager AD support for out-of-tree extension primitives.
traced

Structs§

AdContext
Explicit automatic-differentiation context.
AdContextBuilder
Builder for AdContext.
ContextId
Opaque identifier for an eager AD runtime, used in Error::ContextMismatch.
DotGeneralConfig
DotGeneral dimension configuration.
EagerRuntime
Shared eager execution context for tensors on a backend.
EagerRuntimeCacheStats
Stats for caches owned by an EagerRuntime.
EagerTensor
Eager tensor with reverse-mode autodiff over concrete tensor values.
GatherConfig
StableHLO gather dimension configuration.
PadConfig
StableHLO pad configuration.
ScatterConfig
StableHLO scatter dimension configuration.
SliceConfig
Slice configuration.

Enums§

CompareDir
Comparison direction.
DType
Runtime scalar dtype tag.
EagerBackend
Error
Errors produced by einsum, eval, and other tenferro operations.
Tensor
Dynamic tensor enum over the supported scalar types.

Type Aliases§

Result
Result type alias for tenferro operations.