<?xml version="1.0" encoding="UTF-8"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Engineering Articles: Inference, Models, Harnesses | Jacek Trefon</title><link>https://www.trefon.com/notes/</link><description>Technical articles on LLM inference, model training and agent harnesses: KV cache, quantisation, attention, speculative decoding, RL, evals. Every number shown.</description><language>en-GB</language><atom:link href="https://www.trefon.com/notes/rss.xml" rel="self" type="application/rss+xml"/><item><title>Agent context management: budgets, truncation, compaction, and knowing when to stop</title><link>https://www.trefon.com/notes/agent-context-management/</link><guid isPermaLink="true">https://www.trefon.com/notes/agent-context-management/</guid><pubDate>Tue, 27 Oct 2026 08:00:00 GMT</pubDate><description>A 262K context isn't a licence to dump everything in. Each token of context costs speed on every step. How to budget context for an agent, truncate tool output without losing the signal, compact history without breaking the prefix cache, isolate work in sub-agents, and detect loops before they burn the budget.</description><category>deep dive</category><category>agents</category><category>context</category><category>harnesses</category></item><item><title>Agent eval statistics: is 816 vs 808 a real difference?</title><link>https://www.trefon.com/notes/agent-eval-statistics/</link><guid isPermaLink="true">https://www.trefon.com/notes/agent-eval-statistics/</guid><pubDate>Tue, 27 Oct 2026 08:00:00 GMT</pubDate><description>Leaderboards rank models by a few points; the noise is usually bigger. Confidence intervals on pass rates, worked on my own 49-scenario benchmark, how many scenarios you'd need to separate two models, why paired tests are worth the effort, and why pass^k beats pass@k for agents.</description><category>deep dive</category><category>evals</category><category>statistics</category><category>agents</category><category>benchmarks</category></item><item><title>Attention from the kernel's side: FlashAttention, online softmax and fused dequant</title><link>https://www.trefon.com/notes/flashattention-online-softmax/</link><guid isPermaLink="true">https://www.trefon.com/notes/flashattention-online-softmax/</guid><pubDate>Tue, 27 Oct 2026 08:00:00 GMT</pubDate><description>Attention is three lines of math and one big memory problem. How the online softmax makes tiling exact, what FlashAttention never writes to memory, why decode attention is a stream over the KV cache, and why a quantised cache only pays off when dequant is fused into the kernel.</description><category>deep dive</category><category>attention</category><category>FlashAttention</category><category>CUDA</category><category>KV cache</category></item><item><title>Attention Is All You Need: the paper, the idea, and what it changed</title><link>https://www.trefon.com/notes/attention-is-all-you-need/</link><guid isPermaLink="true">https://www.trefon.com/notes/attention-is-all-you-need/</guid><pubDate>Tue, 27 Oct 2026 08:00:00 GMT</pubDate><description>The 2017 Google paper that introduced the transformer: the problem it set out to solve, what it actually proposed (scaled dot-product attention, multi-head attention, sinusoidal positions, an encoder-decoder for translation), the numbers it reported, what later models changed, and how a translation paper became the basis of modern AI.</description><category>deep dive</category><category>transformer</category><category>attention</category><category>architecture</category><category>history</category></item><item><title>Constrained decoding: grammars and JSON schema so tool calls always parse</title><link>https://www.trefon.com/notes/constrained-decoding-grammars-json/</link><guid isPermaLink="true">https://www.trefon.com/notes/constrained-decoding-grammars-json/</guid><pubDate>Tue, 27 Oct 2026 08:00:00 GMT</pubDate><description>How engines guarantee valid output by masking logits: finite-state machines for regular formats, pushdown automata for nested JSON, why tokens and grammar symbols don't line up, what it costs per step, and why constraining too early can make the model reason worse.</description><category>deep dive</category><category>constrained decoding</category><category>JSON</category><category>tool calling</category><category>llama.cpp</category></item><item><title>Continuous batching and PagedAttention: serving many users from one GPU</title><link>https://www.trefon.com/notes/continuous-batching-pagedattention/</link><guid isPermaLink="true">https://www.trefon.com/notes/continuous-batching-pagedattention/</guid><pubDate>Tue, 27 Oct 2026 08:00:00 GMT</pubDate><description>Why batching is nearly free for memory-bound decode, where it stops being free, why KV memory rather than compute caps the batch, and what continuous batching, PagedAttention and chunked prefill each fix. Worked on a 27B model on one RTX 4090.</description><category>deep dive</category><category>batching</category><category>PagedAttention</category><category>serving</category><category>inference</category></item><item><title>CUDA graphs in LLM decode: launch overhead, and why shape changes cost</title><link>https://www.trefon.com/notes/cuda-graphs-decode/</link><guid isPermaLink="true">https://www.trefon.com/notes/cuda-graphs-decode/</guid><pubDate>Tue, 27 Oct 2026 08:00:00 GMT</pubDate><description>A decode step is hundreds of small kernels, and launching each one costs CPU time. How CUDA graphs capture and replay the step, why a growing KV cache keeps invalidating them, and what raising the KV pad floor to 4096 changed in my fork.</description><category>deep dive</category><category>CUDA</category><category>inference</category><category>llama.cpp</category></item><item><title>Decode is memory-bound: the ~59 tok/s ceiling on an RTX 4090, and how speculative decoding gets past it</title><link>https://www.trefon.com/notes/decode-memory-bound-speculative/</link><guid isPermaLink="true">https://www.trefon.com/notes/decode-memory-bound-speculative/</guid><pubDate>Tue, 27 Oct 2026 08:00:00 GMT</pubDate><description>Single-stream decode speed is set by memory bandwidth, not FLOPs. The bandwidth ceiling for a 17 GB model on a 4090, the math of speculative decoding and MTP, how draft depth trades off against acceptance, and why the draft sampler matters.</description><category>deep dive</category><category>inference</category><category>speculative decoding</category><category>MTP</category><category>CUDA</category></item><item><title>Decoder-only transformers: the architecture behind every chat model</title><link>https://www.trefon.com/notes/decoder-only-transformer/</link><guid isPermaLink="true">https://www.trefon.com/notes/decoder-only-transformer/</guid><pubDate>Tue, 27 Oct 2026 08:00:00 GMT</pubDate><description>Part 1 of the architecture series. The causal block that GPT, Llama, Qwen and Gemma are built from: masked self-attention, the MLP, residuals and norms, where the parameters live (12·d² per layer, checked against GPT-2), why one stack serves both prompt and generation, and why this design won.</description><category>deep dive</category><category>transformer</category><category>architecture</category><category>decoder-only</category></item><item><title>DeepSeek: the architecture behind V3 and R1, and the DeepSeek moment</title><link>https://www.trefon.com/notes/deepseek-architecture-moment/</link><guid isPermaLink="true">https://www.trefon.com/notes/deepseek-architecture-moment/</guid><pubDate>Tue, 27 Oct 2026 08:00:00 GMT</pubDate><description>How a Chinese lab trained a frontier-level open model on export-restricted GPUs, and why one week in January 2025 wiped hundreds of billions off Nvidia. Multi-head latent attention and its 57× smaller cache, fine-grained MoE with shared experts, auxiliary-loss-free balancing, multi-token prediction, FP8 training, and R1's pure-RL reasoning.</description><category>deep dive</category><category>DeepSeek</category><category>MoE</category><category>architecture</category><category>RL</category></item><item><title>Dense vs mixture-of-experts: what you trade, from routing to serving</title><link>https://www.trefon.com/notes/dense-vs-moe/</link><guid isPermaLink="true">https://www.trefon.com/notes/dense-vs-moe/</guid><pubDate>Tue, 27 Oct 2026 08:00:00 GMT</pubDate><description>The architecture-level comparison: how a router picks experts, why load balancing is the hard part, capacity factors and dropped tokens, how much of each model actually runs per token (from Mixtral's 28% to DeepSeek-V3's 5.5%), what MoE buys in training compute, and what it costs in memory, communication and agent behaviour.</description><category>deep dive</category><category>MoE</category><category>architecture</category><category>training</category></item><item><title>Diffusion models: from noise to images, and now to text</title><link>https://www.trefon.com/notes/diffusion-models-explained/</link><guid isPermaLink="true">https://www.trefon.com/notes/diffusion-models-explained/</guid><pubDate>Tue, 27 Oct 2026 08:00:00 GMT</pubDate><description>How diffusion models generate by learning to undo noise: the forward process in one formula, why predicting the noise is the training objective, how sampling went from 1,000 steps to a handful, classifier-free guidance, latent diffusion's 48× compression, transformer backbones and flow matching, and diffusion for text.</description><category>deep dive</category><category>diffusion</category><category>generative models</category><category>architecture</category></item><item><title>Distillation: logit KL, temperature, and on-policy vs off-policy</title><link>https://www.trefon.com/notes/distillation-kl-on-policy/</link><guid isPermaLink="true">https://www.trefon.com/notes/distillation-kl-on-policy/</guid><pubDate>Tue, 27 Oct 2026 08:00:00 GMT</pubDate><description>How a small model learns from a big one: soft targets and the T² factor, forward vs reverse KL and why the direction matters, sequence-level vs logit distillation, the storage cost of teacher logits, and why on-policy distillation fixes the student's own mistakes.</description><category>deep dive</category><category>distillation</category><category>training</category><category>KL divergence</category></item><item><title>Encoder-decoder transformers: cross-attention, T5, Whisper, and when they still win</title><link>https://www.trefon.com/notes/encoder-decoder-transformer/</link><guid isPermaLink="true">https://www.trefon.com/notes/encoder-decoder-transformer/</guid><pubDate>Tue, 27 Oct 2026 08:00:00 GMT</pubDate><description>Part 3 of the architecture series. The original transformer layout: an encoder that reads the input both ways, a decoder that writes with cross-attention into it, T5's span corruption, where the extra parameters go, and why the design still wins for speech, translation and other tasks where the input dwarfs the output.</description><category>deep dive</category><category>transformer</category><category>architecture</category><category>T5</category><category>Whisper</category></item><item><title>Encoder-only transformers: BERT, embeddings and rerankers</title><link>https://www.trefon.com/notes/encoder-only-transformer/</link><guid isPermaLink="true">https://www.trefon.com/notes/encoder-only-transformer/</guid><pubDate>Tue, 27 Oct 2026 08:00:00 GMT</pubDate><description>Part 2 of the architecture series. Bidirectional attention, the masked-language-model objective with its 80/10/10 rule, why encoders can't generate but are still the right tool for classification, embeddings and rerankers, and what modern encoders such as ModernBERT changed.</description><category>deep dive</category><category>transformer</category><category>architecture</category><category>BERT</category><category>embeddings</category></item><item><title>Hybrid models: what Gated DeltaNet replaces in the KV cache</title><link>https://www.trefon.com/notes/hybrid-gated-deltanet-linear-attention/</link><guid isPermaLink="true">https://www.trefon.com/notes/hybrid-gated-deltanet-linear-attention/</guid><pubDate>Tue, 27 Oct 2026 08:00:00 GMT</pubDate><description>Linear attention turns the KV cache into a fixed-size state. The delta rule fixes what it forgets badly, and gating adds decay. Why hybrids keep a few full-attention layers, and what a recurrent state changes for prefix reuse, speculative rollback and long sessions.</description><category>deep dive</category><category>Gated DeltaNet</category><category>linear attention</category><category>architecture</category><category>KV cache</category></item><item><title>KV cache math: what long context costs, and what a 4-bit cache buys</title><link>https://www.trefon.com/notes/kv-cache-math/</link><guid isPermaLink="true">https://www.trefon.com/notes/kv-cache-math/</guid><pubDate>Tue, 27 Oct 2026 08:00:00 GMT</pubDate><description>The weights are a fixed cost; the KV cache grows with every token and decides what fits. Per-token size from first principles, worked on a 27B model at 262K context, why keys are harder to quantise than weights, and why 3-bit is the risk axis.</description><category>deep dive</category><category>KV cache</category><category>quantization</category><category>attention</category><category>llama.cpp</category></item><item><title>LoRA and QLoRA math: rank, alpha, memory, and what actually trains</title><link>https://www.trefon.com/notes/lora-qlora-math/</link><guid isPermaLink="true">https://www.trefon.com/notes/lora-qlora-math/</guid><pubDate>Tue, 27 Oct 2026 08:00:00 GMT</pubDate><description>Low-rank adaptation from the matrix up: how many parameters a rank-16 adapter really trains, what alpha does, why full fine-tuning a 7B model needs over 100 GB and QLoRA fits a 27B base in 14 GB, and what LoRA is good and bad at.</description><category>deep dive</category><category>LoRA</category><category>QLoRA</category><category>fine-tuning</category><category>training</category></item><item><title>Matrix multiplication and how tensor accelerators work</title><link>https://www.trefon.com/notes/matmul-tensor-cores-accelerators/</link><guid isPermaLink="true">https://www.trefon.com/notes/matmul-tensor-cores-accelerators/</guid><pubDate>Tue, 27 Oct 2026 08:00:00 GMT</pubDate><description>Almost all of an LLM's arithmetic is matrix multiplication. What a matmul costs in FLOPs and bytes, the roofline model and the ridge point of real GPUs, why tiling exists, how tensor cores and systolic arrays execute matrix math in hardware, and why precision formats keep shrinking.</description><category>deep dive</category><category>GPU</category><category>tensor cores</category><category>matmul</category><category>hardware</category></item><item><title>MCP under the hood: JSON-RPC, transports, and capability negotiation</title><link>https://www.trefon.com/notes/mcp-under-the-hood/</link><guid isPermaLink="true">https://www.trefon.com/notes/mcp-under-the-hood/</guid><pubDate>Tue, 27 Oct 2026 08:00:00 GMT</pubDate><description>The Model Context Protocol on the wire: the JSON-RPC 2.0 messages, the initialize handshake and capability negotiation, tools, resources and prompts, stdio vs Streamable HTTP, what every tool schema costs in context, and the security model you have to bring yourself.</description><category>deep dive</category><category>MCP</category><category>agents</category><category>harnesses</category><category>JSON-RPC</category></item><item><title>MoE on a single GPU: total vs active parameters, offload and bandwidth</title><link>https://www.trefon.com/notes/moe-single-gpu/</link><guid isPermaLink="true">https://www.trefon.com/notes/moe-single-gpu/</guid><pubDate>Tue, 27 Oct 2026 08:00:00 GMT</pubDate><description>A mixture-of-experts model costs memory by its total parameters and bandwidth by its active ones. What that means on one 24 GB card, how expert offload to system RAM changes the ceiling, why batching helps MoE less than dense models, and how MoE did in my agent benchmark.</description><category>deep dive</category><category>MoE</category><category>inference</category><category>llama.cpp</category></item><item><title>Prefix caching: reusing the KV cache across turns and requests</title><link>https://www.trefon.com/notes/prefix-caching-kv-reuse/</link><guid isPermaLink="true">https://www.trefon.com/notes/prefix-caching-kv-reuse/</guid><pubDate>Tue, 27 Oct 2026 08:00:00 GMT</pubDate><description>Agents resend the whole conversation on every turn. Prefix caching skips the part the server has already computed, and the fork's README records a long-context turn going from ~46 s to ~460 ms. How it works, what breaks it, and why hybrid models need checkpoints.</description><category>deep dive</category><category>prefix caching</category><category>KV cache</category><category>agents</category><category>inference</category></item><item><title>Reasoning and chain of thought: why thinking in tokens works, and what it costs</title><link>https://www.trefon.com/notes/reasoning-chain-of-thought/</link><guid isPermaLink="true">https://www.trefon.com/notes/reasoning-chain-of-thought/</guid><pubDate>Tue, 27 Oct 2026 08:00:00 GMT</pubDate><description>From 'let's think step by step' to models trained to think: why writing intermediate steps adds computation a transformer can't do in one pass, how self-consistency and RL turned it into test-time compute, what an 8,192-token thinking budget costs in seconds, whether the visible reasoning is faithful, and what it changes for agents.</description><category>deep dive</category><category>reasoning</category><category>chain of thought</category><category>RL</category><category>agents</category></item><item><title>Retrieval math for RAG: embeddings, chunking, hybrid search and reranking</title><link>https://www.trefon.com/notes/rag-retrieval-math/</link><guid isPermaLink="true">https://www.trefon.com/notes/rag-retrieval-math/</guid><pubDate>Tue, 27 Oct 2026 08:00:00 GMT</pubDate><description>Retrieval decides what the model gets to read, and most RAG failures happen there. Cosine similarity and what normalisation buys, how much memory a million chunks costs at each precision, how HNSW trades recall for speed, why hybrid BM25 plus dense search wins, and where a reranker earns its cost.</description><category>deep dive</category><category>RAG</category><category>embeddings</category><category>retrieval</category><category>search</category></item><item><title>RL for LLMs: PPO, DPO and GRPO, the objectives side by side</title><link>https://www.trefon.com/notes/rl-ppo-dpo-grpo/</link><guid isPermaLink="true">https://www.trefon.com/notes/rl-ppo-dpo-grpo/</guid><pubDate>Tue, 27 Oct 2026 08:00:00 GMT</pubDate><description>What reinforcement learning optimises after fine-tuning, written as the actual objectives: PPO's clipped surrogate with a KL leash, DPO's preference loss without a reward model, and GRPO's group-relative advantage without a critic. A worked GRPO example, and why verifiable rewards changed the game for code.</description><category>deep dive</category><category>RL</category><category>GRPO</category><category>DPO</category><category>training</category></item><item><title>RNNs, from LSTM to linear attention: why recurrence lost and how it came back</title><link>https://www.trefon.com/notes/rnn-lstm-to-linear-attention/</link><guid isPermaLink="true">https://www.trefon.com/notes/rnn-lstm-to-linear-attention/</guid><pubDate>Tue, 27 Oct 2026 08:00:00 GMT</pubDate><description>Part 4 of the architecture series. The recurrent update, why gradients vanish or explode over long sequences (0.9¹⁰⁰ is 2.7 × 10⁻⁵), how LSTM gates fixed it, why transformers replaced RNNs anyway, and how state-space models and linear attention brought constant-memory recurrence back into today's hybrid LLMs.</description><category>deep dive</category><category>RNN</category><category>LSTM</category><category>architecture</category><category>linear attention</category></item><item><title>RoPE from first principles, and how YaRN stretches a model's context</title><link>https://www.trefon.com/notes/rope-yarn-long-context/</link><guid isPermaLink="true">https://www.trefon.com/notes/rope-yarn-long-context/</guid><pubDate>Tue, 27 Oct 2026 08:00:00 GMT</pubDate><description>How rotary position embeddings encode position as rotation, what the wavelength of each dimension means for long context, and how position interpolation, NTK-aware scaling and YaRN stretch a model trained on 32K toward 262K.</description><category>deep dive</category><category>RoPE</category><category>long context</category><category>attention</category></item><item><title>Sampling math: temperature, top-p, min-p, and why agents loop</title><link>https://www.trefon.com/notes/sampling-temperature-top-p-min-p/</link><guid isPermaLink="true">https://www.trefon.com/notes/sampling-temperature-top-p-min-p/</guid><pubDate>Tue, 27 Oct 2026 08:00:00 GMT</pubDate><description>What each sampler does to the probability distribution, worked on real numbers: temperature, top-k, top-p, min-p and repetition penalties. Why the order of the chain matters, why penalties break code and JSON, and how sampling settings show up in agent loops and decode speed.</description><category>deep dive</category><category>sampling</category><category>inference</category><category>agents</category></item><item><title>Tokenizers: BPE, byte-level models, and what a token costs</title><link>https://www.trefon.com/notes/tokenizers-bpe-byte-level/</link><guid isPermaLink="true">https://www.trefon.com/notes/tokenizers-bpe-byte-level/</guid><pubDate>Tue, 27 Oct 2026 08:00:00 GMT</pubDate><description>How BPE builds a vocabulary from merges, why byte-level BPE never fails on unknown text, what vocabulary size costs in parameters and saves in sequence length, why Polish and code cost more tokens than English prose, and where byte-level models without a tokenizer stand.</description><category>deep dive</category><category>tokenizer</category><category>BPE</category><category>byte-level</category></item><item><title>What Q4_K_M actually stores: weight quantisation from first principles</title><link>https://www.trefon.com/notes/q4-k-m-quantization-explained/</link><guid isPermaLink="true">https://www.trefon.com/notes/q4-k-m-quantization-explained/</guid><pubDate>Tue, 27 Oct 2026 08:00:00 GMT</pubDate><description>Q4_K_M byte by byte, from the ggml source: 256-weight super-blocks, 6-bit scales and mins, which tensors get upgraded to Q6_K and why, what an outlier costs, and where rotation comes in. Plus the size and speed of a 27B model at every k-quant.</description><category>deep dive</category><category>quantization</category><category>GGUF</category><category>llama.cpp</category></item><item><title>What training an LLM costs: 6ND FLOPs, 16 bytes per parameter, Chinchilla</title><link>https://www.trefon.com/notes/training-cost-6nd-memory/</link><guid isPermaLink="true">https://www.trefon.com/notes/training-cost-6nd-memory/</guid><pubDate>Tue, 27 Oct 2026 08:00:00 GMT</pubDate><description>Back-of-envelope training cost you can trust: the 6ND rule for compute, what Chinchilla says about tokens per parameter, why Adam costs 16 bytes per parameter, and where activation memory goes. Worked for a 125M model, a 1B model and a 4.5B fine-tune on one RTX 4090.</description><category>deep dive</category><category>training</category><category>scaling laws</category><category>GPU</category></item><item><title>262K context on one RTX 4090: what I added to llama.cpp-turboq</title><link>https://www.trefon.com/notes/llama-cpp-turboq-262k-rtx-4090/</link><guid isPermaLink="true">https://www.trefon.com/notes/llama-cpp-turboq-262k-rtx-4090/</guid><pubDate>Mon, 26 Oct 2026 08:00:00 GMT</pubDate><description>The engine already kept a 4.125-bit KV cache inside flash attention. Running coding agents on it all day took async checkpoints, fewer CUDA graph re-captures, a stack of MTP fixes and a sampler tune worth +31%.</description><category>inference</category><category>llama.cpp</category><category>CUDA</category><category>MTP</category><category>KV cache</category></item><item><title>amber-bench: benchmarking the harness, not the model</title><link>https://www.trefon.com/notes/amber-bench-harness-not-model/</link><guid isPermaLink="true">https://www.trefon.com/notes/amber-bench-harness-not-model/</guid><pubDate>Mon, 26 Oct 2026 08:00:00 GMT</pubDate><description>A model leaderboard can't tell you whether your agent loop is broken. I built a benchmark that scores the harness and the model as a pair. The first thing it found was bugs in my own harness.</description><category>harnesses</category><category>evals</category><category>C++</category><category>amber</category></item></channel></rss>