TensorPlay

Latest development documentation · Updated 2026-09-08. A documentation snapshot for package 1.0.0.dev20260909 is not available.

On this page

Functions 14

#

custom_op

functionFull reference ↗
tensorplay.library.custom_op(name: str, fn: Callable[[...], Any] | None = None, /, *, mutates_args: Sequence[str] = (), device_types: Any = None, schema: str | None = None) Callable[[Callable[[...], Any]], CustomOpDef][source]

Example:

@tensorplay.library.custom_op("mylib::weighted_sum", mutates_args=())
def weighted_sum(x, weight):
    return (x * weight).sum()

# Optional extra kernels per device:
@weighted_sum.register_kernel("cuda")
def _(x, weight): ...

fn may also be passed positionally (custom_op("mylib::op", my_fn, mutates_args=())), matching operator’s default kernel for the advertised device_types (every device when omitted).

Parameters:
  • name – Qualified "namespace::name" identifier.

  • fn – Operator body; omit to use the return value as a decorator.

  • mutates_args – Names of arguments the kernel mutates in place. Compile-time fusion treats these as barriers regardless of the value; eager execution trusts the declaration.

  • device_types – Restriction advertised to users at definition time. Kernels are selected per call from whatever was registered via CustomOpDef.register_kernel().

  • schema – Optional schema string kept for introspection and opcheck() (TensorPlay models no schema grammar).

Returns:

A decorator producing a callable CustomOpDef.

#

define

functionFull reference ↗
tensorplay.library.define(qualname: str, schema: str | None = None, *, lib: Any = None, tags: Any = ()) None[source]

Creates the CustomOpDef if absent (kernels are then attached with impl() or Library("ns", "IMPL").impl). tags is Like Library.define, a full "ns::op(Tensor) -> Tensor" string may be pasted as qualname.

#

get_kernel

functionFull reference ↗
tensorplay.library.get_kernel(op: str | CustomOpDef, dispatch_key: str) Callable[[...], Any][source]

dispatch_key accepts "cpu"/"cuda"/"default" and the composite spellings. Raises LookupError when nothing usable is registered (a disabled concrete kernel counts as absent, matching CustomOpDef.set_kernel_enabled() visibility).

#

infer_schema

functionFull reference ↗
tensorplay.library.infer_schema(prototype_function: Callable[[...], Any], /, *, mutates_args: Sequence[str], op_name: str | None = None, tags: Any = ()) str[source]

Produces "ns::op(Tensor self, SymInt n, Tensor(a!) out) -> Tensor" alias-annotation (<type>(<letter>!)) marker. Parameters without annotations are treated as tensors; *args/**kwargs are skipped.

#

opcheck

functionFull reference ↗
tensorplay.library.opcheck(op: str | CustomOpDef, args: tuple[Any, ...], kwargs: dict[str, Any] | None = None, *, test_utils: str | Sequence[str] = ('test_schema', 'test_autograd_registration', 'test_faketensor', 'test_aot_dispatch_dynamic'), raise_exception: bool = True, atol: float | None = None, rtol: float | None = None) dict[str, str][source]

Runs each selected check and reports failures keyed by test name:

  • test_schema: undeclared inputs are left unmutated and no output aliases an input storage (declared-mutation direction is trusted, matching TensorPlay’s declaration-driven fusion barriers).

  • test_autograd_registration: gradients reach every floating input with matching shapes. TensorPlay composes Python kernels implicitly (CompositeImplicitAutograd semantics), so a missing explicit formula is legal — this check catches kernels that break the autograd graph or drop gradients.

  • test_faketensor: the fake kernel reproduces the real outputs’ metadata.

  • test_aot_dispatch_dynamic: capture + execution reproduce the

Returns the failure mapping; empty means all checks passed.

#

register_kernel

functionFull reference ↗
tensorplay.library.register_kernel(op: str | CustomOpDef, device_types: Any = None, func: Callable[[...], Any] | None = None, /, *, lib: Any = None) Callable[[Callable[[...], Any]], Callable[[...], Any]][source]

Accepts a CustomOpDef or a qualified operator name. device_types=None or an empty iterable means the device-agnostic slot; composite spellings (Composite…) map there too. Usable directly or as a decorator.

#

triton_op

functionFull reference ↗
tensorplay.library.triton_op(name: str, fn: Callable[[...], Any] | None = None, /, *, mutates_args: Sequence[str] = (), device_types: Any = None, schema: str | None = None) Callable[[Callable[[...], Any]], CustomOpDef][source]

The registered kernel(s) must launch their Triton kernels through wrap_triton() and only mutate arguments listed in mutates_args. Under tensorplay.compile the whole operator is captured as a single opaque node — the compiler never traces into the Triton launches. device_types is a

#

wrap_triton

functionFull reference ↗
tensorplay.library.wrap_triton(kernel: Any) TritonKernelWrapper[source]

Mark a Triton kernel as launchable from within a triton_op.

Accepts a triton.runtime.jit.JITFunction (the @triton.jit result) or any grid-indexable launcher; idempotent on wrappers.

Classes 1

#

Library

classFull reference ↗
class tensorplay.library.Library(namespace: str, kind: str = 'DEF')[source]

one DEF library per process/namespace), "IMPL" adds kernels, and "FRAGMENT" extends an existing namespace from multiple locations.

define(schema: str, *, alias_analysis: str = '', tags: Any = ()) None[source]

Define an operator from a schema like "ns::add(Tensor, Tensor)".

Only the qualified name is meaningful (TensorPlay models no schema schema strings can be pasted verbatim. alias_analysis and tags are accepted and ignored for call-site compatibility.

fallback(kind: str) None[source]

TensorPlay’s dispatcher has no per-key fallthrough table, so this of silently mis-dispatching.

impl(op_name: str, fn: Callable[[...], Any] | None = None, *, device_type: str = 'CompositeExplicitAutograd', dispatch_key: str = '', allow_override: bool = True) Callable[[...], Any][source]

device_type accepts composite spellings (Composite… → the device-agnostic slot) or concrete devices ("CPU"/"CUDA"); (non-empty wins). May be used directly or as a decorator.

Search documentation

Search all 1,743 documentation pages.

Keyboard shortcuts

Global

  • /Focus search
  • ?This dialog
  • ,Open settings
  • jAI assistant

Search

  • Navigate results
  • Open result
  • escClose

Package

  • mMain information
  • dDocs
  • .Code
  • -Changelog
  • tTimeline
  • sStats
  • vVersions