IMPORTANT: To view this page as Markdown, append `.md` to the URL (e.g. /max/get-started.md). For the complete documentation index, see llms.txt.
Skip to main content
For the complete documentation index, see llms.txt. Markdown versions of all pages are available by appending .md to any URL (e.g. /max/get-started.md).

Mojo function

dispatch_mask

def dispatch_mask[mask_type: String, callback_fn: def[mask_t: MHAMask](mask: mask_t) raises capturing thin -> None, local_window_size: Int = Int(-1)]()

Instantiate an MHAMask by name and invoke a callback with it.

Resolves the mask string to one of the built-in MHAMask implementations at compile time and calls callback_fn with a concrete mask instance. This lets callers write mask-agnostic kernels while still specialising the generated code per mask type.

Parameters:

  • โ€‹mask_type (String): Name of the mask (e.g. "causal", "null", "sliding_window_causal"). Must match one of the MaskName constants.
  • โ€‹callback_fn (def[mask_t: MHAMask](mask: mask_t) raises capturing thin -> None): Parametric callback invoked with the resolved mask.
  • โ€‹local_window_size (Int): Sliding-window or chunk size for masks that require it. Must be -1 for masks that ignore it and positive for masks that require it.

Raises:

Compile-time assertion error if mask_type is unrecognised or if local_window_size is inconsistent with the selected mask.

Was this page helpful?