QwenLM/FlashQLA

high-performance linear attention kernel library built on TileLang

What it is

FlashQLA is a high‑performance kernel library that implements the Gated‑Delta‑Rule (GDN) linear‑attention algorithm used in Qwen‑style large language models. It is written on top of the TileLang DSL and ships as a Python package (flash‑qla). The library provides both a convenient high‑level function (chunk_gated_delta_rule) and low‑level forward/backward kernels that can be called from PyTorch code.

Why it matters

Linear‑attention mechanisms replace the quadratic cost of classic soft‑max attention with a computation that scales linearly with sequence length, making very long contexts feasible. FlashQLA speeds up the forward pass by 2‑3× and the backward pass by ~2× compared with the reference Flash Linear Attention (FLA) Triton kernels, especially on NVIDIA Hopper/Blackwell GPUs. Faster kernels mean cheaper pre‑training and lower latency for inference‑heavy or edge‑side agents that rely on Qwen‑style models.

Core features

Feature What it does
Gate‑driven automatic intra‑card context parallelism Detects when the GDN gate’s exponential decay allows the work to be split across multiple CUDA warps/SMs, automatically enabling parallelism inside a single GPU card (TP, long‑seq, small‑head settings).
Hardware‑friendly algebraic reformulation Rewrites the GDN forward/backward equations to reduce Tensor‑Core, CUDA‑Core and SFU usage while keeping numerical precision.
TileLang‑fused warp‑specialized kernels Uses the TileLang DSL to generate a handful of fused kernels that balance data movement, Tensor‑Core matmuls and CUDA‑Core ops, rather than a single monolithic kernel.
Dual‑CP (inter/intra two‑level context parallelism) (v0.1.3) Adds a second level of parallelism across GPUs (inter‑card) and within a GPU (intra‑card).
SM120 backward path (v0.1.3) Adds support for the newest NVIDIA SM120 architecture in the backward kernel.
Plug‑and‑play backend for flash‑linear‑attention (v0.1.2) Can be used as a drop‑in replacement for the FLA GDN kernel via the standard FLA API.

How to get started

# Install the pre‑built wheel (requires CUDA 12.8+, PyTorch 2.8+)
pip install flash-qla

Or build from source:

git clone https://github.com/QwenLM/FlashQLA.git
cd FlashQLA
pip install -v .

Simple usage example

import torch
from flash_qla import chunk_gated_delta_rule

# q, k, v, g, beta are tensors shaped as described in the README
out, final_state = chunk_gated_delta_rule(
    q=q, k=k, v=v, g=g, beta=beta,
    scale=scale,
    initial_state=init_state,
    output_final_state=True,
    cu_seqlens=cu_seqlens,
)

For custom training loops you can call the separate forward and backward functions (*_fwd / *_bwd) and feed the returned cache objects back into the backward pass.

When to use it

  • You are training or fine‑tuning a Qwen‑style model that uses GDN linear attention.
  • Your workloads run on recent NVIDIA GPUs (H100, H200, Blackwell) and you need every ounce of speed for long‑sequence pre‑training or low‑latency inference.
  • You already use PyTorch and want a drop‑in kernel that works with the existing flash-linear-attention API.

Limitations / open points

  • Only supports NVIDIA GPUs with SM 90‑SM 121 and CUDA 12.8+. No CPU or AMD support.
  • The library focuses on the GDN Chunked Prefill variant; other linear‑attention formulations are not covered.
  • Backward‑pass speedups are tied to the dual‑CP implementation; on older GPUs you may see less benefit.
  • Requires the TileLang runtime; users must be comfortable compiling TileLang‑generated kernels.

Community & maintenance

  • The project is maintained by the QwenLM team (see the citation list). Recent releases (v0.1.1‑v0.1.3) show active development.
  • Issues and pull requests can be filed on the GitHub repo; the README links to benchmark scripts and profiling utilities for developers.

All information above is taken directly from the repository’s README; no external speculation is added.

Related

  • Dispatch
  • Project
  • Project
  • Project
  • Project