03 · Writing

Engineering Notes

Deep dives into systems, ML, and data engineering. Search, filter, or browse.

Latest

newest first

Dec 4, 2026

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.

8 min

Dec 3, 2026

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.

8 min

Dec 1, 2026

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.

8 min

Nov 25, 2026

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).

8 min

All Posts

by date

Dec 4, 2026

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.

8 min read
Nov 25, 2026

Nov 25, 2026

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).

8 min

Nov 25, 2026

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.

8 min
Nov 22, 2026

Nov 22, 2026

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.

8 min

Nov 22, 2026

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.

8 min

Nov 22, 2026

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.

7 min