# tensorplay.compiler API Source: https://www.tensorplay.cn/docs/api/tensorplay.compiler.html ## Functions 26 [#](#api-tensorplay.compiler.allow_in_graph) ### allow_in_graph function[Full reference ↗](/docs/generated/tensorplay.compiler.allow_in_graph.html) ```python tensorplay.compiler.allow_in_graph(fn: Any) → Any ``` Capture a callable as one graph operation without entering its body. [#](#api-tensorplay.compiler.assume_constant_result) ### assume_constant_result function[Full reference ↗](/docs/generated/tensorplay.compiler.assume_constant_result.html) ```python tensorplay.compiler.assume_constant_result(fn: Callable[[...], Any]) → Callable[[...], Any] ``` Declare that a callable returns one stable value across captures. [#](#api-tensorplay.compiler.compile) ### compile function[Full reference ↗](/docs/generated/tensorplay.compiler.compile.html) ```python tensorplay.compiler.compile(model: Callable[[...], Any] | None = None, *, fullgraph: bool = False, dynamic: bool | None = None, backend: str | Callable[[...], Any] | None = None, mode: str | None = None, options: dict[str, Any] | None = None, name: str | None = None, disable: bool = False, recompile_limit: int | None = None, isolate_recompiles: bool = False, strict_native: bool = False, dynamic_shapes: Any = None) → Callable[[...], Any] ``` Compile a callable through the TensorPlay capture and lowering pipeline. [#](#api-tensorplay.compiler.disable_capture) ### disable_capture function[Full reference ↗](/docs/generated/tensorplay.compiler.disable_capture.html) ```python tensorplay.compiler.disable_capture() → Iterator[None] ``` Suspend the public capture state for a dynamic Python region. [#](#api-tensorplay.compiler.disable) ### disable function[Full reference ↗](/docs/generated/tensorplay.compiler.disable.html) ```python tensorplay.compiler.disable(fn: Callable[[_P], _R] | None = None, recursive: bool = True, *, reason: str | None = None) → Any ``` Prevent capture from entering a callable. [#](#api-tensorplay.compiler.disallow_in_graph) ### disallow_in_graph function[Full reference ↗](/docs/generated/tensorplay.compiler.disallow_in_graph.html) ```python tensorplay.compiler.disallow_in_graph(fn: Callable[[...], Any]) → Callable[[...], Any] ``` Declare that a callable must not be absorbed into a captured graph. The tracer is meant to treat calls to fn as region boundaries: the surrounding pieces are captured as separate graphs and fn itself runs eagerly between them. Under eager execution the marker is inert metadata, so the callable is returned unchanged. [#](#api-tensorplay.compiler.export) ### export function[Full reference ↗](/docs/generated/tensorplay.compiler.export.html) ```python tensorplay.compiler.export(fn: Callable[[...], Any] | None = None) → Any ``` Mark a module method as an entry point visible to graph capture. [#](#api-tensorplay.compiler.get_backend_capabilities) ### get_backend_capabilities function[Full reference ↗](/docs/generated/tensorplay.compiler.get_backend_capabilities.html) ```python tensorplay.compiler.get_backend_capabilities(backend: str | Callable[[...], Any]) → Any ``` Return the BackendCapabilities a backend declares. [#](#api-tensorplay.compiler.get_default_backend) ### get_default_backend function[Full reference ↗](/docs/generated/tensorplay.compiler.get_default_backend.html) ```python tensorplay.compiler.get_default_backend() → str | Callable[[...], Any] ``` Return the currently selected default backend. [#](#api-tensorplay.compiler.is_compiling) ### is_compiling function[Full reference ↗](/docs/generated/tensorplay.compiler.is_compiling.html) ```python tensorplay.compiler.is_compiling() → bool ``` Return whether the current Python frame is being captured. [#](#api-tensorplay.compiler.is_exporting) ### is_exporting function[Full reference ↗](/docs/generated/tensorplay.compiler.is_exporting.html) ```python tensorplay.compiler.is_exporting() → bool ``` Return whether an export capture session is active. [#](#api-tensorplay.compiler.list_backends) ### list_backends function[Full reference ↗](/docs/generated/tensorplay.compiler.list_backends.html) ```python tensorplay.compiler.list_backends(exclude_tags: tuple[str, ...] | list[str] | None = ('debug', 'experimental'), *, include_unavailable: bool = False) → list[str] ``` Return registered backend names accepted by [compile()](/docs/generated/tensorplay.compiler.compile.html#tensorplay.compiler.compile). Backends whose optional dependencies are missing are hidden unless include_unavailable is set; selecting one by name produces an error naming what to install. [#](#api-tensorplay.compiler.list_mode_options) ### list_mode_options function[Full reference ↗](/docs/generated/tensorplay.compiler.list_mode_options.html) ```python tensorplay.compiler.list_mode_options(mode: str | None = None) → dict[str, Any] ``` Return the optimization options each compile mode selects. With mode set, returns that mode’s option patch; with mode unset, returns the full mode-to-options mapping. Unknown modes raise. [#](#api-tensorplay.compiler.lookup_backend) ### lookup_backend function[Full reference ↗](/docs/generated/tensorplay.compiler.lookup_backend.html) ```python tensorplay.compiler.lookup_backend(backend: str | Callable[[...], Any]) → Callable[[...], Any] ``` Resolve a backend name or validate a backend callable. [#](#api-tensorplay.compiler.mark_static) ### mark_static function[Full reference ↗](/docs/generated/tensorplay.compiler.mark_static.html) ```python tensorplay.compiler.mark_static(tensor: Any, dim: int | None = None) → Any ``` Mark a tensor (or one dimension of it) as fixed for shape policies. A marked dimension is meant to be treated as a compile-time constant rather than a symbolic size. Eager execution has no dynamic shape environment, so the marker records nothing here and the input is returned unchanged; it matters only to a capture that resolves symbolic sizes. [#](#api-tensorplay.compiler.nested_compile_region) ### nested_compile_region function[Full reference ↗](/docs/generated/tensorplay.compiler.nested_compile_region.html) ```python tensorplay.compiler.nested_compile_region(fn: Callable[[_P], _R] | None = None, *, options: Any = None, max_reuse_entries: int = 8, reuse_hash_fn: Callable[[...], Any] | None = None) → Any ``` Mark a callable as a reusable nested graph region. [#](#api-tensorplay.compiler.nonstrict_trace) ### nonstrict_trace function[Full reference ↗](/docs/generated/tensorplay.compiler.nonstrict_trace.html) ```python tensorplay.compiler.nonstrict_trace(traceable_fn: Callable[[_P], _R]) → Callable[[_P], _R] ``` Capture a callable as an opaque operation with structured arguments. [#](#api-tensorplay.compiler.overload_method) ### overload_method function[Full reference ↗](/docs/generated/tensorplay.compiler.overload_method.html) ```python tensorplay.compiler.overload_method(fn: Callable[[...], Any]) → Callable[[...], Any] ``` Mark a method declaration as an overload during inspection. [#](#api-tensorplay.compiler.register_backend) ### register_backend function[Full reference ↗](/docs/generated/tensorplay.compiler.register_backend.html) ```python tensorplay.compiler.register_backend(*args: Any, **kwargs: Any) → Any ``` Register a backend in the TensorPlay compiler registry. [#](#api-tensorplay.compiler.register_debug_backend) ### register_debug_backend function[Full reference ↗](/docs/generated/tensorplay.compiler.register_debug_backend.html) ```python tensorplay.compiler.register_debug_backend(*args: Any, **kwargs: Any) → Any ``` Register a backend tagged for diagnostics. [#](#api-tensorplay.compiler.register_experimental_backend) ### register_experimental_backend function[Full reference ↗](/docs/generated/tensorplay.compiler.register_experimental_backend.html) ```python tensorplay.compiler.register_experimental_backend(*args: Any, **kwargs: Any) → Any ``` Register a backend tagged for experimental use. [#](#api-tensorplay.compiler.reset) ### reset function[Full reference ↗](/docs/generated/tensorplay.compiler.reset.html) ```python tensorplay.compiler.reset() → None ``` Clear compiler specializations and capture-time constant values. [#](#api-tensorplay.compiler.set_default_backend) ### set_default_backend function[Full reference ↗](/docs/generated/tensorplay.compiler.set_default_backend.html) ```python tensorplay.compiler.set_default_backend(backend: str | Callable[[...], Any] | None) → None ``` Set the backend used when [compile()](/docs/generated/tensorplay.compiler.compile.html#tensorplay.compiler.compile) receives no backend name. [#](#api-tensorplay.compiler.substitute_in_graph) ### substitute_in_graph function[Full reference ↗](/docs/generated/tensorplay.compiler.substitute_in_graph.html) ```python tensorplay.compiler.substitute_in_graph(original_fn: Callable[[_P], _R], *, can_constant_fold_through: bool = False, skip_signature_check: bool = False) → Callable[[Callable[[_P], _R]], Callable[[_P], _R]] ``` Register a graph-time implementation for a callable. [#](#api-tensorplay.compiler.unregister_backend) ### unregister_backend function[Full reference ↗](/docs/generated/tensorplay.compiler.unregister_backend.html) ```python tensorplay.compiler.unregister_backend(name: str) → None ``` Remove a named backend from the compiler registry. [#](#api-tensorplay.compiler.unused) ### unused function[Full reference ↗](/docs/generated/tensorplay.compiler.unused.html) ```python tensorplay.compiler.unused(fn: Callable[[...], Any]) → Callable[[...], Any] ``` Mark a callable as an eager-only helper. ## Classes 1 [#](#api-tensorplay.compiler.NestedCompileRegionOptions) ### NestedCompileRegionOptions class[Full reference ↗](/docs/generated/tensorplay.compiler.NestedCompileRegionOptions.html) ```python class tensorplay.compiler.NestedCompileRegionOptions(fw_compiler: Callable[[...], Any] | None = None, bw_compiler: Callable[[...], Any] | None = None) ``` Backend selections for a nested compiler region. ## Exceptions 2 [#](#api-tensorplay.compiler.GraphCaptureError) ### GraphCaptureError exception[Full reference ↗](/docs/generated/tensorplay.compiler.GraphCaptureError.html) ```python exception tensorplay.compiler.GraphCaptureError ``` Raised when Python code cannot be represented by the current graph. [#](#api-tensorplay.compiler.InvalidBackend) ### InvalidBackend exception[Full reference ↗](/docs/generated/tensorplay.compiler.InvalidBackend.html) ```python exception tensorplay.compiler.InvalidBackend(name: str, suggestions: Sequence[str] | None = None) ``` A backend name that no registered, built-in or entry-point backend owns. Derives from ValueError (what unknown names raised historically) and RuntimeError (the compiler error family), so either handler works.