Use eagle with other frameworks

Use eagle with other frameworks#

eagle fits into the program you already have, in both directions. One page per framework shows each.

Your framework calls eagle

eagle runs your framework

In one line

a hawk kernel replaces one step of your program

your model or kernels run as a node, once per step over a whole batch

You keep

your loop, optimizer and transformations

your model, its weights and its gradients

Where to look

the first sections of each page below

the inside-an-eagle-batch section of each page below, and the three tiers

Pass a NumPy array, a CuPy array, a PyTorch tensor, a JAX array or a Warp array; the buffer crosses through DLPack, without a copy where the device allows, and the result comes back in the framework you came from.

  • PyTorch: a kernel inside loss.backward(), torch.compile, torch.func and CUDA graphs; your nn.Module as a node in a stepping loop.

  • JAX: a kernel inside jit, grad, vmap and lax.scan; a jitted step as a node. Then three short tutorials: a training step, batches and Jacobians, a stepping loop.

  • CuPy and NumPy: arrays in, arrays out; your array code as a node between kernels.

  • NVIDIA Warp: wp.array in, a launch next to your Warp kernels; your launches or captured graph as a node.

Colab or Kaggle: run this first cell (it installs the packages and downloads the helper files this notebook uses). Elsewhere it only checks the imports.

Hide code cell source

# Colab setup, generated by python -m raptor_docs.nb colab_setup (do not edit).
import os

try:
    import google.colab  # noqa: F401
    HOSTED = True  # a Colab runtime
except ImportError:
    HOSTED = "KAGGLE_KERNEL_RUN_TYPE" in os.environ  # a Kaggle kernel

if HOSTED:
    import importlib.metadata, pathlib, re, shutil, subprocess, sys, urllib.request

    gpu = bool(shutil.which("nvidia-smi")) and subprocess.run(["nvidia-smi", "-L"], capture_output=True).returncode == 0
    extra = ""
    if gpu:
        # the CUDA major the runtime already has: a CuPy that is installed, else torch's, else the driver's
        major = None
        for m in ("13", "12"):
            try:
                importlib.metadata.version(f"cupy-cuda{m}x")
                major = m
                break
            except importlib.metadata.PackageNotFoundError:
                pass
        if major is None:
            try:
                import torch
                major = "13" if str(torch.version.cuda).startswith("13") else None
            except ImportError:
                pass
        if major is None:
            smi = re.search(r"CUDA Version: (\d+)", subprocess.run(["nvidia-smi"], capture_output=True, text=True).stdout)
            major = "13" if smi and int(smi.group(1)) >= 13 else "12"
        extra = f"[cuda{major}]"
        print(f"GPU found: installing the {extra} extras to match this runtime.")
    pre = ["--pre"] if os.environ.get("RAPTOR_PRE") else []  # optional: test a release candidate
    ref = os.environ.get("RAPTOR_REF", "main")  # optional: fetch the helper files from this git ref
    if pre or "RAPTOR_REF" in os.environ:
        print(f"Pre-release test: installing with --pre, helper files from {ref}.")
    # our packages with --upgrade, so a runtime that kept an older release gets the current one
    subprocess.check_call([sys.executable, "-m", "pip", "install", "-q", "--upgrade", *pre, "raptor-core"])
    if not gpu:
        print("Running on the CPU (no GPU in this runtime). For a GPU: " + ("Settings → Accelerator → GPU T4 x2." if "KAGGLE_KERNEL_RUN_TYPE" in os.environ else "Runtime → Change runtime type → T4 GPU."))

try:
    import raptor  # noqa: F401
except ImportError as err:
    raise ImportError(
        "raptor not found. Install with `pip install raptor-core`."
    ) from err

What’s certified today#

raptor’s interop certification matrix is the family’s single source of truth for which (framework, kind) combinations are exercised end to end — see the interoperability protocols reference. The table below is generated from that matrix, not typed by hand, so it cannot drift from it.

from raptor.conformance import interop as _interop

_KINDS = {"ALIAS": "zero-copy", "COPY": "copies once", "STREAM": "stream-ordered"}
rows = sorted(
    (d.framework, _KINDS[d.kind])
    for d in _interop.ROWS.values()
    if d.framework in _interop.CERTIFIED and d.kind in _KINDS
)
print(f"{'framework':<10} {'crossing'}")
for framework, kind in rows:
    print(f"{framework:<10} {kind}")
framework  crossing
cupy       stream-ordered
cupy       zero-copy
cupy       zero-copy
jax        copies once
jax        stream-ordered
jax        stream-ordered
jax        stream-ordered
jax        stream-ordered
jax        zero-copy
jax        zero-copy
jax        zero-copy
jax        zero-copy
numpy      copies once
numpy      zero-copy
torch      copies once
torch      copies once
torch      stream-ordered
torch      stream-ordered
torch      stream-ordered
torch      stream-ordered
torch      stream-ordered
torch      zero-copy
torch      zero-copy
torch      zero-copy
torch      zero-copy
torch      zero-copy
torch      zero-copy
warp       stream-ordered
warp       zero-copy
warp       zero-copy

Gradients, certified#

The same matrix certifies derivatives: each framework’s own machinery is run through an eagle kernel and compared with the same law written in that framework alone.

  • JAX: grad, jit(grad), vmap(grad), jacfwd and jacrev (tutorials 12 and 13).

  • PyTorch: backward with gradcheck (forward AD included), and torch.func.grad, jvp and vmap (tutorial 3).

  • NVIDIA Warp: wp.Tape, against finite differences (tutorial 16).

  • Through your own code in an eagle graph: your node’s vjp joins the reverse (tutorial 10).

  • NumPy and CuPy have no autodiff; their rows certify the hand-over. Write the vjp yourself and pass it as vjps=.

The rows, read from the matrix:

grad_rows = sorted((d.framework or "-", row) for row, d in _interop.ROWS.items() if "-GRAD-" in row or "VJP" in row)
for framework, row in grad_rows:
    print(f"{framework:<8} {row}")
jax      JX-GRAD-TRANSFORMS
torch    INJ-RUN-VJP
torch    INJ-VJP-CHAIN
torch    T-GRAD-AUTOGRAD
torch    T-GRAD-FUNC
warp     WP-GRAD-TAPE

Roadmap

TensorFlow/Keras, and any other DLPack-capable framework are foreseen — eagle.interop.detect already recognizes a bare DLPack producer — but are not yet certified by raptor’s interop matrix. Treat only the frameworks in the table above as supported until a row for a new one lands there.