03 · Writing
Engineering Notes
~1932 min of readingDeep dives into systems, ML, and data engineering. Search, filter, or browse.
Deep Dives
longest readsPostgreSQL 18 Skip Scan, Measured: Skip Arrays, a Missing Increment That Doubles Descents, and Two Cliffs at One Value per Leaf Page
Who Ran While You Waited? Culprit-Attributed CPU Contention on Stock Kernels
Range as a Key: Why Cloud Block Store Indexes Are a Memory Problem
vAttention: Dynamic KV Cache Allocation Without Breaking Virtual Contiguity
Latest
newest firstDec 4, 2026
GPTQ Is Babai's Nearest Plane, Audited: Bit-Identical Integers, the 1/12 Error Law Holds, Clipping Breaks the Bound at 9% Overflow, and Min-Pivot Ties a 1998 MIMO Ordering
An ICLR 2026 paper proves that GPTQ, run back-to-front, is exactly Babai's nearest-plane algorithm on the lattice spanned by the layer's activations. That gives GPTQ its first worst-case error bound: a quarter of the scale-weighted trace of D, the diagonal of the Hessian's LDL factor. I rebuilt both algorithms in numpy. The integers match on all 16,384 weights. The paper's 'one third of worst case' average holds to 2%, and it gives a closed form nobody states: GPTQ's error over RTN's is tr(D)/tr(H) (0.475 measured vs 0.473 predicted). Once clipping is on, the bound fails on 61% of channels at 8.8% overflow. The proposed min-pivot order is within 0.04% of brute-force optimal at c = 8, and V-BLAST, a MIMO detection order from 1998, ties it to four digits.
Dec 3, 2026
QK-Clip, Audited: Kimi K2's Logit Cap Lags One Step Behind, α = 0.5 Is Load-Bearing Under Muon, and Weight Decay Does the Deactivating
Kimi K2 trained a 1T-parameter MoE on 15.5T tokens with Muon and no loss spikes. The fix it credits is QK-Clip: after each step, rescale a head's W_q and W_k by √(τ/S_max) whenever that head's max attention logit S_max goes over τ = 100. I rebuilt it in numpy. The MLA split checks out: scaling the shared-key path's head-specific rotary query by γ (not √γ) is exactly what makes the logit shrink by γ. Three things the report doesn't say: γ is computed from the logit before the update, so the cap holds at τ·(1 + η·s·(1/σ_q + 1/σ_k)), not τ (20.68 vs 20 in my toy, matching the formula to 0.1%). The 'typically 0.5' split is not cosmetic, because putting all the clipping on W_q under Muon collapses W_q 27× and overshoots τ by 54%. And in my runs the clip only switched itself off when weight decay was on.
Dec 1, 2026
LSHBloom, Audited: The Bloom Filters Are Fine, but Summing MinHash Values Into Band Keys Flags 15% of Unrelated Documents at 1M Docs
LSHBloom replaces the MinHashLSH band index with one Bloom filter per band. The paper reports 18× less disk and 12× more throughput on peS2o. I re-derived the sizing and it checks out: 591 GB for 10B documents at a 1e-10 false-positive budget. The weak point is one step earlier. Before a band goes into its Bloom filter, it is reduced to one integer by summing its MinHash values, on the reasoning that a sum of universal hashes collides with probability 1/N. MinHash values are minima, though, not uniform hashes. Their sums fall in a narrow Gamma-shaped range, and unrelated documents with 1,000 shingles collide 81× more often than the bound says. In a datasketch-exact emulation, the summed key flags 0.74% of new, unrelated documents against a 50k index, 15% against 1M, and a projected 99.9% at peS2o's 39M. Giving each position its own random multiplier fixes it.
Nov 25, 2026
Exact BPE in Linear Time, Audited: Pair Compatibility Holds on cl100k, 97% of Token Pairs Are Compatible (Not 5%), and Each Position Is Scanned At Most Once
GitHub's bpe crate encodes text into byte-pair tokens exactly, in linear time, by checking only whether each new token is compatible with the one before it. I re-implemented the backtracking encoder against the real cl100k vocabulary. It matched reference BPE on every sample, and 0 of 8,000 random pairwise-compatible token chains failed to round-trip. Two of the README's numbers do not survive. 96.97% ± 0.03% of cl100k's 10 billion token pairs are compatible, about 9.75B, against the stated 'roughly 500 million'. Overlapping matches are 2.84 per byte on my corpus, against 3.5. I also prove a bound the README does not state: each input position is scanned at most once, so the worst case is O(n·L).
All Posts
by dateDec 4, 2026
GPTQ Is Babai's Nearest Plane, Audited: Bit-Identical Integers, the 1/12 Error Law Holds, Clipping Breaks the Bound at 9% Overflow, and Min-Pivot Ties a 1998 MIMO Ordering
An ICLR 2026 paper proves that GPTQ, run back-to-front, is exactly Babai's nearest-plane algorithm on the lattice spanned by the layer's activations. That gives GPTQ its first worst-case error bound: a quarter of the scale-weighted trace of D, the diagonal of the Hessian's LDL factor. I rebuilt both algorithms in numpy. The integers match on all 16,384 weights. The paper's 'one third of worst case' average holds to 2%, and it gives a closed form nobody states: GPTQ's error over RTN's is tr(D)/tr(H) (0.475 measured vs 0.473 predicted). Once clipping is on, the bound fails on 61% of channels at 8.8% overflow. The proposed min-pivot order is within 0.04% of brute-force optimal at c = 8, and V-BLAST, a MIMO detection order from 1998, ties it to four digits.
Nov 25, 2026
Exact BPE in Linear Time, Audited: Pair Compatibility Holds on cl100k, 97% of Token Pairs Are Compatible (Not 5%), and Each Position Is Scanned At Most Once
GitHub's bpe crate encodes text into byte-pair tokens exactly, in linear time, by checking only whether each new token is compatible with the one before it. I re-implemented the backtracking encoder against the real cl100k vocabulary. It matched reference BPE on every sample, and 0 of 8,000 random pairwise-compatible token chains failed to round-trip. Two of the README's numbers do not survive. 96.97% ± 0.03% of cl100k's 10 billion token pairs are compatible, about 9.75B, against the stated 'roughly 500 million'. Overlapping matches are 2.84 per byte on my corpus, against 3.5. I also prove a bound the README does not state: each input position is scanned at most once, so the worst case is O(n·L).
Nov 25, 2026
Sorting-Free LLM Sampling, Audited: Single-Pivot Rejection Already Averages ≤ 1 + ln(1/P) Rounds, Dual-Pivot Changes Nothing on Real Logits, and bf16 Ties Make top_k=50 Keep 58 Tokens
FlashInfer replaced sort-then-cumsum top-k/top-p sampling with rejection sampling, then added a dual-pivot version that bounds the worst-case number of rounds. I re-implemented both and ran them on 1,536 real next-token distributions from Qwen2.5-0.5B. Both are exact: 0 invalid tokens in 4M draws. Their round counts are the same on every metric I measured, including the max over a 64-row batch. I derive the expected round count for the single-pivot sampler in closed form, E = 1 + Σ m(v)/M(≥v) ≤ 1 + ln(1/Z), which caps top-p=0.9 at 1.105 rounds. The bigger surprise is semantic: a bf16 row has only about 2,860 distinct logits across 151,665 tokens, so threshold-based top_k=50 keeps more than 50 tokens at 60.7% of positions.
Nov 22, 2026
UUIDv7 in PostgreSQL 18, Audited: The 245 ns Step, a Collision Trade That Is Exactly Neutral, and the Out-of-Order Cliff That Halves Index Fill
PostgreSQL 18 ships a native uuidv7() built on RFC 9562's Method 3: 12 bits of sub-millisecond clock replace random bits. I read uuid.c and nbtsplitloc.c, then checked them with my own code. The 245 ns minimum step is exactly the smallest value that guarantees per-backend monotonicity (244 ns fails 1,728 times per 3 ms). Giving up 12 random bits for clock bits costs nothing in collision odds when arrivals are uniform, and at most 4096× when they cluster. A leaf-level simulation using PostgreSQL's split rules finds a cliff. Out-of-order inserts are harmless up to about 2.5× the fillfactor slack. Beyond that, fill drops to 54%, worse than random v4. And fillfactor=100 on a v7 index sits at 51% with almost any reordering.
Nov 22, 2026
Sarathi-Serve's Chunked Prefill, Audited: KV Re-Reads Cost 0.4%, the 25% Overhead Is Wave Quantization, and 'Stall-Free' Means ~200 Free Tokens
Sarathi-Serve (OSDI '24) splits prompts into chunks and runs them alongside ongoing decodes under a fixed per-iteration token budget. I rebuilt its cost structure as an A100 roofline plus a tile-and-wave model and checked the paper's numbers. Re-reading prior chunks' KV costs 0.37% of an 8K Yi-34B prefill at chunk 512, so the paper is right that it doesn't matter. Launches and re-reads cannot explain the measured ~25% chunking overhead. GEMM and attention grids that leave the A100's 108 SMs partly idle predict +21–32%. Only 157–335 prefill tokens ride along with a decode batch for free; at the strict budget of 512, an iteration costs 1.7–2.4× a decode-only one.
Nov 22, 2026
Stochastic Rounding for Pure-BF16 Training, Audited: Weight Decay Is a No-Op Without It, Adam's β2 = 0.999 Becomes a Ratchet, and a Convergence Floor That Ignores β2
Ozkara, Yu and Park (AISTATS 2025) train GPT-Neo up to 6.7B with every tensor in BF16 and stochastic rounding. They beat FP32-master mixed precision on perplexity, with up to 1.54× throughput. I reimplemented BF16 rounding at the bit level and checked the mechanics. Under round-to-nearest, decoupled weight decay at lr·λ = 7e-5 changes 100.000% of weights by exactly nothing. 69–85% of N(0, 0.02) weights freeze at the end of a cosine schedule with the paper's default learning rates. For any β2 above 1 − 2⁻⁹ = 0.99805, Adam's second moment can never decrease, which leaves it 16.6× too high after a gradient-scale drop. The paper's Adam bound has a quantization floor of about R·d·L·Δ for every β2.