ETPPrimitive#
- class braintrace.ETPPrimitive(name)[source]#
A JAX
Primitivewith ETP rule registration helpers.Returned by
register_primitive(). Supports every standard JAX primitive operation (bind,def_impl, …) and adds five convenience methods for installing ETP-specific rules into the global registries.See also
register_primitiveFactory that creates and returns an instance.
Examples
>>> import jax.numpy as jnp >>> import braintrace >>> >>> # Register a primitive whose forward delegates to a standard op. >>> def my_impl(x, w): ... return x @ w >>> my_p = braintrace.register_primitive('etp_demo_mm', my_impl, batched=True) >>> y = my_p.bind(jnp.ones((2, 3)), jnp.ones((3, 4))) >>> print(y.shape) (2, 4)
- register_etp_rules(*, dt_to_t=None, xy_to_dw=None, init_drtrl=None, init_pp=None, fast_path=None, pp_x_repr=None)[source]#
Install multiple ETP rules in one call.
Any argument left as
Noneis skipped.- Parameters:
dt_to_t (
Callable[...,Any] |None) – D-RTRL trace propagation rule. DefaultNone.xy_to_dw (
Callable[...,Any] |None) – Weight-gradient rule. DefaultNone.init_drtrl (
Callable[...,Any] |None) – D-RTRL trace initialiser. DefaultNone.init_pp (
Callable[...,Any] |None) – pp_prop (IO-dim) df trace initialiser. DefaultNone.fast_path (
FastPathRules|None) – Closed-form param-dim D-RTRL fast-path kernel bundle (instant / recurrent / solve kernels plus theapplicablegate). Registered intoETP_FAST_PATH_RULES. Supplied only by primitives with an elementwisedt_to_trule (mm / mv / elemwise);Noneleaves the primitive without a fast path. DefaultNone.pp_x_repr (
Callable[...,Any] |None) – IO-dim x-trace representation rule(x, weight_avals) -> x_repr. Registered intoETP_RULES_PP_X_REPR. Supply it when the rawxis not the operand the op is linear in (e.g.etp_emb_pfilters the one-hot encoding of its integer indices);Noneleaves the IO-dim trace filtering the rawx. DefaultNone.
- Return type: