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): ...fnmay also be passed positionally (custom_op("mylib::op", my_fn, mutates_args=())), matching operator’s default kernel for the advertiseddevice_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
CustomOpDefif absent (kernels are then attached withimpl()orLibrary("ns", "IMPL").impl).tagsis LikeLibrary.define, a full"ns::op(Tensor) -> Tensor"string may be pasted asqualname.
get_kernel
functionFull reference ↗- tensorplay.library.get_kernel(op: str | CustomOpDef, dispatch_key: str) Callable[[...], Any][source]
dispatch_keyaccepts"cpu"/"cuda"/"default"and the composite spellings. RaisesLookupErrorwhen nothing usable is registered (a disabled concrete kernel counts as absent, matchingCustomOpDef.set_kernel_enabled()visibility).
impl_abstract
functionFull reference ↗impl
functionFull reference ↗- tensorplay.library.impl(qualname: str, types: Any, func: Callable[[...], Any] | None = None, /, *, lib: Any = None) Callable[[...], Any] | Callable[[Callable[[...], Any]], Callable[[...], Any]][source]
typesaccepts concrete devices ("CPU"/"CUDA") or composite spellings (CompositeExplicitAutograd→ the device-agnostic slot).
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/**kwargsare 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_autocast
functionFull reference ↗register_autograd
functionFull reference ↗register_fake
functionFull reference ↗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
CustomOpDefor a qualified operator name.device_types=Noneor an empty iterable means the device-agnostic slot; composite spellings (Composite…) map there too. Usable directly or as a decorator.
register_vmap
functionFull reference ↗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 inmutates_args. Undertensorplay.compilethe whole operator is captured as a single opaque node — the compiler never traces into the Triton launches.device_typesis a
wrap_triton
functionFull reference ↗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_analysisandtagsare 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_typeaccepts composite spellings (Composite…→ the device-agnostic slot) or concrete devices ("CPU"/"CUDA"); (non-empty wins). May be used directly or as a decorator.

