Skip to main content

flash_attention2_forward

Function flash_attention2_forward 

Source
pub fn flash_attention2_forward<T: Triton, D: Float, const HEAD_DIM: i32>(
    q_ptr: T::Pointer<D>,
    k_ptr: T::Pointer<D>,
    v_ptr: T::Pointer<D>,
    o_ptr: T::Pointer<D>,
    l_ptr: T::Pointer<D>,
    n_ctx_q: i32,
    n_ctx_k: i32,
    softmax_scale: f32,
    neg_inf: f32,
)
where T::I32Tensor: Tensor<i32, 1> + Comparison<i32, BoolTensor = T::BoolTensor>, T::Pointer<D>: AddOffsets<i32, 1, T::I32Tensor, Output = T::Tensor<T::Pointer<D>>>,
Expand description

Flash Attention 2 forward pass.

Inputs (all [BH, N_CTX, HEAD_DIM] row-major, where BH = BATCH * N_HEADS): q_ptr, k_ptr, v_ptr

Outputs: o_ptr — attention output [BH, N_CTX_Q, HEAD_DIM] l_ptr — log-sum-exp [BH, N_CTX_Q] (saved for backward)

Grid: (N_CTX_Q, BH, 1) — one CTA per (batch_head, q_row) pair.