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.grad)The gradient is the derivative of the sum of squared output values with
respect to the selected parameter. Inputs are contiguous, one-dimensional
CPU float64 tensors. 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 input_shape(self) -> tuple[int]: ... @property def output_shape(self) -> tuple[int]: ... def __call__(self, parameters: torch.Tensor) -> torch.Tensor: ...Register a program as a PyTorch operator in this process.
def bind(program: DifferentiableProgram) -> TorchProgram: ...