For the complete documentation index, see llms.txt. Markdown versions of all pages are available by appending .md to any URL (e.g. /get-started.md).
Mojo function
naive_fa_decode_apple
def naive_fa_decode_apple[output_type: DType, k_t: MHAOperand, v_t: MHAOperand, mask_t: MHAMask, //, ragged: Bool = False, sink: Bool = False, _use_valid_length: Bool = False, _is_cache_length_accurate: Bool = False](q: LayoutTensor[element_layout=q.element_layout, layout_int_type=q.layout_int_type, linear_idx_type=q.linear_idx_type, masked=q.masked, alignment=q.alignment], k: k_t, v: v_t, mask_functor: mask_t, output: LayoutTensor[output_type, element_layout=output.element_layout, layout_int_type=output.layout_int_type, linear_idx_type=output.linear_idx_type, masked=output.masked, alignment=output.alignment], valid_length: LayoutTensor[DType.uint32, element_layout=valid_length.element_layout, layout_int_type=valid_length.layout_int_type, linear_idx_type=valid_length.linear_idx_type, masked=valid_length.masked, alignment=valid_length.alignment], scale: Float32, batch_size: Int, max_prompt_len: Int, max_cache_size: Int, num_heads: Int, depth: Int, group: Int, ctx: DeviceContext, sink_weights: OptionalReg[LayoutTensor[q.dtype, Layout.row_major(Int(-1)), ImmutAnyOrigin]] = None)
Host launcher for the Apple split-K decode attention pair (decode-only).
Parameters:
- output_type (
DType): The element type of theoutputtensor (inferred). Unused by the kernels; mirrorsmha_gpu_naivefor dispatch uniformity. - k_t (
MHAOperand): TheMHAOperandtype of the key cache operand (inferred). - v_t (
MHAOperand): TheMHAOperandtype of the value cache operand (inferred). - mask_t (
MHAMask): TheMHAMaskfunctor type applied to attention scores (inferred). - ragged (
Bool): Whether sequences are ragged with variable lengths and row offsets invalid_length(defaults toFalse). - sink (
Bool): Whether attention sink is enabled, pre-seeding split 0 with per-head sink weights (defaults toFalse). - _use_valid_length (
Bool): Whether to usevalid_lengthfor KVCache decode as per-sequence query lengths (defaults toFalse). - _is_cache_length_accurate (
Bool): Whether the cache length equals the query length, so no new-token KV is added (defaults toFalse).
Args:
- q (
LayoutTensor[element_layout=q.element_layout, layout_int_type=q.layout_int_type, linear_idx_type=q.linear_idx_type, masked=q.masked, alignment=q.alignment]): The query tensor; one token per sequence (decode). - k (
k_t): The key cache operand implementing theMHAOperandcontract. - v (
v_t): The value cache operand implementing theMHAOperandcontract. - mask_functor (
mask_t): The mask functor applied to each attention score. - output (
LayoutTensor[output_type, element_layout=output.element_layout, layout_int_type=output.layout_int_type, linear_idx_type=output.linear_idx_type, masked=output.masked, alignment=output.alignment]): The output tensor; written by the stitch kernel with the normalized attention output. - valid_length (
LayoutTensor[DType.uint32, element_layout=valid_length.element_layout, layout_int_type=valid_length.layout_int_type, linear_idx_type=valid_length.linear_idx_type, masked=valid_length.masked, alignment=valid_length.alignment]): Per-sequence row offsets or query lengths (uint32); meaning depends onraggedand_use_valid_length. - scale (
Float32): The softmax scale factor applied toQ.K^Tscores. - batch_size (
Int): Number of sequences in the batch. - max_prompt_len (
Int): Maximum prompt length; the dense decode path's query length. - max_cache_size (
Int): Full key count for the dense decode path (the K tensor's seq dim). - num_heads (
Int): Number of query attention heads. - depth (
Int): Head dimension; must be a multiple ofWARP_SIZEand at mostNAIVE_FA_DECODE_APPLE_MAX_HEAD_DIM. - group (
Int): Number of query heads per KV head (GQA group size). - ctx (
DeviceContext): The device context used to enqueue kernels and allocate partial buffers. - sink_weights (
OptionalReg[LayoutTensor[q.dtype, Layout.row_major(Int(-1)), ImmutAnyOrigin]]): Per-head sink weights (shape[num_heads]); read only whensinkisTrue(defaults toNone).