Skip to main content

GradientExecutor

Trait GradientExecutor 

Source
pub trait GradientExecutor {
    // Required method
    fn compute_gradient(
        &self,
        op: &str,
        inputs: &[Tensor<f64>],
    ) -> Result<Vec<Tensor<f64>>>;
}
Expand description

Bridges tenflowers-core’s gradient validation framework to a real forward+backward implementation living in a higher-level crate (normally tenflowers-autograd).

Implementations always operate in f64, regardless of the dtype under test in crate::gradient_validation_framework::GradientTestCase: f64 has enough precision to be a safe universal choice for a validation/testing framework, and keeping the trait monomorphic avoids needing a type-erased/generic trait object design for this bridge.

Required Methods§

Source

fn compute_gradient( &self, op: &str, inputs: &[Tensor<f64>], ) -> Result<Vec<Tensor<f64>>>

Compute the gradient(s) of op applied to inputs, with respect to each element of inputs, in order.

Returns one gradient tensor per input, each with the same shape as its corresponding input tensor. Returns Err if op is not recognized by this executor, or if the gradient computation itself fails – never fabricates a placeholder result.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§