raptor.protocols.backend

raptor.protocols.backend#

The program-level execution protocol.

program (the argument to Backend.compile()) is typed as a duck (structural) reference to a downstream package’s spec layer — documented here, never imported (raptor depends on nothing). Naming is LOCKED: compile/Executable is the torch.compile / JAX-AOT verb; the internal template-layer .build() word stays distinct and is not used here. vjp/jvp + cotangents/tangents are the JAX/torch.func canonical functional-AD pair; backward is a documented ALIAS of vjp (torch parity) that implementations should also expose, bound to the same method — the capability string itself stays "vjp", never "backward".

A toy implementation, just enough to satisfy the protocol:

class EchoExecutable:
    def forward(self, inputs): return inputs
    def vjp(self, cotangents): raise CapabilityError("vjp not supported")
    def jvp(self, tangents): raise CapabilityError("jvp not supported")
    def parameters(self): return []

class EchoBackend:
    name = "echo"
    def capabilities(self): return frozenset({"forward"})
    def compile(self, program): return EchoExecutable()

Module Attributes

CAPABILITIES

the capability names a Backend/Executable may advertise.

Classes

Backend

A program-level execution substrate.

Executable

A compiled/wired program instance, ready to run.

Exceptions

CapabilityError

Raised when a requested capability is not implemented.