latest (dev)
Copy
Latest development documentation · Updated 2026-11-18
tensorplay.compiler
Shape policy
A compile call chooses how tensor extents are treated:
With no shape argument, capture fixes the example sizes. If a later call misses only because a size changed (and nothing else in the guard set did), the frontend clears the concrete specialization and captures the region again with every extent that is not 0 or 1 symbolic, so one artifact then serves the sizes already seen and the ones that follow. This upgrade needs a backend that declares
supports_symbolic_shapesand is controlled bytensorplay.compiler.config.automatic_dynamic_shapes.dynamic=Truecaptures extents symbolically from the first call. It keeps the rank in the specialization key and lets the backend accept the shape range.dynamic_shapesnames the axes that may vary, per argument:tensorplay.compile( fn, dynamic_shapes={"x": {0: tensorplay.export.Dim("batch")}}, )Unnamed axes keep the example size and are checked before a cached region runs, so changing one creates a new specialization instead of silently reusing a region sized for the example. A dimension may carry
min/maxbounds; an example outside them is rejected before capture. The specification needs a backend that declaressupports_symbolic_shapes.
tensorplay.compiler.mark_static(tensor, dim=None) pins a tensor’s extents (or
one axis) to the example sizes. Called before compile, it removes those axes
from the shape policy; called inside the captured function, it makes reads of
that extent answer with the example size and keeps a condition on it, so a
changed size recompiles rather than reusing a region that assumed the old one.
tensorplay.compiler.disallow_in_graph(fn) declares that a callable must not
be absorbed into a captured region. A capture that reaches it raises
GraphCaptureError instead of recording the call: the region is one graph, so
there is no partial capture to resume after the call, and recording a call
whose effect the graph cannot carry would repeat that effect once per compiled
call.
Autograd limitations
In v1.1.0, regions compiled with STAX or an AOT autograd backend support
first-order reverse-mode gradients. They do not support second-order gradients
(double backward). A first gradient computed with create_graph=True has the
correct value, but differentiating it again raises RuntimeError with an
explicit message about this limitation.
Run the original function without compilation when computing Hessians, Hessian-vector products, or other higher-order derivatives. Operator support for higher-order gradients in eager execution does not extend to compiled regions.
Classes
Raised when Python code cannot be represented by the current graph. |
|
A backend name that no registered, built-in or entry-point backend owns. |
|
Backend selections for a nested compiler region. |
Functions
Capture a callable as one graph operation without entering its body. |
|
Declare that a callable returns one stable value across captures. |
|
Compile a callable through the TensorPlay capture and lowering pipeline. |
|
Declare that a callable must not be absorbed into a captured graph. |
|
Prevent capture from entering a callable. |
|
Suspend the public capture state for a dynamic Python region. |
|
Mark a module method as an entry point visible to graph capture. |
|
Return the |
|
Return the currently selected default backend. |
|
Return whether the current Python frame is being captured. |
|
Return whether an export capture session is active. |
|
Return registered backend names accepted by |
|
Return the optimization options each compile |
|
Resolve a backend name or validate a backend callable. |
|
Mark a tensor (or one dimension of it) as fixed for shape policies. |
|
Mark a callable as a reusable nested graph region. |
|
Capture a callable as an opaque operation with structured arguments. |
|
Mark a method declaration as an overload during inspection. |
|
Register a backend in the TensorPlay compiler registry. |
|
Register a backend tagged for diagnostics. |
|
Register a backend tagged for experimental use. |
|
Clear compiler specializations and capture-time constant values. |
|
Set the backend used when |
|
Register a graph-time implementation for a callable. |
|
Remove a named backend from the compiler registry. |
|
Mark a callable as an eager-only helper. |
Help improve this page
Found an error, an unclear step, or a missing example?

