<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
    <channel>
        <title>KV Cache on KnightLi Blog</title>
        <link>https://knightli.com/en/tags/kv-cache/</link>
        <description>Recent content in KV Cache on KnightLi Blog</description>
        <generator>Hugo -- gohugo.io</generator>
        <language>en</language>
        <lastBuildDate>Mon, 18 May 2026 18:38:26 +0800</lastBuildDate><atom:link href="https://knightli.com/en/tags/kv-cache/index.xml" rel="self" type="application/rss+xml" /><item>
        <title>DeepSeek-V4 KV Cache Explained: Why 1M Context Uses Less VRAM</title>
        <link>https://knightli.com/en/2026/05/18/deepseek-v4-kv-cache-compressed-attention/</link>
        <pubDate>Mon, 18 May 2026 18:38:26 +0800</pubDate>
        
        <guid>https://knightli.com/en/2026/05/18/deepseek-v4-kv-cache-compressed-attention/</guid>
        <description>&lt;p&gt;The real cost of long-context models is often not whether they can accept one million tokens, but how much VRAM the KV Cache consumes during inference.&lt;/p&gt;
&lt;p&gt;During Transformer decoding, every newly generated token needs access to the Key and Value states of previous tokens. The longer the context, the larger the KV Cache. A larger KV Cache puts pressure on VRAM, memory bandwidth, time to first token, and throughput.&lt;/p&gt;
&lt;p&gt;DeepSeek-V4 is interesting because it does not only reduce cache along the attention-head dimension. It pushes compression into the sequence-length dimension. According to Hugging Face&amp;rsquo;s discussion of DeepSeek-V4, in a 1M-token setting, DeepSeek-V4-Pro&amp;rsquo;s KV Cache is about 10% of DeepSeek-V3.2, and about 2% of a common bf16 GQA architecture.&lt;/p&gt;
&lt;p&gt;That is the key difference: DeepSeek-V4 does not merely store each KV entry in a smaller format. It reduces the number of KV entries that must be kept and searched over long history.&lt;/p&gt;
&lt;h2 id=&#34;several-generations-of-kv-cache-optimization&#34;&gt;Several generations of KV Cache optimization
&lt;/h2&gt;&lt;p&gt;KV Cache optimization has evolved through several routes.&lt;/p&gt;
&lt;p&gt;The first is traditional MHA, or Multi-Head Attention. Each Query head typically has its own Key/Value heads. The structure is direct, but under long context the cache grows linearly with sequence length, making VRAM pressure heavy.&lt;/p&gt;
&lt;p&gt;The second is GQA, or Grouped Query Attention. Multiple Query heads share fewer Key/Value heads. Many modern models such as LLaMA, Mistral, and Qwen use similar ideas. It significantly reduces KV head count and is now a common long-context optimization.&lt;/p&gt;
&lt;p&gt;The third is MLA, or Multi-head Latent Attention. DeepSeek-V2 and DeepSeek-V3 use this route, compressing Key/Value into low-rank latent representations and further reducing cache along the attention-head dimension.&lt;/p&gt;
&lt;p&gt;The fourth is DeepSeek-V4&amp;rsquo;s hybrid compressed attention. It focuses on sequence length: instead of only reducing how much KV each token stores, it compresses multiple historical tokens into fewer KV entries and retrieves them through sparse or dense attention.&lt;/p&gt;
&lt;p&gt;Roughly:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;MHA: every head remembers separately.&lt;/li&gt;
&lt;li&gt;GQA: multiple Query heads share memory.&lt;/li&gt;
&lt;li&gt;MLA: each token&amp;rsquo;s KV representation is compressed into a latent vector.&lt;/li&gt;
&lt;li&gt;DeepSeek-V4: many historical tokens are aggregated into fewer compressed memory blocks.&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&#34;key-change-from-head-compression-to-sequence-compression&#34;&gt;Key change: from head compression to sequence compression
&lt;/h2&gt;&lt;p&gt;GQA and MLA mainly optimize how much KV each token stores. That works well, but when context reaches 1M tokens, the token count itself becomes the problem.&lt;/p&gt;
&lt;p&gt;DeepSeek-V4 compresses old context into blocks. The model does not necessarily preserve full KV for every distant token. Instead, multiple tokens form compressed entries.&lt;/p&gt;
&lt;p&gt;It is a bit like reading a very long book: you remember recent pages in detail, while earlier chapters are stored more as summaries, themes, and key clues. DeepSeek-V4&amp;rsquo;s attention design follows a similar split: keep detail nearby, use compressed representation farther away.&lt;/p&gt;
&lt;h2 id=&#34;csa-4x-compression-plus-sparse-retrieval&#34;&gt;CSA: 4x compression plus sparse retrieval
&lt;/h2&gt;&lt;p&gt;CSA stands for Compressed Sparse Attention. It is the finer-grained long-context compression mechanism.&lt;/p&gt;
&lt;p&gt;In CSA, the model compresses neighboring tokens into fewer KV entries. The Hugging Face Transformers documentation gives a default compression ratio of &lt;code&gt;m=4&lt;/code&gt;, meaning roughly every four tokens become one compressed entry.&lt;/p&gt;
&lt;p&gt;But it is not simple averaging. CSA uses a learned compression pool and overlapping windows so the model can preserve more useful information. After compression, the query does not attend to all compressed blocks directly. It first uses a Lightning Indexer to score them, selects the most relevant top-k compressed blocks, and then performs the core attention computation.&lt;/p&gt;
&lt;p&gt;This gives two benefits:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;The number of historical KV entries becomes smaller.&lt;/li&gt;
&lt;li&gt;Each query only looks at a relevant subset of compressed blocks.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;CSA is suitable for long-range context where details still matter, such as codebases, long documents, and tool-call histories.&lt;/p&gt;
&lt;h2 id=&#34;hca-128x-compression-plus-dense-attention&#34;&gt;HCA: 128x compression plus dense attention
&lt;/h2&gt;&lt;p&gt;HCA stands for Heavily Compressed Attention, and it is more aggressive.&lt;/p&gt;
&lt;p&gt;The Transformers documentation gives a default compression ratio of &lt;code&gt;m&#39;=128&lt;/code&gt;. HCA compresses a much longer context span into one compressed entry. Because the compressed sequence becomes very short, it does not need sparse top-k retrieval like CSA. The query can simply perform dense attention over all HCA compressed entries.&lt;/p&gt;
&lt;p&gt;HCA acts more like a global summary. It does not try to preserve every detail. Instead, it covers very long history at extremely low cost, helping the model stay aware of global context, long-range topics, and far-away information.&lt;/p&gt;
&lt;p&gt;If CSA is &amp;ldquo;searchable compressed notes,&amp;rdquo; HCA is closer to a &amp;ldquo;global table of contents and summary.&amp;rdquo;&lt;/p&gt;
&lt;h2 id=&#34;sliding-window-recent-context-keeps-details&#34;&gt;Sliding window: recent context keeps details
&lt;/h2&gt;&lt;p&gt;DeepSeek-V4 does not compress everything.&lt;/p&gt;
&lt;p&gt;In addition to CSA and HCA, it keeps a sliding-window branch for the most recent uncompressed context. The Transformers documentation notes that DeepSeek-V4 attention blocks concatenate long-range compressed branches with sliding-window K/V.&lt;/p&gt;
&lt;p&gt;This matters. When generating the next token, the nearest context is often the most important: variable names, function signatures, the current sentence, fresh tool outputs, or the user&amp;rsquo;s latest instruction. If recent context were over-compressed, output quality would suffer.&lt;/p&gt;
&lt;p&gt;So the design is:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Nearby context: preserve uncompressed details.&lt;/li&gt;
&lt;li&gt;Mid-to-long context: use CSA for searchable compression.&lt;/li&gt;
&lt;li&gt;Farther context: use HCA for heavily compressed global summary.&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&#34;hybrid-layer-stack-different-layers-use-different-attention&#34;&gt;Hybrid layer stack: different layers use different attention
&lt;/h2&gt;&lt;p&gt;DeepSeek-V4 does not use one attention mechanism in every layer.&lt;/p&gt;
&lt;p&gt;The Hugging Face DeepSeek-V4 article notes that V4-Pro&amp;rsquo;s 61-layer structure uses HCA in the first two layers, alternates CSA and HCA afterward, and uses a sliding-window MTP block at the end. The Transformers documentation also describes V4-Pro as using two HCA bootstrap layers followed by alternating CSA/HCA layers.&lt;/p&gt;
&lt;p&gt;This shows that DeepSeek-V4 treats attention as a layered system. Different layers handle different information roles: some favor global compression, some favor sparse retrieval, and some preserve local windows.&lt;/p&gt;
&lt;p&gt;Compared with using one attention type everywhere, this hybrid structure is more complex but better suited to 1M-token context.&lt;/p&gt;
&lt;h2 id=&#34;fp8-and-fp4-further-reduce-cache-cost&#34;&gt;FP8 and FP4 further reduce cache cost
&lt;/h2&gt;&lt;p&gt;DeepSeek-V4&amp;rsquo;s savings do not come only from compression ratio.&lt;/p&gt;
&lt;p&gt;The Hugging Face article notes that most KV entries in V4 use FP8 storage, RoPE-related dimensions remain BF16, and the Lightning Indexer in CSA uses FP4. Compression ratio, low-precision storage, and sparse retrieval together create very low KV Cache usage.&lt;/p&gt;
&lt;p&gt;This is a reminder: do not only look at the headline context length. Deployment feasibility is determined by VRAM usage, bandwidth pressure, latency, and implementation quality under long context.&lt;/p&gt;
&lt;h2 id=&#34;differences-from-other-models&#34;&gt;Differences from other models
&lt;/h2&gt;&lt;p&gt;Compared with traditional MHA, DeepSeek-V4 no longer keeps full attention memory for every token in long history, so cache pressure drops sharply.&lt;/p&gt;
&lt;p&gt;Compared with GQA, DeepSeek-V4 does not merely reduce the number of KV heads. It also reduces the number of KV entries for long history. GQA still accumulates cache linearly with sequence length; V4 compresses distant context into blocks.&lt;/p&gt;
&lt;p&gt;Compared with DeepSeek-V3&amp;rsquo;s MLA, V4 extends optimization from &amp;ldquo;making each token representation more compact&amp;rdquo; to &amp;ldquo;compressing the number of historical token entries.&amp;rdquo; MLA already lowers per-token KV cost significantly, but under million-token context, sequence length remains a bottleneck.&lt;/p&gt;
&lt;p&gt;Compared with ordinary sparse attention, CSA compresses first and then performs sparse retrieval over a shorter compressed sequence. HCA goes further, using 128x compression so dense attention becomes cheap.&lt;/p&gt;
&lt;h2 id=&#34;what-it-means-for-agents-and-long-tasks&#34;&gt;What it means for agents and long tasks
&lt;/h2&gt;&lt;p&gt;Agent workflows are especially hungry for long context. They read files, call tools, receive tool results, generate plans, revise plans, and call tools again. The longer the context, the more likely KV Cache becomes the bottleneck.&lt;/p&gt;
&lt;p&gt;DeepSeek-V4&amp;rsquo;s cache design may help in several ways:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Easier handling of long codebases, long documents, and multi-round tool histories.&lt;/li&gt;
&lt;li&gt;Less pressure on time to first token and throughput from KV Cache.&lt;/li&gt;
&lt;li&gt;Longer context or more concurrent requests on the same hardware.&lt;/li&gt;
&lt;li&gt;Million-token context becomes closer to practical deployment, not just a benchmark number.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;But compressed attention is not free. Compressing historical tokens into blocks involves information trade-offs. The model must balance saving VRAM with preserving retrievable details. Real performance depends on the task: code navigation, legal documents, long-form QA, and agent toolchains all have different detail-recall needs.&lt;/p&gt;
&lt;h2 id=&#34;do-not-read-2-as-2-of-all-cost&#34;&gt;Do not read 2% as 2% of all cost
&lt;/h2&gt;&lt;p&gt;&amp;ldquo;KV Cache is about 2% of GQA&amp;rdquo; is easy to misread.&lt;/p&gt;
&lt;p&gt;It mainly refers to KV Cache memory size. It does not mean total inference cost drops to 2%, or that every scenario becomes 50x faster. Inference still includes model weight reads, MoE routing, feed-forward networks, attention computation, scheduling, and communication overhead.&lt;/p&gt;
&lt;p&gt;The Hugging Face article separates two numbers: in 1M-token context, DeepSeek-V4-Pro&amp;rsquo;s per-token inference FLOPs are 27% of DeepSeek-V3.2, while KV Cache is 10%. Cache and compute are different dimensions.&lt;/p&gt;
&lt;p&gt;The safer statement is: DeepSeek-V4 greatly reduces KV Cache pressure for ultra-long context, improving deployment feasibility for million-token scenarios. Actual latency and throughput still depend on implementation, hardware, batching, quantization, and inference framework.&lt;/p&gt;
&lt;h2 id=&#34;summary&#34;&gt;Summary
&lt;/h2&gt;&lt;p&gt;The biggest difference between DeepSeek-V4 and other large models is that it moves KV Cache optimization from the attention-head dimension into the sequence-length dimension.&lt;/p&gt;
&lt;p&gt;GQA stores fewer KV heads. MLA makes each token&amp;rsquo;s KV representation more compact. DeepSeek-V4 further aggregates distant tokens into compressed blocks and combines CSA, HCA, sliding windows, and low-precision storage so million-token context is not immediately blocked by KV Cache.&lt;/p&gt;
&lt;p&gt;This is not a single trick. It is a long-context inference architecture: preserve details nearby, compress distant context, retrieve details when needed, and summarize globally when possible.&lt;/p&gt;
&lt;p&gt;For developers and agent applications, the meaning is direct: long context is not just about accepting more input. It must be runnable, stable, and affordable. That is what DeepSeek-V4 changes.&lt;/p&gt;
&lt;h2 id=&#34;references&#34;&gt;References
&lt;/h2&gt;&lt;ul&gt;
&lt;li&gt;&lt;a class=&#34;link&#34; href=&#34;https://huggingface.co/blog/deepseekv4&#34;  target=&#34;_blank&#34; rel=&#34;noopener&#34;
    &gt;Hugging Face: DeepSeek-V4: a million-token context that agents can actually use&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a class=&#34;link&#34; href=&#34;https://huggingface.co/docs/transformers/model_doc/deepseek_v4&#34;  target=&#34;_blank&#34; rel=&#34;noopener&#34;
    &gt;Hugging Face Transformers: DeepSeek-V4 model documentation&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a class=&#34;link&#34; href=&#34;https://arxiv.org/abs/2412.19437&#34;  target=&#34;_blank&#34; rel=&#34;noopener&#34;
    &gt;DeepSeek-V3 Technical Report&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
</description>
        </item>
        <item>
        <title>How to Tune llama.cpp on 8GB VRAM: Why 32K Is Safer and 64K Needs KV Cache Quantization</title>
        <link>https://knightli.com/en/2026/04/23/llama-cpp-8g-vram-32k-64k-kv-cache-tuning/</link>
        <pubDate>Thu, 23 Apr 2026 12:13:04 +0800</pubDate>
        
        <guid>https://knightli.com/en/2026/04/23/llama-cpp-8g-vram-32k-64k-kv-cache-tuning/</guid>
        <description>&lt;p&gt;Whether &lt;code&gt;8GB&lt;/code&gt; of VRAM is enough to run local LLMs smoothly, especially under long-context workloads, is one of the most common questions people run into when using &lt;code&gt;llama.cpp&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;There are three key takeaways worth remembering first:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;On &lt;code&gt;8GB&lt;/code&gt; VRAM, &lt;code&gt;32K&lt;/code&gt; context is usually the safer balance point&lt;/li&gt;
&lt;li&gt;If you really want to run &lt;code&gt;64K&lt;/code&gt;, &lt;code&gt;KV Cache&lt;/code&gt; quantization is often essential&lt;/li&gt;
&lt;li&gt;In full-GPU inference, blindly increasing &lt;code&gt;CPU&lt;/code&gt; thread count can actually make performance worse&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&#34;1-first-what-do-32k-64k-and-kv-cache-actually-mean&#34;&gt;1. First, what do 32K, 64K, and KV Cache actually mean?
&lt;/h2&gt;&lt;p&gt;For many readers, these are the three terms that cause the most confusion.&lt;/p&gt;
&lt;p&gt;&lt;code&gt;32K&lt;/code&gt; and &lt;code&gt;64K&lt;/code&gt; refer to context length, meaning how many &lt;code&gt;tokens&lt;/code&gt; the model can process at one time. Here, &lt;code&gt;K&lt;/code&gt; means thousand, so &lt;code&gt;32K&lt;/code&gt; is about &lt;code&gt;32000 tokens&lt;/code&gt;, and &lt;code&gt;64K&lt;/code&gt; is about &lt;code&gt;64000 tokens&lt;/code&gt;. The longer the context, the more prior content the model can see at once, which is useful for long-document QA, long conversations, and multi-step analysis.&lt;/p&gt;
&lt;p&gt;&lt;code&gt;KV Cache&lt;/code&gt; is an intermediate-result cache that the model keeps in order to speed up autoregressive generation. You can think of it like this: once the model has already read and computed part of the context, it does not need to recompute everything from scratch every time. Instead, it stores key intermediate information and reuses it. The &lt;code&gt;K&lt;/code&gt; and &lt;code&gt;V&lt;/code&gt; come from &lt;code&gt;Key&lt;/code&gt; and &lt;code&gt;Value&lt;/code&gt; in the Transformer architecture.&lt;/p&gt;
&lt;p&gt;Why do these three terms always appear together? Because:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;32K&lt;/code&gt; and &lt;code&gt;64K&lt;/code&gt; define how much content you want the model to remember at once&lt;/li&gt;
&lt;li&gt;&lt;code&gt;KV Cache&lt;/code&gt; determines how much extra VRAM is needed to maintain that memory&lt;/li&gt;
&lt;li&gt;The longer the context, the larger the &lt;code&gt;KV Cache&lt;/code&gt; usually becomes, and the higher the VRAM pressure gets&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;So when long-context inference slows down, the root problem is often not that the model is &amp;ldquo;bad at computing&amp;rdquo;, but that the cache has grown large enough to push VRAM to its limit.&lt;/p&gt;
&lt;h2 id=&#34;2-why-does-32k-perform-so-differently-from-64k&#34;&gt;2. Why does 32K perform so differently from 64K?
&lt;/h2&gt;&lt;p&gt;Using roughly &lt;code&gt;30000&lt;/code&gt; Chinese characters from &lt;em&gt;The Three-Body Problem&lt;/em&gt; as a stress-test input, the comparison between &lt;code&gt;32K&lt;/code&gt; and &lt;code&gt;64K&lt;/code&gt; context can look dramatic: with similar document size, &lt;code&gt;64K&lt;/code&gt; can become much slower and total runtime can increase significantly.&lt;/p&gt;
&lt;p&gt;The reason is not that the model suddenly becomes worse. The real issue is hitting the VRAM boundary.&lt;/p&gt;
&lt;p&gt;At &lt;code&gt;32K&lt;/code&gt;, model weights plus cache may still fit within &lt;code&gt;8GB&lt;/code&gt; VRAM, so most data traffic stays on the GPU&amp;rsquo;s own memory bandwidth. But once you move to &lt;code&gt;64K&lt;/code&gt;, the cache grows further, total memory use approaches or exceeds the VRAM ceiling, and part of the data gets pushed into shared or system memory.&lt;/p&gt;
&lt;p&gt;At that point, what collapses is not raw compute, but bandwidth.&lt;/p&gt;
&lt;p&gt;In other words, what looks like &amp;ldquo;context doubled and performance crashed&amp;rdquo; is often really a case of the data path falling out of VRAM and into much slower memory.&lt;/p&gt;
&lt;h2 id=&#34;3-if-you-want-64k-kv-cache-quantization-matters-a-lot&#34;&gt;3. If you want 64K, KV Cache quantization matters a lot
&lt;/h2&gt;&lt;p&gt;One of the most important conclusions for &lt;code&gt;8GB&lt;/code&gt; VRAM users is that &lt;code&gt;KV Cache&lt;/code&gt; quantization matters a great deal.&lt;/p&gt;
&lt;p&gt;Without changing the model itself, quantizing only the cache can directly reduce cache memory usage under long context. That means some of the data that previously spilled out of VRAM can move back into VRAM. As a result, &lt;code&gt;64K&lt;/code&gt; is still heavier than &lt;code&gt;32K&lt;/code&gt;, but it is less likely to fall into the slowest performance zone.&lt;/p&gt;
&lt;p&gt;Put simply:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;32K&lt;/code&gt; is the more practical default range for &lt;code&gt;8GB&lt;/code&gt; VRAM&lt;/li&gt;
&lt;li&gt;&lt;code&gt;64K&lt;/code&gt; is not impossible&lt;/li&gt;
&lt;li&gt;But without cache quantization, performance can drop from &amp;ldquo;usable&amp;rdquo; to &amp;ldquo;hard to use&amp;rdquo;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;If your goal is stable long-context inference, the usual priority should be:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Check whether VRAM is already near its ceiling&lt;/li&gt;
&lt;li&gt;Decide whether to enable &lt;code&gt;KV Cache&lt;/code&gt; quantization&lt;/li&gt;
&lt;li&gt;Only then continue experimenting with more aggressive throughput settings&lt;/li&gt;
&lt;/ol&gt;
&lt;h2 id=&#34;4-low-gpu-utilization-does-not-mean-the-gpu-is-idle&#34;&gt;4. Low GPU utilization does not mean the GPU is idle
&lt;/h2&gt;&lt;p&gt;This is a point that often breaks intuition.&lt;/p&gt;
&lt;p&gt;When people see only 20% or 30% &lt;code&gt;GPU&lt;/code&gt; usage in Task Manager, they often assume:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;the parameters must be wrong&lt;/li&gt;
&lt;li&gt;the model is not really running on the GPU&lt;/li&gt;
&lt;li&gt;the GPU is not being used fully&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;But the more likely explanation in &lt;code&gt;llama.cpp&lt;/code&gt; inference is that the bottleneck is not core compute, but memory reads and writes.&lt;/p&gt;
&lt;p&gt;That means GPU cores may finish a batch of computation quickly, then spend the rest of the time waiting for the next batch of weights or cached data to arrive.&lt;/p&gt;
&lt;p&gt;So what you see becomes:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;core utilization is not especially high&lt;/li&gt;
&lt;li&gt;but end-to-end speed still fails to improve&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;This is not the GPU being lazy. It is the data path being too narrow.&lt;/p&gt;
&lt;p&gt;That is why you should not look only at &lt;code&gt;GPU Usage&lt;/code&gt; when judging local LLM performance. VRAM capacity, memory bandwidth, and cache spillover often matter more.&lt;/p&gt;
&lt;h2 id=&#34;5-increasing-throughput-parameters-can-help-but-only-if-vram-can-handle-it&#34;&gt;5. Increasing throughput parameters can help, but only if VRAM can handle it
&lt;/h2&gt;&lt;p&gt;Another useful idea is this: if GPU cores are not fully saturated, maybe you can increase throughput-related parameters so the GPU processes more data at once and uses its parallelism more effectively.&lt;/p&gt;
&lt;p&gt;This can indeed improve speed.&lt;/p&gt;
&lt;p&gt;But there is an important condition: VRAM must still have headroom.&lt;/p&gt;
&lt;p&gt;Because once you increase throughput-related settings, you often also increase VRAM usage. If you are already in a &lt;code&gt;64K&lt;/code&gt; scenario with large cache and VRAM near exhaustion, pushing those parameters further can lead to two outcomes:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;a crash&lt;/li&gt;
&lt;li&gt;or a fallback into much slower shared-memory behavior&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;So the safer sequence is usually not &amp;ldquo;max out the knobs first&amp;rdquo;, but:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;protect the VRAM boundary first&lt;/li&gt;
&lt;li&gt;then try throughput optimization&lt;/li&gt;
&lt;li&gt;after every change, check both speed and stability again&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&#34;6-more-cpu-threads-are-not-always-better&#34;&gt;6. More CPU threads are not always better
&lt;/h2&gt;&lt;p&gt;This is one of the easiest traps to remember.&lt;/p&gt;
&lt;p&gt;It is very natural to assume that more threads should mean better speed. But in practice, once the model is already running mostly on the GPU, forcing &lt;code&gt;CPU&lt;/code&gt; thread count higher can make performance noticeably worse.&lt;/p&gt;
&lt;p&gt;The reason is straightforward.&lt;/p&gt;
&lt;p&gt;In full-GPU inference, the &lt;code&gt;CPU&lt;/code&gt; is more of a scheduler and preprocessing helper than the main compute engine. If you open too many threads, CPU-side thread contention, scheduling overhead, and context-switching costs all become heavier, which can disrupt the data flow that should have stayed smooth.&lt;/p&gt;
&lt;p&gt;The result is:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;the &lt;code&gt;CPU&lt;/code&gt; looks busier&lt;/li&gt;
&lt;li&gt;but overall speed gets slower&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;So in this kind of setup, default settings or lower thread counts are often more reliable than simply maxing everything out.&lt;/p&gt;
&lt;h2 id=&#34;7-a-more-practical-approach-for-8gb-vram-users&#34;&gt;7. A more practical approach for 8GB VRAM users
&lt;/h2&gt;&lt;p&gt;If we compress the conclusions above into a practical workflow, it looks roughly like this:&lt;/p&gt;
&lt;h3 id=&#34;1-treat-32k-as-the-default-goal&#34;&gt;1. Treat 32K as the default goal
&lt;/h3&gt;&lt;p&gt;If you only have an &lt;code&gt;8GB&lt;/code&gt; GPU, do not rush to chase &lt;code&gt;64K&lt;/code&gt;. &lt;code&gt;32K&lt;/code&gt; is usually the more realistic balance between speed, stability, and memory usage.&lt;/p&gt;
&lt;h3 id=&#34;2-if-you-want-64k-deal-with-the-cache-first&#34;&gt;2. If you want 64K, deal with the cache first
&lt;/h3&gt;&lt;p&gt;Do not start by asking whether you can squeeze out a little more speed. First confirm whether &lt;code&gt;KV Cache&lt;/code&gt; is quantized and whether VRAM is already near the limit.&lt;/p&gt;
&lt;h3 id=&#34;3-do-not-judge-everything-by-gpu-utilization&#34;&gt;3. Do not judge everything by GPU utilization
&lt;/h3&gt;&lt;p&gt;Low utilization does not necessarily mean the settings are wrong. It may simply mean memory bandwidth is the real bottleneck.&lt;/p&gt;
&lt;h3 id=&#34;4-throughput-optimization-is-valid-but-do-not-cross-the-vram-boundary&#34;&gt;4. Throughput optimization is valid, but do not cross the VRAM boundary
&lt;/h3&gt;&lt;p&gt;These parameters can help, but only if there is still enough VRAM headroom.&lt;/p&gt;
&lt;h3 id=&#34;5-be-conservative-with-cpu-threads-first&#34;&gt;5. Be conservative with CPU threads first
&lt;/h3&gt;&lt;p&gt;If the model is already running mostly on the GPU, higher CPU thread counts are not automatically better. Start with defaults or lower thread counts, then test gradually.&lt;/p&gt;
&lt;h2 id=&#34;conclusion&#34;&gt;Conclusion
&lt;/h2&gt;&lt;p&gt;The most valuable part of this whole discussion is not just a few benchmark numbers, but the fact that it makes one easily overlooked truth much clearer:&lt;/p&gt;
&lt;p&gt;Local LLM tuning is often not about pushing every setting to the maximum. It is about understanding whether your real bottleneck is compute, VRAM capacity, memory bandwidth, or &lt;code&gt;CPU&lt;/code&gt; scheduling.&lt;/p&gt;
&lt;p&gt;For &lt;code&gt;8GB&lt;/code&gt; VRAM users, the safer strategy is usually not to force the longest possible context, but to protect the VRAM boundary first and only then decide how far to push further.&lt;/p&gt;
&lt;p&gt;If you only remember one sentence, make it this:&lt;/p&gt;
&lt;p&gt;&lt;code&gt;32K&lt;/code&gt; is often the more stable working range for &lt;code&gt;8GB&lt;/code&gt; VRAM; &lt;code&gt;64K&lt;/code&gt; is possible, but only if you have already brought &lt;code&gt;KV Cache&lt;/code&gt; and VRAM usage under control.&lt;/p&gt;
</description>
        </item>
        
    </channel>
</rss>
