eqiora.torch
Use Eqiora differentiable programs with PyTorch autograd.
View sourceExample: differentiate a scalar objective
Section titled “Example: differentiate a scalar objective”Install the torch extra, then create program with the
differentiation example:
import torchfrom eqiora.torch import bind
operator = bind(program)parameters = (torch.tensor(1.5, dtype=torch.float64, requires_grad=True),)values, = operator(parameters)values.square().sum().backward()print(parameters[0].grad)The gradient is the derivative of the sum of squared output values with
respect to the selected parameter. Inputs are ordered contiguous CPU tensor leaves, with the native signature
shape and float64 or complex128 dtype. See framework adapters for
installation and compiled execution.
TorchProgram
Section titled “TorchProgram”Functional PyTorch view of one Eqiora program, valid in this process.
class TorchProgram: def __init__(self, program: DifferentiableProgram) -> None: ... @property def program(self) -> DifferentiableProgram: ... @property def inputs(self) -> tuple[DifferentiableValueSignature, ...]: ... @property def outputs(self) -> tuple[DifferentiableValueSignature, ...]: ... def __call__(self, parameters: tuple[torch.Tensor, ...] | list[torch.Tensor]) -> tuple[torch.Tensor, ...]: ...Register a program as a PyTorch operator in this process.
def bind(program: DifferentiableProgram) -> TorchProgram: ...