jax.experimental.pallas.fuser.custom_fusion

jax.experimental.pallas.fuser.custom_fusion#

class jax.experimental.pallas.fuser.custom_fusion(fun)[source]#

Wraps a pure JAX function as a primitive with user-defined fuser rules.

custom_fusion allows defining custom block spec propagation and block-level evaluation rules for an operation so that it can participate in input and output fusions without decomposing into its constituent JAX primitives. Effects are not supported.

Rule registration methods and expected callback signatures:
  • def_eval_rule(fn): Required. fn(ctx: CustomEvalContext, *args) -> Sequence[Any] evaluates the operation on a single block and must return a sequence of flat output leaves (even for a single output).

  • def_pull_block_spec(fn): Required. fn(out_block_transforms: tuple[BlockIndexTransform, ...]) -> Sequence[BlockIndexTransform] propagates output block transforms backward to the inputs.

  • def_push_block_spec(fn): Optional (only needed for output fusions). fn(in_block_specs: tuple[BlockSpec, ...]) -> tuple[BlockSpec, ...] propagates input BlockSpecs forward to the outputs.

  • def_pallas_impl(fn): Optional alternative implementation for use inside a Pallas kernel; must produce the same output abstract values as fun.

Parameters:

fun (Callable[..., Any]) – The pure JAX function defining the operation’s abstract evaluation and default eager/lowering behavior outside of a fused Pallas kernel.

__init__(fun)[source]#
Parameters:

fun (Callable[..., Any])

Methods

__init__(fun)

def_eval_rule(eval_rule)

def_pallas_impl(pallas_impl)

def_pull_block_spec(pull_block_spec_rule)

def_push_block_spec(push_block_spec_rule)

Attributes

eval_rule

pallas_impl

pull_block_spec_rule

push_block_spec_rule

fun