When 128k–1M token prompts exceed latency budgets, score 4k chunks in parallel with a 128-token overlap stride and prune below quantile threshold tau.
TL;DR30-second simplified summary▾
Parallel SLM perplexity scoring measures conditional surprisal across 4k chunks with a 128-token overlap stride to avoid boundary spikes. Combined with query-contrastive PMI and a 450 ms fail-open breaker, it sustains >98% entity recall.
P · Problem & Why Naive Context Truncation Fails.
A 70B LLM with GQA-8 uses ~160 KB of FP16 KV cache per token. At 1M tokens, a single session needs 160 GB of KV cache—exceeding an 80 GB H100—and takes ~18–35 seconds just to prefill before emitting token #1.
If you naively truncate to the last 16k tokens, you amputate the system prompt, JSON tool definitions, and early API keys or user constraints—causing immediate tool-call schema failures and safety regressions.
Raw 1M Prefill / Naive Truncation vs. Anchor-Pinned Perplexity Pruning
- 160 GB KV cache per 70B session
- 18–35s Time-To-First-Token
- Tail cut drops tool schemas
- 1.92 GB KV cache (12k tokens)
- <120 ms parallel SLM scoring
- 0% anchor loss; >98% entity recall
R · Representation: Pinned Anchors & Conditional Surprisal.
Every prompt is partitioned into Class A Pinned Anchors (system prompt, tool schemas, safety invariants, pinned facts) with weight w = infinity, and Class B Compressible Segments (RAG passages, tool stdout, old turns).
For Class B tokens, a 0.5B–1.5B INT8 SLM computes conditional surprisal I(x_i) = -log2 P(x_i | x_<i). Tokens the SLM predicts with >95% probability carry <0.07 bits of information and are safe to drop; unexpected tokens (UUIDs, latency numbers, stack traces) carry 6–12 bits and are kept.
Anchor Partitioning & Query-Aware Perplexity Graph
I · Invariant & Safe Python Implementation.
A critical implementation bug when scoring 1M tokens in parallel 4k chunks is boundary perplexity inflation: token 0 of every chunk has no left context, so its surprisal spikes artificially.
The fix is a 128-token overlap stride between adjacent 4,096-token chunks, discarding scores from the first 64 tokens of chunk k > 0 (only ~3.1% compute overhead) before running O(N) threshold selection.
Overlap-Stride Chunk Scoring & Quantile Assembly
M · Mechanics at Scale: Hierarchical Trees & KV Eviction.
Token-level perplexity pruning excels at 8x–20x compression, but 1M -> 8k (125x) needs structural abstraction over old turns.
Aging 4k-token leaves are asynchronously distilled into 512-token branch summaries and a 128-token root spine, while H2O Heavy-Hitter Oracle retains attention sinks (indices 0..7) and high-attention tokens in GPU HBM.
Perplexity Pruning vs. Abstractive Trees vs. Hybrid
An agent coding session has 180k tokens of old build logs plus a 2k-token JSON tool schema, and p95 SLM scoring latency spikes to 470 ms. Which action protects both correctness and SLO?
E · Edge Cases, Assumptions, When NOT to Use & Glossary.
Assumptions & Limitations: Assumes an 8k–16k target window, quantized 0.5B–1.5B SLM workers co-located with LLM inference pods, and deterministic anchor delimiters.
When NOT to Use It: Do not run perplexity pruning on short <8k prompts (adds unnecessary 90 ms overhead), cryptographic/legal verbatim contracts where single-word omissions alter liability, or dense minified code where every symbol has high entropy.
450 ms Compression Circuit Breaker State Machine
Practice: Make the trade-off yourself.
Why must system prompts and JSON tool schemas be locked as Pinned Anchors before perplexity pruning?