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_fusionallows 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 inputBlockSpecsforward to the outputs.def_pallas_impl(fn): Optional alternative implementation for use inside a Pallas kernel; must produce the same output abstract values asfun.
- 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.
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_rulepallas_implpull_block_spec_rulepush_block_spec_rulefun