← Back to blog

FlashQLA: Qwen's Linear Attention Kernel Revolution for Edge AI

The Qwen team achieves 2-3x speedup in linear attention layers with FlashQLA built on TileLang. GDN architecture, automatic context parallelism, and hardware-friendly optimizations push agentic AI on edge devices into a new era.

FlashQLA: Qwen's Linear Attention Kernel Revolution for Edge AI

FlashQLA: Qwen's Linear Attention Kernel Revolution for Edge AI

The performance of Large Language Models (LLM) has gained tremendous momentum in recent years. However, the cost of this progress has been a continuous increase in computational expense. In particular, the quadratic complexity of the attention mechanism remains a fundamental bottleneck for long contexts and agentic systems running on personal devices. At this point, linear attention solutions emerged as an alternative to classical softmax attention. Yet this alternative had its own efficiency problems. The Qwen team released a new linear attention kernel library called FlashQLA as open source to address these issues. In this article, we examine FlashQLA's technical infrastructure, the gains it provides, and its significance for the edge AI ecosystem in detail.

FlashQLA banner image

Why Linear Attention Matters

In the classical transformer architecture, the attention mechanism works by multiplying query, key, and value matrices. The complexity of this operation increases quadratically with sequence length. That is, a 4096-token input requires approximately four times more computation than an 8192-token input. Linear attention reduces this quadratic dependency to a linear form based on hidden dimension. This theoretically provides a significant speed advantage on long sequences.

However, this theoretical advantage does not always deliver expected performance in practice. Current implementations of linear attention layers, especially Flash Linear Attention (FLA) Triton-based solutions, contained some fundamental inefficiencies. As the Qwen team emphasized in their FlashQLA blog post, these inefficiencies fall under two main headings. The first is memory-bound execution. The continuous reading and writing of K, V, and intermediate variables from and to HBM causes compute units to sit idle. The second is low GPU utilization. The SSM state recurrence limits concurrent thread blocks to batch_size multiplied by num_heads. This means that a large portion of GPU SMs remain idle in small models, low batch sizes, or Tensor Parallelism (TP) scenarios.

FlashQLA's Technical Foundation and Three Main Innovations

FlashQLA is a library built on the attention layer called Gated Delta Network (GDN). GDN is the cornerstone of the architecture used in the Qwen3-Next, Qwen3.5, and Qwen3.6 families. FlashQLA's solutions can be grouped under three main headings. Let's examine these headings with formulas and explanations taken from the technical blog published by the Qwen team.

1. Gate-Driven Automatic Intra-Card Context Parallelism (AutoCP)

One of the most distinctive features of GDN is its gate mechanism with exponential decay property. This is a coefficient that controls how much the previous state influences subsequent steps. The FlashQLA team developed an automatic context parallelism mechanism using this feature. So what does this mean in practice?

Under normal conditions, even if the entire linear attention layer is fused into a single kernel, GPU SM utilization remains low. Because the SSM state recurrence makes computation serial. FlashQLA splits the computation into two stages. In the first stage, local states are calculated. In the second stage, cross-rank correction is applied. The interesting part is that thanks to the gate's exponential decay property, the influence of past states drops below the noise level after a certain point. Analyses conducted by the Qwen team on real data show that in 60-80% of linear attention heads, this decay coefficient is not constantly 1. In this case, starting a 6-8 chunk warmup period from zero initial state drives the error below the noise floor.

What does this mean? When the M correction matrix would normally need to be computed, this matrix can be skipped and a much lighter warmup operation suffices. FlashQLA automatically selects the chunk count (L) for each CP rank using a runtime model. For total N chunks, steps 2.1 and 3 scale as L, while step 2.2 scales as N/L. FlashQLA automatically finds an optimum at L = square root(N). AutoCP trigger conditions are as follows: if batch_size multiplied by num_heads is 40 or less, or if batch_size multiplied by num_heads is 56 or less and sequence length is 8192 or more.

2. Hardware-Friendly Algebraic Reformulation

FlashQLA's second major contribution is the algebraic reformulation of GDN Chunked Prefill's forward and backward passes. The Qwen team analyzed the computation steps in the current FLA implementation and reduced the load on Tensor Core, CUDA Core, and SFU (Special Function Unit). This was done without sacrificing numerical precision.

Simply put, computation steps that were broken into independent kernels in the current implementation have been reorganized in FlashQLA. Steps such as computing the A matrix, extracting W and U variables, then V correction, and finally producing the output (O) have been structured in a way that better suits the hardware's parallel processing capabilities. This reformulation not only reduces memory traffic but also enables more efficient use of Tensor Cores' matrix multiplication capabilities.

3. Warp-Specialized Kernels Built on TileLang

FlashQLA's third and perhaps most technical innovation is being built on the TileLang framework. TileLang is a DSL (Domain Specific Language) and compiler infrastructure designed for GPU kernel optimization. Instead of fusing the entire computation into a single massive kernel, the FlashQLA team created several critical fused kernels taking context parallelism and backward pass requirements into account.

In these kernels, producer/consumer warpgroup specialization is used to overlap data movement, Tensor Core computation, and CUDA Core computation. That is, while one warp group fetches data from memory, another can perform computation on previous data. This technique enables maintaining the memory bandwidth gains provided by kernel fusion while increasing parallelism.

Benchmark Results and Performance Gains

FlashQLA's performance was compared against FLA Triton and FlashInfer baselines on the NVIDIA Hopper (SM90) architecture. Tests used the head configurations employed by the Qwen3.5 and Qwen3.6 families (h_k,v elements {64, 48, 32, 24, 16, 8}, corresponding to TP1 through TP8).

FlashQLA benchmark results forward and backward comparison

The results are quite impressive. In the forward pass, a speedup of 2 to 3 times was achieved. In the backward pass, 2 times speedup was obtained. These gains were consistently observed across different model sizes and TP settings at varying batch lengths. The speedup becomes even more pronounced especially in pretraining scenarios and small models.

As the Qwen team states in their technical blog, FlashQLA's most striking performance gain appears in small models and long-context work. And right at this point, a great hope arises for agentic systems running on edge devices.

What It Means for Edge AI and Agentic Systems

The release of FlashQLA represents an important milestone in the field of local AI and agentic systems. As developers, we know that powerful agents running on personal computers or mobile devices are often limited to small models due to hardware constraints. These small models, in turn, struggle to process long contexts due to the inefficiency of the attention layer.

With FlashQLA, this situation is beginning to change. A 2-3x speedup in the forward pass and 2x in the backward pass means that on the same hardware, it is possible to process larger contexts or get faster responses at the same context length. This elevates the potential of Small Language Models on edge devices to a new level. Alongside efficient models like Gemma 4 and Qwen 3.6, kernel-level optimizations like FlashQLA make it possible to offer truly agentic experiences on personal devices.

Furthermore, FlashQLA's automatic context parallelism mechanism enables work sharing across multiple GPUs or even different SMs on a single GPU. This means more efficient use of limited GPU resources on edge devices. In other words, the same phone or laptop will now be able to process task definitions (system prompts) and memory contexts at lengths that were previously impossible.

When considering models with agentic coding capabilities like Kimi K2.6 or systems that conduct self-research like Karpathy's autoresearch project, the added value of such kernel-level optimizations becomes clearer. Agentic systems continuously work on long contexts, so the efficiency of the attention layer directly impacts user experience.

Installation and Usage

FlashQLA works on NVIDIA Hopper (SM90) and above architectures, with CUDA 12.8 and PyTorch 2.8 and above. Installation is quite simple:

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

High-level API usage is as follows:

import torch
from flash_qla import chunk_gated_delta_rule

o, final_state = chunk_gated_delta_rule(
    q=q,          # [B, T, H_q, K]
    k=k,          # [B, T, H_q, K]
    v=v,          # [B, T, H_v, V]
    g=g,          # [B, T, H_v]
    beta=beta,    # [B, T, H_v]
    scale=scale,
    initial_state=initial_state,
    output_final_state=True,
    cu_seqlens=cu_seqlens,
)

Separate forward and backward pass calls are also possible with lower-level APIs. For details, check the Qwen team's GitHub repository.

Conclusion and Assessment

FlashQLA represents a significant technical advancement in the field of linear attention. The Qwen team identified the fundamental inefficiencies in the current FLA Triton implementation and provided solutions through AutoCP leveraging the gate mechanism's exponential decay property, hardware-friendly algebraic reformulation, and TileLang-based warp-specialized kernels. The achieved speedup of up to 2-3x is of critical importance for the edge AI ecosystem, especially in small models and long contexts.

The fundamental lesson for us as developers is this: to fully utilize the capabilities offered by hardware, algorithmic design must be optimized according to the hardware architecture. FlashQLA stands out as a beautiful application of this principle. It is also proof of how modern kernel DSLs like TileLang can be much more efficient compared to traditional CUDA programming.

Have you tried FlashQLA in your own projects? Are you developing agentic applications running on edge devices? Share your thoughts in the comments. Don't forget to follow my site to stay informed about new articles.

Technical details, benchmark data, and images used in this article are taken from the Qwen team's FlashQLA blog post.

Efe Hüseyin Özkan

Software Engineer & AI Developer

Working on AI systems, full-stack development, and scalable product architecture. Follow the blog for more technical articles.