Skip to content

Projective Shannon Sketches for Transformer KV Memory: Needle Rescue under Compressed Keys on GPT Model

Sep 2026 · Zenodo (CERN European Organization for Nuclear Research)

Abstract

Projective KV-Cache: Slashing LLM Memory Costs by 50%–75% Without Context Amnesia (Empirical Validation on GPT-2) The Executive Problem: Large Language Models (LLMs) processing long documents face an expensive bottleneck: the Key-Value (KV) Cache. Storing every token's attention memory in GPU VRAM creates immense hardware costs. Current industry workarounds—such as static eviction or sliding-window pruning (e.g., StreamingLLM)—suffer from severe "middle-context amnesia": they discard older tokens, causing the model to hallucinate or miss critical facts hidden deep inside long prompts. The Solution (Two-Tier Hierarchical Memory): This repository implements a mathematically grounded two-tier retrieval architecture: Ultra-Compact Sketching: Incoming attention keys are compressed into low-dimensional random Gaussian sketches (D = 16 or D = 32 dimensions instead of the full 64/128-dimensional space), cutting key memory by 50% to 75%. Dynamic Needle Retrieval & Exact Re-Attention: When a query arrives, the lightweight sketch scans the entire sequence in milliseconds to locate relevant deep-context tokens. Full-precision attention is then computed strictly on a small, high-value candidate set (64 tokens). Empirical Validation on Production Weights (GPT-2 124M): Tested on a ~943-token prompt containing an operational factual "needle" buried in the middle (token #468), evaluated across 12 attention heads in deep layers: Layer 11 (Critical Semantic Integration Layer): Industry Baseline (Static Eviction, 64 tokens): Output cosine fidelity drops to 76.5%, and the model misses the critical fact across 100% of heads (0/12 heads). Projective Sketch D = 16 (75% Key VRAM reduction): Output fidelity stays at 93.8%, recovering the hidden fact in 8 out of 12 heads. Projective Sketch D = 32 (50% Key VRAM reduction): Output fidelity reaches 95.8%, recovering the hidden fact in 10 out of 12 heads (83.3% retrieval recall). Business & Infrastructure Impact: Drastic Cost Reduction: Slashes GPU VRAM footprints for enterprise long-context inference (chatbots, legal analysis, document search) without sacrificing factual recall. Edge & On-Device Deployment: Enables long-context reasoning on consumer GPUs, laptops, and mobile devices that previously suffered out-of-memory crashes. No Re-training Required: Operates as a zero-shot, drop-in memory layer compatible with existing Transformer weights.

View source

Similar papers

#computer vision Review Sep 2017

Agile Software Development Methods: Review and Analysis

This publication proposes a definition and a classification of agile software development approaches and analyses ten software development methods that can be characterized as being "agile" against the defined criterion.

P. Abrahamsson, O. Salo, Jussi Ronkainen et al. · 727 citations · ⚡54
#computer vision Jun 2008

The impact of agile practices on communication in software development

The study shows that agile practices improve both informal and formal communication, but indicates that, in larger development situations involving multiple external stakeholders, a mismatch of adequate communication mechanisms can sometimes even hinder the communication.

M. Pikkarainen, Jukka Haikara, O. Salo et al. · 401 citations · ⚡48
#machine learning Review Open access Oct 2014

Software development in startup companies: A systematic mapping study

The results indicate that software engineering work practices are chosen opportunistically, adapted and configured to provide value under the constrains imposed by the startup context.

Nicolò Paternoster, Carmine Giardino, M. Unterkalmsteiner et al. · 394 citations · ⚡54

Related blog posts

Microsoft Research Blog Aug 31, 2026

GigaPath-Flash and GigaTIME-Flash: Toward population-scale discovery with efficient pathology foundation models

What if pathology foundation models could do more with less? GigaPath-Flash and GigaTIME-Flash cut computational demands while maintaining strong performance, opening the door to larger studies and broader exploration. The post GigaPath-Flash and GigaTIME-Flash: Toward population-scale discovery with efficient pathology foundation models appeared first on Microsoft Research.

Microsoft Research Blog Jul 30, 2026

EvoLib: Turning experience into evolving knowledge

LLMs do not get smarter just by remembering more. EvoLib turns experience into evolving knowledge, taking reusable skills and insights that help models learn and adapt across tasks long after deployment. The post EvoLib: Turning experience into evolving knowledge appeared first on Microsoft Research.

We use cookies to run the site and, with your consent, for analytics and to show ads. See our Cookie Policy.