Why DeepSeek stores its KV cache on disk
Magnitude is an open-source inference engine written in Rust designed to run local large language models faster on Apple Silicon. Unlike prebuilt engines that use compromised generic GPU kernels, Magnitude compiles and benchmarks kernel configurations directly on the host machine to maximize performance for specific chip architectures. In benchmark tests running Qwen3.5 4B on a base M5 MacBook Pro, Magnitude achieved 1.6x faster prefill and 2.7x faster decode speeds compared to Ollama. The engine also features automatic speculative decoding pairing and shared prefix caching to accelerate parallel agentic workloads. DeepSeek open-sourced DeepInfer, an inference stack that achieves up to 26x faster time-to-first-token by serving KV caches directly from SSDs rather than GPU memory. This approach is made feasible by Multi-head Latent Attention (MLA) in DeepSeek-V2, which compresses the KV cache by 93.3% and makes reading from disk faster than recomputing. To overcome single-disk bandwidth bottlenecks, DeepSeek uses its distributed file system, 3FS, to parallelize reads across thousands of SSDs. Consequently, long prefixes can be retained cheaply for days, reducing cache-hit API costs by up to 50x. This section explains the role of the early_exaggeration parameter in the t-SNE dimensionality reduction algorithm. In t-SNE, high-dimensional distances and low-dimensional projections are modeled as probability distributions and aligned using KL divergence. Early exaggeration inflates high-dimensional probabilities by multiplying them by a constant factor greater than one during early optimization iterations, creating tight and well-separated clusters in low-dimensional space. The author also suggests an improved threshold-based exaggeration strategy that only inflates probabilities exceeding a specific value while suppressing lower ones.
Read the original ↗Contents
An open-source engine for faster local LLMs on Mac
Magnitude is an open-source inference engine written in Rust designed to run local large language models faster on Apple Silicon. Unlike prebuilt engines that use compromised generic GPU kernels, Magnitude compiles and benchmarks kernel configurations directly on the host machine to maximize performance for specific chip architectures. In benchmark tests running Qwen3.5 4B on a base M5 MacBook Pro, Magnitude achieved 1.6x faster prefill and 2.7x faster decode speeds compared to Ollama. The engine also features automatic speculative decoding pairing and shared prefix caching to accelerate parallel agentic workloads.
- Magnitude delivers 2.7x faster token decoding (60.0 tok/s vs. 22.6 tok/s) and 1.6x faster prefill (755 tok/s vs. 464 tok/s) than Ollama on an M5 MacBook Pro with Qwen3.5 4B at 4-bit precision.
- Magnitude achieves higher performance by compiling and tuning GPU kernels locally on the user's machine instead of relying on pre-tuned, compromise configurations.
- The engine pairs downloaded models with the fastest speculative decoding drafter it discovers to output multiple tokens per pass.
- Concurrent agent sessions benefit from shared prefix caches, preventing slowdowns during parallel execution.
- Magnitude is licensed under Apache 2.0, written in Rust, and integrates directly with tools such as Claude Code, Codex, OpenCode, and Pi.
Why DeepSeek stores its KV cache on disk
DeepSeek open-sourced DeepInfer, an inference stack that achieves up to 26x faster time-to-first-token by serving KV caches directly from SSDs rather than GPU memory. This approach is made feasible by Multi-head Latent Attention (MLA) in DeepSeek-V2, which compresses the KV cache by 93.3% and makes reading from disk faster than recomputing. To overcome single-disk bandwidth bottlenecks, DeepSeek uses its distributed file system, 3FS, to parallelize reads across thousands of SSDs. Consequently, long prefixes can be retained cheaply for days, reducing cache-hit API costs by up to 50x.
- DeepInfer serves cached prefixes from SSDs, returning the first token up to 26x faster and handling 56% of production input tokens from disk in a single day.
- Multi-head Latent Attention (MLA), introduced in DeepSeek-V2, cuts KV cache size by 93.3% compared to an earlier 67B model by storing compressed vectors per token.
- DeepSeek's distributed file system, 3FS, parallelizes read bandwidth by distributing file chunks across thousands of SSDs on many storage nodes.
- Low-cost disk storage enables long prefix retention periods of 3 days for agent workloads and 7 days for chat traffic.
- On deepseek-flash, prefix cache hits cost 50x less than misses, but require an exact match starting from the initial token.
What is Early Exaggeration in tSNE?
This section explains the role of the early_exaggeration parameter in the t-SNE dimensionality reduction algorithm. In t-SNE, high-dimensional distances and low-dimensional projections are modeled as probability distributions and aligned using KL divergence. Early exaggeration inflates high-dimensional probabilities by multiplying them by a constant factor greater than one during early optimization iterations, creating tight and well-separated clusters in low-dimensional space. The author also suggests an improved threshold-based exaggeration strategy that only inflates probabilities exceeding a specific value while suppressing lower ones.
- t-SNE projects high-dimensional data into low dimensions by minimizing the Kullback-Leibler (KL) divergence between high-dimensional and low-dimensional probability distributions.
- Early exaggeration multiplies all high-dimensional probabilities by a constant factor greater than 1 during initial optimization steps.
- Inflating high-dimensional probabilities forces the optimization to produce larger low-dimensional probabilities, leading to tighter and more widely separated clusters.
- A drawback of standard early exaggeration is that it uniformly inflates probabilities for points that are far apart as well as points that are close.
- A proposed improvement is setting a threshold (λ) to exaggerate probabilities only when they exceed the threshold, while understating those that fall below it.