Skip to main content
Back

ByteDance's LongFlow Cuts Reasoning AI Memory Costs by 11.8x

A new KV cache compression method squeezes reasoning models by 80% and delivers up to 11.8x higher throughput with almost no accuracy loss.

Pro

  • LongFlow compresses the KV cache by 80% for reasoning models while delivering up to 11.8x higher inference throughput.
  • Importance score is derived from an intermediate attention tensor using only the current query, needing no history storage.
  • A custom Triton kernel fuses FlashAttention, scoring, and eviction, cutting attention latency from 47ms to 8ms.
  • Accuracy drop is 0.08% for DeepSeek-R1-Distill-Llama-8B and 1.3% for Qwen3-8B at 80% compression.
  • Static KV cache with one-token-per-step eviction avoids fragmentation and enables larger max batch sizes.
  • Code is available on GitHub; method targets long-output decoding, not long-prefill workloads.

Reasoning models like OpenAI's o1 and DeepSeek-R1 have gotten scary good at math and code, but they pay for it in tokens. A single answer can span tens of thousands of chain-of-thought steps, and every one of those tokens has to sit in the KV cache while attention keeps re-reading it. That is where inference cost quietly explodes.

A team from Soochow University and ByteDance is proposing a fix called LongFlow, a KV cache compression method built specifically for the long-output regime that reasoning models create. Experiments show that LongFlow achieves up to an 11.8 times throughput improvement with 80% KV cache compression with minimal impact on model accuracy. The code is open source.

Why old KV cache tricks break on reasoning models

Most KV cache compression research assumes the classic setup: a huge prompt goes in, a short answer comes out. Reasoning models flip that. The prompt is short, but the model then generates thousands of intermediate thinking tokens before producing an answer, and each new token grows the cache and slows the next attention step.

The authors point out three specific ways existing methods fall apart in this setting:

  • Many methods are confined to the prefill stage, compressing only the initial prompt, which results in a drastically diminished compression ratio in long-output scenarios where most tokens are generated during decoding.
  • Existing methods rely on token importance for eviction, and that evaluation process is computationally expensive, adding significant latency to each compression step. They also often require storing auxiliary metadata such as attention scores or past queries, consuming extra memory that partially cancels out the benefits of compression.
  • Modern inference relies on operator fusion like FlashAttention or PagedAttention, but many compression algorithms are not compatible with these kernels. Their logic can interrupt the fusion process, forcing data movement between SRAM and HBM, or requiring recalculation of intermediate results.

In other words, prior methods either don't compress the part that matters, cost more than they save, or block the fused kernels that make modern serving fast.

The trick: a free importance score

LongFlow's central idea is that you don't need history to decide which tokens to throw out. The central hypothesis is that the current query alone contains sufficient information to effectively estimate the importance of all historical tokens. The authors back this up with a preliminary experiment showing that SnapKV's accuracy barely drops even when its query observation window is shrunk aggressively.

The second principle is what they call zero-cost estimation. Instead of running a separate scoring pass, the importance metric is pulled directly out of an intermediate tensor that attention already computes. Concretely, LongFlow scores each token by:

LongFlowScore(t_i) = ||alpha_i * v_i||_1
                   = attention_weight_i * sum(abs(value_vector_i))

That quantity, the L1 norm of a token's contribution vector, is derived from the math of how attention affects the output. The paper shows that if you evict a token, the change in the attention output is approximately that token's contribution vector, assuming the softmax denominator barely shifts (which holds when there are many tokens). They also argue the current query is a good proxy for the next query because adjacent queries in long chain-of-thought generation have high cosine similarity, and they give a Lipschitz-based error bound to prove it.

Fusing everything into one kernel

The algorithm is cheap on paper, but the real speedup comes from a custom Triton kernel that folds attention, scoring, and eviction into a single pass. The custom kernel fuses FlashAttention, importance estimation, and token eviction into a single optimized operator, reducing attention latency from 47 ms to 8 ms.

The kernel makes three deliberate changes to a FlashAttention-style design:

  1. Since the query length is always 1 during decoding, the outer loop over queries is removed.
  2. The running-max trick for numerically stable softmax is dropped so the score computation can be inlined; FP32 is used to avoid overflow.
  3. The un-normalized contribution vectors exp(scores) * V are reused twice per block: summed along the sequence dimension for the attention output, and reduced with an L1 norm for the LongFlowScore.

Memory management is deliberately boring in a good way. A static KV cache is pre-allocated once, and every decoding step overwrites exactly one slot, chosen by the previous step's eviction decision. That gives a fully predictable workload and, critically, almost no fragmentation, which is what unlocks the larger batch sizes at inference time.

The numbers

The team evaluated on DeepSeek-R1-Distill-Llama-8B and the Qwen3 family (0.6B, 1.7B, 4B, 8B) across a wide reasoning suite: AIME-24, AIME-25, AMC-23, MATH-500, GPQA, GSM8K, Minerva, and OlympiadBench. Generation length was set to 16,000 tokens with KV budgets of either 2,400 or 3,200 tokens, corresponding to roughly 80% and 85% compression.

On accuracy, LongFlow keeps pace with strong baselines like H2O, VATP, and R-KV. The average performance degradation compared to the uncompressed Vanilla baseline is as low as 0.08% for DeepSeek-R1-Distill-Llama-8B and approximately 1.3% for Qwen3-8B. When the budget is tightened from 3.2k to 2.4k, LongFlow degrades less than H2O and VATP.

System-level results on Qwen3-1.7B on a single A100 40GB are where LongFlow pulls ahead sharply. LongFlow outperforms FullKV by a remarkable 11.8 times and is approximately 4.0 times faster than other methods. Peak memory is comparable to other compression baselines, but because eviction happens one token at a time into a static layout, fragmentation stays low, which lets LongFlow push to a larger maximum batch size before hitting OOM.

Where it works and where it doesn't

LongFlow is squarely aimed at autoregressive decoding with long outputs, which is exactly the workload that reasoning models generate. If you are serving DeepSeek-R1-style, Qwen3-thinking, or any long-CoT model at scale and your GPUs are memory-bound on the KV cache, this is designed for you.

The authors are honest about the boundaries. The method leans on the observation that consecutive decoding queries are similar, so in settings with abrupt distribution shifts such as topic switches, tool-use interleaving, or highly stochastic decoding, the current query may be a weaker proxy for near-future behavior, potentially making eviction decisions less optimal. It is also not built for long-prefill, short-output workloads or bidirectional attention. A method that jointly optimizes prefill and long-output decoding is listed as future work.

The bigger picture is that KV cache research is bifurcating. The long-input world is largely solved by prefill-time compressors like SnapKV or PyramidKV. The long-output world, driven by reasoning models that overthink, needs something cheap enough to run every step and friendly enough to live inside a fused attention kernel. LongFlow is one of the first methods designed from the ground up for that regime, and the fact that it comes with a working Triton kernel and open code makes it something you can actually try on your own reasoning stack.