Moonshot AI Open-Sources FlashKDA: A Deep Dive into High-Performance CUDA Kernels for KDA Attention

Moonshot AI open-sources FlashKDA, delivering high-performance CUDA kernels for its Kimi Delta Attention mechanism.
Moonshot AI has open-sourced FlashKDA, a project providing optimized CUDA kernel implementations for Kimi Delta Attention (KDA)—a linear attention variant that reduces complexity from O(n²) to near O(n). The project accelerates training, speeds up inference, and reduces memory usage for long-context scenarios, following the hardware-aware optimization philosophy of FlashAttention applied to Delta Rule-based attention mechanisms.
Introduction: The Efficiency Battle of Attention Mechanisms
In the rapidly evolving world of large language models, the attention mechanism—the core component of the Transformer architecture—directly determines model training costs and inference speed through its computational efficiency. The attention mechanism was first proposed by Bahdanau et al. in 2014 for machine translation tasks. Its core idea is to allow the model to dynamically focus on the most relevant parts of the input sequence when processing each position. In 2017, Google's paper "Attention Is All You Need" elevated self-attention to a central role, proposing a Transformer architecture based entirely on attention that completely replaced the previously dominant RNN/LSTM structures. However, standard self-attention computes attention weights through interactions among Query, Key, and Value matrices with a computational complexity of O(n²d), causing computation and memory usage to grow dramatically when processing long sequences—becoming the primary bottleneck limiting large model capability scaling.
Recently, Moonshot AI (月之暗面), a leading Chinese large model company, open-sourced a project called FlashKDA on GitHub, dedicated to providing high-performance CUDA kernel implementations for their Kimi Delta Attention (KDA). The project attracted significant industry attention immediately upon release, gaining over 216 new stars in a single day, with cumulative Stars now reaching 886 and Forks totaling 90.

This open-source initiative not only demonstrates Moonshot AI's technical expertise in low-level operator optimization but also provides the open-source community with a production-ready, high-performance attention implementation.
What is Kimi Delta Attention (KDA)
From Standard Attention to Linear Attention Variants
Kimi Delta Attention (KDA for short) is an attention variant proposed by Moonshot AI during the development of their Kimi series of models. The term "Delta" typically refers to a class of linear attention mechanisms based on the Delta Rule (incremental update) concept.
The Delta Rule originally comes from classical neural network learning theory and is a form of the Widrow-Hoff learning rule. Its core idea is to incrementally update model states by computing the difference (i.e., Delta) between predicted and target values. When this concept is applied to attention mechanisms, the model can recursively maintain a finite-sized state matrix (often called a compressed representation of the KV cache), performing only incremental updates at each time step rather than recomputing attention scores across the entire sequence. This approach is closely related to Linear Attention—linear attention removes the Softmax operation and uses kernel function decomposition to transform attention computation into a recursively updatable form. Representative works include Katharopoulos et al.'s Linear Transformers, RetNet, and the selective state space models in Mamba. Delta Attention further introduces forget gates and incremental update rules on top of these foundations, making state compression more precise and approaching the expressive power of standard Softmax attention while maintaining linear complexity.
Compared to standard Softmax attention, these mechanisms reduce attention computation complexity from quadratic (O(n²)) to near-linear (O(n)) through state compression and recursive updates, providing significant efficiency advantages when processing ultra-long contexts.
For models like Kimi that are renowned for "ultra-long context" capabilities, attention computation efficiency is the key factor determining whether they can efficiently handle hundreds of thousands or even millions of tokens. Long-context capability is one of the core differentiating directions in current large model competition—from GPT-4's 128K context window, to Claude's 200K, to Kimi's claimed million-token input support, the context length arms race continues to intensify. However, extending context length faces multiple technical challenges including computational complexity, KV Cache memory usage (128K context can consume tens of GB of memory under standard implementations), and positional encoding extrapolation. Industry solutions include positional encoding improvements (such as RoPE's NTK extension), sparse attention (such as Longformer's local+global pattern), and the linear/sub-linear complexity attention variants that KDA represents. KDA is a technology born precisely from these demands.
Why Dedicated CUDA Kernels Are Needed
Algorithmic innovations can only deliver real value when they are efficiently executed on hardware. FlashKDA's core contribution lies in its deeply optimized CUDA implementation of KDA's algorithmic logic—the project's primary language is CUDA.
CUDA (Compute Unified Device Architecture) is NVIDIA's parallel computing platform and programming model that allows developers to write parallel programs that run directly on GPUs. Writing high-performance CUDA kernels requires deep understanding of GPU hardware architecture, including: Streaming Multiprocessor (SM) thread scheduling mechanisms, the hierarchy of Shared Memory and registers, Coalesced Access patterns for global memory, Warp-level synchronization primitives, and more. This means developers can run KDA directly on GPUs at near-hardware-limit efficiency without writing complex low-level kernels from scratch.
This follows the same philosophy as the widely acclaimed FlashAttention. FlashAttention was proposed by Tri Dao et al. from Stanford University in 2022 and represents a milestone in hardware-aware attention optimization. Its core insight is that the primary bottleneck of standard attention implementations is not the computation itself, but the data transfer overhead between GPU High Bandwidth Memory (HBM) and on-chip SRAM. FlashAttention uses a tiling strategy to decompose attention computation into small blocks that can be completed within SRAM, avoiding writing the complete n×n attention matrix to HBM. It also employs an online Softmax algorithm to make tiled computation mathematically equivalent to standard attention without introducing any approximation errors. FlashAttention 2 and 3 further optimized parallelism and pipeline scheduling, improving actual attention computation speed by 2-4x and reducing memory usage from O(n²) to O(n). FlashKDA can be viewed as applying similar hardware-aware optimization principles to Delta Attention, a novel attention variant—through fine-grained memory access optimization, Kernel Fusion, and full utilization of GPU compute units, it dramatically improves actual execution speed and reduces memory usage without sacrificing precision.
Technical Value and Core Advantages of FlashKDA

Practical Benefits of High-Performance Kernels
Positioned as "high-performance kernels," FlashKDA delivers value across three dimensions:
- Training Acceleration: Efficient attention kernels directly shorten model training cycles and reduce compute costs. Kernel Fusion is a key technique here—merging multiple originally independent operations (such as matrix multiplication, activation functions, normalization, etc.) into a single CUDA kernel execution, reducing the overhead of writing intermediate results back to global memory. For memory-bandwidth-bound operations like attention, the benefits of kernel fusion are particularly significant.
- Inference Speedup: During inference, especially in long-context scenarios, optimized KDA kernels can significantly improve throughput and reduce latency. Adapting to Tensor Core instruction sets for different GPU architectures (such as A100's Ampere architecture and H100's Hopper architecture) is also key to achieving hardware-limit performance.
- Memory Efficiency: Linear attention combined with kernel-level optimization effectively alleviates the memory pressure from long sequences, making longer contexts possible. Compared to standard attention that requires storing the complete n×n attention matrix or caching KV vectors for all historical tokens, KDA's recursive state compression mechanism inherently has memory advantages, and FlashKDA's kernel implementation further pushes this advantage to the extreme through tiling strategies and register reuse.
Strategic Significance of Open-Sourcing
Moonshot AI's decision to open-source FlashKDA carries multiple strategic implications. On one hand, it gives back to the community, enabling more researchers and engineers to reuse, verify, and improve this attention implementation. On the other hand, open-sourcing low-level operators helps build an ecosystem around the Kimi technology stack, attracting developers to participate in collaborative development.
Interestingly, open-sourcing attention kernels has a higher "engineering" threshold compared to open-sourcing model weights—it's closer to production deployment and holds extremely high practical value for teams looking to integrate novel attention mechanisms into their own models. Open-source in the large model era has gradually deepened from model weights to infrastructure: early open-source efforts focused on model weights and training code (such as LLaMA, Mistral), while in recent years more low-level optimization tools have been open-sourced—the FlashAttention series, NVIDIA's TensorRT-LLM, PagedAttention in the vLLM inference framework, DeepSeek's DeepGEMM, etc. The common characteristics of these projects are that they are highly engineered, deeply coupled with hardware, and require teams with the compound ability to understand both algorithms and GPU architecture. FlashKDA's value lies not only in the code itself but in exposing the engineering implementation details of a novel attention mechanism, enabling the community to evaluate, reproduce, and improve upon it. For algorithm researchers, the availability of high-performance kernels directly determines whether novel attention mechanisms can be fairly benchmarked and practically deployed.
Industry Implications
Operator-Level Competition Becomes the New Battleground
The release of FlashKDA once again confirms a trend: competition in large models has shifted from pure model scale and data volume to efficiency battles at the level of low-level operators and systems engineering. Whoever can achieve higher efficiency on the same hardware gains advantages in both cost and performance.
From FlashAttention to various proprietary attention kernels, leading companies are investing heavily in this space. Moonshot AI's open-source release is both a demonstration of technical strength and a proactive response to this competitive logic.
The Foundation Supporting Long-Context Capabilities
The Kimi series is known for its long-context capabilities, and FlashKDA is one of the foundational engines supporting this ability. This reminds us that any user-facing model capability requires solid system-level optimization as its foundation. For practitioners focused on deploying large models in production, understanding and mastering these high-performance kernels is becoming an increasingly important core competency.
Conclusion
The open-sourcing of FlashKDA represents a powerful move by Moonshot AI in their low-level technology strategy. It not only provides the community with a high-quality CUDA implementation of KDA but also sends a clear signal: in the era of large models, extreme optimization of low-level operators is becoming a decisive variable. For developers who want to deeply understand linear attention and high-performance kernel implementations, this project is undoubtedly worth thorough study and hands-on practice.
Related articles

OpenAI's Git Optimization: Tackling Performance Bottlenecks in Massive Repositories
Analysis of how OpenAI optimizes Git for massive repositories, covering monorepo bottlenecks, partial clone, sparse checkout, fsmonitor, and practical tips for engineering teams.

AI Can't Build Usable Products — Developers' Jobs Haven't Disappeared
AI can generate code snippets and demos, but usable products still require human engineers' judgment and responsibility. This article analyzes AI coding tools' limits and developers' evolving roles.

Solid Queue 1.6.0 Fiber Worker Support: A New Concurrency Option for Rails Background Jobs
Solid Queue 1.6.0 introduces Fiber Worker support, offering a lightweight and efficient concurrency model for I/O-intensive Rails background jobs.