HyperAIHyperAI

Command Palette

Search for a command to run...

SparDA: 효율적인 장문 LLM 추론을 위한 희소 분리형 어텐션

Yaosheng Fu Guangxuan Xiao Xin Dong Song Han Oreste Villa

초록

희소 어텐션은 장문 LLM 추론에서 연산량과 메모리 대역폭을 줄여준다. 그러나 두 가지 주요 과제가 남아 있다: (1) KV 캐시 용량이 여전히 시퀀스 길이에 따라 증가하며, CPU 메모리로 오프로드할 경우 PCIe 전송 병목이 발생한다; (2) 희소 선택 단계 자체가 O(T2)O(T^2)O(T2) 복잡도를 유지하여 장문에서 어텐션 비용을 지배할 수 있다. 우리는 SparDA를 제안하는데, 이는 레이어별로 Query, Key, Value와 함께 Forecast라는 네 번째 투영을 도입한 분리형 희소 어텐션 구조이다. Forecast는 다음 레이어에 필요한 KV 블록을 예측하여, 현재 레이어 실행과 CPU-to-GPU 프리페치를 중첩시키는 선견 선택을 가능하게 한다. Forecast가 어텐션 쿼리와 분리되어 있기 때문에, 우리의 GQA 구현은 GQA 그룹당 하나의 Forecast 헤드를 사용하여 기존 멀티헤드 선택기 대비 선택 오버헤드를 줄인다. SparDA는 0.5% 미만의 파라미터를 추가하며, 원래 선택기의 어텐션 분포를 모방하도록 Forecast 투영만 학습시킨다. 두 개의 희소 사전학습 8B 모델에서, SparDA는 정확도를 유지하거나 약간 개선하며, 희소 어텐션 오프로드 기준 대비 최대 1.25배의 프리필 속도 향상과 1.7배의 디코드 속도 향상을 제공한다. 단일 GPU에서 더 큰 배치 크기를 가능하게 함으로써, SparDA는 비오프로드 희소 기준 대비 최대 5.3배 높은 디코드 처리량을 달성한다. 소스 코드는 https://github.com/NVlabs/SparDA에서 확인할 수 있다.

One-sentence Summary

NVIDIA et al. propose SparDA, a decoupled sparse attention architecture that introduces a Forecast projection for lookahead KV-block prefetch overlapping computation, where using one Forecast head per GQA group reduces selection overhead, adds <0.5%< 0 . 5 \%<0.5% parameters, trains only the Forecast projections by matching the original selector's attention distribution, and on two sparse-pretrained 8B models matches or slightly improves accuracy while achieving up to 1.25×1.25\times1.25× prefill speedup, 1.7×1.7\times1.7× decode speedup over the sparse-attention offload baseline, and up to 5.3×5.3\times5.3× higher decode throughput than the non-offload sparse baseline.

Key Contributions

  • SparDA is a decoupled sparse attention architecture that adds a Forecast projection per layer to predict the KV blocks needed by the next layer, enabling lookahead prefetching that overlaps CPU-to-GPU data transfer with current-layer computation.
  • The design uses one Forecast head per GQA group, reducing sparse selection overhead versus multi-head selectors while adding under 0.5% parameters and training only the Forecast projections by matching the original selector's attention distribution.
  • On two sparse-pretrained 8B models, SparDA achieves up to 1.25× prefill and 1.7× decode speedup over a sparse-attention offload baseline, and by enabling larger batch sizes it reaches up to 5.3× higher decode throughput than a non-offload sparse baseline.

Introduction

Long-context LLM serving strains infrastructure with high compute for prefill attention, memory bandwidth pressure during decoding, and growing KV cache capacity demands. Sparse attention alleviates compute and bandwidth but leaves capacity pressure unresolved, and offloading the KV cache to CPU memory with selective fetching introduces PCIe latency bottlenecks. Prior lookahead prefetching methods like InfiniGen attempt to hide this latency by using the raw hidden state as a proxy for future attention, but they become inaccurate when layer-to-layer similarity breaks down. Meanwhile, sparse selection itself incurs O(T²) overhead that can dominate as context length grows, and existing optimizations often trade accuracy for speed. The authors propose SparDA, which decouples sparse selection from attention by training a lightweight Forecast projection to predict next-layer KV block selections directly, enabling accurate asynchronous prefetching and a compact indexer that reduces selection overhead without retraining the base model.

Method

The authors build SparDA on top of InfLLM-V2, which represents a block-sparse attention architecture. InfLLM-V2 decomposes attention into initial tokens, a local sliding window, and top-kkk selected blocks. It merges selected attention and sliding-window attention into a single sparse attention module with shared KV projections. To compute block-level relevance scores, it employs a parameter-free, coarse-to-fine compression pipeline where keys are mean-pooled into overlapping compressed representations.

To enable KV cache prefetching that overlaps with layer execution for latency hiding and to reduce the overhead of sparse selection, the authors introduce a single architectural change: a fourth per-layer projection called the Forecast Fl\mathbf{F}_lFl. This projection is produced alongside the standard Ql\mathbf{Q}_lQl, Kl\mathbf{K}_lKl, and Vl\mathbf{V}_lVl to drive a compact sparse-selection indexer. By decoupling sparse selection from the attention query, the Forecast can be computed one layer ahead.

As shown in the figure below:

In the baseline InfLLM-V2, the query Ql\mathbf{Q}_lQl drives both top-kkk selection and sparse attention within the same layer, placing selection on the attention critical path. SparDA decouples these roles. The linear projection ϕl\phi_lϕl in each layer produces the additional Forecast Fl\mathbf{F}_lFl: (Ql,Kl,Vl,Fl)=ϕl(Xl).(\mathbf{Q}_l, \mathbf{K}_l, \mathbf{V}_l, \mathbf{F}_l) = \phi_l(\mathbf{X}_l).(Ql,Kl,Vl,Fl)=ϕl(Xl). The Forecast Fl\mathbf{F}_lFl is used for top-kkk sparse selection, while Ql\mathbf{Q}_lQl is reserved solely for the sparse attention computation. Specifically, Fl\mathbf{F}_lFl scores against the compressed keys K~l+1\widetilde{\mathbf{K}}_{l+1}Kl+1 of the next layer, and the resulting top-kkk blocks are merged with the initial and local blocks to form the attended set for layer l+1l+1l+1. During prefill, the Forecast replaces the expensive multi-head selector with an indexer that uses one Forecast head per GQA group. During decode, Fl\mathbf{F}_lFl predicts the blocks for the next layer early enough to asynchronously prefetch the selected KV blocks from CPU memory, effectively hiding the PCIe transfer behind the current layer compute.

For training, the authors add SparDA to existing sparse-pretrained models by training only the Forecast projections, which adds a negligible number of parameters. Inspired by DeepSeek DSA, the Forecast indexer is trained to match target block-attention scores via Kullback-Leibler divergence after top-kkk restriction and renormalization. The target and predicted scores are defined as: Sl,mtgt=h=1Gsoftmax(Ql,m,hK~l,mtgt/τ),Sl,mpred=softmax(Fl1,mK~l,mpred/τ),\mathbf{S}_{l,m}^{\mathrm{tgt}} = \sum_{h=1}^{G} \operatorname{softmax}\left(\mathbf{Q}_{l,m,h} \widetilde{\mathbf{K}}_{l,m}^{\mathrm{tgt}\top} / \tau\right), \quad \mathbf{S}_{l,m}^{\mathrm{pred}} = \operatorname{softmax}\left(\mathbf{F}_{l-1,m} \widetilde{\mathbf{K}}_{l,m}^{\mathrm{pred}\top} / \tau\right),Sl,mtgt=h=1Gsoftmax(Ql,m,hKl,mtgt/τ),Sl,mpred=softmax(Fl1,mKl,mpred/τ), where the predicted branch uses the Forecast from the previous layer indexer to produce a single score per KV head directly. The training loss computes the KL divergence over a top-kkk partitioned distribution, focusing the indexer on the relative ranking within the selected set while constraining the total mass on non-selected blocks through a rest bucket.

To provide fine-grained training supervision, the authors use a smaller kernel size and stride for the target compressed keys compared to the inference-time configuration. This finer-grained compression provides a higher-resolution supervision signal, allowing the indexer to learn sharper selection. The target score tensor is then downsampled to the standard grid before computing the KL loss.

At inference, SparDA exploits the early availability of the Forecast through an asynchronous prefetch pipeline. The authors employ a persistent Triton kernel based on Unified Virtual Addressing to fetch selected KV blocks from pinned CPU memory on a dedicated CUDA stream. This kernel maintains a small fixed set of GPU thread blocks to continuously process block-transfer tasks within a single launch, reducing overhead and limiting interference with the main compute stream. To balance prefetch throughput and layer execution speed, SparDA adopts a batch-adaptive CTA allocation heuristic. This approach allocates more Cooperative Thread Arrays as the batch size grows to maximize overall throughput for the underlying hardware.

Experiment

The evaluation compares SparDA against dense, sparse, and InfiniGen baselines on two 8B models using long-context benchmarks, measuring accuracy and efficiency on NVIDIA H100 and A100 GPUs. SparDA’s learned Forecast indexer improves accuracy over the sparse baseline, especially on reasoning and length generalization, while also reducing block-selection overhead to accelerate prefill and decode. Its lookahead prefetch design overlaps KV cache transfers with computation, yielding substantial decode throughput gains at long contexts. In contrast, the training-free InfiniGen method suffers significant accuracy loss and is slower due to CPU-side gather operations.

SparDA improves average accuracy over the Sparse baseline on both models, with the largest gains on reasoning and RULER benchmarks. While dense attention still leads on HELMET and RULER, SparDA narrows the gap on RULER and surpasses dense on reasoning tasks. InfiniGen consistently underperforms Sparse across all metrics. SparDA achieves higher overall average accuracy than Sparse, with a modest gain on MiniCPM4.1-8B and a larger improvement on NOSA-8B. Reasoning accuracy benefits the most, with SparDA outperforming even dense attention on both models. RULER scores improve with SparDA, reducing the gap to dense attention, while LongBench remains essentially unchanged. HELMET accuracy slightly decreases on MiniCPM4.1-8B but increases on NOSA-8B. InfiniGen trails Sparse across all benchmarks, with the largest drops on HELMET and RULER.

SparDA consistently improves RULER accuracy over the Sparse baseline at every evaluated sequence length for both MiniCPM4.1-8B and NOSA-8B. The advantage is most pronounced on NOSA-8B, where the gap widens steadily from 32K to 128K, while MiniCPM4.1-8B shows a more variable but always positive margin. This indicates the learned Forecast indexer generalizes at least as well as the training-free selector, and in some regimes better. SparDA outperforms Sparse on RULER at all sequence lengths from 32K to 128K across both models. On NOSA-8B, the accuracy gap grows monotonically with context length, reaching +4.3 points at 128K.

Dense attention achieves the highest prefill throughput at short sequences (32K) but its quadratic scaling causes a steep decline as context length increases. SparDA surpasses all methods at longer contexts, leading from 64K on MiniCPM4.1-8B and from 96K on NOSA-8B, with speedups over both Sparse and Dense that grow with sequence length. The improvement is driven by a more efficient block selection step, while KV cache offloading itself introduces negligible prefill overhead. Dense attention leads at 32K but its throughput drops sharply with longer sequences, falling behind sparse methods. SparDA achieves the highest prefill throughput from 64K onward on MiniCPM4.1-8B and from 96K onward on NOSA-8B. On MiniCPM4.1-8B at 128K, SparDA delivers a 1.25× speedup over Sparse and a 2.11× speedup over Dense. The speedup comes from a block selection mechanism that scales more favorably with sequence length than the baseline multi-head selector. KV cache offloading has negligible impact on prefill throughput, as seen by the near-identical numbers for Sparse with and without offload. All sparse methods are slower on NOSA-8B because its query-agnostic eviction head adds extra work.

SparDA's offloading design allows decode throughput to scale to much larger batch sizes than non-offload baselines, which run out of memory beyond batch 16 at long contexts. At 32K context, SparDA overtakes Sparse at batch 128 on MiniCPM4.1-8B, while InfiniGen is consistently slower because its CPU-side KV gather becomes a bottleneck. The largest relative gains occur at middle batch sizes where prefetch overlap is most effective, and SparDA achieves up to 1.69× speedup over Sparse at 128K. At 32K, SparDA reaches 1358.2 tok/s at batch 128 on MiniCPM4.1-8B, exceeding Sparse's 1225.1 tok/s, while Dense without offload runs out of memory after batch 16. Offloading lets SparDA run batches up to 128, whereas non-offload baselines OOM past batch 16 at long contexts, leading to throughput gains of up to 9.21× over Dense without offload. InfiniGen's decode throughput is far lower (e.g., 222.4 tok/s at batch 128, 32K) because it gathers KV blocks on the CPU before transferring them to the GPU. The largest speedups appear at middle batch sizes (8–16), where the overlap of KV prefetch with layer execution is roughly balanced.

The evaluation compares SparDA against sparse and dense baselines, as well as InfiniGen, on two models (MiniCPM4.1-8B and NOSA-8B) using accuracy benchmarks, prefill throughput, and decode throughput. SparDA consistently improves accuracy over the sparse baseline, with the largest gains on reasoning and RULER tasks, and it even surpasses dense attention on reasoning while narrowing the gap on RULER. In throughput, SparDA achieves the highest prefill speeds at long contexts due to efficient block selection, and its KV cache offloading allows decoding at much larger batch sizes, yielding substantial speedups over non-offloading methods. InfiniGen trails in both accuracy and throughput across all settings.


AI로 AI 구축

아이디어에서 출시까지 — 무료 AI 코코딩, 즉시 사용 가능한 환경, 최적의 GPU 가격으로 AI 개발을 가속화하세요.

AI 협업 코딩
바로 사용 가능한 GPU
최적의 가격

HyperAI Newsletters

최신 정보 구독하기
한국 시간 매주 월요일 오전 9시 에 이번 주의 최신 업데이트를 메일로 발송합니다
이메일 서비스 제공: MailChimp