Command Palette

Search for a command to run...

UnylyUnyly
Назад к скиллам

flashkda-delta-attention

БесплатноБез исполняемых скриптовНе проверен

High-performance Kimi Delta Attention CUDA kernels built on CUTLASS for efficient recurrent state inference

reason-machinesот reason-machines★ 99 звёзд на GitHub

Об этом скилле

FlashKDA Delta Attention Skill

Skill by ara.so — Daily 2026 Skills collection.

FlashKDA provides high-performance CUDA kernels for Kimi Delta Attention (KDA) built on CUTLASS. It targets SM90+ GPUs (H100/H20 class) and integrates as a drop-in backend for flash-linear-attention's chunk_kda operation.

Requirements

  • GPU: SM90+ (H100, H20, or newer)
  • CUDA 12.9+
  • PyTorch 2.4+
  • Python 3.8+

Installation

git clone https://github.com/MoonshotAI/FlashKDA.git flash-kda
cd flash-kda
git submodule update --init --recursive
pip install -v .

Install the FLA integration (optional but recommended):

pip install -U flash-linear-attention  # >= 0.5.0

Core Kernel API

flash_kda.fwd

The primary low-level kernel call:

import torch
import flash_kda

flash_kda.fwd(
    q, k, v, g, beta, scale, out,
    A_log, dt_bias, lower_bound,
    initial_state=None,
    final_state=None,
    cu_seqlens=None
)

Tensor shapes and dtypes:

Parameter Dtype Shape Notes
q bf16 [B, T, H, K] Query; K must be 128
k bf16 [B, T, H, K] Key; K must be 128
v bf16 [B, T, H, V] Value; V must be 128
g bf16 [B, T, H, K] Gate logits (sigmoid/activation applied internally)
beta bf16 [B, T, H] Beta logits (sigmoid applied internally)
scale float scalar Attention scale factor
out bf16 [B, T, H, V] Pre-allocated output tensor
A_log fp32 [H] Per-head log-gate parameter
dt_bias fp32 [H, K] Per-head gate bias
lower_bound float scalar Gate lower bound, range [-5.0, 0]
initial_state bf16/fp32/None [B, H, V, K] or [N, H, V, K] Optional initial recurrent state
final_state bf16/fp32/None [B, H, V, K] or [N, H, V, K] Optional output final state
cu_seqlens int64 [N+1] Optional cumulative seq lengths for varlen

Constraints:

  • K == V == 128 required
  • When cu_seqlens is provided, B must be 1 and T is total tokens across all sequences
  • initial_state and final_state dtypes must match when both provided

Usage via flash-linear-attention Backend (Recommended)

FlashKDA auto-dispatches from FLA's chunk_kda when installed:

import torch
import logging
from fla.ops.kda import chunk_kda

# Optional: see dispatch decisions
logging.basicConfig(level=logging.INFO)

B, T, H, K, V = 2, 2048, 16, 128, 128

q     = torch.randn(B, T, H, K,  dtype=torch.bfloat16, device='cuda')
k     = torch.randn(B, T, H, K,  dtype=torch.bfloat16, device='cuda')
v     = torch.randn(B, T, H, V,  dtype=torch.bfloat16, device='cuda')
g     = torch.randn(B, T, H, K,  dtype=torch.bfloat16, device='cuda')
beta  = torch.randn(B, T, H,     dtype=torch.bfloat16, device='cuda')
A_log = torch.randn(H,           dtype=torch.float32,  device='cuda')
dt_bias = torch.zeros(H, K,      dtype=torch.float32,  device='cuda')
h0    = torch.zeros(B, H, V, K,  dtype=torch.float32,  device='cuda')

scale = K ** -0.5
lower_bound = -5.0

with torch.inference_mode():
    out, final_state = chunk_kda(
        q=q, k=k, v=v, g=g, beta=beta,
        scale=scale,
        initial_state=h0,
        output_final_state=True,
        use_gate_in_kernel=True,
        use_qk_l2norm_in_kernel=True,
        use_beta_sigmoid_in_kernel=True,
        safe_gate=True,
        A_log=A_log,
        dt_bias=dt_bias,
        lower_bound=lower_bound,
        transpose_state_layout=True,
    )
# out: [B, T, H, V], final_state: [B, H, V, K]

Direct Low-Level Kernel Usage

import torch
import flash_kda

def run_flash_kda(
    q, k, v, g, beta,
    A_log, dt_bias,
    lower_bound=-5.0,
    initial_state=None,
):
    B, T, H, K = q.shape
    V = v.shape[-1]
    scale = K ** -0.5

    out = torch.empty(B, T, H, V, dtype=torch.bfloat16, device=q.device)
    final_state = torch.zeros(B, H, V, K, dtype=torch.float32, device=q.device)

    flash_kda.fwd(
        q, k, v, g, beta,
        scale, out,
        A_log, dt_bias, lower_bound,
        initial_state=initial_state,
        final_state=final_state,
        cu_seqlens=None,
    )
    return out, final_state


B, T, H, K = 1, 4096, 8, 128
device = 'cuda'
dtype  = torch.bfloat16

q       = torch.randn(B, T, H, K,   device=device, dtype=dtype)
k       = torch.randn(B, T, H, K,   device=device, dtype=dtype)
v       = torch.randn(B, T, H, K,
Полный SKILL.md на GitHub

Установить flashkda-delta-attention в Claude Code и Claude Desktop

Зарегайся, чтобы установить скилл

Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.

  • Открой команду установки в одну строку
  • Сохраняй скиллы в синхронизируемую библиотеку
  • Уведомления, когда скиллы обновляются
Зарегаться бесплатноУ меня уже есть аккаунт

Разрешённые инструменты

Инструменты, которые скиллу разрешено вызывать.

Без ограничений — скилл может использовать любой инструмент.

FAQ

Что делает скилл flashkda-delta-attention?

High-performance Kimi Delta Attention CUDA kernels built on CUTLASS for efficient recurrent state inference

Как установить скилл flashkda-delta-attention?

Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.

Скилл flashkda-delta-attention запускает скрипты?

Нет, скилл состоит только из инструкций (SKILL.md), без исполняемых скриптов.

Похожие скиллы

Сравнить flashkda-delta-attention с