ercem (@erguncm) profile picture
Joined March 2015
Photo by ercem (@erguncm)
6 KV cache quantization approaches, explained visually: Quantizing model weights doesn't automatically shrink the KV cache. The cache stores activations generated during inference, and its memory grows with retained tokens and concurrent requests. KV quantization reduces the bytes used to store those activations. For instance, moving from 16-bit to 8-bit halves the raw KV payload, before scales, metadata, and any high-precision buffers. The diagram covers six approaches. In practice, several approaches can be combined within the same implementation. 1. FP8 cache The KV cache normally stores each number using 16 bits. FP8 reduces this to 8 bits, so the numbers take up half the space. A scaling factor adjusts their range before storage. The serving engine needs an attention kernel that supports this format. 2. INT8 / INT4 cache These methods convert cached numbers into 8-bit or 4-bit integers. INT4 uses less memory, but has fewer values to choose from, so rounding introduces more error. During attention, the kernel converts the stored integers back into approximate versions of the original numbers. 3. Quantization granularity Quantization uses a scale to convert numbers into a smaller format. One scale can serve the whole tensor, or separate scales can serve individual channels, tokens, or small groups. Smaller groups fit their numbers more closely. But each group needs its own scale, which also takes memory. 4. KIVI-style quantization Keys and values don't have the same pattern of large numbers, so KIVI compresses them differently. For keys, it groups numbers from the same channel across tokens. For values, it groups numbers within each token. This helps preserve accuracy even at 2-bit precision, without fine-tuning the model. 5. Mixed precision This approach keeps recent tokens' keys and values at higher precision and compresses older entries. Attention reads both parts. Keeping some entries uncompressed avoids rounding errors for those entries, but uses more memory than compressing the entire cache. 6. Non-uniform / outlier-aware quantization Uniform quantization rounds numbers to evenly spaced levels. Non-uniform quantization changes the spacing to better represent the numbers that matter. Outlier-aware methods handle unusually large numbers separately. KVQuant stores these outliers in a separate structure, so they don't force the remaining numbers into a range that's too wide. A smaller cache can fit longer contexts or more requests on the same GPU. It doesn't guarantee faster decoding, because compressing and reading the numbers also takes work. Compare each method against an unquantized cache to check how much memory it saves, whether decoding gets faster or slower, and whether answer quality drops. If you want to dive deeper, I wrote a KV Cache Engineering article covering quantization and other ways to reduce cache memory, with code examples and their trade-offs. Read it below.
16
36
1
230
14,120
How do LLMs handle GBs of KV cache in production? (a popular technical LLM interview question) At scale, KV cache becomes a storage system. Every attention layer creates KV tensors while processing a prompt. During generation, the model reads this state instead of processing the entire sequence again for every new token. For a single request, this is temporary GPU data. But when multiple requests and inference workers reuse the same prompt prefix, the cached data must remain available after the original request finishes. It may even need to survive after the engine that created it restarts. So a cache hit now requires more than identifying matching tokens. The system must find the relevant blocks, bring them back into GPU memory, remove old blocks when storage fills, and let multiple workers reuse the same data. Consider a request that shares 80% of its prompt with an earlier request. The matching tensors may already be in GPU memory. Otherwise, the system could retrieve them from CPU memory, a local SSD, or remote storage. The model then processes only the uncached 20%. It stores the newly created tensors so later requests can reuse them. This involves moving large amounts of data between memory and storage while the GPU is also generating tokens. Inference engines such as vLLM are mainly designed to schedule requests and run the model. Cache management requires a different set of operations around storage, movement, and cleanup. The solution is actually open-source and implemented in the LMCache package. It runs KV cache management as a standalone service beside the inference engine. The engine requests the required blocks, while LMCache finds them, moves them into the right memory, and stores new blocks afterward. LMCache uses CUDA IPC, a mechanism that lets separate processes access the same GPU memory. This avoids copying the full cached tensors through ordinary messages between the two processes. Cached blocks can also move between GPU memory, CPU memory, local storage, and remote storage. On a hit, the inference engine restores the reusable blocks and processes only the missing tokens. Multiple vLLM instances on the same machine can share one LMCache service. Cache storage can scale separately, and restarting an inference worker does not automatically remove the saved cache. The LMCache paper reports up to 15x higher throughput when combining it with vLLM across the evaluated workloads. The visual below traces one prompt through the inference engine, cache service, shared GPU memory, and storage levels. LMCache GitHub: github.com/LMCache/LMCache (don’t forget to star it ⭐) If you want to dive deeper, we wrote a detailed breakdown of KV, prefix, prompt, and semantic caching, including where LMCache fits into the serving stack. Read it below.
12
24
100
8,040
this is pure f*cking gold for anyone running coding agents Jev founder Diogo Amogo wrote a PDF on building a Jev harness the promise: > 200x faster > 400x cheaper the model hasn't been the slow part for a while the speed and the cost sit in the harness wrapped around it • how to use it > drop this PDF and the article below into Claude Code or Codex > let it rebuild its own setup one evening of setup and your agent starts next week on a harness most teams still don't have
40
139
4
1,175
79,340
Google just open-sourced Harness². (turn any harness into a self-improving system) a harness is everything wrapped around the model, like the system prompt, tools, memory, skills, and subagents. today a person designs it once, and the agent runs every new task with that same fixed setup. Harness² lets the agent refine that setup for each new task on its own, with the model weights left untouched. on every task, the agent proposes edits to its harness, runs a few candidate versions, and composes a better harness by comparing how those runs behaved. because it learns from the differences between runs, it needs no correct answer or grader for the task. that covers a single task. Harness² also carries what it learns from one task into the next. after each task, it saves the harness it settled on along with the lessons that held up across the runs. the next time it refines a harness, it starts from those notes instead of from scratch. this means every finished task makes the next round of edits more informed. Google tested this with Gemini 3.5 Flash and GLM-5 on legal, office, and professional work benchmarks. one round of edits was enough to beat their original harnesses, and giving the agent more rounds pushed scores higher. those extra rounds can go wide or deep. the agent either tries several candidate harnesses at once or keeps refining a single one step by step, using OpenCode or Codex to carry out the work. you can find the Harness² repo here: github.com/google-research/h… I wrote about a similar idea for agents already running in production, where the harness should repair itself after a failure instead of waiting for someone to debug the trace by hand. that piece walks through how @Cometml's Opik (open-source) closes this loop, going from a failing trace to a proposed fix to a regression test that stops the same failure from coming back. it's quoted below.
347
994
106
7,497
754,458
reverse engineer anything. (100% open-source, 200k+ stars) when you like a feature in someone else's app, you usually can't see how it was built because the source code isn't available. figuring it out used to mean hours jumping between 10+ specialized tools and reading machine code by hand. REA is an open-source MCP server that hands this work to your agent. you give it an app and a question, and the agent traces the feature down to the compiled code, explains how it works, and can build a version for your own project. how it works: REA brings the tools reverse engineers rely on, like Ghidra, IDA and JADX, under one interface that Claude Code, Codex, Cursor and other agents can call. your agent asks REA to inspect the app, and REA picks the right tool, runs it locally, and returns what it found along with the evidence behind each finding. the agent then uses those findings to dig further, explain the behavior, or write and test its own version. since every claim points back to real code, the agent works from evidence instead of guessing. what you can do with it ↳ see how a desktop app like Notion handles copy and paste, from the button you click to the code that runs behind it. ↳ look inside compiled programs and games to understand the logic they were built on. ↳ break down Android apps into readable code to see how a feature is put together. ↳ inspect how a website is structured and what it sends over the network. ↳ examine device firmware, network recordings and other files that were never meant to be read by people. in one of their showcases, it rebuilt a sound function from the old DX-Ball game that compiles back to the exact same code as the original. everything runs on your machine, and setup adds it to your agent with a single command: 𝗻𝗽𝘅 𝗿𝗲𝗮-𝗮𝗴𝗲𝗻𝘁𝘀 𝘀𝗲𝘁𝘂𝗽 it's meant for software you own or are authorized to analyze. repo: github.com/morluto/rea a while back, i wrote about two gaps in Claude Code. it only gets a summary when it reads a web page instead of the full content, and it can't see the full state of your backend. adding the right skills fixes both. REA builds on that same setup and covers one more gap, since your agent can now understand apps it never had the source code for. the full article is in the quoted post below.
52
100
3
576
34,111
🚨 ÇİN'DEN YENİ OCR DEVRİMİ: 100 SAYFALIK PDF'LERİ TEK SEFERDE YUTAN MODEL! Baidu, 100 sayfalık PDF dosyalarını parçalamadan tek geçişte okuyabilen "Unlimited OCR" modelini açık kaynak olarak yayınladı! DeepSeek OCR'ı bir adım öteye taşımak için geliştirilen 3B parametreli modelin öne çıkan detayları: → **Kesintisiz Bağlam (32K Window):** Belgeleri sayfa sayfa bölüp bağlamı kaybetmek yerine, 32K bağlam penceresiyle tüm dokümanı tek seferde işliyor. → **Yerel ve Ücretsiz:** Transformers, vLLM, SGLang, Docker, Ollama ve llama.cpp desteğiyle %100 kendi donanımınızda ve ücretsiz çalışıyor. → **Üstün Performans:** Standart ayrıştırma testlerinde %93 başarı (baz modelden 6 puan yüksek) ve 40 sayfayı geçen belgelerde 0.11'in altında hata oranı. → **Maliyet Devrimi:** 1.000 sayfada 1.5$ - 15$ alan geleneksel bulut servislerinin (Textract, Google Vision vb.) aksine sıfır maliyet sunuyor. Hugging Face'te şimdiden 1.9 milyon indirmeye ulaşan ve çok dilli destek sunan devasa bir açık kaynak hamlesi! Bu paylaşımı kaydet, açık kaynak yapay zeka araçlarını ve OCR teknolojisindeki gelişmeleri kaçırma. KAYDET ve PAYLAŞ
5
103
1
608
35,662
Jev for Agent Memory, clearly explained: An agent-memory system often passes conversations, tool results, and task outcomes through an extractor. The extractor identifies possible memories such as user preferences, facts, and procedures. Consider a travel assistant. The user says: - I usually prefer an aisle seat. - For this flight, book a window seat. - The flight is delayed by 25 minutes. These statements should not receive identical treatment. The aisle-seat preference could help with future bookings. The window-seat request applies to one flight. The delay becomes useless once the flight is over. A capable memory system may already handle this distinction. Graphiti, for example, records where a fact came from, resolves it against existing facts, and tracks when it becomes valid or invalid. If the source contains enough context, it can keep the window-seat request specific to one trip. So Jev should not be added to recreate logic the memory system already provides. It becomes useful when the application has its own rules for what may enter long-term memory. A travel application might require that: - Only preferences stated or confirmed by the user become account-level memories. - Preferences inferred from one booking remain attached to that trip. - Passport numbers and payment details never enter general memory. - Ambiguous candidates remain in the session until the user confirms them. These rules require semantic judgment. Once the info has been classified, ordinary code can enforce the policy. The challenge here is deciding whether a sentence describes a lasting preference, a one-time instruction, or weak evidence for an inferred preference. Jev can make that decision before the app even invokes Graphiti. For each candidate, the application sends Jev the proposed fact, its source evidence, and the current user, trip, and session state. It can ask typed questions such as: - Did the user state this preference explicitly? - Does it apply beyond the current trip? - Which retention scope fits it? - Would reusing it on another booking create a meaningful risk? Jev returns choices, scores, and probabilities. Application code applies the thresholds: ↳ Save the aisle-seat preference for the user. ↳ Keep the window-seat request with this trip. ↳ Leave the delay in the active session. ↳ Reject sensitive fields before they reach general memory. Several questions can share the same state in one Jev request. - Approved candidates are then sent to Graphiti as episodes. - From there, Graphiti handles extraction, entity resolution, provenance, temporal updates, and retrieval. GitHub repo: github.com/getzep/graphiti (don't forget to star it ⭐) Note that if Graphiti's existing ingestion behavior meets your application's requirements, the Jev gate is unnecessary. Add Jev when you need to check product-specific rules, such as whether a preference was explicitly confirmed or whether a fact is safe to store, before sending it to Graphiti. If you want to dive deeper, I have also written a hands-on guide showing how to build a Jev-style model with open models, entirely locally. Read it below.
23
38
4
202
16,573
If you've ever wondered how Large Language Models like ChatGPT work, this course is for you. It covers the data preparation, model training, and fine-tuning that has to happen before an LLM is ready to go. You'll learn about the whole training process from tokenizing raw text to fine-tuning a functional chatbot. freecodecamp.org/news/train-…
8
83
1
793
40,213
Systems Thinking for Agentic AI — Design reliable LLM and agentic AI systems with RAG, MCP, guardrails, evaluation, and observability: link.amazon/B0exzW2nC
4
83
1
420
17,125
You can literally type a sentence and watch a Transformer process it. This interactive explainer runs a GPT-style model in the browser and lets you follow the whole path: tokenization → embeddings → Q/K/V → attention → MLP → logits → next-token probabilities You can inspect attention maps, intermediate values, and change temperature, top-k and top-p to see how generation changes. If Transformers still feel like boxes connected by arrows, this is worth opening. poloclub.github.io/transform…
36
375
25
2,392
135,139
Full Claude Course Master Claude to automate repetitive tasks, build apps without coding, create real portfolio projects, and become more valuable at work.
🤖 Made with AI

696
1,198
66
14,073
54,528,653
ercem retweeted
1
110
1
511
17,214
Seriously?! Over 3000 pages of scientific programming power with Python! Download this 3582-page PDF “SciPy Reference Guide” at static.scipy.org/doc/scipy-1…
4
91
437
18,245
Full Claude Course Master Claude to automate repetitive tasks, build apps without coding, create real portfolio projects, and become more valuable at work.

2,255
4,312
100
29,729
169,748,252
8 Types of LLMs used in AI Agents (Must know for Gen AI Data Scientists & AI Engineers): Here's what they are and what they do: 🧵
6
76
1
329
10,037
A full-stack LLM engineering roadmap covering: > Prompt engineering > RAG systems > Fine-tuning > Agents > LLM deployment > LLM optimization > Safety, evals & observability > Context engineering Free and open-source resources in the article below. (bookmark this)
16
58
3
322
20,521
Awesome updated 309-page PDF eBook >> "Patterns, Predictions, and Actions: Foundations of Machine Learning" arxiv.org/abs/2102.05242 …sharpen your Probability, Calculus, and Linear Algebra knowledge with this! ————— #ML #DataScience #DataScientist
5
55
276
13,982
ercem retweeted
Really nice paper on harness-aware distillation for small language model agents. (bookmark it) It's a super interesting distillation framework for small language model agents that are deployed with a harness. In simple terms, you run the big model with and without harness info, then train the small model on cases where its action changes. Researchers show that adding the harness to on-policy distillation raises how often the student uses harness information on ALFWorld (65.7% to 73.1%) but leaves success flat (43.1% to 43.5%). Their method, Harness-Aware Distillation, queries the same teacher with and without the harness information and trains the student to prefer the action chosen with it. A filter drops pairs whose preferred action contradicts the harness records. The method uses no task rewards or success labels. The student reaches 63.4% on unseen ALFWorld tasks, compared with 47.0% for the best baseline, and exceeds its 8B teacher. It also escapes 59.7% of stalls, while the baselines stay near the untrained student's 46.8%. Paper: arxiv.org/abs/2610.02858 Chat with Paper: academy.dair.ai/papers/harne…
16
29
1
186
12,200
Python for Data Analysis — Free PDF Want to take your Python skills into real-world data analysis? This 905-page guide covers a wide range of topics around: Python for Data Analysis Data Analytics & Visualization Advanced Models Automation & Scalable Data Workflows Practical tools and techniques for modern data work A useful resource for Python developers, data analysts, and anyone building skills in data science. Free PDF: clcoding.com/2026/07/python-…
3
86
3
400
23,662
The LLM scheduling loop, clearly explained: (bookmark this) Whenever a user sends a prompt to an LLM, the resulting inference request does not go straight from the API endpoint to the GPU. Instead, it first enters the serving engine, where a scheduler decides when and how its tokens will be processed. Here is the complete lifecycle: 1) The request enters the waiting queue Each request arrives with a prompt, sampling settings, and a maximum output length. Prompt lengths vary, and the scheduler cannot know the final generation length in advance. It therefore manages requests one iteration at a time. 2) The scheduler builds the next batch Before every model step, the scheduler checks two main constraints: - How many tokens can be processed in this iteration - How much KV-cache space remains It then applies a scheduling policy, often prioritizing running decode requests before admitting new work. 3) New requests enter prefill During prefill, the model processes the prompt tokens and creates the K and V tensors needed by attention. This stage can process many prompt tokens in parallel. Long prompts may be split into chunks so they do not block active generations for too long. 4) Running requests enter decode Once prefill finishes, the request moves to decode. The model now generates the next token using the KV cache created for all previous tokens. Standard autoregressive decoding usually adds one new token per active request during a model step. 5) The GPU executes the selected work Modern serving engines can place prefill and decode work in the same GPU batch. For example, request A may be processing its prompt while requests B and C generate their next tokens. The batch is therefore not a fixed group that runs until every request finishes. Its composition can change after every model step. 6) The engine updates request state After execution, generated tokens are sampled and appended to their requests. A finished request releases its KV-cache blocks and leaves the batch. An unfinished request keeps its state and becomes eligible for the next scheduling iteration. The scheduler can then use the freed token budget and cache space to admit another waiting request. In the visual below, C finishes after iteration 1, so D enters during iteration 2. By iteration 3, the active batch contains only A and D. This iteration-level replacement is continuous batching. It keeps the GPU working while requests with different prompt and output lengths progress independently. If you want to dive deeper, I wrote a detailed article covering the full LLM inference pipeline, including tokenization, prefill, decode, KV caching, and the latency metrics each stage controls. Read it below.
24
48
247
24,696