<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0">
  <channel>
    <title>Architecture — mizorewww</title>
    <link>https://mizore.blog/en/tags/architecture/</link>
    <link xmlns="http://www.w3.org/2005/Atom" href="https://mizore.blog/en/tags/architecture/feed.xml" rel="self" type="application/rss+xml"></link>
    <description>2 posts</description>
    <language>en</language>
    <lastBuildDate>Tue, 24 Nov 2026 00:00:00 +0000</lastBuildDate>
    <item>
      <title>From Transformer Matrix Flows to Modern Optimizer Derivations (SGD → AdamW → Muon)</title>
      <link>https://mizore.blog/en/posts/from-transformer-matrices-to-muon/</link>
      <description>&lt;p&gt;Deep learning courses and production codebases often meet across a noticeable conceptual gap. Chapters on neural architectures—such as the Transformer&lt;sup class=&#34;cite&#34;&gt;&lt;a id=&#34;cite-vaswani2017-1&#34; href=&#34;#ref-vaswani2017&#34;&gt;[1]&lt;/a&gt;&lt;/sup&gt;—revolve around three-dimensional activation tensors, multi-head subspace projections, and causal attention matrices. Chapters on optimization—such as SGD&lt;sup class=&#34;cite&#34;&gt;&lt;a id=&#34;cite-robbins1951-1&#34; href=&#34;#ref-robbins1951&#34;&gt;[2]&lt;/a&gt;&lt;/sup&gt; and AdamW&lt;sup class=&#34;cite&#34;&gt;&lt;a id=&#34;cite-loshchilov2019-1&#34; href=&#34;#ref-loshchilov2019&#34;&gt;[3]&lt;/a&gt;&lt;/sup&gt;—collapse every parameter in the network into a flat vector &lt;code&gt;$\theta \in \mathbb{R}^p$&lt;/code&gt; and study scalar coordinate updates on quadratic bowls.&lt;/p&gt;&#xA;&lt;p&gt;The moment you open an actual large language model pretraining script, the seam between those two narratives surfaces as concrete questions about memory layout, matrix contractions, and operator geometry. This post follows a single bottom-up chain of derivations to align both halves into one coherent picture.&lt;/p&gt;&#xA;&lt;h2 id=&#34;five-core-questions-and-roadmap&#34;&gt;Five Core Questions and Roadmap&lt;/h2&gt;&#xA;&lt;p&gt;Specifically, we work through five connected questions in order:&lt;/p&gt;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;GPU memory simultaneously holds token embedding tables, &lt;code&gt;$Q/K/V$&lt;/code&gt; projection weights, &lt;code&gt;$T \times T$&lt;/code&gt; attention score matrices, the &lt;code&gt;KV Cache&lt;/code&gt;, gradient buffers, and momentum states. What mathematical role does each of these &amp;quot;matrices&amp;quot; play, which ones belong to the model itself, and which ones exist only transiently during inference or training?&lt;/li&gt;&#xA;&lt;li&gt;Chat inference generates one token at a time sequentially—so why does training code have no token-by-token loop, feeding the entire sequence into the network at once? And why does training the exact same model require several times more VRAM than running inference?&lt;/li&gt;&#xA;&lt;li&gt;The loss function outputs a single scalar &lt;code&gt;$L \in \mathbb{R}$&lt;/code&gt;. Through what exact matrix algebra does &lt;code&gt;loss.backward()&lt;/code&gt; produce a two-dimensional gradient matrix &lt;code&gt;$G$&lt;/code&gt; matching the shape of each weight matrix &lt;code&gt;$W$&lt;/code&gt;—and why is the singular value spectrum of &lt;code&gt;$G$&lt;/code&gt; so heavily skewed?&lt;/li&gt;&#xA;&lt;li&gt;Moving from &lt;code&gt;SGD&lt;/code&gt; to &lt;code&gt;Momentum&lt;/code&gt;, &lt;code&gt;Adam&lt;/code&gt;, and &lt;code&gt;AdamW&lt;/code&gt;, what specific mathematical limitation did each generation solve, and how are bias correction and decoupled weight decay derived from first principles?&lt;/li&gt;&#xA;&lt;li&gt;When a parameter is a two-dimensional linear operator of shape &lt;code&gt;$d_{\mathrm{out}} \times d_{\mathrm{in}}$&lt;/code&gt;, what geometric structure do entrywise adaptive methods ignore? How does the matrix optimizer &lt;code&gt;Muon&lt;/code&gt;&lt;sup class=&#34;cite&#34;&gt;&lt;a id=&#34;cite-jordan2024-1&#34; href=&#34;#ref-jordan2024&#34;&gt;[4]&lt;/a&gt;&lt;/sup&gt;&lt;sup class=&#34;cite&#34;&gt;&lt;a id=&#34;cite-liu2025-1&#34; href=&#34;#ref-liu2025&#34;&gt;[5]&lt;/a&gt;&lt;/sup&gt; derive the semi-orthogonal update direction &lt;code&gt;$U V^\top$&lt;/code&gt; from induced operator norms, and how does it replace singular value decomposition with five half-precision matrix multiplications?&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&lt;p&gt;We start from the autoregressive factorization of sequence probability and classify every tensor in inference and training into four lifecycle families (Section 1). Next, we derive the forward and backward equations of a single training step, exposing the sum-of-outer-products structure of linear-layer gradients (Section 2). Under a unified variational principle—local linearization plus a proximal penalty or norm-ball constraint—we then derive four generations of entrywise optimizers (&lt;code&gt;SGD&lt;/code&gt; &lt;code&gt;$\to$&lt;/code&gt; &lt;code&gt;Momentum&lt;/code&gt; &lt;code&gt;$\to$&lt;/code&gt; &lt;code&gt;Adam&lt;/code&gt; &lt;code&gt;$\to$&lt;/code&gt; &lt;code&gt;AdamW&lt;/code&gt;, Section 3) followed by two-dimensional spectral optimizers (&lt;code&gt;Shampoo&lt;/code&gt; &lt;code&gt;$\to$&lt;/code&gt; &lt;code&gt;Muon&lt;/code&gt; &lt;code&gt;$\to$&lt;/code&gt; Moonshot AI&#39;s RMS-aligned scaling, Sections 4–5). Finally, we close the loop with a GPU roofline analysis, controlled ablation benchmarks, and a self-contained single-file PyTorch implementation (Sections 6–7).&lt;/p&gt;&#xA;&lt;h2 id=&#34;birds-eye-overview-model-inference-training-and-optimizers-on-one-map&#34;&gt;Bird&#39;s-Eye Overview: Model, Inference, Training, and Optimizers on One Map&lt;/h2&gt;&#xA;&lt;p&gt;Before diving into local equations, it helps to see how the pieces fit together globally. An LLM itself is nothing more than a fixed set of &lt;strong&gt;static parameter matrices &lt;code&gt;$\Theta$&lt;/code&gt;&lt;/strong&gt; persisted on disk and in VRAM—comprising the boundary vocabulary tables &lt;code&gt;$E_{\mathrm{tok}}, W_{\mathrm{head}}$&lt;/code&gt;, &lt;code&gt;$L$&lt;/code&gt; stacked layers of 2D linear operators &lt;code&gt;$W_q, W_k, W_v, W_o, W_{\mathrm{up}}, W_{\mathrm{down}}$&lt;/code&gt;, and 1D normalization gain vectors &lt;code&gt;$\gamma$&lt;/code&gt;. Around that single set of parameters &lt;code&gt;$\Theta$&lt;/code&gt;, &lt;strong&gt;inference&lt;/strong&gt; and &lt;strong&gt;training&lt;/strong&gt; form two distinct dataflows:&lt;/p&gt;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;&lt;strong&gt;Inference is a read-only one-way pipeline&lt;/strong&gt; (Section 1): &lt;code&gt;$\Theta$&lt;/code&gt; remains frozen throughout. Input prompt tokens first pass through a parallel &lt;code&gt;Prefill&lt;/code&gt; GEMM stage that populates the historical &lt;code&gt;KV Cache&lt;/code&gt;; subsequent &lt;code&gt;Decode&lt;/code&gt; steps feed a single new token row via matrix-vector products (GEMV) to sample one token at a time, freeing transient activations immediately after each layer.&lt;/li&gt;&#xA;&lt;li&gt;&lt;strong&gt;Training is a parameter-mutating four-step closed loop&lt;/strong&gt; (Sections 2–5): to propagate prediction errors back through every layer, &lt;strong&gt;1. Parallel Forward&lt;/strong&gt; must retain intermediate activations &lt;code&gt;$X$&lt;/code&gt; in VRAM; &lt;strong&gt;2. Cross-Entropy Loss&lt;/strong&gt; reduces all token predictions into a single scalar &lt;code&gt;$L$&lt;/code&gt;; &lt;strong&gt;3. Backward&lt;/strong&gt; applies the chain-rule contraction &lt;code&gt;$G = \Delta^\top X$&lt;/code&gt; to sum out the batch-and-token axis, producing a gradient matrix &lt;code&gt;$G$&lt;/code&gt; of the exact same shape as each parameter; finally, &lt;strong&gt;4. Optimizer Step&lt;/strong&gt; combines &lt;code&gt;$G$&lt;/code&gt; with historical states to overwrite &lt;code&gt;$\Theta$&lt;/code&gt;—routing boundary lookup/scoring tables to entrywise &lt;code&gt;AdamW&lt;/code&gt; (Section 3) and the internal 2D linear operators (&amp;gt;95% of non-embedding parameters) to spectral &lt;code&gt;Muon&lt;/code&gt; (Sections 4–5).&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&lt;figure class=&#34;diagram&#34; style=&#34;--h:292px;--hn:484px&#34;&gt;&lt;figcaption&gt;Bird&amp;#39;s-Eye Overview: How Static Parameters &lt;code&gt;$\Theta$&lt;/code&gt; Sit Between Read-Only Inference and the 4-Step Training Loop&lt;/figcaption&gt;&lt;p&gt;&lt;a href=&#34;https://mizore.blog/en/posts/from-transformer-matrices-to-muon/&#34;&gt;(See the figure in the post.)&lt;/a&gt;&lt;/p&gt;&lt;p class=&#34;figure-note&#34;&gt;Blue denotes static model parameters &lt;code&gt;$\Theta$&lt;/code&gt;; teal denotes transient activations or updates; violet denotes the inference KV Cache or momentum buffers; orange denotes backward gradient matrices.&lt;/p&gt;&lt;/figure&gt;&#xA;&lt;hr&gt;&#xA;&lt;h2 id=&#34;1-autoregressive-factorization-and-the-four-tensor-families-in-vram&#34;&gt;1. Autoregressive Factorization and the Four Tensor Families in VRAM&lt;/h2&gt;&#xA;&lt;h3 id=&#34;11-what-a-language-model-computes-chain-rule-of-probability-and-token-embeddings&#34;&gt;1.1 What a Language Model Computes: Chain Rule of Probability and Token Embeddings&lt;/h3&gt;&#xA;&lt;p&gt;Let the vocabulary &lt;code&gt;$\mathcal{V} = \{0, 1, \dots, V-1\}$&lt;/code&gt; contain &lt;code&gt;$V$&lt;/code&gt; discrete tokens. Given a token sequence &lt;code&gt;$x_{1:T} = (x_1, x_2, \dots, x_T) \in \mathcal{V}^T$&lt;/code&gt; of length &lt;code&gt;$T$&lt;/code&gt;, the product rule of probability decomposes the joint distribution of the entire sequence—with zero approximation—into a product of next-token conditional probabilities given each prefix:&lt;/p&gt;&#xA;&lt;p&gt;&lt;code&gt;$$p_\Theta(x_1, x_2, \dots, x_T) = \prod_{t=1}^{T} p_\Theta(x_t \mid x_1, \dots, x_{t-1})$$&lt;/code&gt;&lt;/p&gt;&#xA;&lt;p&gt;Here &lt;code&gt;$\Theta$&lt;/code&gt; denotes the collection of all learnable parameters. The modeling objective of an LLM is to construct a &lt;code&gt;$\Theta$&lt;/code&gt;-parameterized function that takes a prefix &lt;code&gt;$x_{1:t}$&lt;/code&gt;, outputs a vector of unnormalized log-scores (logits) &lt;code&gt;$z_t \in \mathbb{R}^V$&lt;/code&gt; over all &lt;code&gt;$V$&lt;/code&gt; candidate next tokens, and maps them to a valid probability distribution via Softmax:&lt;/p&gt;&#xA;&lt;p&gt;&lt;code&gt;$$p_\Theta(x_{t+1} = k \mid x_{1:t}) = \frac{\exp(z_{t,k})}{\sum_{m=0}^{V-1} \exp(z_{t,m})}, \qquad k \in \{0, \dots, V-1\}$$&lt;/code&gt;&lt;/p&gt;&#xA;&lt;p&gt;Because discrete token IDs are arbitrary dictionary indices—token &lt;code&gt;500&lt;/code&gt; is not &amp;quot;twice&amp;quot; token &lt;code&gt;250&lt;/code&gt;—calculus derivatives cannot act directly on integers. The network therefore begins with a token embedding matrix &lt;code&gt;$E_{\mathrm{tok}} \in \mathbb{R}^{V \times D}$&lt;/code&gt; that maps each integer ID &lt;code&gt;$x_t$&lt;/code&gt; to row &lt;code&gt;$x_t$&lt;/code&gt; in continuous space &lt;code&gt;$\mathbb{R}^D$&lt;/code&gt;. Writing &lt;code&gt;$u_{x_t} \in \{0,1\}^V$&lt;/code&gt; for the one-hot column vector with a &lt;code&gt;$1$&lt;/code&gt; only at index &lt;code&gt;$x_t$&lt;/code&gt;, row lookup is algebraically identical to the sparse matrix product &lt;code&gt;$u_{x_t}^\top E_{\mathrm{tok}} \in \mathbb{R}^{1 \times D}$&lt;/code&gt;.&lt;/p&gt;&#xA;&lt;p&gt;Row lookup alone is still not enough on a sequence of length &lt;code&gt;$T$&lt;/code&gt;: inner products in self-attention are permutation-equivariant with respect to token order (without positional information, swapping &amp;quot;cat chased dog&amp;quot; into &amp;quot;dog chased cat&amp;quot; merely permutes the output rows without changing their representations). Adding absolute or relative positional encodings &lt;code&gt;$E_{\mathrm{pos}} \in \mathbb{R}^{T \times D}$&lt;/code&gt; produces the initial hidden state &lt;code&gt;$X^{(0)} \in \mathbb{R}^{T \times D}$&lt;/code&gt; (or a 3D tensor in &lt;code&gt;$\mathbb{R}^{B \times T \times D}$&lt;/code&gt; across a batch of &lt;code&gt;$B$&lt;/code&gt; sequences). Every subsequent sublayer adds its output back onto this shared highway via &lt;code&gt;$X \leftarrow X + \mathrm{Sublayer}(X)$&lt;/code&gt;, known as the &lt;strong&gt;residual stream&lt;/strong&gt;.&lt;/p&gt;&#xA;&lt;h3 id=&#34;12-forward-equations-of-a-single-transformer-block&#34;&gt;1.2 Forward Equations of a Single Transformer Block&lt;/h3&gt;&#xA;&lt;p&gt;Modern open-weights LLMs (such as Llama, Qwen, and DeepSeek) almost universally adopt a bias-free Pre-RMSNorm decoder block&lt;sup class=&#34;cite&#34;&gt;&lt;a id=&#34;cite-vaswani2017-2&#34; href=&#34;#ref-vaswani2017&#34;&gt;[1]&lt;/a&gt;&lt;/sup&gt;&lt;sup class=&#34;cite&#34;&gt;&lt;a id=&#34;cite-zhang2019-1&#34; href=&#34;#ref-zhang2019&#34;&gt;[6]&lt;/a&gt;&lt;/sup&gt;. Given a single sequence&#39;s residual stream &lt;code&gt;$X \in \mathbb{R}^{T \times D}$&lt;/code&gt; with hidden width &lt;code&gt;$D$&lt;/code&gt;, define row-wise root-mean-square normalization on a row vector &lt;code&gt;$x \in \mathbb{R}^D$&lt;/code&gt; as &lt;code&gt;$\mathrm{RMSNorm}(x) = \frac{x}{\sqrt{\frac{1}{D}\sum_{i=1}^D x_i^2 + \epsilon}} \odot \gamma$&lt;/code&gt;, where &lt;code&gt;$\epsilon &amp;gt; 0$&lt;/code&gt; guards against division by zero, &lt;code&gt;$\gamma \in \mathbb{R}^D$&lt;/code&gt; is a learnable per-channel gain vector, and &lt;code&gt;$\odot$&lt;/code&gt; denotes elementwise (Hadamard) multiplication (whose backward orthogonality we derive in Section 2.1). Each Transformer layer then applies two sublayers:&lt;/p&gt;&#xA;&lt;p&gt;&lt;strong&gt;Sublayer 1: Multi-Head Causal Self-Attention.&lt;/strong&gt; Row-wise normalization &lt;code&gt;$H = \mathrm{RMSNorm}(X) \in \mathbb{R}^{T \times D}$&lt;/code&gt; is projected by three linear matrices into queries, keys, and values:&lt;/p&gt;&#xA;&lt;p&gt;&lt;code&gt;$$Q = H W_q^\top, \qquad K = H W_k^\top, \qquad V_{\mathrm{val}} = H W_v^\top$$&lt;/code&gt;&lt;/p&gt;&#xA;&lt;p&gt;where &lt;code&gt;$W_q, W_k, W_v \in \mathbb{R}^{D \times D}$&lt;/code&gt;. Computing a single inner product across the full &lt;code&gt;$D$&lt;/code&gt;-dimensional space would give each token only one scalar attention distribution per layer, forcing coreference, syntactic modification, and local collocations to compete for the same weights. Instead, the hidden width &lt;code&gt;$D$&lt;/code&gt; is partitioned into &lt;code&gt;$H_{\mathrm{head}}$&lt;/code&gt; parallel subspaces (attention heads) of width &lt;code&gt;$d_k = D / H_{\mathrm{head}}$&lt;/code&gt;. In batched code, a &lt;code&gt;$(B, T, D)$&lt;/code&gt; tensor is reshaped to &lt;code&gt;$(B, T, H_{\mathrm{head}}, d_k)$&lt;/code&gt; and transposed to &lt;code&gt;$(B, H_{\mathrm{head}}, T, d_k)$&lt;/code&gt;. On head &lt;code&gt;$h$&lt;/code&gt;&#39;s slices &lt;code&gt;$Q^{(h)}, K^{(h)}, V_{\mathrm{val}}^{(h)} \in \mathbb{R}^{T \times d_k}$&lt;/code&gt;, scaled causal dot-product attention computes:&lt;/p&gt;&#xA;&lt;p&gt;&lt;code&gt;$$S^{(h)} = \frac{Q^{(h)} \bigl(K^{(h)}\bigr)^\top}{\sqrt{d_k}} + M_{\mathrm{causal}}, \qquad P^{(h)} = \mathrm{softmax}\!\left(S^{(h)}\right), \qquad O^{(h)} = P^{(h)} V_{\mathrm{val}}^{(h)}$$&lt;/code&gt;&lt;/p&gt;&#xA;&lt;p&gt;Here both the score matrix &lt;code&gt;$S^{(h)}$&lt;/code&gt; and the probability matrix &lt;code&gt;$P^{(h)}$&lt;/code&gt; have shape &lt;code&gt;$T \times T$&lt;/code&gt;. The causal mask &lt;code&gt;$M_{\mathrm{causal}} \in \{0, -\infty\}^{T \times T}$&lt;/code&gt; equals &lt;code&gt;$0$&lt;/code&gt; on and below the main diagonal (&lt;code&gt;$i \ge j$&lt;/code&gt;) and &lt;code&gt;$-\infty$&lt;/code&gt; strictly above it (&lt;code&gt;$i &amp;lt; j$&lt;/code&gt;, where position &lt;code&gt;$i$&lt;/code&gt; would peek at a future token &lt;code&gt;$j$&lt;/code&gt;). Since &lt;code&gt;$\exp(-\infty) = 0$&lt;/code&gt;, row-wise Softmax turns &lt;code&gt;$P^{(h)}$&lt;/code&gt; into a strictly lower-triangular stochastic matrix whose &lt;code&gt;$i$&lt;/code&gt;-th output row depends only on positions &lt;code&gt;$\le i$&lt;/code&gt;.&lt;/p&gt;&#xA;&lt;p&gt;Why divide by &lt;code&gt;$\sqrt{d_k}$&lt;/code&gt;? Suppose the coordinates of &lt;code&gt;$q \in \mathbb{R}^{d_k}$&lt;/code&gt; and &lt;code&gt;$k \in \mathbb{R}^{d_k}$&lt;/code&gt; are independent with zero mean and unit variance. Each product term has &lt;code&gt;$\mathbb{E}[q_m k_m] = 0$&lt;/code&gt; and &lt;code&gt;$\mathrm{Var}(q_m k_m) = \mathbb{E}[q_m^2]\mathbb{E}[k_m^2] - 0 = 1$&lt;/code&gt;, so the variance of the full dot product grows linearly with subspace width:&lt;/p&gt;&#xA;&lt;p&gt;&lt;code&gt;$$\mathrm{Var}(q^\top k) = \sum_{m=1}^{d_k} \mathrm{Var}(q_m k_m) = d_k$$&lt;/code&gt;&lt;/p&gt;&#xA;&lt;p&gt;Without dividing by &lt;code&gt;$\sqrt{d_k}$&lt;/code&gt;, at &lt;code&gt;$d_k = 64$&lt;/code&gt; or &lt;code&gt;$128$&lt;/code&gt; the dot product&#39;s standard deviation reaches &lt;code&gt;$8$&lt;/code&gt;–&lt;code&gt;$11.3$&lt;/code&gt;, pushing the largest entry in each row far above the rest and driving &lt;code&gt;$P_{i,a} = e^{S_{i,a}} / \sum_c e^{S_{i,c}}$&lt;/code&gt; toward a one-hot corner. Differentiating the quotient shows that the local Jacobian of Softmax is &lt;code&gt;$\partial P_{i,a} / \partial S_{i,b} = P_{i,a}(\delta_{ab} - P_{i,b})$&lt;/code&gt; (where the Kronecker delta &lt;code&gt;$\delta_{ab}$&lt;/code&gt; is &lt;code&gt;$1$&lt;/code&gt; if &lt;code&gt;$a=b$&lt;/code&gt; and &lt;code&gt;$0$&lt;/code&gt; otherwise); once &lt;code&gt;$P$&lt;/code&gt; saturates to &lt;code&gt;$0$&lt;/code&gt;s and &lt;code&gt;$1$&lt;/code&gt;s, every entry of that Jacobian vanishes for both &lt;code&gt;$a=b$&lt;/code&gt; and &lt;code&gt;$a \neq b$&lt;/code&gt;, starving the query and key projections of gradient&lt;sup class=&#34;cite&#34;&gt;&lt;a id=&#34;cite-vaswani2017-3&#34; href=&#34;#ref-vaswani2017&#34;&gt;[1]&lt;/a&gt;&lt;/sup&gt;. Dividing by &lt;code&gt;$\sqrt{d_k}$&lt;/code&gt; restores unit variance.&lt;/p&gt;&#xA;&lt;p&gt;Concatenating all &lt;code&gt;$H_{\mathrm{head}}$&lt;/code&gt; heads back along the last axis into &lt;code&gt;$O = [O^{(1)}, \dots, O^{(H_{\mathrm{head}})}] \in \mathbb{R}^{T \times D}$&lt;/code&gt;, multiplying by &lt;code&gt;$W_o^\top$&lt;/code&gt; (&lt;code&gt;$W_o \in \mathbb{R}^{D \times D}$&lt;/code&gt;), and adding back to the residual pathway yields &lt;code&gt;$X&amp;#39; = X + O W_o^\top$&lt;/code&gt;.&lt;/p&gt;&#xA;&lt;p&gt;&lt;strong&gt;Sublayer 2: Position-wise FFN / MLP.&lt;/strong&gt; Normalizing again via &lt;code&gt;$H&amp;#39; = \mathrm{RMSNorm}(X&amp;#39;)$&lt;/code&gt;, the hidden representation expands through &lt;code&gt;$W_{\mathrm{up}} \in \mathbb{R}^{d_{\mathrm{ff}} \times D}$&lt;/code&gt; (classically &lt;code&gt;$d_{\mathrm{ff}} = 4D$&lt;/code&gt;), passes through an elementwise nonlinearity &lt;code&gt;$\sigma(\cdot)$&lt;/code&gt; such as &lt;code&gt;$\mathrm{SiLU}(z) = z / (1 + e^{-z})$&lt;/code&gt;, projects back down via &lt;code&gt;$W_{\mathrm{down}} \in \mathbb{R}^{D \times d_{\mathrm{ff}}}$&lt;/code&gt;, and joins the residual stream:&lt;/p&gt;&#xA;&lt;p&gt;&lt;code&gt;$$X_{\mathrm{out}} = X&amp;#39; + \sigma(H&amp;#39; W_{\mathrm{up}}^\top) W_{\mathrm{down}}^\top$$&lt;/code&gt;&lt;/p&gt;&#xA;&lt;p&gt;After &lt;code&gt;$L$&lt;/code&gt; stacked blocks, a final &lt;code&gt;RMSNorm&lt;/code&gt; followed by the language-modeling head &lt;code&gt;$W_{\mathrm{head}}^\top$&lt;/code&gt; (&lt;code&gt;$W_{\mathrm{head}} \in \mathbb{R}^{V \times D}$&lt;/code&gt;) produces the full-sequence logit matrix &lt;code&gt;$Z \in \mathbb{R}^{T \times V}$&lt;/code&gt;.&lt;/p&gt;&#xA;&lt;blockquote&gt;&#xA;&lt;p&gt;&lt;strong&gt;Note on PyTorch &lt;code&gt;nn.Linear&lt;/code&gt; weight shapes&lt;/strong&gt;: calling &lt;code&gt;nn.Linear(in_features=64, out_features=256, bias=False)&lt;/code&gt; stores &lt;code&gt;.weight&lt;/code&gt; with transposed shape &lt;code&gt;(256, 64)&lt;/code&gt;—that is, &lt;code&gt;$(d_{\mathrm{out}}, d_{\mathrm{in}})$&lt;/code&gt;—and evaluates &lt;code&gt;$H W^\top$&lt;/code&gt; in the forward pass. Because C/CUDA arrays are row-major, laying out the &lt;code&gt;$d_{\mathrm{in}}$&lt;/code&gt; weights of each output neuron contiguously along a row makes inner-product reads sequential in memory. Throughout this post, every 2D weight matrix &lt;code&gt;$W \in \mathbb{R}^{A \times B}$&lt;/code&gt; follows PyTorch&#39;s layout with &lt;code&gt;$A = d_{\mathrm{out}}$&lt;/code&gt; rows and &lt;code&gt;$B = d_{\mathrm{in}}$&lt;/code&gt; columns.&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&lt;h3 id=&#34;13-the-four-tensor-families-in-gpu-memory&#34;&gt;1.3 The Four Tensor Families in GPU Memory&lt;/h3&gt;&#xA;&lt;p&gt;Every multi-dimensional array appearing in the equations above is casually called a &amp;quot;matrix,&amp;quot; yet by mathematical definition, shape dependence, and memory lifetime, they partition cleanly into four distinct families:&lt;/p&gt;&#xA;&lt;figure class=&#34;diagram&#34; style=&#34;--h:268px;--hn:499px&#34;&gt;&lt;figcaption&gt;Mathematical Roles and Lifetimes of the Four Tensor Families in VRAM&lt;/figcaption&gt;&lt;p&gt;&lt;a href=&#34;https://mizore.blog/en/posts/from-transformer-matrices-to-muon/&#34;&gt;(See the figure in the post.)&lt;/a&gt;&lt;/p&gt;&lt;p class=&#34;figure-note&#34;&gt;Static parameter shapes depend only on architecture hyperparameters; dynamic activations scale with batch B and sequence length T; the KV Cache grows token-by-token only during decoding; gradients and optimizer states are allocated alongside parameters only during training.&lt;/p&gt;&lt;/figure&gt;&#xA;&lt;p&gt;For newcomers, the easiest pair of objects to conflate is the &lt;strong&gt;projection weights &lt;code&gt;$W_q, W_k \in \mathbb{R}^{D \times D}$&lt;/code&gt;&lt;/strong&gt; versus the &lt;strong&gt;attention probability matrix &lt;code&gt;$P \in \mathbb{R}^{T \times T}$&lt;/code&gt;&lt;/strong&gt;. The former are Family 1 static parameters: whether the prompt is 4 tokens or 4,096 tokens long, their shape is permanently &lt;code&gt;$D \times D$&lt;/code&gt;, and they are the actual weights modified by the optimizer. The latter is a Family 2 transient activation: its dimensions stretch and shrink with the current sequence length &lt;code&gt;$T$&lt;/code&gt;, capturing pairwise token alignments inside a single forward pass—never saved to a checkpoint and never directly stepped by an optimizer.&lt;/p&gt;&#xA;&lt;figure class=&#34;diagram&#34; style=&#34;--h:202px;--hn:362px&#34;&gt;&lt;figcaption&gt;Static Projection Weights &lt;code&gt;$W_q, W_k$&lt;/code&gt; vs. Transient Attention Matrix &lt;code&gt;$P$&lt;/code&gt;&lt;/figcaption&gt;&lt;p&gt;&lt;a href=&#34;https://mizore.blog/en/posts/from-transformer-matrices-to-muon/&#34;&gt;(See the figure in the post.)&lt;/a&gt;&lt;/p&gt;&lt;p class=&#34;figure-note&#34;&gt;Projection matrices &lt;code&gt;$W_q, W_k$&lt;/code&gt; have fixed shape &lt;code&gt;$(D, D)$&lt;/code&gt; shared across all inputs; the attention matrix &lt;code&gt;$P$&lt;/code&gt; has dynamic shape &lt;code&gt;$(T, T)$&lt;/code&gt; representing temporary token-to-token routing inside one sequence.&lt;/p&gt;&lt;/figure&gt;&#xA;&lt;p&gt;Comparing the mini Transformer used in Section 7 (&lt;code&gt;$B=20, T=16, D=64, H=4, d_k=16, V=1000$&lt;/code&gt;) against a production 7B-class model summarizes all 14 tensors across the pipeline:&lt;/p&gt;&#xA;&lt;figure class=&#34;data wide&#34;&gt;&lt;figcaption&gt;14 Tensor Types Across Transformer Inference and Training&lt;/figcaption&gt;&lt;div class=&#34;data-scroll&#34; tabindex=&#34;0&#34;&gt;&lt;table&gt;&lt;thead&gt;&lt;tr&gt;&lt;th&gt;Tensor &amp;amp; Symbol&lt;/th&gt;&lt;th&gt;Family&lt;/th&gt;&lt;th&gt;Mini Shape&lt;/th&gt;&lt;th&gt;Typical 7B Shape&lt;/th&gt;&lt;th&gt;Inference&lt;/th&gt;&lt;th&gt;Training&lt;/th&gt;&lt;/tr&gt;&lt;/thead&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td class=&#34;row-key prose-col&#34;&gt;Inputs &amp;amp; targets &lt;code&gt;$x, y$&lt;/code&gt;&lt;/td&gt;&lt;td class=&#34;prose-col&#34;&gt;Token IDs&lt;/td&gt;&lt;td class=&#34;prose-col&#34;&gt;&lt;code&gt;$(20, 16)$&lt;/code&gt;&lt;/td&gt;&lt;td class=&#34;prose-col&#34;&gt;&lt;code&gt;$(B, 4096)$&lt;/code&gt;&lt;/td&gt;&lt;td class=&#34;prose-col&#34;&gt;Prefix only&lt;/td&gt;&lt;td class=&#34;prose-col&#34;&gt;Shifted by 1 token&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td class=&#34;row-key prose-col&#34;&gt;Token emb &lt;code&gt;$E_{\mathrm{tok}}$&lt;/code&gt;&lt;/td&gt;&lt;td class=&#34;prose-col&#34;&gt;1. Parameter&lt;/td&gt;&lt;td class=&#34;prose-col&#34;&gt;&lt;code&gt;$(1000, 64)$&lt;/code&gt;&lt;/td&gt;&lt;td class=&#34;prose-col&#34;&gt;&lt;code&gt;$(128256, 4096)$&lt;/code&gt;&lt;/td&gt;&lt;td class=&#34;prose-col&#34;&gt;Read-only lookup&lt;/td&gt;&lt;td class=&#34;prose-col&#34;&gt;AdamW step&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td class=&#34;row-key prose-col&#34;&gt;Pos emb &lt;code&gt;$E_{\mathrm{pos}}$&lt;/code&gt;&lt;/td&gt;&lt;td class=&#34;prose-col&#34;&gt;1. Parameter&lt;/td&gt;&lt;td class=&#34;prose-col&#34;&gt;&lt;code&gt;$(32, 64)$&lt;/code&gt;&lt;/td&gt;&lt;td class=&#34;prose-col&#34;&gt;Parameter-free RoPE&lt;/td&gt;&lt;td class=&#34;prose-col&#34;&gt;Broadcast add&lt;/td&gt;&lt;td class=&#34;prose-col&#34;&gt;AdamW step&lt;/td&gt;&lt;/tr&gt;&lt;tr class=&#34;mark&#34;&gt;&lt;td class=&#34;row-key prose-col&#34;&gt;Attention &lt;code&gt;$W_q \dots W_o$&lt;/code&gt;&lt;/td&gt;&lt;td class=&#34;prose-col&#34;&gt;1. Parameter&lt;/td&gt;&lt;td class=&#34;prose-col&#34;&gt;Four &lt;code&gt;$(64, 64)$&lt;/code&gt;&lt;/td&gt;&lt;td class=&#34;prose-col&#34;&gt;&lt;code&gt;$(4096, 4096)$&lt;/code&gt;&lt;/td&gt;&lt;td class=&#34;prose-col&#34;&gt;Read-only GEMM&lt;/td&gt;&lt;td class=&#34;prose-col&#34;&gt;Muon orthogonal step&lt;/td&gt;&lt;/tr&gt;&lt;tr class=&#34;mark&#34;&gt;&lt;td class=&#34;row-key prose-col&#34;&gt;FFN &lt;code&gt;$W_{\mathrm{up}} / W_{\mathrm{down}}$&lt;/code&gt;&lt;/td&gt;&lt;td class=&#34;prose-col&#34;&gt;1. Parameter&lt;/td&gt;&lt;td class=&#34;prose-col&#34;&gt;&lt;code&gt;$(256,64)/(64,256)$&lt;/code&gt;&lt;/td&gt;&lt;td class=&#34;prose-col&#34;&gt;&lt;code&gt;$(11008, 4096)$&lt;/code&gt;&lt;/td&gt;&lt;td class=&#34;prose-col&#34;&gt;Read-only GEMM&lt;/td&gt;&lt;td class=&#34;prose-col&#34;&gt;Muon orthogonal step&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td class=&#34;row-key prose-col&#34;&gt;Norm gain &lt;code&gt;$\gamma$&lt;/code&gt;&lt;/td&gt;&lt;td class=&#34;prose-col&#34;&gt;1. Parameter&lt;/td&gt;&lt;td class=&#34;prose-col&#34;&gt;&lt;code&gt;$(64,)$&lt;/code&gt; 1D&lt;/td&gt;&lt;td class=&#34;prose-col&#34;&gt;&lt;code&gt;$(4096,)$&lt;/code&gt; 1D&lt;/td&gt;&lt;td class=&#34;prose-col&#34;&gt;Channel scale&lt;/td&gt;&lt;td class=&#34;prose-col&#34;&gt;AdamW (wd=0)&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td class=&#34;row-key prose-col&#34;&gt;LM head &lt;code&gt;$W_{\mathrm{head}}$&lt;/code&gt;&lt;/td&gt;&lt;td class=&#34;prose-col&#34;&gt;1. Parameter&lt;/td&gt;&lt;td class=&#34;prose-col&#34;&gt;&lt;code&gt;$(1000, 64)$&lt;/code&gt;&lt;/td&gt;&lt;td class=&#34;prose-col&#34;&gt;&lt;code&gt;$(128256, 4096)$&lt;/code&gt;&lt;/td&gt;&lt;td class=&#34;prose-col&#34;&gt;Last-row logits&lt;/td&gt;&lt;td class=&#34;prose-col&#34;&gt;AdamW step&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td class=&#34;row-key prose-col&#34;&gt;Residual &amp;amp; norm &lt;code&gt;$X, H$&lt;/code&gt;&lt;/td&gt;&lt;td class=&#34;prose-col&#34;&gt;2. Activation&lt;/td&gt;&lt;td class=&#34;prose-col&#34;&gt;&lt;code&gt;$(20, 16, 64)$&lt;/code&gt;&lt;/td&gt;&lt;td class=&#34;prose-col&#34;&gt;&lt;code&gt;$(B, T, 4096)$&lt;/code&gt;&lt;/td&gt;&lt;td class=&#34;prose-col&#34;&gt;Freed per layer&lt;/td&gt;&lt;td class=&#34;prose-col&#34;&gt;Cached for backward&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td class=&#34;row-key prose-col&#34;&gt;Multi-head &lt;code&gt;$Q, K, V_{\mathrm{val}}$&lt;/code&gt;&lt;/td&gt;&lt;td class=&#34;prose-col&#34;&gt;2. Activation&lt;/td&gt;&lt;td class=&#34;prose-col&#34;&gt;&lt;code&gt;$(20, 4, 16, 16)$&lt;/code&gt;&lt;/td&gt;&lt;td class=&#34;prose-col&#34;&gt;&lt;code&gt;$(B, 32, T, 128)$&lt;/code&gt;&lt;/td&gt;&lt;td class=&#34;prose-col&#34;&gt;Freed per layer&lt;/td&gt;&lt;td class=&#34;prose-col&#34;&gt;Cached for backward&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td class=&#34;row-key prose-col&#34;&gt;Attention &lt;code&gt;$S, P$&lt;/code&gt;&lt;/td&gt;&lt;td class=&#34;prose-col&#34;&gt;2. Activation&lt;/td&gt;&lt;td class=&#34;prose-col&#34;&gt;&lt;code&gt;$(20, 4, 16, 16)$&lt;/code&gt;&lt;/td&gt;&lt;td class=&#34;prose-col&#34;&gt;&lt;code&gt;$(B, 32, T, T)$&lt;/code&gt;&lt;/td&gt;&lt;td class=&#34;prose-col&#34;&gt;Freed per layer&lt;/td&gt;&lt;td class=&#34;prose-col&#34;&gt;Cached or recomputed&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td class=&#34;row-key prose-col&#34;&gt;Logit tensor &lt;code&gt;$Z$&lt;/code&gt;&lt;/td&gt;&lt;td class=&#34;prose-col&#34;&gt;2. Activation&lt;/td&gt;&lt;td class=&#34;prose-col&#34;&gt;&lt;code&gt;$(20, 16, 1000)$&lt;/code&gt;&lt;/td&gt;&lt;td class=&#34;prose-col&#34;&gt;&lt;code&gt;$(B, T, 128256)$&lt;/code&gt;&lt;/td&gt;&lt;td class=&#34;prose-col&#34;&gt;Last row only&lt;/td&gt;&lt;td class=&#34;prose-col&#34;&gt;Full-seq CE loss&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td class=&#34;row-key prose-col&#34;&gt;Cache &lt;code&gt;$K/V_{\mathrm{cache}}$&lt;/code&gt;&lt;/td&gt;&lt;td class=&#34;prose-col&#34;&gt;3. KV Cache&lt;/td&gt;&lt;td class=&#34;prose-col&#34;&gt;&lt;code&gt;$(1, 4, t, 16)$&lt;/code&gt;&lt;/td&gt;&lt;td class=&#34;prose-col&#34;&gt;&lt;code&gt;$(B, 8, t, 128)$&lt;/code&gt;&lt;/td&gt;&lt;td class=&#34;prose-col&#34;&gt;+1 row per step&lt;/td&gt;&lt;td class=&#34;prose-col&#34;&gt;Not allocated&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td class=&#34;row-key prose-col&#34;&gt;Weight grad &lt;code&gt;$G$&lt;/code&gt;&lt;/td&gt;&lt;td class=&#34;prose-col&#34;&gt;4. Train State&lt;/td&gt;&lt;td class=&#34;prose-col&#34;&gt;Same as param&lt;/td&gt;&lt;td class=&#34;prose-col&#34;&gt;Same as param&lt;/td&gt;&lt;td class=&#34;prose-col&#34;&gt;Not allocated&lt;/td&gt;&lt;td class=&#34;prose-col&#34;&gt;Written in backward&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td class=&#34;row-key prose-col&#34;&gt;Opt states &lt;code&gt;$M, V$&lt;/code&gt;&lt;/td&gt;&lt;td class=&#34;prose-col&#34;&gt;4. Train State&lt;/td&gt;&lt;td class=&#34;prose-col&#34;&gt;Same as param&lt;/td&gt;&lt;td class=&#34;prose-col&#34;&gt;Same as param&lt;/td&gt;&lt;td class=&#34;prose-col&#34;&gt;Not allocated&lt;/td&gt;&lt;td class=&#34;prose-col&#34;&gt;Resident (Muon drops &lt;code&gt;$V$&lt;/code&gt;)&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/div&gt;&lt;p class=&#34;data-note&#34;&gt;Production models (e.g., Llama 3 / Qwen) commonly use Grouped-Query Attention (GQA) to shrink the output rows of &lt;code&gt;$W_k, W_v$&lt;/code&gt; for a smaller KV Cache, and add a gate matrix &lt;code&gt;$W_{\mathrm{gate}}$&lt;/code&gt; in SwiGLU FFNs; all remain dense 2D linear operators.&lt;/p&gt;&lt;/figure&gt;&#xA;&lt;h3 id=&#34;14-why-inference-needs-a-kv-cache-while-training-runs-in-parallel&#34;&gt;1.4 Why Inference Needs a &lt;code&gt;KV Cache&lt;/code&gt; While Training Runs in Parallel&lt;/h3&gt;&#xA;&lt;p&gt;A second payoff of classifying these four families comes from examining the lower-triangular causal mask &lt;code&gt;$M_{\mathrm{causal}}$&lt;/code&gt;, which explains both the &lt;strong&gt;two-stage structure of inference (&lt;code&gt;Prefill&lt;/code&gt; vs. &lt;code&gt;Decode&lt;/code&gt;)&lt;/strong&gt; and &lt;strong&gt;parallel &lt;code&gt;Teacher Forcing&lt;/code&gt; during training&lt;/strong&gt;.&lt;/p&gt;&#xA;&lt;p&gt;Consider &lt;strong&gt;inference&lt;/strong&gt; first. Future tokens do not exist yet: given a user prompt &lt;code&gt;$x_{1:T_0}$&lt;/code&gt;, the model must predict &lt;code&gt;$x_{T_0+1}$&lt;/code&gt;, append &lt;code&gt;$x_{T_0+1}$&lt;/code&gt; to the sequence, and only then predict &lt;code&gt;$x_{T_0+2}$&lt;/code&gt;.&lt;/p&gt;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;&lt;strong&gt;Prefill stage&lt;/strong&gt;: all &lt;code&gt;$T_0$&lt;/code&gt; prompt tokens are known simultaneously, so &lt;code&gt;$H \in \mathbb{R}^{T_0 \times D}$&lt;/code&gt; multiplies &lt;code&gt;$W^\top \in \mathbb{R}^{D \times D}$&lt;/code&gt; via dense matrix-matrix multiplication (GEMM), computing keys &lt;code&gt;$K_{1:T_0}$&lt;/code&gt; and values &lt;code&gt;$V_{1:T_0}$&lt;/code&gt; across all &lt;code&gt;$T_0$&lt;/code&gt; positions at once and sampling the first generated token &lt;code&gt;$x_{T_0+1}$&lt;/code&gt; from row &lt;code&gt;$T_0$&lt;/code&gt;&#39;s logits.&lt;/li&gt;&#xA;&lt;li&gt;&lt;strong&gt;Autoregressive Decode stage and redundancy&lt;/strong&gt;: at step &lt;code&gt;$t$&lt;/code&gt;, when &lt;code&gt;$x_{1:t}$&lt;/code&gt; is available and we want &lt;code&gt;$x_{t+1}$&lt;/code&gt;, feeding the entire prefix &lt;code&gt;$x_{1:t}$&lt;/code&gt; back through the network would recompute identical hidden states &lt;code&gt;$h_1, \dots, h_{t-1}$&lt;/code&gt; and identical projections &lt;code&gt;$k_1, \dots, k_{t-1}$&lt;/code&gt;, &lt;code&gt;$v_1, \dots, v_{t-1}$&lt;/code&gt; bit-for-bit, because the causal mask at every layer forbids positions &lt;code&gt;$1 \dots t-1$&lt;/code&gt; from reading position &lt;code&gt;$t$&lt;/code&gt;. Moreover, sampling &lt;code&gt;$x_{t+1}$&lt;/code&gt; requires only the final output row &lt;code&gt;$o_t$&lt;/code&gt;:&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&lt;p&gt;&lt;code&gt;$$o_t^{(h)} = \sum_{j=1}^{t} P_{t,j}^{(h)} v_j^{(h)}, \qquad P_{t, :}^{(h)} = \mathrm{softmax}\!\left(\frac{q_t^{(h)} K_{1:t}^{(h)\top}}{\sqrt{d_k}}\right) \in \mathbb{R}^{1 \times t}$$&lt;/code&gt;&lt;/p&gt;&#xA;&lt;p&gt;Neither historical queries &lt;code&gt;$q_1, \dots, q_{t-1}$&lt;/code&gt; nor the upper &lt;code&gt;$t-1$&lt;/code&gt; rows of the &lt;code&gt;$t \times t$&lt;/code&gt; attention table are needed. By caching &lt;code&gt;$K_{1:t-1}$&lt;/code&gt; and &lt;code&gt;$V_{1:t-1}$&lt;/code&gt; in VRAM (the &lt;code&gt;KV Cache&lt;/code&gt;), step &lt;code&gt;$t$&lt;/code&gt; feeds only the single new row &lt;code&gt;$h_t \in \mathbb{R}^{1 \times D}$&lt;/code&gt;, computes &lt;code&gt;$q_t, k_t, v_t$&lt;/code&gt; via matrix-vector products (GEMV), appends &lt;code&gt;$k_t, v_t$&lt;/code&gt; as row &lt;code&gt;$t$&lt;/code&gt; of the cache to form &lt;code&gt;$K_{1:t}, V_{1:t}$&lt;/code&gt;, and executes a lightweight &lt;code&gt;$(1, d_k) \times (d_k, t)$&lt;/code&gt; product.&lt;/p&gt;&#xA;&lt;p&gt;Counting multiply-accumulate operations (MACs, where &lt;code&gt;$1\;\text{MAC} = 2\;\text{FLOPs}$&lt;/code&gt;) per layer of width &lt;code&gt;$D$&lt;/code&gt; makes the asymptotic gap explicit. Without a &lt;code&gt;KV Cache&lt;/code&gt;, recomputing projections at length &lt;code&gt;$t$&lt;/code&gt; costs &lt;code&gt;$\mathcal{O}(t D^2)$&lt;/code&gt; and attention costs &lt;code&gt;$\mathcal{O}(t^2 D)$&lt;/code&gt;; summed from &lt;code&gt;$t = T_0$&lt;/code&gt; to &lt;code&gt;$N$&lt;/code&gt;, cumulative work scales as &lt;code&gt;$\sum_{t=T_0}^N \mathcal{O}(t D^2 + t^2 D) = \mathcal{O}(N^2 D^2 + N^3 D)$&lt;/code&gt;. With a &lt;code&gt;KV Cache&lt;/code&gt;, each decode step projects a single row in &lt;code&gt;$\mathcal{O}(D^2)$&lt;/code&gt; and attends over &lt;code&gt;$t$&lt;/code&gt; cached keys in &lt;code&gt;$\mathcal{O}(t D)$&lt;/code&gt;, reducing cumulative work to &lt;code&gt;$\mathcal{O}(N D^2 + N^2 D)$&lt;/code&gt;.&lt;/p&gt;&#xA;&lt;p&gt;Now contrast &lt;strong&gt;training&lt;/strong&gt;. During training, the complete ground-truth sequence &lt;code&gt;$x_{1:T+1}$&lt;/code&gt; from the corpus is already on hand. Feeding &lt;code&gt;$x_{1:T}$&lt;/code&gt; as input and the one-token-shifted sequence &lt;code&gt;$x_{2:T+1}$&lt;/code&gt; as targets (&lt;strong&gt;Teacher Forcing&lt;/strong&gt;), the causal mask &lt;code&gt;$M_{\mathrm{causal}}$&lt;/code&gt; blocks row &lt;code&gt;$t$&lt;/code&gt; from attending to any column &lt;code&gt;$j &amp;gt; t$&lt;/code&gt; inside the matrix itself. One parallel &lt;code&gt;$(B, T, D) \times (D, D)$&lt;/code&gt; GEMM is therefore mathematically identical to running &lt;code&gt;$B \times T$&lt;/code&gt; prefix-prediction tasks at once—saturating GPU Tensor Cores without ever allocating a &lt;code&gt;KV Cache&lt;/code&gt;.&lt;/p&gt;&#xA;&lt;figure class=&#34;diagram&#34; style=&#34;--h:700px;--hn:604px&#34;&gt;&lt;figcaption&gt;Full-Flow LLM Inference Matrix Shapes: Tracking Dimension Alignment &amp;amp; Contraction with Unit Blocks&lt;/figcaption&gt;&lt;p&gt;&lt;a href=&#34;https://mizore.blog/en/posts/from-transformer-matrices-to-muon/&#34;&gt;(See the figure in the post.)&lt;/a&gt;&lt;/p&gt;&lt;p class=&#34;figure-note&#34;&gt;Each discrete square represents one scalar entry (&lt;code&gt;$T_0=3, D=4, d_k=2, d_{\mathrm{ff}}=6, V=6$&lt;/code&gt;). Dashed arcs connect matching inner dimensions summed out in matrix multiplication; moving from Stage 1 to Stage 2 collapses every &lt;code&gt;$T_0=3$&lt;/code&gt;-row activation into a single &lt;code&gt;$1$&lt;/code&gt;-row strip while appending just &lt;code&gt;$1$&lt;/code&gt; row to the violet KV Cache.&lt;/p&gt;&lt;/figure&gt;&#xA;&lt;h3 id=&#34;15-unfolding-the-matrices-hand-tracing-a-3-token-sentence-through-prefill-and-decode&#34;&gt;1.5 Unfolding the Matrices: Hand-Tracing a 3-Token Sentence Through &lt;code&gt;Prefill&lt;/code&gt; and &lt;code&gt;Decode&lt;/code&gt;&lt;/h3&gt;&#xA;&lt;p&gt;Compact matrix equations and block-shape diagrams summarize the architecture cleanly, yet newcomers often hit a wall when asking what happens &lt;em&gt;inside&lt;/em&gt; the brackets: how do actual numbers transform step by step from token IDs to attention outputs? Shrinking the dimensions to hand-calculable integers lets us unfold every matrix on the page.&lt;/p&gt;&#xA;&lt;p&gt;Take a 5-token toy vocabulary &lt;code&gt;$V = 5$&lt;/code&gt; (&lt;code&gt;0:&amp;lt;pad&amp;gt;&lt;/code&gt;, &lt;code&gt;1:cat&lt;/code&gt;, &lt;code&gt;2:chases&lt;/code&gt;, &lt;code&gt;3:dog&lt;/code&gt;, &lt;code&gt;4:runs&lt;/code&gt;), hidden width &lt;code&gt;$D = 3$&lt;/code&gt;, and single-head width &lt;code&gt;$d_k = 2$&lt;/code&gt;. Suppose the input prompt is the 3-token prefix &lt;code&gt;[&amp;quot;cat&amp;quot;, &amp;quot;chases&amp;quot;, &amp;quot;dog&amp;quot;]&lt;/code&gt;, mapped to integer IDs &lt;code&gt;$(1, 2, 3)$&lt;/code&gt;.&lt;/p&gt;&#xA;&lt;p&gt;&lt;strong&gt;Step 1: Embedding lookup as one-hot row selection.&lt;/strong&gt; Unfold the static embedding table &lt;code&gt;$E_{\mathrm{tok}} \in \mathbb{R}^{5 \times 3}$&lt;/code&gt;. Indexing rows &lt;code&gt;$(1, 2, 3)$&lt;/code&gt; is algebraically identical to left-multiplying by a &lt;code&gt;$3 \times 5$&lt;/code&gt; one-hot selector matrix &lt;code&gt;$U$&lt;/code&gt; (omitting positional offsets here and taking the normalized hidden state directly as &lt;code&gt;$H$&lt;/code&gt;, whose three rows already share identical RMS):&lt;/p&gt;&#xA;&lt;p&gt;&lt;code&gt;$$H = U E_{\mathrm{tok}} = \begin{bmatrix} 0 &amp;amp; \mathbf{1} &amp;amp; 0 &amp;amp; 0 &amp;amp; 0 \\ 0 &amp;amp; 0 &amp;amp; \mathbf{1} &amp;amp; 0 &amp;amp; 0 \\ 0 &amp;amp; 0 &amp;amp; 0 &amp;amp; \mathbf{1} &amp;amp; 0 \end{bmatrix} \begin{bmatrix} 0 &amp;amp; 0 &amp;amp; 0 \\ 1 &amp;amp; 0 &amp;amp; 1 \\ 0 &amp;amp; 1 &amp;amp; 1 \\ 1 &amp;amp; 1 &amp;amp; 0 \\ 1 &amp;amp; 0 &amp;amp; -1 \end{bmatrix} = \begin{bmatrix} 1 &amp;amp; 0 &amp;amp; 1 \\ 0 &amp;amp; 1 &amp;amp; 1 \\ 1 &amp;amp; 1 &amp;amp; 0 \end{bmatrix} \begin{matrix} \leftarrow \text{token 1 (&amp;#34;cat&amp;#34;)} \\ \leftarrow \text{token 2 (&amp;#34;chases&amp;#34;)} \\ \leftarrow \text{token 3 (&amp;#34;dog&amp;#34;)} \end{matrix}$$&lt;/code&gt;&lt;/p&gt;&#xA;&lt;p&gt;Nothing mysterious happens here: embedding lookup simply copies rows 1, 2, and 3 out of the vocabulary table into a &lt;code&gt;$3 \times 3$&lt;/code&gt; activation matrix, leaving unused vocabulary rows (0 and 4) untouched.&lt;/p&gt;&#xA;&lt;p&gt;&lt;strong&gt;Step 2: Linear projections into &lt;code&gt;$Q, K, V_{\mathrm{val}}$&lt;/code&gt;.&lt;/strong&gt; Multiply &lt;code&gt;$H\;(3 \times 3)$&lt;/code&gt; on the right by the static transposed projection matrices &lt;code&gt;$W_q^\top, W_k^\top, W_v^\top \in \mathbb{R}^{3 \times 2}$&lt;/code&gt;:&lt;/p&gt;&#xA;&lt;p&gt;&lt;code&gt;$$Q = H W_q^\top = \begin{bmatrix} 1 &amp;amp; 0 &amp;amp; 1 \\ 0 &amp;amp; 1 &amp;amp; 1 \\ 1 &amp;amp; 1 &amp;amp; 0 \end{bmatrix} \begin{bmatrix} 1 &amp;amp; 0 \\ 0 &amp;amp; 1 \\ 1 &amp;amp; -1 \end{bmatrix} = \begin{bmatrix} 2 &amp;amp; -1 \\ 1 &amp;amp; 0 \\ 1 &amp;amp; 1 \end{bmatrix}, \quad K = H W_k^\top = \begin{bmatrix} 1 &amp;amp; 0 &amp;amp; 1 \\ 0 &amp;amp; 1 &amp;amp; 1 \\ 1 &amp;amp; 1 &amp;amp; 0 \end{bmatrix} \begin{bmatrix} 1 &amp;amp; 1 \\ 0 &amp;amp; 1 \\ 1 &amp;amp; 0 \end{bmatrix} = \begin{bmatrix} 2 &amp;amp; 1 \\ 1 &amp;amp; 1 \\ 1 &amp;amp; 2 \end{bmatrix}, \quad V_{\mathrm{val}} = H W_v^\top = \begin{bmatrix} 1 &amp;amp; 0 &amp;amp; 1 \\ 0 &amp;amp; 1 &amp;amp; 1 \\ 1 &amp;amp; 1 &amp;amp; 0 \end{bmatrix} \begin{bmatrix} 2 &amp;amp; 0 \\ 0 &amp;amp; 2 \\ 1 &amp;amp; 1 \end{bmatrix} = \begin{bmatrix} 3 &amp;amp; 1 \\ 1 &amp;amp; 3 \\ 2 &amp;amp; 2 \end{bmatrix}$$&lt;/code&gt;&lt;/p&gt;&#xA;&lt;p&gt;For instance, top-left entry &lt;code&gt;$Q_{1,1} = 2$&lt;/code&gt; is the dot product of row 1 of &lt;code&gt;$H$&lt;/code&gt; (&lt;code&gt;$[1, 0, 1]$&lt;/code&gt;) with column 1 of &lt;code&gt;$W_q^\top$&lt;/code&gt; (&lt;code&gt;$[1, 0, 1]^\top$&lt;/code&gt;): &lt;code&gt;$1\times 1 + 0\times 0 + 1\times 1 = 2$&lt;/code&gt;. Notice that &lt;strong&gt;linear projections remix feature columns strictly within each token&#39;s own row—the 3 tokens have not exchanged information yet&lt;/strong&gt;. Meanwhile, &lt;code&gt;$K$&lt;/code&gt; and &lt;code&gt;$V_{\mathrm{val}}$&lt;/code&gt; are saved into VRAM as the initial 3-row &lt;code&gt;KV Cache&lt;/code&gt;.&lt;/p&gt;&#xA;&lt;p&gt;&lt;strong&gt;Step 3: Four-stage causal self-attention (dot products &lt;code&gt;$\to$&lt;/code&gt; mask &lt;code&gt;$\to$&lt;/code&gt; Softmax &lt;code&gt;$\to$&lt;/code&gt; weighted sum of &lt;code&gt;$V$&lt;/code&gt;).&lt;/strong&gt; Now tokens interact across positions. First multiply &lt;code&gt;$Q\;(3\times 2)$&lt;/code&gt; by &lt;code&gt;$K^\top\;(2\times 3)$&lt;/code&gt; to get all pairwise dot products:&lt;/p&gt;&#xA;&lt;p&gt;&lt;code&gt;$$Q K^\top = \begin{bmatrix} 2 &amp;amp; -1 \\ 1 &amp;amp; 0 \\ 1 &amp;amp; 1 \end{bmatrix} \begin{bmatrix} 2 &amp;amp; 1 &amp;amp; 1 \\ 1 &amp;amp; 1 &amp;amp; 2 \end{bmatrix} = \begin{bmatrix} 3 &amp;amp; 1 &amp;amp; 0 \\ 2 &amp;amp; 1 &amp;amp; 1 \\ 3 &amp;amp; 2 &amp;amp; 3 \end{bmatrix}$$&lt;/code&gt;&lt;/p&gt;&#xA;&lt;p&gt;Divide by &lt;code&gt;$\sqrt{d_k} = \sqrt{2} \approx 1.414$&lt;/code&gt;, add the causal mask &lt;code&gt;$M_{\mathrm{causal}}$&lt;/code&gt; (replacing every above-diagonal entry &lt;code&gt;$i &amp;lt; j$&lt;/code&gt; with &lt;code&gt;$-\infty$&lt;/code&gt;), and apply row-wise Softmax &lt;code&gt;$P_{i,j} = e^{S_{i,j}} / \sum_c e^{S_{i,c}}$&lt;/code&gt; (since &lt;code&gt;$e^{-\infty} = 0$&lt;/code&gt;, future weights vanish identically):&lt;/p&gt;&#xA;&lt;p&gt;&lt;code&gt;$$S = \frac{Q K^\top}{\sqrt{2}} + M_{\mathrm{causal}} \approx \begin{bmatrix} 2.12 &amp;amp; -\infty &amp;amp; -\infty \\ 1.41 &amp;amp; 0.71 &amp;amp; -\infty \\ 2.12 &amp;amp; 1.41 &amp;amp; 2.12 \end{bmatrix} \;\xrightarrow{\text{row Softmax}}\; P \approx \begin{bmatrix} 1.00 &amp;amp; 0 &amp;amp; 0 \\ 0.67 &amp;amp; 0.33 &amp;amp; 0 \\ 0.40 &amp;amp; 0.20 &amp;amp; 0.40 \end{bmatrix}$$&lt;/code&gt;&lt;/p&gt;&#xA;&lt;p&gt;Multiplying the lower-triangular probability table &lt;code&gt;$P\;(3\times 3)$&lt;/code&gt; into &lt;code&gt;$V_{\mathrm{val}}\;(3\times 2)$&lt;/code&gt; yields:&lt;/p&gt;&#xA;&lt;p&gt;&lt;code&gt;$$O = P V_{\mathrm{val}} \approx \begin{bmatrix} 1.00 &amp;amp; 0 &amp;amp; 0 \\ 0.67 &amp;amp; 0.33 &amp;amp; 0 \\ 0.40 &amp;amp; 0.20 &amp;amp; 0.40 \end{bmatrix} \begin{bmatrix} 3 &amp;amp; 1 \\ 1 &amp;amp; 3 \\ 2 &amp;amp; 2 \end{bmatrix} = \begin{bmatrix} 3.00 &amp;amp; 1.00 \\ 2.34 &amp;amp; 1.66 \\ 2.20 &amp;amp; 1.80 \end{bmatrix}$$&lt;/code&gt;&lt;/p&gt;&#xA;&lt;p&gt;Reading &lt;code&gt;$P V_{\mathrm{val}}$&lt;/code&gt; one row at a time strips away all abstraction:&lt;/p&gt;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;&lt;strong&gt;Row 1 (&lt;code&gt;&amp;quot;cat&amp;quot;&lt;/code&gt;)&lt;/strong&gt;: &lt;code&gt;$1.00 \times [3, 1] + 0 + 0 = [3.00, 1.00]$&lt;/code&gt;, seeing only itself;&lt;/li&gt;&#xA;&lt;li&gt;&lt;strong&gt;Row 2 (&lt;code&gt;&amp;quot;chases&amp;quot;&lt;/code&gt;)&lt;/strong&gt;: &lt;code&gt;$0.67 \times [3, 1] + 0.33 \times [1, 3] + 0 = [2.34, 1.66]$&lt;/code&gt;, pulling &lt;code&gt;$67\%$&lt;/code&gt; of &lt;code&gt;&amp;quot;cat&amp;quot;&lt;/code&gt;&#39;s value vector into &lt;code&gt;&amp;quot;chases&amp;quot;&lt;/code&gt; while remaining blind to future token &lt;code&gt;&amp;quot;dog&amp;quot;&lt;/code&gt;;&lt;/li&gt;&#xA;&lt;li&gt;&lt;strong&gt;Row 3 (&lt;code&gt;&amp;quot;dog&amp;quot;&lt;/code&gt;)&lt;/strong&gt;: &lt;code&gt;$0.40 \times [3, 1] + 0.20 \times [1, 3] + 0.40 \times [2, 2] = [2.20, 1.80]$&lt;/code&gt;, pooling context across all 3 prefix tokens. At the end of &lt;code&gt;Prefill&lt;/code&gt;, only this final row is projected through the FFN and LM head &lt;code&gt;$W_{\mathrm{head}}^\top$&lt;/code&gt;—suppose sampling picks token &lt;code&gt;4:runs&lt;/code&gt;.&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&lt;p&gt;&lt;strong&gt;Step 4: Advancing to &lt;code&gt;Decode&lt;/code&gt; step &lt;code&gt;$t = 4$&lt;/code&gt; (why a single row suffices).&lt;/strong&gt; To predict token 5 given newly sampled &lt;code&gt;4:runs&lt;/code&gt;, causal masking guarantees that rows 1..3 of &lt;code&gt;$K$&lt;/code&gt; and &lt;code&gt;$V_{\mathrm{val}}$&lt;/code&gt; would never change even if we reran the whole 4-word sequence. So step 4 &lt;strong&gt;does not build a &lt;code&gt;$4 \times 3$&lt;/code&gt; input matrix&lt;/strong&gt;: it looks up only the single row &lt;code&gt;$h_4 = [1, 0, -1] \in \mathbb{R}^{1 \times 3}$&lt;/code&gt; and runs three vector-matrix products:&lt;/p&gt;&#xA;&lt;p&gt;&lt;code&gt;$$q_4 = h_4 W_q^\top = \begin{bmatrix} 0 &amp;amp; 1 \end{bmatrix}, \qquad k_4 = h_4 W_k^\top = \begin{bmatrix} 0 &amp;amp; 1 \end{bmatrix}, \qquad v_4 = h_4 W_v^\top = \begin{bmatrix} 1 &amp;amp; -1 \end{bmatrix}$$&lt;/code&gt;&lt;/p&gt;&#xA;&lt;p&gt;Appending &lt;code&gt;$k_4, v_4$&lt;/code&gt; as row 4 of the cached &lt;code&gt;$3 \times 2$&lt;/code&gt; tables forms &lt;code&gt;$K_{1:4}, V_{1:4} \in \mathbb{R}^{4 \times 2}$&lt;/code&gt;, after which attention reduces to a single &lt;code&gt;$1 \times 4$&lt;/code&gt; dot-product strip:&lt;/p&gt;&#xA;&lt;p&gt;&lt;code&gt;$$q_4 K_{1:4}^\top = \begin{bmatrix} 0 &amp;amp; 1 \end{bmatrix} \begin{bmatrix} 2 &amp;amp; 1 &amp;amp; 1 &amp;amp; \mathbf{0} \\ 1 &amp;amp; 1 &amp;amp; 2 &amp;amp; \mathbf{1} \end{bmatrix} = \begin{bmatrix} 1 &amp;amp; 1 &amp;amp; 2 &amp;amp; 1 \end{bmatrix} \;\xrightarrow{\mathrm{softmax}(\cdot / \sqrt{2})}\; p_4 \approx \begin{bmatrix} 0.20 &amp;amp; 0.20 &amp;amp; 0.40 &amp;amp; 0.20 \end{bmatrix}$$&lt;/code&gt;&lt;/p&gt;&#xA;&lt;p&gt;Taking that 4-weight average of &lt;code&gt;$V_{1:4}$&lt;/code&gt; gives &lt;code&gt;$o_4 = p_4 V_{1:4} = 0.20[3,1] + 0.20[1,3] + 0.40[2,2] + 0.20[1,-1] = [1.80, 1.40] \in \mathbb{R}^{1 \times 2}$&lt;/code&gt;—without ever materializing the upper 3 rows of a &lt;code&gt;$4 \times 4$&lt;/code&gt; attention matrix.&lt;/p&gt;&#xA;&lt;figure class=&#34;diagram&#34; style=&#34;--h:494px;--hn:602px&#34;&gt;&lt;figcaption&gt;Unfolded Numeric Walkthrough: Cell-by-Cell Matrix Transformations in 3-Token Prefill and Step-4 Decode&lt;/figcaption&gt;&lt;p&gt;&lt;a href=&#34;https://mizore.blog/en/posts/from-transformer-matrices-to-muon/&#34;&gt;(See the figure in the post.)&lt;/a&gt;&lt;/p&gt;&lt;p class=&#34;figure-note&#34;&gt;Replacing abstract symbols with hand-verifiable numbers (&lt;code&gt;$d_k=2$&lt;/code&gt;, scale &lt;code&gt;$\sqrt{2}\approx 1.41$&lt;/code&gt;). Stage 1 shows how causal masking turns each output row into a convex combination of visible value vectors; Stage 2 shows step-4 decoding computing &lt;code&gt;$o_4$&lt;/code&gt; from a single query row &lt;code&gt;$q_4$&lt;/code&gt; and a 1-row append to the violet KV Cache.&lt;/p&gt;&lt;/figure&gt;&#xA;&lt;p&gt;The two empirical figures below quantify both memory footprint and compute scaling. In the 6-layer &lt;code&gt;float32&lt;/code&gt; model of the first chart (&lt;code&gt;$V=2000, D=256, L=6$&lt;/code&gt;, 4 bytes per parameter), static weights total &lt;code&gt;$5.82 \times 10^6$&lt;/code&gt; parameters (&lt;code&gt;$1.04 \times 10^6$&lt;/code&gt; in embeddings/head and &lt;code&gt;$4.72 \times 10^6$&lt;/code&gt; in internal 2D matrices), occupying &lt;code&gt;$22.2\;\text{MB}$&lt;/code&gt;; during training at &lt;code&gt;$B=16, T=64$&lt;/code&gt;, cached forward activations across the 6 layers take &lt;code&gt;$103.8\;\text{MB}$&lt;/code&gt;; and under &lt;code&gt;Muon+AdamW&lt;/code&gt;, dropping the second-moment buffer &lt;code&gt;$V$&lt;/code&gt; from all internal 2D matrices leaves only &lt;code&gt;$4.2\;\text{MB}$&lt;/code&gt; of &lt;code&gt;$V$&lt;/code&gt; states on the boundary layers. The second chart tracks cumulative MACs across a 4-layer model decoding 112 tokens from &lt;code&gt;$T_0=8$&lt;/code&gt; to &lt;code&gt;$t=120$&lt;/code&gt;.&lt;/p&gt;&#xA;&lt;figure class=&#34;echart&#34; style=&#34;--h:360px&#34;&gt;&lt;figcaption&gt;VRAM Breakdown of a 6-Layer Transformer Across Inference and Three Training Optimizers&lt;/figcaption&gt;&lt;p&gt;&lt;a href=&#34;https://mizore.blog/en/posts/from-transformer-matrices-to-muon/&#34;&gt;(See the figure in the post.)&lt;/a&gt;&lt;/p&gt;&lt;p class=&#34;figure-note&#34;&gt;Measured tensor byte counts on a 6-layer Transformer (&lt;code&gt;$V=2000, D=256$&lt;/code&gt;, 8 heads, fp32, batch &lt;code&gt;$B=16$&lt;/code&gt;, length &lt;code&gt;$T=64$&lt;/code&gt;). Training retains forward activations and allocates gradients &lt;code&gt;$G$&lt;/code&gt; plus state buffers; Muon+AdamW eliminates second-moment &lt;code&gt;$V$&lt;/code&gt; on all internal 2D layers (keeping only 4.2 MB on boundary params).&lt;/p&gt;&lt;/figure&gt;&#xA;&lt;figure class=&#34;plotfig&#34;&gt;&lt;figcaption&gt;Autoregressive Decoding from Prefix 8 to Length 120: KV Cache Cuts Cumulative MACs to Near-Linear&lt;/figcaption&gt;&lt;p&gt;&lt;a href=&#34;https://mizore.blog/en/posts/from-transformer-matrices-to-muon/&#34;&gt;(See the figure in the post.)&lt;/a&gt;&lt;/p&gt;&lt;p class=&#34;plot-xlabel&#34;&gt;Sequence length &lt;code&gt;$t$&lt;/code&gt; (Prefill finishes at &lt;code&gt;$t=8$&lt;/code&gt;, followed by 112 Decode steps for &lt;code&gt;$t=9 \dots 120$&lt;/code&gt;)&lt;/p&gt;&lt;p class=&#34;figure-note&#34;&gt;4-layer Transformer (&lt;code&gt;$D=128, V=512$&lt;/code&gt;) after an 8-token Prefill (&lt;code&gt;$T_0=8$&lt;/code&gt;), followed by 112 autoregressive Decode steps (&lt;code&gt;$t=9 \dots 120$&lt;/code&gt;). Cumulative MACs drop from 6,758.5M to 109.7M (-98.4%).&lt;/p&gt;&lt;/figure&gt;&#xA;&lt;p&gt;With &amp;quot;optimizers only mutate Family 1 static parameters &lt;code&gt;$\Theta$&lt;/code&gt;&amp;quot; established, the next question is how a single scalar loss &lt;code&gt;$L$&lt;/code&gt; differentiates backward into a full two-dimensional gradient matrix &lt;code&gt;$G$&lt;/code&gt; for every weight layer.&lt;/p&gt;&#xA;&lt;hr&gt;&#xA;&lt;h2 id=&#34;2-normalization-scale-invariance-and-matrix-backpropagation&#34;&gt;2. Normalization Scale Invariance and Matrix Backpropagation&lt;/h2&gt;&#xA;&lt;p&gt;Walking through the calculus inside a single training step explains why forward activations dominate training VRAM and establishes two foundational properties used throughout the rest of the post: &lt;strong&gt;how &lt;code&gt;RMSNorm&lt;/code&gt; fixes the input RMS scale of hidden layers&lt;/strong&gt;, and &lt;strong&gt;why linear-layer gradients &lt;code&gt;$G$&lt;/code&gt; form a sum of rank-one outer products&lt;/strong&gt;.&lt;/p&gt;&#xA;&lt;h3 id=&#34;21-origin-of-rmsnorm-and-proof-of-radial-gradient-orthogonality&#34;&gt;2.1 Origin of &lt;code&gt;RMSNorm&lt;/code&gt; and Proof of Radial Gradient Orthogonality&lt;/h3&gt;&#xA;&lt;p&gt;Original Transformers used &lt;code&gt;LayerNorm&lt;/code&gt;: given a token vector &lt;code&gt;$x \in \mathbb{R}^D$&lt;/code&gt;, compute its mean &lt;code&gt;$\mu = \frac{1}{D}\sum_{i=1}^D x_i$&lt;/code&gt;, then its variance &lt;code&gt;$\sigma^2 = \frac{1}{D}\sum_{i=1}^D (x_i - \mu)^2$&lt;/code&gt;, and output &lt;code&gt;$\frac{x - \mu}{\sqrt{\sigma^2 + \epsilon}} \odot \gamma + \beta$&lt;/code&gt;. On GPUs, because variance depends on the mean, every token vector requires two cross-channel reductions whose memory latency outweighs arithmetic cost.&lt;/p&gt;&#xA;&lt;p&gt;In 2019, Zhang and Sennrich hypothesized that &lt;code&gt;LayerNorm&lt;/code&gt; stabilizes deep networks not through mean-centering (shift invariance), but through rescaling vector magnitude (scale invariance)&lt;sup class=&#34;cite&#34;&gt;&lt;a id=&#34;cite-zhang2019-2&#34; href=&#34;#ref-zhang2019&#34;&gt;[6]&lt;/a&gt;&lt;/sup&gt;. Dropping mean subtraction and bias &lt;code&gt;$\beta$&lt;/code&gt; yields Root Mean Square Layer Normalization (&lt;code&gt;RMSNorm&lt;/code&gt;):&lt;/p&gt;&#xA;&lt;p&gt;&lt;code&gt;$$r(x) = \sqrt{\frac{1}{D} \sum_{i=1}^{D} x_i^2 + \epsilon}, \qquad y = \mathrm{RMSNorm}(x) = \frac{x}{r(x)} \odot \gamma = \hat{x} \odot \gamma$$&lt;/code&gt;&lt;/p&gt;&#xA;&lt;p&gt;where &lt;code&gt;$\gamma \in \mathbb{R}^D$&lt;/code&gt; is initialized to all ones. Two algebraic consequences follow directly:&lt;/p&gt;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;&lt;strong&gt;Unit-RMS forward outputs&lt;/strong&gt;: as &lt;code&gt;$\epsilon \to 0$&lt;/code&gt; with &lt;code&gt;$\gamma = \mathbf{1}$&lt;/code&gt;, &lt;code&gt;$\hat{x} = x / r(x)$&lt;/code&gt; satisfies &lt;code&gt;$\frac{1}{D}\|\hat{x}\|_2^2 = \frac{\frac{1}{D}\|x\|_2^2}{\frac{1}{D}\|x\|_2^2} = 1$&lt;/code&gt;. Consequently, every linear projection &lt;code&gt;$W$&lt;/code&gt; immediately following &lt;code&gt;RMSNorm&lt;/code&gt; receives input vectors normalized to unit root-mean-square magnitude—a fact that directly dictates the natural operator norm for measuring weight updates &lt;code&gt;$\Delta W$&lt;/code&gt; in Section 4.&lt;/li&gt;&#xA;&lt;li&gt;&lt;strong&gt;Inverse-scale backward gradients and radial orthogonality&lt;/strong&gt;: at &lt;code&gt;$\epsilon = 0$&lt;/code&gt;, for any scalar &lt;code&gt;$\alpha &amp;gt; 0$&lt;/code&gt;, &lt;code&gt;$\mathrm{RMSNorm}(\alpha x) = \frac{\alpha x}{\alpha r(x)} \odot \gamma = \mathrm{RMSNorm}(x)$&lt;/code&gt;. Let the downstream loss be &lt;code&gt;$L(y)$&lt;/code&gt; with upstream gradient &lt;code&gt;$\delta_y = \partial L / \partial y \in \mathbb{R}^D$&lt;/code&gt;, and set &lt;code&gt;$\tilde{\delta} = \delta_y \odot \gamma$&lt;/code&gt;. Differentiating with respect to coordinate &lt;code&gt;$x_j$&lt;/code&gt; (using &lt;code&gt;$\partial r / \partial x_j = \frac{x_j}{D r}$&lt;/code&gt;) gives:&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&lt;p&gt;&lt;code&gt;$$\frac{\partial L}{\partial x_j} = \sum_{i=1}^{D} \tilde{\delta}_i \frac{\partial}{\partial x_j}\left(\frac{x_i}{r}\right) = \frac{\tilde{\delta}_j}{r} - \sum_{i=1}^{D} \tilde{\delta}_i \frac{x_i x_j}{D r^3} = \frac{1}{r}\left(\tilde{\delta}_j - \hat{x}_j \cdot \frac{1}{D}\langle \tilde{\delta}, \hat{x} \rangle\right)$$&lt;/code&gt;&lt;/p&gt;&#xA;&lt;p&gt;In vector form:&lt;/p&gt;&#xA;&lt;p&gt;&lt;code&gt;$$\nabla_x L = \frac{1}{r(x)}\left(I_D - \frac{\hat{x} \hat{x}^\top}{D}\right) \tilde{\delta}, \qquad \nabla_\gamma L = \delta_y \odot \hat{x}$$&lt;/code&gt;&lt;/p&gt;&#xA;&lt;p&gt;Since &lt;code&gt;$\frac{1}{D}\hat{x}^\top \hat{x} = 1$&lt;/code&gt;, left-multiplying &lt;code&gt;$\nabla_x L$&lt;/code&gt; by &lt;code&gt;$x^\top = r(x)\hat{x}^\top$&lt;/code&gt; yields:&lt;/p&gt;&#xA;&lt;p&gt;&lt;code&gt;$$x^\top \nabla_x L = \hat{x}^\top \tilde{\delta} - \frac{\hat{x}^\top \hat{x}}{D} \hat{x}^\top \tilde{\delta} = 0$$&lt;/code&gt;&lt;/p&gt;&#xA;&lt;p&gt;Thus the gradient propagated back to &lt;code&gt;$x$&lt;/code&gt; is strictly orthogonal to &lt;code&gt;$x$&lt;/code&gt; itself (zero directional derivative along radial rescaling of &lt;code&gt;$x$&lt;/code&gt;) and scales inversely with &lt;code&gt;$r(x)$&lt;/code&gt;: inflating activations by &lt;code&gt;$\alpha$&lt;/code&gt; shrinks backward gradients by &lt;code&gt;$1/\alpha$&lt;/code&gt;, preventing norm explosion in deep residual stacks&lt;sup class=&#34;cite&#34;&gt;&lt;a id=&#34;cite-zhang2019-3&#34; href=&#34;#ref-zhang2019&#34;&gt;[6]&lt;/a&gt;&lt;/sup&gt;.&lt;/p&gt;&#xA;&lt;h3 id=&#34;22-derivative-of-cross-entropy-loss-with-respect-to-logits&#34;&gt;2.2 Derivative of Cross-Entropy Loss with Respect to Logits&lt;/h3&gt;&#xA;&lt;p&gt;Now trace a training batch of &lt;code&gt;$B=20$&lt;/code&gt; sequences of length &lt;code&gt;$T=16$&lt;/code&gt;, giving &lt;code&gt;$N = B \times T = 320$&lt;/code&gt; next-token prediction positions. Flatten the final logits into &lt;code&gt;$Z \in \mathbb{R}^{N \times V}$&lt;/code&gt;, and let &lt;code&gt;$y_n \in \{0, \dots, V-1\}$&lt;/code&gt; denote the ground-truth next token at position &lt;code&gt;$n$&lt;/code&gt;.&lt;/p&gt;&#xA;&lt;p&gt;Cross-entropy loss averages the negative log-likelihood of the true token across all &lt;code&gt;$N$&lt;/code&gt; positions:&lt;/p&gt;&#xA;&lt;p&gt;&lt;code&gt;$$L = -\frac{1}{N} \sum_{n=1}^{N} \ln P_{n, y_n} = -\frac{1}{N} \sum_{n=1}^{N} \left(Z_{n, y_n} - \ln \sum_{m=0}^{V-1} e^{Z_{n, m}}\right)$$&lt;/code&gt;&lt;/p&gt;&#xA;&lt;p&gt;where &lt;code&gt;$P_{n, k} = e^{Z_{n,k}} / \sum_{m=0}^{V-1} e^{Z_{n,m}}$&lt;/code&gt;. At random initialization, all logits are nearly equal so &lt;code&gt;$P_{n, k} \approx 1/V$&lt;/code&gt;, placing the theoretical initial loss right at &lt;code&gt;$\ln V$&lt;/code&gt; (&lt;code&gt;$\ln 1000 \approx 6.91$&lt;/code&gt; for &lt;code&gt;$V=1000$&lt;/code&gt;, or &lt;code&gt;$\ln 128 \approx 4.85$&lt;/code&gt; for &lt;code&gt;$V=128$&lt;/code&gt;).&lt;/p&gt;&#xA;&lt;p&gt;Differentiating with respect to logit &lt;code&gt;$Z_{n, j}$&lt;/code&gt;—noting that row &lt;code&gt;$n$&lt;/code&gt;&#39;s probabilities depend only on row &lt;code&gt;$n$&lt;/code&gt;&#39;s logits—eliminates all terms &lt;code&gt;$n&amp;#39; \neq n$&lt;/code&gt;:&lt;/p&gt;&#xA;&lt;p&gt;&lt;code&gt;$$\frac{\partial L}{\partial Z_{n, j}} = -\frac{1}{N}\left(\frac{\partial Z_{n, y_n}}{\partial Z_{n, j}} - \frac{1}{\sum_{m=0}^{V-1} e^{Z_{n, m}}} \cdot \frac{\partial}{\partial Z_{n, j}} \sum_{m=0}^{V-1} e^{Z_{n, m}}\right) = -\frac{1}{N}\left(\mathbf{1}_{j = y_n} - \frac{e^{Z_{n, j}}}{\sum_{m=0}^{V-1} e^{Z_{n, m}}}\right)$$&lt;/code&gt;&lt;/p&gt;&#xA;&lt;p&gt;Collecting entries yields the root backward error matrix &lt;code&gt;$\Delta^{(Z)} = \partial L / \partial Z \in \mathbb{R}^{N \times V}$&lt;/code&gt;:&lt;/p&gt;&#xA;&lt;p&gt;&lt;code&gt;$$\Delta_{n, j}^{(Z)} = \frac{\partial L}{\partial Z_{n, j}} = \frac{1}{N}\left(P_{n, j} - \mathbf{1}_{j = y_n}\right)$$&lt;/code&gt;&lt;/p&gt;&#xA;&lt;p&gt;Its sign structure is transparent: on the ground-truth column &lt;code&gt;$j = y_n$&lt;/code&gt;, since &lt;code&gt;$P_{n, y_n} \le 1$&lt;/code&gt;, the derivative &lt;code&gt;$(P_{n, y_n} - 1)/N$&lt;/code&gt; is negative, instructing gradient descent to push that logit up; on every incorrect column &lt;code&gt;$j \neq y_n$&lt;/code&gt;, the derivative &lt;code&gt;$+P_{n, j}/N$&lt;/code&gt; is positive and proportional to the probability mass mistakenly assigned to token &lt;code&gt;$j$&lt;/code&gt;; and every row sums identically to &lt;code&gt;$\frac{1}{N}(1 - 1) = 0$&lt;/code&gt;.&lt;/p&gt;&#xA;&lt;h3 id=&#34;23-linear-layer-matrix-calculus-and-the-root-cause-of-spectral-skew&#34;&gt;2.3 Linear-Layer Matrix Calculus and the Root Cause of Spectral Skew&lt;/h3&gt;&#xA;&lt;p&gt;With the top-level error matrix in hand, consider any internal bias-free linear layer &lt;code&gt;$Y = X W^\top$&lt;/code&gt;, where flattened inputs are &lt;code&gt;$X \in \mathbb{R}^{N \times d_{\mathrm{in}}}$&lt;/code&gt;, weights are &lt;code&gt;$W \in \mathbb{R}^{d_{\mathrm{out}} \times d_{\mathrm{in}}}$&lt;/code&gt;, outputs are &lt;code&gt;$Y \in \mathbb{R}^{N \times d_{\mathrm{out}}}$&lt;/code&gt;, and the upstream gradient &lt;code&gt;$\Delta = \partial L / \partial Y \in \mathbb{R}^{N \times d_{\mathrm{out}}}$&lt;/code&gt; (&lt;code&gt;$\Delta_{n, i} = \partial L / \partial Y_{n, i}$&lt;/code&gt;) has arrived from above.&lt;/p&gt;&#xA;&lt;p&gt;Expanding &lt;code&gt;$Y$&lt;/code&gt; coordinate by coordinate:&lt;/p&gt;&#xA;&lt;p&gt;&lt;code&gt;$$Y_{n, i} = \sum_{k=1}^{d_{\mathrm{in}}} X_{n, k} W_{i, k}$$&lt;/code&gt;&lt;/p&gt;&#xA;&lt;p&gt;Ask where a single scalar weight &lt;code&gt;$W_{i, j}$&lt;/code&gt; participates: across every token &lt;code&gt;$n = 1, \dots, N$&lt;/code&gt;, &lt;code&gt;$W_{i, j}$&lt;/code&gt; appears exclusively in output channel &lt;code&gt;$i$&lt;/code&gt;&#39;s &lt;code&gt;$k = j$&lt;/code&gt; term with local derivative &lt;code&gt;$\partial Y_{n, i} / \partial W_{i, j} = X_{n, j}$&lt;/code&gt; (and &lt;code&gt;$\partial Y_{n, p} / \partial W_{i, j} = 0$&lt;/code&gt; whenever &lt;code&gt;$p \neq i$&lt;/code&gt;). Summing over all paths via the multivariable chain rule gives:&lt;/p&gt;&#xA;&lt;p&gt;&lt;code&gt;$$G_{i, j} \triangleq \frac{\partial L}{\partial W_{i, j}} = \sum_{n=1}^{N} \sum_{p=1}^{d_{\mathrm{out}}} \frac{\partial L}{\partial Y_{n, p}} \frac{\partial Y_{n, p}}{\partial W_{i, j}} = \sum_{n=1}^{N} \Delta_{n, i} X_{n, j} = \sum_{n=1}^{N} (\Delta^\top)_{i, n} X_{n, j}$$&lt;/code&gt;&lt;/p&gt;&#xA;&lt;p&gt;By definition of matrix multiplication, the right-hand side is entry &lt;code&gt;$(i, j)$&lt;/code&gt; of &lt;code&gt;$\Delta^\top \in \mathbb{R}^{d_{\mathrm{out}} \times N}$&lt;/code&gt; times &lt;code&gt;$X \in \mathbb{R}^{N \times d_{\mathrm{in}}}$&lt;/code&gt;. By the same reasoning, input coordinate &lt;code&gt;$X_{n, j}$&lt;/code&gt; contributes to all &lt;code&gt;$d_{\mathrm{out}}$&lt;/code&gt; output channels of row &lt;code&gt;$n$&lt;/code&gt; with &lt;code&gt;$\partial Y_{n, i} / \partial X_{n, j} = W_{i, j}$&lt;/code&gt;, yielding &lt;code&gt;$\frac{\partial L}{\partial X_{n, j}} = \sum_{i=1}^{d_{\mathrm{out}}} \Delta_{n, i} W_{i, j} = (\Delta W)_{n, j}$&lt;/code&gt;. Together:&lt;/p&gt;&#xA;&lt;p&gt;&lt;code&gt;$$G = \frac{\partial L}{\partial W} = \Delta^\top X = \sum_{n=1}^{N} \delta_n x_n^\top \in \mathbb{R}^{d_{\mathrm{out}} \times d_{\mathrm{in}}}, \qquad \frac{\partial L}{\partial X} = \Delta W \in \mathbb{R}^{N \times d_{\mathrm{in}}}$$&lt;/code&gt;&lt;/p&gt;&#xA;&lt;p&gt;where &lt;code&gt;$\delta_n \in \mathbb{R}^{d_{\mathrm{out}}}$&lt;/code&gt; and &lt;code&gt;$x_n \in \mathbb{R}^{d_{\mathrm{in}}}$&lt;/code&gt; are the column vectors for token &lt;code&gt;$n$&lt;/code&gt;&#39;s upstream error and layer input.&lt;/p&gt;&#xA;&lt;figure class=&#34;diagram&#34; style=&#34;--h:684px;--hn:629px&#34;&gt;&lt;figcaption&gt;Full-Flow LLM Training Matrix Shapes: Tracking Cached Activations, Transpose Contraction &amp;amp; Dual Optimizers&lt;/figcaption&gt;&lt;p&gt;&lt;a href=&#34;https://mizore.blog/en/posts/from-transformer-matrices-to-muon/&#34;&gt;(See the figure in the post.)&lt;/a&gt;&lt;/p&gt;&lt;p class=&#34;figure-note&#34;&gt;Batch tokens &lt;code&gt;$N = B \times T = 5$&lt;/code&gt; (clay rows), input dim &lt;code&gt;$d_{\mathrm{in}}=4$&lt;/code&gt; (blue cols), output dim &lt;code&gt;$d_{\mathrm{out}}=3$&lt;/code&gt; (violet cols). Stage 2 right shows how the &lt;code&gt;$5$&lt;/code&gt; horizontal columns of &lt;code&gt;$\Delta_Y^\top$&lt;/code&gt; pair with and cancel the &lt;code&gt;$5$&lt;/code&gt; vertical rows of cached &lt;code&gt;$X$&lt;/code&gt;, leaving a &lt;code&gt;$12$&lt;/code&gt;-cell gradient &lt;code&gt;$G\;[3\times 4]$&lt;/code&gt; identical in shape to &lt;code&gt;$W$&lt;/code&gt;.&lt;/p&gt;&lt;/figure&gt;&#xA;&lt;p&gt;These two compact equations simultaneously explain four central facts of LLM engineering and optimization:&lt;/p&gt;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;&lt;strong&gt;Why &lt;code&gt;$G$&lt;/code&gt; always has the exact shape of &lt;code&gt;$W$&lt;/code&gt;&lt;/strong&gt;: the batch-and-token dimension &lt;code&gt;$N$&lt;/code&gt; is the shared inner axis contracted out in &lt;code&gt;$\Delta^\top X$&lt;/code&gt;, leaving &lt;code&gt;$(d_{\mathrm{out}}, d_{\mathrm{in}})$&lt;/code&gt; regardless of batch size &lt;code&gt;$B$&lt;/code&gt; or context length &lt;code&gt;$T$&lt;/code&gt;.&lt;/li&gt;&#xA;&lt;li&gt;&lt;strong&gt;Why training VRAM dwarfs inference VRAM&lt;/strong&gt;: evaluating &lt;code&gt;$\Delta^\top X$&lt;/code&gt; in the backward pass explicitly requires the forward activation &lt;code&gt;$X$&lt;/code&gt; saved from Stage 1. Attention behaves identically—differentiating &lt;code&gt;$O = P V_{\mathrm{val}}$&lt;/code&gt; and &lt;code&gt;$S = Q K^\top / \sqrt{d_k}$&lt;/code&gt; gives &lt;code&gt;$\Delta_V = P^\top \Delta_O$&lt;/code&gt;, &lt;code&gt;$\Delta_P = \Delta_O V_{\mathrm{val}}^\top$&lt;/code&gt;, &lt;code&gt;$\Delta_Q = \frac{1}{\sqrt{d_k}}\Delta_S K$&lt;/code&gt;, and &lt;code&gt;$\Delta_K = \frac{1}{\sqrt{d_k}}\Delta_S^\top Q$&lt;/code&gt;, requiring forward &lt;code&gt;$Q, K, V_{\mathrm{val}}, P$&lt;/code&gt; (FlashAttention avoids materializing the &lt;code&gt;$T \times T$&lt;/code&gt; matrix &lt;code&gt;$P$&lt;/code&gt; in HBM by recomputing tiles in SRAM, but &lt;code&gt;$Q, K, V_{\mathrm{val}}$&lt;/code&gt; and layer inputs still stay resident unless activation checkpointing trades extra forward compute for memory).&lt;/li&gt;&#xA;&lt;li&gt;&lt;strong&gt;Why &lt;code&gt;zero_grad()&lt;/code&gt; is required before backward&lt;/strong&gt;: when full batches exceed GPU memory, training splits each step into micro-batches and calls &lt;code&gt;loss.backward()&lt;/code&gt; repeatedly so PyTorch accumulates (&lt;code&gt;+=&lt;/code&gt;) each micro-batch&#39;s &lt;code&gt;$\Delta^\top X$&lt;/code&gt; into &lt;code&gt;W.grad&lt;/code&gt; before stepping once. Standard single-batch steps must therefore zero out stale gradients explicitly.&lt;/li&gt;&#xA;&lt;li&gt;&lt;strong&gt;Why neural network gradient matrices exhibit extreme singular-value skew&lt;/strong&gt;: look at the outer-product sum &lt;code&gt;$G = \sum_{n=1}^N \delta_n x_n^\top$&lt;/code&gt;. Natural language token frequencies follow a heavy-tailed Zipf distribution, so frequent function words and shared syntactic directions dominate every batch, concentrating the eigenvalues of &lt;code&gt;$\frac{1}{N}X^\top X$&lt;/code&gt; into a handful of top principal components. Consequently, &lt;code&gt;$G$&lt;/code&gt; is severely anisotropic: its top few singular values are orders of magnitude larger than the dozens or hundreds of tail singular directions carrying rare facts and fine-grained contextual circuits.&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&lt;h3 id=&#34;24-unfolding-backpropagation-hand-tracing-2-token-cross-entropy-and-outer-product-gradients&#34;&gt;2.4 Unfolding Backpropagation: Hand-Tracing 2-Token Cross-Entropy and Outer-Product Gradients&lt;/h3&gt;&#xA;&lt;p&gt;Let us likewise substitute concrete numbers into Sections 2.2 and 2.3 so we can watch a single scalar loss &lt;code&gt;$L$&lt;/code&gt; differentiate back into a 2D weight gradient matrix &lt;code&gt;$G$&lt;/code&gt;—and see firsthand why &lt;code&gt;$G$&lt;/code&gt; naturally exhibits severe singular-value skew.&lt;/p&gt;&#xA;&lt;p&gt;&lt;strong&gt;Step 1: From logits &lt;code&gt;$Z$&lt;/code&gt; to top-level gradient &lt;code&gt;$\Delta^{(Z)}$&lt;/code&gt;.&lt;/strong&gt; Consider &lt;code&gt;$N = 2$&lt;/code&gt; token positions over a 3-word vocabulary &lt;code&gt;$V = 3$&lt;/code&gt;, with ground-truth target IDs &lt;code&gt;$y_1 = 0$&lt;/code&gt; and &lt;code&gt;$y_2 = 1$&lt;/code&gt; (one-hot matrix &lt;code&gt;$Y_{\mathrm{true}} = \begin{bsmallmatrix} 1 &amp;amp; 0 &amp;amp; 0 \\ 0 &amp;amp; 1 &amp;amp; 0 \end{bsmallmatrix}$&lt;/code&gt;). Suppose forward logits &lt;code&gt;$Z \in \mathbb{R}^{2 \times 3}$&lt;/code&gt; are:&lt;/p&gt;&#xA;&lt;p&gt;&lt;code&gt;$$Z = \begin{bmatrix} 2.0 &amp;amp; 1.0 &amp;amp; 0.0 \\ 0.0 &amp;amp; 2.0 &amp;amp; 1.0 \end{bmatrix} \;\xrightarrow{\text{row Softmax}}\; P \approx \begin{bmatrix} 0.67 &amp;amp; 0.24 &amp;amp; 0.09 \\ 0.09 &amp;amp; 0.67 &amp;amp; 0.24 \end{bmatrix}$$&lt;/code&gt;&lt;/p&gt;&#xA;&lt;p&gt;Mean cross-entropy is the scalar &lt;code&gt;$L = -\frac{1}{2}(\ln 0.67 + \ln 0.67) \approx 0.40$&lt;/code&gt;. Plugging &lt;code&gt;$P$&lt;/code&gt; and &lt;code&gt;$Y_{\mathrm{true}}$&lt;/code&gt; into &lt;code&gt;$\Delta^{(Z)} = \frac{1}{N}(P - Y_{\mathrm{true}})$&lt;/code&gt; with &lt;code&gt;$N = 2$&lt;/code&gt; gives:&lt;/p&gt;&#xA;&lt;p&gt;&lt;code&gt;$$\Delta^{(Z)} = \frac{1}{2} \left( \begin{bmatrix} 0.67 &amp;amp; 0.24 &amp;amp; 0.09 \\ 0.09 &amp;amp; 0.67 &amp;amp; 0.24 \end{bmatrix} - \begin{bmatrix} 1 &amp;amp; 0 &amp;amp; 0 \\ 0 &amp;amp; 1 &amp;amp; 0 \end{bmatrix} \right) = \begin{bmatrix} \mathbf{-0.17} &amp;amp; +0.12 &amp;amp; +0.05 \\ +0.05 &amp;amp; \mathbf{-0.17} &amp;amp; +0.12 \end{bmatrix}$$&lt;/code&gt;&lt;/p&gt;&#xA;&lt;p&gt;Every sign has a direct physical meaning: ground-truth columns receive negative derivatives (&lt;code&gt;$-0.17$&lt;/code&gt;) so gradient descent &lt;code&gt;$Z - \eta \Delta^{(Z)}$&lt;/code&gt; pushes those target scores up, while wrong candidates receive positive derivatives (&lt;code&gt;$+0.12, +0.05$&lt;/code&gt;) proportional to the probability mass mistakenly assigned to them.&lt;/p&gt;&#xA;&lt;p&gt;&lt;strong&gt;Step 2: Forward caching and two-way backward split inside &lt;code&gt;$Y = X W^\top$&lt;/code&gt;.&lt;/strong&gt; Zoom into an internal linear layer mapping &lt;code&gt;$d_{\mathrm{in}} = 3 \to d_{\mathrm{out}} = 2$&lt;/code&gt;. Let the cached forward input for our &lt;code&gt;$N = 2$&lt;/code&gt; tokens be &lt;code&gt;$X \in \mathbb{R}^{2 \times 3}$&lt;/code&gt; and weights be &lt;code&gt;$W \in \mathbb{R}^{2 \times 3}$&lt;/code&gt;:&lt;/p&gt;&#xA;&lt;p&gt;&lt;code&gt;$$X = \begin{bmatrix} 1 &amp;amp; 2 &amp;amp; 0 \\ 1 &amp;amp; 2 &amp;amp; 1 \end{bmatrix}, \qquad W = \begin{bmatrix} 1.0 &amp;amp; 0.5 &amp;amp; -1.0 \\ -0.5 &amp;amp; 1.0 &amp;amp; 1.0 \end{bmatrix}, \qquad Y = X W^\top = \begin{bmatrix} 1 &amp;amp; 2 &amp;amp; 0 \\ 1 &amp;amp; 2 &amp;amp; 1 \end{bmatrix} \begin{bmatrix} 1.0 &amp;amp; -0.5 \\ 0.5 &amp;amp; 1.0 \\ -1.0 &amp;amp; 1.0 \end{bmatrix} = \begin{bmatrix} 2.0 &amp;amp; 1.5 \\ 1.0 &amp;amp; 2.5 \end{bmatrix}$$&lt;/code&gt;&lt;/p&gt;&#xA;&lt;p&gt;Suppose upstream backpropagation hands back &lt;code&gt;$\Delta_Y = \begin{bsmallmatrix} -0.6 &amp;amp; 0.2 \\ -0.4 &amp;amp; 0.2 \end{bsmallmatrix} \in \mathbb{R}^{2 \times 2}$&lt;/code&gt;. The backward pass splits into two matrix products:&lt;/p&gt;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;&lt;strong&gt;Left branch (propagating error to earlier layer input &lt;code&gt;$X$&lt;/code&gt;)&lt;/strong&gt;: multiply by &lt;code&gt;$W$&lt;/code&gt; (untransposed), contracting out &lt;code&gt;$d_{\mathrm{out}} = 2$&lt;/code&gt; to recover a &lt;code&gt;$2 \times 3$&lt;/code&gt; activation gradient matching &lt;code&gt;$X$&lt;/code&gt;:&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&lt;p&gt;&lt;code&gt;$$\Delta_X = \Delta_Y W = \begin{bmatrix} -0.6 &amp;amp; 0.2 \\ -0.4 &amp;amp; 0.2 \end{bmatrix} \begin{bmatrix} 1.0 &amp;amp; 0.5 &amp;amp; -1.0 \\ -0.5 &amp;amp; 1.0 &amp;amp; 1.0 \end{bmatrix} = \begin{bmatrix} -0.7 &amp;amp; -0.1 &amp;amp; 0.8 \\ -0.5 &amp;amp; 0.0 &amp;amp; 0.6 \end{bmatrix} \in \mathbb{R}^{2 \times 3}$$&lt;/code&gt;&lt;/p&gt;&#xA;&lt;ol start=&#34;2&#34;&gt;&#xA;&lt;li&gt;&lt;strong&gt;Right branch (joining with cached &lt;code&gt;$X$&lt;/code&gt; to form weight gradient &lt;code&gt;$G$&lt;/code&gt;)&lt;/strong&gt;: transpose &lt;code&gt;$\Delta_Y$&lt;/code&gt; and multiply into &lt;code&gt;$X\;(2 \times 3)$&lt;/code&gt;. Expanding across tokens &lt;code&gt;$n = 1, 2$&lt;/code&gt; exposes the sum of rank-one outer products &lt;code&gt;$\delta_1 x_1^\top + \delta_2 x_2^\top$&lt;/code&gt;:&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&lt;p&gt;&lt;code&gt;$$G = \Delta_Y^\top X = \begin{bmatrix} -0.6 &amp;amp; -0.4 \\ 0.2 &amp;amp; 0.2 \end{bmatrix} \begin{bmatrix} 1 &amp;amp; 2 &amp;amp; 0 \\ 1 &amp;amp; 2 &amp;amp; 1 \end{bmatrix} = \underbrace{\begin{bmatrix} -0.6 \\ 0.2 \end{bmatrix} \begin{bmatrix} 1 &amp;amp; 2 &amp;amp; 0 \end{bmatrix}}_{\text{token 1 outer }\delta_1 x_1^\top} + \underbrace{\begin{bmatrix} -0.4 \\ 0.2 \end{bmatrix} \begin{bmatrix} 1 &amp;amp; 2 &amp;amp; 1 \end{bmatrix}}_{\text{token 2 outer }\delta_2 x_2^\top} = \begin{bmatrix} -0.6 &amp;amp; -1.2 &amp;amp; 0.0 \\ 0.2 &amp;amp; 0.4 &amp;amp; 0.0 \end{bmatrix} + \begin{bmatrix} -0.4 &amp;amp; -0.8 &amp;amp; -0.4 \\ 0.2 &amp;amp; 0.4 &amp;amp; 0.2 \end{bmatrix} = \begin{bmatrix} -1.0 &amp;amp; -2.0 &amp;amp; -0.4 \\ 0.4 &amp;amp; 0.8 &amp;amp; 0.2 \end{bmatrix}$$&lt;/code&gt;&lt;/p&gt;&#xA;&lt;p&gt;Inspect the resulting &lt;code&gt;$2 \times 3$&lt;/code&gt; gradient &lt;code&gt;$G = \begin{bsmallmatrix} -1.0 &amp;amp; -2.0 &amp;amp; -0.4 \\ 0.4 &amp;amp; 0.8 &amp;amp; 0.2 \end{bsmallmatrix}$&lt;/code&gt;: because both tokens shared the frequent prefix features &lt;code&gt;$[1, 2]$&lt;/code&gt; in columns 1 and 2, row 1 is &lt;code&gt;$-2.5\times$&lt;/code&gt; row 2 across the first two columns; only column 3 (&lt;code&gt;$-0.4$&lt;/code&gt; vs. &lt;code&gt;$0.2$&lt;/code&gt;, contributed by token 2&#39;s unique 3rd coordinate &lt;code&gt;1&lt;/code&gt;) breaks exact collinearity. Taking the square roots of the eigenvalues of &lt;code&gt;$G G^\top = \begin{bsmallmatrix} 5.16 &amp;amp; -2.08 \\ -2.08 &amp;amp; 0.84 \end{bsmallmatrix}$&lt;/code&gt; gives the two singular values of &lt;code&gt;$G$&lt;/code&gt;:&lt;/p&gt;&#xA;&lt;p&gt;&lt;code&gt;$$\sigma_1(G) \approx 2.449, \qquad \sigma_2(G) \approx 0.037 \qquad (\sigma_1 / \sigma_2 \approx 67.1)$$&lt;/code&gt;&lt;/p&gt;&#xA;&lt;p&gt;Even across a 2-token toy batch, shared input directions open a &lt;strong&gt;&lt;code&gt;$67\times$&lt;/code&gt; singular-value gap&lt;/strong&gt;—setting the stage for Section 4.&lt;/p&gt;&#xA;&lt;figure class=&#34;diagram&#34; style=&#34;--h:432px;--hn:551px&#34;&gt;&lt;figcaption&gt;Unfolded Numeric Walkthrough: 2-Token Cross-Entropy Gradient and Rank-One Outer-Product Weight Gradient&lt;/figcaption&gt;&lt;p&gt;&lt;a href=&#34;https://mizore.blog/en/posts/from-transformer-matrices-to-muon/&#34;&gt;(See the figure in the post.)&lt;/a&gt;&lt;/p&gt;&lt;p class=&#34;figure-note&#34;&gt;Step 1 shows &lt;code&gt;$\Delta^{(Z)} = (P - Y_{\mathrm{true}})/N$&lt;/code&gt; assigning negative entries to ground-truth columns and positive entries elsewhere; Step 2 unfolds &lt;code&gt;$G = \Delta_Y^\top X$&lt;/code&gt; as the cellwise sum of token rank-1 matrices &lt;code&gt;$\delta_1 x_1^\top + \delta_2 x_2^\top$&lt;/code&gt;, revealing how shared features create a 67× singular-value skew.&lt;/p&gt;&lt;/figure&gt;&#xA;&lt;p&gt;Once &lt;code&gt;$G$&lt;/code&gt; is computed, how should &lt;code&gt;optimizer.step()&lt;/code&gt; update the weights? We begin with flat vectors and derive four generations of entrywise optimizers.&lt;/p&gt;&#xA;&lt;hr&gt;&#xA;&lt;h2 id=&#34;3-proximal-steepest-descent-and-four-generations-of-entrywise-optimizers&#34;&gt;3. Proximal Steepest Descent and Four Generations of Entrywise Optimizers&lt;/h2&gt;&#xA;&lt;p&gt;To compare &lt;code&gt;SGD&lt;/code&gt;, &lt;code&gt;Momentum&lt;/code&gt;, &lt;code&gt;Adam&lt;/code&gt;, &lt;code&gt;AdamW&lt;/code&gt;, and eventually &lt;code&gt;Muon&lt;/code&gt; on equal footing, we formulate first-order updates in &lt;strong&gt;proximal steepest-descent form&lt;/strong&gt;.&lt;/p&gt;&#xA;&lt;p&gt;Let &lt;code&gt;$\theta_{t-1} \in \mathbb{R}^p$&lt;/code&gt; be the parameter vector after step &lt;code&gt;$t-1$&lt;/code&gt;, and let &lt;code&gt;$g_t = \nabla L_t(\theta_{t-1}) \in \mathbb{R}^p$&lt;/code&gt; be the current mini-batch gradient. A first-order Taylor expansion around &lt;code&gt;$\theta_{t-1}$&lt;/code&gt; gives &lt;code&gt;$L_t(\theta) \approx L_t(\theta_{t-1}) + \langle g_t, \theta - \theta_{t-1} \rangle$&lt;/code&gt;. Because this linear approximation holds only locally—minimizing a bare linear function over &lt;code&gt;$\mathbb{R}^p$&lt;/code&gt; would diverge to &lt;code&gt;$-\infty$&lt;/code&gt;—we add a quadratic proximal penalty measuring step size:&lt;/p&gt;&#xA;&lt;p&gt;&lt;code&gt;$$\theta_t = \mathrm{arg}\min_{\theta \in \mathbb{R}^p} \left\{ \langle g_t, \theta - \theta_{t-1} \rangle + \frac{1}{2\eta} \|\theta - \theta_{t-1}\|_2^2 \right\}$$&lt;/code&gt;&lt;/p&gt;&#xA;&lt;p&gt;with learning rate &lt;code&gt;$\eta &amp;gt; 0$&lt;/code&gt;. Setting the gradient of this strictly convex quadratic with respect to &lt;code&gt;$\theta$&lt;/code&gt; to zero yields:&lt;/p&gt;&#xA;&lt;p&gt;&lt;code&gt;$$g_t + \frac{1}{\eta}(\theta_t - \theta_{t-1}) = 0 \quad \Longrightarrow \quad \theta_t = \theta_{t-1} - \eta g_t$$&lt;/code&gt;&lt;/p&gt;&#xA;&lt;p&gt;This is classical &lt;strong&gt;Stochastic Gradient Descent (SGD)&lt;/strong&gt;&lt;sup class=&#34;cite&#34;&gt;&lt;a id=&#34;cite-robbins1951-2&#34; href=&#34;#ref-robbins1951&#34;&gt;[2]&lt;/a&gt;&lt;/sup&gt;. Crucially, the statement that &amp;quot;&lt;code&gt;$-\eta g_t$&lt;/code&gt; is the steepest descent step&amp;quot; &lt;strong&gt;depends entirely on choosing the isotropic Euclidean norm &lt;code&gt;$\|\cdot\|_2$&lt;/code&gt; to measure parameter displacement&lt;/strong&gt;. Whenever loss curvature varies wildly across directions, Euclidean distance becomes a poor local metric.&lt;/p&gt;&#xA;&lt;h3 id=&#34;31-generation-1-sgd-bottlenecks-under-ill-conditioned-curvature&#34;&gt;3.1 Generation 1: &lt;code&gt;SGD&lt;/code&gt; Bottlenecks Under Ill-Conditioned Curvature&lt;/h3&gt;&#xA;&lt;p&gt;Consider the simplest 2D anisotropic quadratic loss—a narrow canyon whose Hessian eigenvalues differ sharply:&lt;/p&gt;&#xA;&lt;p&gt;&lt;code&gt;$$L(\theta_1, \theta_2) = \frac{1}{2}\lambda_1 \theta_1^2 + \frac{1}{2}\lambda_2 \theta_2^2, \qquad 0 &amp;lt; \lambda_1 \ll \lambda_2$$&lt;/code&gt;&lt;/p&gt;&#xA;&lt;p&gt;Its gradient is &lt;code&gt;$\nabla L(\theta) = (\lambda_1 \theta_1, \lambda_2 \theta_2)^\top$&lt;/code&gt;, its unique minimum sits at &lt;code&gt;$(0, 0)$&lt;/code&gt;, and its &lt;strong&gt;condition number&lt;/strong&gt; is &lt;code&gt;$\kappa \triangleq \lambda_2 / \lambda_1 \gg 1$&lt;/code&gt;. Under vanilla gradient descent, the two coordinates decouple into geometric progressions:&lt;/p&gt;&#xA;&lt;p&gt;&lt;code&gt;$$\theta_{t, 1} = (1 - \eta \lambda_1)^t \theta_{0, 1}, \qquad \theta_{t, 2} = (1 - \eta \lambda_2)^t \theta_{0, 2}$$&lt;/code&gt;&lt;/p&gt;&#xA;&lt;p&gt;Preventing divergence along the steep wall &lt;code&gt;$\theta_2$&lt;/code&gt; requires &lt;code&gt;$|1 - \eta \lambda_2| &amp;lt; 1$&lt;/code&gt;, imposing a strict ceiling on the learning rate:&lt;/p&gt;&#xA;&lt;p&gt;&lt;code&gt;$$0 &amp;lt; \eta &amp;lt; \frac{2}{\lambda_2}$$&lt;/code&gt;&lt;/p&gt;&#xA;&lt;p&gt;Whenever &lt;code&gt;$\frac{1}{\lambda_2} &amp;lt; \eta &amp;lt; \frac{2}{\lambda_2}$&lt;/code&gt;, the factor &lt;code&gt;$1 - \eta \lambda_2$&lt;/code&gt; is negative, so &lt;code&gt;$\theta_{t, 2}$&lt;/code&gt; flips sign every step and zigzags across the canyon walls. Worse still, capping &lt;code&gt;$\eta &amp;lt; 2/\lambda_2$&lt;/code&gt; forces the contraction factor along the flat valley floor &lt;code&gt;$\theta_1$&lt;/code&gt; to satisfy:&lt;/p&gt;&#xA;&lt;p&gt;&lt;code&gt;$$1 - \eta \lambda_1 &amp;gt; 1 - \frac{2\lambda_1}{\lambda_2} = 1 - \frac{2}{\kappa}$$&lt;/code&gt;&lt;/p&gt;&#xA;&lt;p&gt;Using &lt;code&gt;$\ln(1 - u) \approx -u$&lt;/code&gt;, shrinking &lt;code&gt;$\theta_1$&lt;/code&gt;&#39;s initial error by &lt;code&gt;$\varepsilon$&lt;/code&gt; takes &lt;code&gt;$t \ge \frac{\kappa}{2}\ln(1/\varepsilon)$&lt;/code&gt; steps. In deep networks where Hessian condition numbers routinely reach &lt;code&gt;$\kappa \sim 10^4$&lt;/code&gt;–&lt;code&gt;$10^6$&lt;/code&gt;, progress along flat directions crawls.&lt;/p&gt;&#xA;&lt;h3 id=&#34;32-generation-2-polyak-heavy-ball-momentum-and-nesterov-lookahead-reformulation&#34;&gt;3.2 Generation 2: Polyak Heavy-Ball Momentum and Nesterov Lookahead Reformulation&lt;/h3&gt;&#xA;&lt;p&gt;How can we damp sign-flipping oscillations across steep walls while accelerating consistent progress down the valley floor? In 1964, Boris Polyak drew on the damped mechanics of a heavy ball rolling on a potential surface, accumulating an exponential moving average (EMA) of past gradients&lt;sup class=&#34;cite&#34;&gt;&lt;a id=&#34;cite-polyak1964-1&#34; href=&#34;#ref-polyak1964&#34;&gt;[7]&lt;/a&gt;&lt;/sup&gt;:&lt;/p&gt;&#xA;&lt;p&gt;&lt;code&gt;$$m_t = \beta_1 m_{t-1} + (1 - \beta_1) g_t, \qquad \theta_t = \theta_{t-1} - \eta m_t$$&lt;/code&gt;&lt;/p&gt;&#xA;&lt;p&gt;(Implementations often omit &lt;code&gt;$(1 - \beta_1)$&lt;/code&gt; as &lt;code&gt;$u_t = \mu u_{t-1} + g_t$&lt;/code&gt;, absorbing the constant &lt;code&gt;$1/(1-\mu)$&lt;/code&gt; into &lt;code&gt;$\eta$&lt;/code&gt;.) Evaluating steady-state gain on two canonical gradient sequences shows why this works:&lt;/p&gt;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;&lt;strong&gt;Consistent flat direction&lt;/strong&gt; (&lt;code&gt;$g_\tau = g$&lt;/code&gt; every step): for large &lt;code&gt;$t$&lt;/code&gt;, &lt;code&gt;$m_t = (1 - \beta_1)\sum_{k=0}^\infty \beta_1^k g = g$&lt;/code&gt;, preserving full forward drive (or amplifying effective step size by &lt;code&gt;$\frac{1}{1-\mu} = 10\times$&lt;/code&gt; at &lt;code&gt;$\mu = 0.9$&lt;/code&gt; in the unscaled convention);&lt;/li&gt;&#xA;&lt;li&gt;&lt;strong&gt;Alternating steep direction&lt;/strong&gt; (&lt;code&gt;$g_\tau = (-1)^\tau g$&lt;/code&gt; flipping sign every step): the steady-state amplitude is&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&lt;p&gt;&lt;code&gt;$$|m_t| = (1 - \beta_1) |g| \left|\sum_{k=0}^{\infty} (-\beta_1)^k\right| = \frac{1 - \beta_1}{1 + \beta_1} |g|$$&lt;/code&gt;&lt;/p&gt;&#xA;&lt;p&gt;At &lt;code&gt;$\beta_1 = 0.9$&lt;/code&gt;, &lt;code&gt;$\frac{1 - 0.9}{1 + 0.9} \approx 0.0526$&lt;/code&gt;, damping cross-wall oscillation by nearly &lt;code&gt;$95\%$&lt;/code&gt;. On convex quadratics, optimal momentum improves iteration complexity from &lt;code&gt;$\mathcal{O}(\kappa)$&lt;/code&gt; to &lt;code&gt;$\mathcal{O}(\sqrt{\kappa})$&lt;/code&gt;.&lt;/p&gt;&#xA;&lt;p&gt;In 1983, Yurii Nesterov observed a further refinement: since momentum is about to carry the iterate forward by &lt;code&gt;$\mu v_{t-1}$&lt;/code&gt; anyway, rather than evaluating the gradient at the old point &lt;code&gt;$x_{t-1}$&lt;/code&gt;, we should &lt;strong&gt;step to the lookahead point &lt;code&gt;$x_{t-1} + \mu v_{t-1}$&lt;/code&gt; first and evaluate the gradient there&lt;/strong&gt; to correct course earlier&lt;sup class=&#34;cite&#34;&gt;&lt;a id=&#34;cite-nesterov1983-1&#34; href=&#34;#ref-nesterov1983&#34;&gt;[8]&lt;/a&gt;&lt;/sup&gt;:&lt;/p&gt;&#xA;&lt;p&gt;&lt;code&gt;$$v_t = \mu v_{t-1} - \eta \nabla L(x_{t-1} + \mu v_{t-1}), \qquad x_t = x_{t-1} + v_t$$&lt;/code&gt;&lt;/p&gt;&#xA;&lt;p&gt;At first glance, evaluating &lt;code&gt;$\nabla L(x_{t-1} + \mu v_{t-1})$&lt;/code&gt; seems to require a second forward/backward pass at a temporary point. Deep learning frameworks (both PyTorch&#39;s &lt;code&gt;SGD(..., nesterov=True)&lt;/code&gt; and &lt;code&gt;Muon&lt;/code&gt; below) eliminate that extra pass via a change of variables: store the lookahead point itself as the model parameter &lt;code&gt;$\theta_{t-1} \triangleq x_{t-1} + \mu v_{t-1}$&lt;/code&gt;, so the standard backward pass directly yields &lt;code&gt;$g_t = \nabla L(\theta_{t-1})$&lt;/code&gt;. Defining &lt;code&gt;$M_t \triangleq -v_t / \eta$&lt;/code&gt; gives &lt;code&gt;$v_t = -\eta M_t$&lt;/code&gt; with &lt;code&gt;$M_t = \mu M_{t-1} + g_t$&lt;/code&gt;. Expressing &lt;code&gt;$\theta_t$&lt;/code&gt; in terms of &lt;code&gt;$\theta_{t-1}$&lt;/code&gt;:&lt;/p&gt;&#xA;&lt;p&gt;&lt;code&gt;$$\begin{aligned} \theta_t &amp;amp;= x_t + \mu v_t = (x_{t-1} + v_t) + \mu v_t \\ &amp;amp;= (x_{t-1} + \mu v_{t-1}) - \mu v_{t-1} + (1 + \mu) v_t \\ &amp;amp;= \theta_{t-1} + \eta \mu M_{t-1} - \eta (1 + \mu)(\mu M_{t-1} + g_t) \\ &amp;amp;= \theta_{t-1} - \eta \bigl(g_t + \mu (\mu M_{t-1} + g_t)\bigr) = \theta_{t-1} - \eta (g_t + \mu M_t) \end{aligned}$$&lt;/code&gt;&lt;/p&gt;&#xA;&lt;p&gt;Setting &lt;code&gt;$\tilde{M}_t \triangleq g_t + \mu M_t$&lt;/code&gt; produces the exact two-line recurrence &lt;code&gt;M = mu * M + G; tilde_M = G + mu * M&lt;/code&gt; used inside &lt;code&gt;Muon&lt;/code&gt; in Section 7. Compared with heavy-ball momentum &lt;code&gt;$M_t = g_t + \mu M_{t-1}$&lt;/code&gt;, Nesterov lookahead &lt;code&gt;$\tilde{M}_t = (1 + \mu)g_t + \mu^2 M_{t-1}$&lt;/code&gt; weights the freshest gradient &lt;code&gt;$g_t$&lt;/code&gt; by &lt;code&gt;$(1 + \mu)$&lt;/code&gt;, braking earlier around curved ravines.&lt;/p&gt;&#xA;&lt;h3 id=&#34;33-generation-3-adaptive-preconditioning-and-adams-bias-correction&#34;&gt;3.3 Generation 3: Adaptive Preconditioning and Adam&#39;s Bias Correction&lt;/h3&gt;&#xA;&lt;p&gt;Momentum tames curvature within a layer, but deep Transformers also exhibit multi-order-of-magnitude gradient disparities across layers and token frequencies: a rare token&#39;s embedding row may see gradients of &lt;code&gt;$10^{-5}$&lt;/code&gt; while an attention projection sees &lt;code&gt;$10^1$&lt;/code&gt;.&lt;/p&gt;&#xA;&lt;p&gt;Returning to the proximal framework, replace the isotropic Euclidean penalty &lt;code&gt;$\|\theta - \theta_{t-1}\|_2^2$&lt;/code&gt; with a coordinate-weighted diagonal Riemannian metric &lt;code&gt;$(\theta - \theta_{t-1})^\top D_t (\theta - \theta_{t-1})$&lt;/code&gt; for &lt;code&gt;$D_t = \mathrm{diag}(d_{t,1}, \dots, d_{t,p}) \succ 0$&lt;/code&gt;:&lt;/p&gt;&#xA;&lt;p&gt;&lt;code&gt;$$\theta_t = \mathrm{arg}\min_{\theta \in \mathbb{R}^p} \left\{ \langle g_t, \theta - \theta_{t-1} \rangle + \frac{1}{2\eta} (\theta - \theta_{t-1})^\top D_t (\theta - \theta_{t-1}) \right\} \quad \Longrightarrow \quad \theta_t = \theta_{t-1} - \eta D_t^{-1} g_t$$&lt;/code&gt;&lt;/p&gt;&#xA;&lt;p&gt;Three classic algorithms construct &lt;code&gt;$D_t$&lt;/code&gt; progressively:&lt;/p&gt;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;&lt;strong&gt;AdaGrad (Duchi et al., 2011)&lt;sup class=&#34;cite&#34;&gt;&lt;a id=&#34;cite-duchi2011-1&#34; href=&#34;#ref-duchi2011&#34;&gt;[9]&lt;/a&gt;&lt;/sup&gt;&lt;/strong&gt;: accumulate all historical squared gradients &lt;code&gt;$G_{\mathrm{sum}, t} = \sum_{\tau=1}^t g_\tau \odot g_\tau$&lt;/code&gt; and set &lt;code&gt;$D_t = \mathrm{diag}\!\left(\sqrt{G_{\mathrm{sum}, t}} + \epsilon\right)$&lt;/code&gt;. Optimal for sparse convex online learning, its non-decreasing denominator &lt;code&gt;$\sqrt{G_{\mathrm{sum}, t}}$&lt;/code&gt; steadily shrinks effective learning rates toward zero over tens of thousands of non-convex training steps.&lt;/li&gt;&#xA;&lt;li&gt;&lt;strong&gt;RMSProp (Hinton, 2012)&lt;/strong&gt;: introduce a decay factor &lt;code&gt;$\beta_2 \in (0, 1)$&lt;/code&gt; (e.g., &lt;code&gt;$0.999$&lt;/code&gt; or &lt;code&gt;$0.95$&lt;/code&gt;) to replace infinite summation with a leaky EMA over an effective window of &lt;code&gt;$\frac{1}{1-\beta_2}$&lt;/code&gt; steps: &lt;code&gt;$v_t = \beta_2 v_{t-1} + (1 - \beta_2) (g_t \odot g_t)$&lt;/code&gt;, dividing by &lt;code&gt;$\sqrt{v_t} + \epsilon$&lt;/code&gt;.&lt;/li&gt;&#xA;&lt;li&gt;&lt;strong&gt;Adam (Kingma &amp;amp; Ba, 2015) and cold-start bias correction&lt;sup class=&#34;cite&#34;&gt;&lt;a id=&#34;cite-kingma2015-1&#34; href=&#34;#ref-kingma2015&#34;&gt;[10]&lt;/a&gt;&lt;/sup&gt;&lt;/strong&gt;: combine first-moment momentum &lt;code&gt;$m_t$&lt;/code&gt; in the numerator with second-moment &lt;code&gt;$v_t$&lt;/code&gt; in the denominator, initialized at &lt;code&gt;$m_0 = 0, v_0 = 0$&lt;/code&gt;:&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&lt;p&gt;&lt;code&gt;$$m_t = \beta_1 m_{t-1} + (1 - \beta_1) g_t, \qquad v_t = \beta_2 v_{t-1} + (1 - \beta_2) g_t^2$$&lt;/code&gt;&lt;/p&gt;&#xA;&lt;p&gt;(where &lt;code&gt;$g_t^2$&lt;/code&gt; denotes elementwise &lt;code&gt;$g_t \odot g_t$&lt;/code&gt;). Why is bias correction essential? Unrolling &lt;code&gt;$v_t$&lt;/code&gt; back to &lt;code&gt;$t=1$&lt;/code&gt; by induction gives:&lt;/p&gt;&#xA;&lt;p&gt;&lt;code&gt;$$v_t = (1 - \beta_2) \sum_{i=1}^{t} \beta_2^{t-i} g_i^2$$&lt;/code&gt;&lt;/p&gt;&#xA;&lt;p&gt;Taking expectations on both sides—letting &lt;code&gt;$\sigma_{g,t}^2 \triangleq \mathbb{E}[g_t^2]$&lt;/code&gt; and writing &lt;code&gt;$\mathbb{E}[g_i^2] = \sigma_{g,t}^2 + (\mathbb{E}[g_i^2] - \sigma_{g,t}^2)$&lt;/code&gt; so the non-stationarity remainder &lt;code&gt;$\zeta = 0$&lt;/code&gt; under locally stationary gradients—the finite geometric series &lt;code&gt;$\sum_{k=0}^{t-1} \beta_2^k = \frac{1 - \beta_2^t}{1 - \beta_2}$&lt;/code&gt; yields:&lt;/p&gt;&#xA;&lt;p&gt;&lt;code&gt;$$\mathbb{E}[v_t] = (1 - \beta_2) \sum_{i=1}^{t} \beta_2^{t-i} \mathbb{E}[g_i^2] = \sigma_{g,t}^2 (1 - \beta_2) \frac{1 - \beta_2^t}{1 - \beta_2} + \zeta = \sigma_{g,t}^2 (1 - \beta_2^t) + \zeta$$&lt;/code&gt;&lt;/p&gt;&#xA;&lt;p&gt;Similarly, &lt;code&gt;$\mathbb{E}[m_t] = \mathbb{E}[g_t](1 - \beta_1^t) + \zeta&amp;#39;$&lt;/code&gt;. Because &lt;code&gt;$m_0 = 0$&lt;/code&gt; and &lt;code&gt;$v_0 = 0$&lt;/code&gt; carry the remaining weights &lt;code&gt;$\beta_1^t$&lt;/code&gt; and &lt;code&gt;$\beta_2^t$&lt;/code&gt;, both raw estimators are biased toward zero early in training. At step &lt;code&gt;$t = 1$&lt;/code&gt; with standard defaults &lt;code&gt;$\beta_1 = 0.9, \beta_2 = 0.999$&lt;/code&gt;, the uncorrected ratio for any nonzero gradient &lt;code&gt;$g_1$&lt;/code&gt; has magnitude:&lt;/p&gt;&#xA;&lt;p&gt;&lt;code&gt;$$\frac{|m_1|}{\sqrt{v_1}} = \frac{(1 - \beta_1)|g_1|}{\sqrt{(1 - \beta_2) g_1^2}} = \frac{1 - 0.9}{\sqrt{1 - 0.999}} = \frac{0.1}{\sqrt{0.001}} \approx 3.162$$&lt;/code&gt;&lt;/p&gt;&#xA;&lt;p&gt;Because &lt;code&gt;$\beta_2$&lt;/code&gt; is much closer to &lt;code&gt;$1$&lt;/code&gt; than &lt;code&gt;$\beta_1$&lt;/code&gt;, the denominator is biased toward zero far more strongly than the numerator, inflating the very first step by &lt;code&gt;$3.16\times$&lt;/code&gt; (or &lt;code&gt;$10\times$&lt;/code&gt; at &lt;code&gt;$\beta_2 = 0.9999$&lt;/code&gt;) and risking early divergence.&lt;/p&gt;&#xA;&lt;p&gt;Dividing each EMA by the sum of its weights &lt;code&gt;$(1 - \beta_1^t)$&lt;/code&gt; and &lt;code&gt;$(1 - \beta_2^t)$&lt;/code&gt; yields the unbiased estimators &lt;code&gt;$\hat{m}_t, \hat{v}_t$&lt;/code&gt;:&lt;/p&gt;&#xA;&lt;p&gt;&lt;code&gt;$$\hat{m}_t = \frac{m_t}{1 - \beta_1^t}, \qquad \hat{v}_t = \frac{v_t}{1 - \beta_2^t}, \qquad \theta_t = \theta_{t-1} - \eta \frac{\hat{m}_t}{\sqrt{\hat{v}_t} + \epsilon}$$&lt;/code&gt;&lt;/p&gt;&#xA;&lt;p&gt;Now &lt;code&gt;$|\hat{m}_1| / \sqrt{\hat{v}_1} = |g_1| / |g_1| = 1$&lt;/code&gt; at step &lt;code&gt;$1$&lt;/code&gt;, while &lt;code&gt;$\beta_1^t, \beta_2^t \to 0$&lt;/code&gt; smoothly as &lt;code&gt;$t \to \infty$&lt;/code&gt;. Statistically, &lt;code&gt;$\hat{m}_t / \sqrt{\hat{v}_t}$&lt;/code&gt; acts as a per-coordinate &lt;strong&gt;empirical signal-to-noise ratio (SNR)&lt;/strong&gt;: near a minimum where &lt;code&gt;$\mathbb{E}[g_t] \to 0$&lt;/code&gt;, mini-batch variance keeps &lt;code&gt;$\hat{v}_t &amp;gt; 0$&lt;/code&gt; while sign cancellation drives &lt;code&gt;$\hat{m}_t \to 0$&lt;/code&gt;, automatically annealing step sizes&lt;sup class=&#34;cite&#34;&gt;&lt;a id=&#34;cite-kingma2015-2&#34; href=&#34;#ref-kingma2015&#34;&gt;[10]&lt;/a&gt;&lt;/sup&gt;.&lt;/p&gt;&#xA;&lt;h3 id=&#34;34-generation-4-non-equivalence-of-l_2-regularization-and-decoupled-weight-decay-adamw&#34;&gt;3.4 Generation 4: Non-Equivalence of &lt;code&gt;$L_2$&lt;/code&gt; Regularization and Decoupled Weight Decay (&lt;code&gt;AdamW&lt;/code&gt;)&lt;/h3&gt;&#xA;&lt;p&gt;Without norm control on overparameterized networks, minimizing finite-sample cross-entropy drives redundant weights to large magnitudes, sharpening logits and hurting generalization. From a Bayesian MAP perspective, placing an isotropic zero-mean Gaussian prior &lt;code&gt;$p(\theta) \propto \exp\!\left(-\frac{\lambda}{2}\|\theta\|_2^2\right)$&lt;/code&gt; on the parameters adds a quadratic &lt;strong&gt;&lt;code&gt;$L_2$&lt;/code&gt; penalty&lt;/strong&gt; to the loss:&lt;/p&gt;&#xA;&lt;p&gt;&lt;code&gt;$$L_{\mathrm{reg}}(\theta) = L(\theta) + \frac{\lambda}{2}\|\theta\|_2^2 \quad \Longrightarrow \quad \nabla L_{\mathrm{reg}}(\theta) = \nabla L(\theta) + \lambda \theta$$&lt;/code&gt;&lt;/p&gt;&#xA;&lt;p&gt;Independently, Hanson and Pratt (1988) defined &lt;strong&gt;weight decay&lt;/strong&gt; as directly shrinking parameters each step via &lt;code&gt;$(1 - w)\theta_{t-1}$&lt;/code&gt;. Substituting &lt;code&gt;$\nabla L_{\mathrm{reg}}$&lt;/code&gt; into vanilla &lt;code&gt;SGD&lt;/code&gt; gives:&lt;/p&gt;&#xA;&lt;p&gt;&lt;code&gt;$$\theta_t = \theta_{t-1} - \eta (g_t + \lambda \theta_{t-1}) = (1 - \eta \lambda)\theta_{t-1} - \eta g_t$$&lt;/code&gt;&lt;/p&gt;&#xA;&lt;p&gt;Setting &lt;code&gt;$w = \eta \lambda$&lt;/code&gt; makes the two identical. Because of this coincidence, deep learning libraries implemented &lt;code&gt;weight_decay&lt;/code&gt; by adding &lt;code&gt;wd * theta&lt;/code&gt; onto &lt;code&gt;g_t&lt;/code&gt; before running the optimizer. Yet once &lt;code&gt;Adam&lt;/code&gt; became popular, models trained with &lt;code&gt;Adam&lt;/code&gt; + &lt;code&gt;$L_2$&lt;/code&gt; regularization generalized noticeably worse than &lt;code&gt;SGD + Momentum&lt;/code&gt;.&lt;/p&gt;&#xA;&lt;p&gt;In 2019, Loshchilov and Hutter proved why the two are inequivalent under adaptive preconditioning&lt;sup class=&#34;cite&#34;&gt;&lt;a id=&#34;cite-loshchilov2019-2&#34; href=&#34;#ref-loshchilov2019&#34;&gt;[3]&lt;/a&gt;&lt;/sup&gt;. Consider any preconditioned update with symmetric positive-definite preconditioner &lt;code&gt;$P_t \succ 0$&lt;/code&gt; and decoupled decay rate &lt;code&gt;$w$&lt;/code&gt;:&lt;/p&gt;&#xA;&lt;p&gt;&lt;code&gt;$$\theta_t = (1 - w)\theta_{t-1} - \eta P_t^{-1} \nabla L(\theta_{t-1})$$&lt;/code&gt;&lt;/p&gt;&#xA;&lt;p&gt;Does there exist a fixed differentiable regularizer &lt;code&gt;$R(\theta)$&lt;/code&gt; such that running the same preconditioner without decoupled decay on &lt;code&gt;$\tilde{L}(\theta) = L(\theta) + R(\theta)$&lt;/code&gt; produces the exact same iterate? First, when &lt;code&gt;$P_t$&lt;/code&gt; evolves with historical gradients, no time-independent function &lt;code&gt;$R(\theta)$&lt;/code&gt; can match it at all; even if &lt;code&gt;$P_t = P$&lt;/code&gt; is held constant, equating the two updates requires:&lt;/p&gt;&#xA;&lt;p&gt;&lt;code&gt;$$\theta_{t-1} - \eta P^{-1}\bigl(\nabla L(\theta_{t-1}) + \nabla R(\theta_{t-1})\bigr) = (1 - w)\theta_{t-1} - \eta P^{-1} \nabla L(\theta_{t-1})$$&lt;/code&gt;&lt;/p&gt;&#xA;&lt;p&gt;Canceling common terms and left-multiplying by &lt;code&gt;$P$&lt;/code&gt; yields the exact condition:&lt;/p&gt;&#xA;&lt;p&gt;&lt;code&gt;$$\nabla R(\theta_{t-1}) = \frac{w}{\eta} P \theta_{t-1} \quad \Longleftrightarrow \quad R(\theta) = \frac{w}{2\eta} \theta^\top P \theta$$&lt;/code&gt;&lt;/p&gt;&#xA;&lt;p&gt;Two conclusions follow immediately:&lt;/p&gt;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;&lt;strong&gt;Necessary and sufficient condition&lt;/strong&gt;: isotropic &lt;code&gt;$L_2$&lt;/code&gt; regularization &lt;code&gt;$R(\theta) = \frac{\lambda}{2}\|\theta\|_2^2$&lt;/code&gt; equals weight decay &lt;strong&gt;if and only if &lt;code&gt;$P_t = c I$&lt;/code&gt; is a scalar multiple of the identity&lt;/strong&gt; (&lt;code&gt;SGD&lt;/code&gt;).&lt;/li&gt;&#xA;&lt;li&gt;&lt;strong&gt;Distortion of coupled &lt;code&gt;$L_2$&lt;/code&gt; inside &lt;code&gt;Adam&lt;/code&gt;&lt;/strong&gt;: in &lt;code&gt;Adam&lt;/code&gt;, &lt;code&gt;$P_t = \mathrm{diag}\!\left(\sqrt{\hat{v}_t} + \epsilon\right)$&lt;/code&gt; varies across coordinates. Mixing &lt;code&gt;$\lambda \theta_{t-1}$&lt;/code&gt; into &lt;code&gt;$g_t^{\mathrm{L2}} = g_t + \lambda \theta_{t-1}$&lt;/code&gt; both contaminates &lt;code&gt;$\hat{v}_t^{\mathrm{L2}}$&lt;/code&gt; and (taking &lt;code&gt;$\beta_1 = 0$&lt;/code&gt; to inspect a single step) produces:&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&lt;p&gt;&lt;code&gt;$$\theta_{t, i} = \theta_{t-1, i} - \eta \frac{g_{t, i} + \lambda \theta_{t-1, i}}{\sqrt{\hat{v}_{t, i}^{\mathrm{L2}}} + \epsilon} = \left(1 - \frac{\eta \lambda}{\sqrt{\hat{v}_{t, i}^{\mathrm{L2}}} + \epsilon}\right)\theta_{t-1, i} - \eta \frac{g_{t, i}}{\sqrt{\hat{v}_{t, i}^{\mathrm{L2}}} + \epsilon}$$&lt;/code&gt;&lt;/p&gt;&#xA;&lt;p&gt;Coordinate &lt;code&gt;$i$&lt;/code&gt;&#39;s effective shrinkage rate becomes &lt;code&gt;$\frac{\eta \lambda}{\sqrt{\hat{v}_{t, i}^{\mathrm{L2}}} + \epsilon}$&lt;/code&gt;, divided by its historical gradient RMS: active weights with large gradients (&lt;code&gt;$\sqrt{\hat{v}_{t,i}} \gg 1$&lt;/code&gt;) barely decay at all, whereas quiet weights (&lt;code&gt;$\sqrt{\hat{v}_{t,i}} \ll 1$&lt;/code&gt;) are aggressively crushed—the exact opposite of an isotropic Gaussian prior.&lt;/p&gt;&#xA;&lt;p&gt;&lt;code&gt;AdamW&lt;/code&gt; fixes this by decoupling weight shrinkage from the adaptive gradient ratio:&lt;/p&gt;&#xA;&lt;p&gt;&lt;code&gt;$$\theta_t = (1 - \eta \lambda)\theta_{t-1} - \eta \frac{\hat{m}_t}{\sqrt{\hat{v}_t} + \epsilon}$$&lt;/code&gt;&lt;/p&gt;&#xA;&lt;figure class=&#34;diagram&#34; style=&#34;--h:224px;--hn:339px&#34;&gt;&lt;figcaption&gt;Dataflow Comparison: Coupled &lt;code&gt;$L_2$&lt;/code&gt; Regularization vs. Decoupled Weight Decay (AdamW)&lt;/figcaption&gt;&lt;p&gt;&lt;a href=&#34;https://mizore.blog/en/posts/from-transformer-matrices-to-muon/&#34;&gt;(See the figure in the post.)&lt;/a&gt;&lt;/p&gt;&lt;p class=&#34;figure-note&#34;&gt;Under coupled &lt;code&gt;$L_2$&lt;/code&gt;, the penalty &lt;code&gt;$\lambda\theta_{t-1}$&lt;/code&gt; enters the gradient and gets divided by &lt;code&gt;$\sqrt{\hat{v}_t}$&lt;/code&gt;, distorting per-coordinate shrinkage; AdamW applies uniform multiplicative decay directly to the weights.&lt;/p&gt;&lt;/figure&gt;&#xA;&lt;p&gt;The numerical verification below illustrates both derivations: the left panel plots 26 steps of &lt;code&gt;SGD&lt;/code&gt;, &lt;code&gt;Momentum&lt;/code&gt;, and &lt;code&gt;AdamW&lt;/code&gt; on the &lt;code&gt;$\kappa = 36$&lt;/code&gt; canyon &lt;code&gt;$L(\theta_1, \theta_2) = 0.5\theta_1^2 + 18\theta_2^2$&lt;/code&gt;; the right panel runs &lt;code&gt;Adam+L2&lt;/code&gt; versus &lt;code&gt;AdamW&lt;/code&gt; on two redundant parameters initialized at &lt;code&gt;$2.5$&lt;/code&gt; under zero-mean alternating gradient noise of amplitude &lt;code&gt;$40$&lt;/code&gt; versus &lt;code&gt;$0.05$&lt;/code&gt;, showing &lt;code&gt;Adam+L2&lt;/code&gt;&#39;s noisy coordinate stalling at &lt;code&gt;$2.39$&lt;/code&gt; while both &lt;code&gt;AdamW&lt;/code&gt; trajectories overlap identically down to &lt;code&gt;$0.74$&lt;/code&gt;.&lt;/p&gt;&#xA;&lt;figure class=&#34;plotfig&#34;&gt;&lt;figcaption&gt;Entrywise Optimizer Verification: Ill-Conditioned Trajectories and Coupled &lt;code&gt;$L_2$&lt;/code&gt; Decay Distortion&lt;/figcaption&gt;&lt;p&gt;&lt;a href=&#34;https://mizore.blog/en/posts/from-transformer-matrices-to-muon/&#34;&gt;(See the figure in the post.)&lt;/a&gt;&lt;/p&gt;&lt;p class=&#34;figure-note&#34;&gt;Left: 26 steps on &lt;code&gt;$L(\theta_1, \theta_2) = 0.5\theta_1^2 + 18\theta_2^2$&lt;/code&gt; (&lt;code&gt;$\kappa = 36$&lt;/code&gt;). Right: decay toward zero under zero-mean alternating noise (&lt;code&gt;$\theta_1$&lt;/code&gt; amp 40, &lt;code&gt;$\theta_2$&lt;/code&gt; amp 0.05, init &lt;code&gt;$2.5$&lt;/code&gt;, &lt;code&gt;$\eta=0.02, \lambda=0.4$&lt;/code&gt;).&lt;/p&gt;&lt;/figure&gt;&#xA;&lt;p&gt;One practical corollary: why is &lt;code&gt;weight_decay&lt;/code&gt; set to &lt;code&gt;0.0&lt;/code&gt; on 1D &lt;code&gt;RMSNorm&lt;/code&gt; gains &lt;code&gt;$\gamma$&lt;/code&gt; (and biases) in &lt;code&gt;AdamW&lt;/code&gt;? Initialized to &lt;code&gt;$1$&lt;/code&gt;, &lt;code&gt;$\gamma$&lt;/code&gt; rescales unit-RMS activations per channel and accounts for less than &lt;code&gt;$0.05\%$&lt;/code&gt; of model parameters; pulling &lt;code&gt;$\gamma$&lt;/code&gt; toward &lt;code&gt;$0$&lt;/code&gt; does not regularize high-rank capacity and merely dampens layer outputs.&lt;/p&gt;&#xA;&lt;hr&gt;&#xA;&lt;h2 id=&#34;4-from-entrywise-norms-to-2d-operator-spectral-norms-deriving-muon&#34;&gt;4. From Entrywise Norms to 2D Operator Spectral Norms: Deriving &lt;code&gt;Muon&lt;/code&gt;&lt;/h2&gt;&#xA;&lt;p&gt;&lt;code&gt;AdamW&lt;/code&gt; gives us the modern entrywise baseline. Now return to the structural facts from Sections 1 and 2: over &lt;code&gt;$95\%$&lt;/code&gt; of non-embedding parameters in a Transformer (&lt;code&gt;$W_q, W_k, W_v, W_o, W_{\mathrm{up}}, W_{\mathrm{down}}$&lt;/code&gt;) are 2D linear operators &lt;code&gt;$W \in \mathbb{R}^{d_{\mathrm{out}} \times d_{\mathrm{in}}}$&lt;/code&gt; whose gradients &lt;code&gt;$G = \sum_{n=1}^N \delta_n x_n^\top$&lt;/code&gt; have heavily skewed singular spectra. What geometry does &lt;code&gt;AdamW&lt;/code&gt; implicitly impose when handed such a 2D matrix?&lt;/p&gt;&#xA;&lt;h3 id=&#34;41-adamws-hidden-geometry-steepest-descent-under-the-entrywise-max-norm&#34;&gt;4.1 AdamW&#39;s Hidden Geometry: Steepest Descent Under the Entrywise Max Norm&lt;/h3&gt;&#xA;&lt;p&gt;To compare non-Euclidean norms cleanly, rewrite the proximal penalty of Section 3 in constrained &lt;strong&gt;normalized steepest descent&lt;/strong&gt; form. Let &lt;code&gt;$\langle A, B \rangle_F \triangleq \mathrm{tr}(A^\top B) = \sum_{i, j} A_{i, j} B_{i, j}$&lt;/code&gt; denote the Frobenius inner product, with Frobenius norm &lt;code&gt;$\|A\|_F = \sqrt{\langle A, A \rangle_F}$&lt;/code&gt;. Given any matrix norm &lt;code&gt;$\|\cdot\|$&lt;/code&gt; and step budget &lt;code&gt;$\eta &amp;gt; 0$&lt;/code&gt;, steepest descent on the &lt;code&gt;$\|\cdot\|$&lt;/code&gt;-ball solves:&lt;/p&gt;&#xA;&lt;p&gt;&lt;code&gt;$$\Delta W^* = \mathrm{arg}\min_{\|\Delta W\| \le \eta} \langle G, \Delta W \rangle_F$$&lt;/code&gt;&lt;/p&gt;&#xA;&lt;p&gt;(By Lagrangian duality, the ball-constrained solution shares the exact direction of the quadratic penalty problem while fixing step length &lt;code&gt;$\|\Delta W^*\| = \eta$&lt;/code&gt;; under the Frobenius norm &lt;code&gt;$\|\Delta W\|_F \le \eta$&lt;/code&gt;, for instance, &lt;code&gt;$\Delta W^* = -\eta G / \|G\|_F$&lt;/code&gt;.)&lt;/p&gt;&#xA;&lt;p&gt;Now inspect &lt;code&gt;Adam&lt;/code&gt; in the memoryless limit (&lt;code&gt;$\beta_1 = 0, \beta_2 = 0, \epsilon \to 0$&lt;/code&gt;): each entry &lt;code&gt;$(i, j)$&lt;/code&gt; steps by &lt;code&gt;$-\eta \frac{G_{i, j}}{\sqrt{G_{i, j}^2}} = -\eta \,\mathrm{sign}(G_{i, j})$&lt;/code&gt; (&lt;code&gt;SignSGD&lt;/code&gt;). That is the exact steepest-descent step under the &lt;strong&gt;entrywise max norm&lt;/strong&gt; &lt;code&gt;$\|\Delta W\|_{\max} \triangleq \max_{i, j} |\Delta W_{i, j}|$&lt;/code&gt; (the &lt;code&gt;$\ell_\infty$&lt;/code&gt; norm of the flattened matrix):&lt;/p&gt;&#xA;&lt;p&gt;&lt;code&gt;$$\min_{\|\Delta W\|_{\max} \le \eta} \langle G, \Delta W \rangle_F = \min_{\forall i, j:\; |\Delta W_{i, j}| \le \eta} \sum_{i=1}^{d_{\mathrm{out}}} \sum_{j=1}^{d_{\mathrm{in}}} G_{i, j} \Delta W_{i, j} \quad \Longrightarrow \quad \Delta W_{i, j}^* = -\eta \,\mathrm{sign}(G_{i, j})$$&lt;/code&gt;&lt;/p&gt;&#xA;&lt;p&gt;Geometrically, &lt;code&gt;AdamW&lt;/code&gt; is &lt;strong&gt;EMA-smoothed steepest descent under the entrywise &lt;code&gt;$\ell_\infty$&lt;/code&gt; norm&lt;/strong&gt;&lt;sup class=&#34;cite&#34;&gt;&lt;a id=&#34;cite-bernstein2024-1&#34; href=&#34;#ref-bernstein2024&#34;&gt;[12]&lt;/a&gt;&lt;/sup&gt;.&lt;/p&gt;&#xA;&lt;p&gt;Treating a &lt;code&gt;$d_{\mathrm{out}} \times d_{\mathrm{in}}$&lt;/code&gt; linear map as &lt;code&gt;$d_{\mathrm{out}} \cdot d_{\mathrm{in}}$&lt;/code&gt; uncoupled scalar boxes has two fundamental limitations:&lt;/p&gt;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;&lt;strong&gt;Basis dependence&lt;/strong&gt;: rotating the hidden representation by an orthogonal basis change &lt;code&gt;$h \mapsto Q h$&lt;/code&gt; (&lt;code&gt;$Q^\top Q = I$&lt;/code&gt;) leaves Euclidean/RMS geometry invariant, yet entrywise sign is not rotation-equivariant (&lt;code&gt;$\mathrm{sign}(Q G) \neq Q \,\mathrm{sign}(G)$&lt;/code&gt;).&lt;/li&gt;&#xA;&lt;li&gt;&lt;strong&gt;Equalizing entries does not equalize singular subspaces&lt;/strong&gt;: if &lt;code&gt;$G = \sum_n \delta_n x_n^\top$&lt;/code&gt; is dominated by a rank-&lt;code&gt;$1$&lt;/code&gt; outer product &lt;code&gt;$u v^\top$&lt;/code&gt;, taking elementwise signs yields &lt;code&gt;$\mathrm{sign}(u v^\top) = \mathrm{sign}(u)\,\mathrm{sign}(v)^\top$&lt;/code&gt;—&lt;strong&gt;still a rank-&lt;code&gt;$1$&lt;/code&gt; matrix&lt;/strong&gt;! Dividing each cell by &lt;code&gt;$\sqrt{\hat{v}_{i, j}}$&lt;/code&gt; cannot amplify updates along the dozens of low-singular-value subspaces buried underneath dominant directions.&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&lt;p&gt;Substituting the exact &lt;code&gt;$2 \times 3$&lt;/code&gt; gradient matrix &lt;code&gt;$G = \begin{bsmallmatrix} -1.0 &amp;amp; -2.0 &amp;amp; -0.4 \\ 0.4 &amp;amp; 0.8 &amp;amp; 0.2 \end{bsmallmatrix}$&lt;/code&gt; hand-computed in Section 2.4 into step &lt;code&gt;$t = 1$&lt;/code&gt; of bias-corrected &lt;code&gt;Adam&lt;/code&gt; (&lt;code&gt;$\hat{M}_1 = G$&lt;/code&gt;, &lt;code&gt;$\hat{V}_1 = G \odot G = \begin{bsmallmatrix} 1.00 &amp;amp; 4.00 &amp;amp; 0.16 \\ 0.16 &amp;amp; 0.64 &amp;amp; 0.04 \end{bsmallmatrix}$&lt;/code&gt;, neglecting tiny &lt;code&gt;$\epsilon$&lt;/code&gt;) makes this blind spot concrete:&lt;/p&gt;&#xA;&lt;p&gt;&lt;code&gt;$$U_{\mathrm{Adam}, 1} = \frac{\hat{M}_1}{\sqrt{\hat{V}_1}} = \begin{bmatrix} -1.0 / 1.0 &amp;amp; -2.0 / 2.0 &amp;amp; -0.4 / 0.4 \\ 0.4 / 0.4 &amp;amp; 0.8 / 0.8 &amp;amp; 0.2 / 0.2 \end{bmatrix} = \begin{bmatrix} -1 &amp;amp; -1 &amp;amp; -1 \\ +1 &amp;amp; +1 &amp;amp; +1 \end{bmatrix}$$&lt;/code&gt;&lt;/p&gt;&#xA;&lt;p&gt;All six cells now have unit magnitude, yet because row 2 has become the exact negative of row 1, the update has collapsed into a &lt;strong&gt;rank-1 matrix&lt;/strong&gt; (&lt;code&gt;$\sigma_1 \approx 2.45,\; \sigma_2 = \mathbf{0.00}$&lt;/code&gt;)—completely erasing the subtle column-3 feature signal (&lt;code&gt;$\sigma_2 \approx 0.037$&lt;/code&gt;) that distinguished token 2 from token 1. By contrast, the semi-orthogonal polar factor &lt;code&gt;$U V^\top$&lt;/code&gt; derived next maps the very same &lt;code&gt;$G$&lt;/code&gt; to the full-rank matrix &lt;code&gt;$\begin{bsmallmatrix} -0.438 &amp;amp; -0.877 &amp;amp; +0.199 \\ +0.089 &amp;amp; +0.178 &amp;amp; \mathbf{+0.980} \end{bsmallmatrix}$&lt;/code&gt; (orthogonal rows, &lt;code&gt;$\sigma_1 = \sigma_2 = 1$&lt;/code&gt;), automatically steering &lt;code&gt;$98\%$&lt;/code&gt; of neuron 2&#39;s step along the novel 3rd feature.&lt;/p&gt;&#xA;&lt;h3 id=&#34;42-algebraic-simplification-from-shampoo-to-its-stateless-limit&#34;&gt;4.2 Algebraic Simplification from &lt;code&gt;Shampoo&lt;/code&gt; to Its Stateless Limit&lt;/h3&gt;&#xA;&lt;p&gt;How can we precondition a matrix gradient without losing row-column coupling? Flattening &lt;code&gt;$W \in \mathbb{R}^{A \times B}$&lt;/code&gt; into full-matrix &lt;code&gt;AdaGrad&lt;/code&gt; would require an &lt;code&gt;$(AB) \times (AB)$&lt;/code&gt; covariance matrix—&lt;code&gt;$2.8 \times 10^{14}$&lt;/code&gt; floats for a single &lt;code&gt;$4096 \times 4096$&lt;/code&gt; layer, completely intractable.&lt;/p&gt;&#xA;&lt;p&gt;In 2018, Gupta, Koren, and Singer proposed &lt;strong&gt;Shampoo&lt;/strong&gt;&lt;sup class=&#34;cite&#34;&gt;&lt;a id=&#34;cite-gupta2018-1&#34; href=&#34;#ref-gupta2018&#34;&gt;[11]&lt;/a&gt;&lt;/sup&gt;, factoring the preconditioner via a Kronecker product into a left row-covariance accumulator &lt;code&gt;$L_t = \sum_{s=1}^t G_s G_s^\top \in \mathbb{R}^{A \times A}$&lt;/code&gt; and a right column-covariance accumulator &lt;code&gt;$R_t = \sum_{s=1}^t G_s^\top G_s \in \mathbb{R}^{B \times B}$&lt;/code&gt;, stepping along &lt;code&gt;$L_t^{-1/4} G_t R_t^{-1/4}$&lt;/code&gt;. Why the &lt;code&gt;$-1/4$&lt;/code&gt; exponent rather than &lt;code&gt;AdaGrad&lt;/code&gt;&#39;s &lt;code&gt;$-1/2$&lt;/code&gt;? Because both &lt;code&gt;$L_t$&lt;/code&gt; and &lt;code&gt;$R_t$&lt;/code&gt; are quadratic in &lt;code&gt;$G$&lt;/code&gt; (units &lt;code&gt;$G^2$&lt;/code&gt;), multiplying on the left by &lt;code&gt;$L_t^{-1/4}$&lt;/code&gt; (&lt;code&gt;$G^{-1/2}$&lt;/code&gt;) and on the right by &lt;code&gt;$R_t^{-1/4}$&lt;/code&gt; (&lt;code&gt;$G^{-1/2}$&lt;/code&gt;) together cancel one power of &lt;code&gt;$G$&lt;/code&gt;, matching &lt;code&gt;AdaGrad&lt;/code&gt;&#39;s zero-order scaling &lt;code&gt;$(G^2)^{-1/2} G$&lt;/code&gt;.&lt;/p&gt;&#xA;&lt;p&gt;Subsequent experiments revealed a striking empirical fact: turning off cross-step accumulation in &lt;code&gt;Shampoo&lt;/code&gt; and evaluating the instantaneous stateless form &lt;code&gt;$((G G^\top)^+)^{1/4} G ((G^\top G)^+)^{1/4}$&lt;/code&gt; (where &lt;code&gt;$(\cdot)^+$&lt;/code&gt; is the Moore-Penrose pseudoinverse) on the current momentum matrix not only avoids degradation, but often converges faster&lt;sup class=&#34;cite&#34;&gt;&lt;a id=&#34;cite-bernstein2024-2&#34; href=&#34;#ref-bernstein2024&#34;&gt;[12]&lt;/a&gt;&lt;/sup&gt;. Let us simplify that expression algebraically.&lt;/p&gt;&#xA;&lt;p&gt;Let &lt;code&gt;$G \in \mathbb{R}^{A \times B}$&lt;/code&gt; have rank &lt;code&gt;$r \le \min(A, B)$&lt;/code&gt; with &lt;strong&gt;reduced singular value decomposition (SVD)&lt;/strong&gt;:&lt;/p&gt;&#xA;&lt;p&gt;&lt;code&gt;$$G = U \Sigma V^\top$$&lt;/code&gt;&lt;/p&gt;&#xA;&lt;p&gt;where &lt;code&gt;$U \in \mathbb{R}^{A \times r}$&lt;/code&gt; has orthonormal columns (&lt;code&gt;$U^\top U = I_r$&lt;/code&gt;), &lt;code&gt;$\Sigma = \mathrm{diag}(\sigma_1, \dots, \sigma_r) \in \mathbb{R}^{r \times r}$&lt;/code&gt; has positive singular values &lt;code&gt;$\sigma_1 \ge \dots \ge \sigma_r &amp;gt; 0$&lt;/code&gt;, and &lt;code&gt;$V \in \mathbb{R}^{B \times r}$&lt;/code&gt; has orthonormal columns (&lt;code&gt;$V^\top V = I_r$&lt;/code&gt;). (Note also the Frobenius identity &lt;code&gt;$\|G\|_F^2 = \mathrm{tr}(G^\top G) = \mathrm{tr}(\Sigma^2 V^\top V) = \sum_{i=1}^r \sigma_i^2$&lt;/code&gt;.) Forming the left and right Gram matrices gives:&lt;/p&gt;&#xA;&lt;p&gt;&lt;code&gt;$$G G^\top = (U \Sigma V^\top)(V \Sigma U^\top) = U \Sigma^2 U^\top, \qquad G^\top G = (V \Sigma U^\top)(U \Sigma V^\top) = V \Sigma^2 V^\top$$&lt;/code&gt;&lt;/p&gt;&#xA;&lt;p&gt;Taking the &lt;code&gt;$1/4$&lt;/code&gt; power of the pseudoinverse on the active range space raises each positive diagonal entry of &lt;code&gt;$\Sigma^2$&lt;/code&gt; to &lt;code&gt;$-1/4$&lt;/code&gt;, i.e., &lt;code&gt;$\Sigma^{-1/2}$&lt;/code&gt;:&lt;/p&gt;&#xA;&lt;p&gt;&lt;code&gt;$$((G G^\top)^+)^{1/4} = U \Sigma^{-1/2} U^\top, \qquad ((G^\top G)^+)^{1/4} = V \Sigma^{-1/2} V^\top$$&lt;/code&gt;&lt;/p&gt;&#xA;&lt;p&gt;Multiplying all three factors and applying &lt;code&gt;$U^\top U = I_r$&lt;/code&gt;, &lt;code&gt;$V^\top V = I_r$&lt;/code&gt;:&lt;/p&gt;&#xA;&lt;p&gt;&lt;code&gt;$$((G G^\top)^+)^{1/4} G ((G^\top G)^+)^{1/4} = \bigl(U \Sigma^{-1/2} U^\top\bigr)(U \Sigma V^\top)\bigl(V \Sigma^{-1/2} V^\top\bigr) = U \Sigma^{-1/2} \Sigma \Sigma^{-1/2} V^\top = U I_r V^\top = U V^\top$$&lt;/code&gt;&lt;/p&gt;&#xA;&lt;p&gt;Every nonzero singular value &lt;code&gt;$\sigma_1, \dots, \sigma_r$&lt;/code&gt;—no matter how many orders of magnitude apart—cancels out identically to &lt;code&gt;$1$&lt;/code&gt;. When &lt;code&gt;$G$&lt;/code&gt; has full rank &lt;code&gt;$r = \min(A, B)$&lt;/code&gt; (which holds almost surely under stochastic gradients), &lt;code&gt;$U V^\top \in \mathbb{R}^{A \times B}$&lt;/code&gt; is the nearest &lt;strong&gt;semi-orthogonal matrix&lt;/strong&gt; to &lt;code&gt;$G$&lt;/code&gt; (&lt;code&gt;$(U V^\top)^\top (U V^\top) = I_B$&lt;/code&gt; if &lt;code&gt;$A \ge B$&lt;/code&gt;, or &lt;code&gt;$(U V^\top)(U V^\top)^\top = I_A$&lt;/code&gt; if &lt;code&gt;$A \le B$&lt;/code&gt;; if &lt;code&gt;$r &amp;lt; \min(A, B)$&lt;/code&gt;, it is a rank-&lt;code&gt;$r$&lt;/code&gt; partial isometry).&lt;/p&gt;&#xA;&lt;h3 id=&#34;43-first-principles-derivation-steepest-descent-under-the-induced-mathrmrms-to-mathrmrms-operator-norm&#34;&gt;4.3 First-Principles Derivation: Steepest Descent Under the Induced &lt;code&gt;$\mathrm{RMS} \to \mathrm{RMS}$&lt;/code&gt; Operator Norm&lt;/h3&gt;&#xA;&lt;p&gt;In &lt;em&gt;Old Optimizer, New Norm&lt;/em&gt; (2024), Bernstein and Newhouse proved that &lt;code&gt;$U V^\top$&lt;/code&gt; needs no second-order curvature approximation to justify it: it is the &lt;strong&gt;exact first-order steepest-descent step under the natural induced operator norm of hidden linear layers&lt;/strong&gt;&lt;sup class=&#34;cite&#34;&gt;&lt;a id=&#34;cite-bernstein2024-3&#34; href=&#34;#ref-bernstein2024&#34;&gt;[12]&lt;/a&gt;&lt;/sup&gt;. Here is the complete proof.&lt;/p&gt;&#xA;&lt;p&gt;Consider a hidden linear map &lt;code&gt;$y = W x$&lt;/code&gt; taking &lt;code&gt;$x \in \mathbb{R}^{d_{\mathrm{in}}}$&lt;/code&gt; to &lt;code&gt;$y \in \mathbb{R}^{d_{\mathrm{out}}}$&lt;/code&gt;. Recall from Section 2.1 that &lt;code&gt;RMSNorm&lt;/code&gt; normalizes hidden token vectors in &lt;strong&gt;root-mean-square norm&lt;/strong&gt;:&lt;/p&gt;&#xA;&lt;p&gt;&lt;code&gt;$$\|x\|_{\mathrm{RMS}} \triangleq \frac{1}{\sqrt{d_{\mathrm{in}}}} \|x\|_2, \qquad \|y\|_{\mathrm{RMS}} \triangleq \frac{1}{\sqrt{d_{\mathrm{out}}}} \|y\|_2$$&lt;/code&gt;&lt;/p&gt;&#xA;&lt;p&gt;Perturbing &lt;code&gt;$W \to W + \Delta W$&lt;/code&gt; shifts the layer&#39;s output on input &lt;code&gt;$x$&lt;/code&gt; by &lt;code&gt;$\Delta y = \Delta W x$&lt;/code&gt;. To keep the maximum output RMS perturbation bounded across arbitrary layer widths &lt;code&gt;$d_{\mathrm{in}}, d_{\mathrm{out}}$&lt;/code&gt;, the physically meaningful ruler on &lt;code&gt;$\Delta W$&lt;/code&gt; is the worst-case output RMS change per unit input RMS—the &lt;strong&gt;induced &lt;code&gt;$\mathrm{RMS} \to \mathrm{RMS}$&lt;/code&gt; operator norm&lt;/strong&gt;:&lt;/p&gt;&#xA;&lt;p&gt;&lt;code&gt;$$\|\Delta W\|_{\mathrm{RMS} \to \mathrm{RMS}} \triangleq \max_{x \neq 0} \frac{\|\Delta W x\|_{\mathrm{RMS}}}{\|x\|_{\mathrm{RMS}}} = \max_{x \neq 0} \frac{\frac{1}{\sqrt{d_{\mathrm{out}}}}\|\Delta W x\|_2}{\frac{1}{\sqrt{d_{\mathrm{in}}}}\|x\|_2} = \sqrt{\frac{d_{\mathrm{in}}}{d_{\mathrm{out}}}} \max_{\|x\|_2 = 1} \|\Delta W x\|_2 = \sqrt{\frac{d_{\mathrm{in}}}{d_{\mathrm{out}}}}\, \sigma_1(\Delta W)$$&lt;/code&gt;&lt;/p&gt;&#xA;&lt;p&gt;where &lt;code&gt;$\sigma_1(\Delta W) = \|\Delta W\|_2$&lt;/code&gt; is the largest singular value (spectral norm) of &lt;code&gt;$\Delta W$&lt;/code&gt;.&lt;/p&gt;&#xA;&lt;p&gt;Given the current lookahead momentum matrix &lt;code&gt;$\tilde{M} \in \mathbb{R}^{d_{\mathrm{out}} \times d_{\mathrm{in}}}$&lt;/code&gt; with reduced SVD &lt;code&gt;$\tilde{M} = U \Sigma V^\top = \sum_{i=1}^r \sigma_i u_i v_i^\top$&lt;/code&gt; (&lt;code&gt;$\sigma_i &amp;gt; 0$&lt;/code&gt;), steepest descent inside this induced operator-norm ball solves:&lt;/p&gt;&#xA;&lt;p&gt;&lt;code&gt;$$\min_{\|\Delta W\|_{\mathrm{RMS} \to \mathrm{RMS}} \le \eta} \langle \tilde{M}, \Delta W \rangle_F \quad \Longleftrightarrow \quad \min_{\sigma_1(\Delta W) \le \eta \sqrt{d_{\mathrm{out}} / d_{\mathrm{in}}}} \mathrm{tr}(\tilde{M}^\top \Delta W)$$&lt;/code&gt;&lt;/p&gt;&#xA;&lt;p&gt;By cyclic invariance of the trace:&lt;/p&gt;&#xA;&lt;p&gt;&lt;code&gt;$$\langle \tilde{M}, \Delta W \rangle_F = \mathrm{tr}\!\left(\sum_{i=1}^{r} \sigma_i v_i u_i^\top \Delta W\right) = \sum_{i=1}^{r} \sigma_i \, u_i^\top \Delta W v_i$$&lt;/code&gt;&lt;/p&gt;&#xA;&lt;p&gt;Since &lt;code&gt;$\|u_i\|_2 = \|v_i\|_2 = 1$&lt;/code&gt;, Cauchy-Schwarz and the definition of &lt;code&gt;$\sigma_1(\Delta W)$&lt;/code&gt; bound every term &lt;code&gt;$i \in \{1, \dots, r\}$&lt;/code&gt;:&lt;/p&gt;&#xA;&lt;p&gt;&lt;code&gt;$$|u_i^\top \Delta W v_i| \le \|u_i\|_2 \, \|\Delta W v_i\|_2 \le \sigma_1(\Delta W) \le \eta \sqrt{\frac{d_{\mathrm{out}}}{d_{\mathrm{in}}}}$$&lt;/code&gt;&lt;/p&gt;&#xA;&lt;p&gt;Because &lt;code&gt;$\sigma_i &amp;gt; 0$&lt;/code&gt;, summing over &lt;code&gt;$i$&lt;/code&gt; yields a tight lower bound on the objective:&lt;/p&gt;&#xA;&lt;p&gt;&lt;code&gt;$$\langle \tilde{M}, \Delta W \rangle_F = \sum_{i=1}^{r} \sigma_i \, u_i^\top \Delta W v_i \ge -\eta \sqrt{\frac{d_{\mathrm{out}}}{d_{\mathrm{in}}}} \sum_{i=1}^{r} \sigma_i$$&lt;/code&gt;&lt;/p&gt;&#xA;&lt;p&gt;When is equality achieved? If and only if &lt;code&gt;$u_i^\top \Delta W v_i = -\eta \sqrt{d_{\mathrm{out}} / d_{\mathrm{in}}}$&lt;/code&gt; holds &lt;strong&gt;simultaneously for every active singular direction &lt;code&gt;$i = 1, \dots, r$&lt;/code&gt;&lt;/strong&gt;. Substituting the semi-orthogonal candidate&lt;/p&gt;&#xA;&lt;p&gt;&lt;code&gt;$$\Delta W^* = -\eta \sqrt{\frac{d_{\mathrm{out}}}{d_{\mathrm{in}}}} \, U V^\top$$&lt;/code&gt;&lt;/p&gt;&#xA;&lt;p&gt;verifies feasibility (&lt;code&gt;$\sigma_1(\Delta W^*) = \eta \sqrt{d_{\mathrm{out}} / d_{\mathrm{in}}}$&lt;/code&gt;) and attains the lower bound identically: &lt;code&gt;$u_i^\top \Delta W^* v_i = -\eta \sqrt{d_{\mathrm{out}} / d_{\mathrm{in}}} \, u_i^\top \left(\sum_{k=1}^r u_k v_k^\top\right) v_i = -\eta \sqrt{d_{\mathrm{out}} / d_{\mathrm{in}}}$&lt;/code&gt; (unique whenever &lt;code&gt;$r = \min(d_{\mathrm{out}}, d_{\mathrm{in}})$&lt;/code&gt;).&lt;/p&gt;&#xA;&lt;p&gt;That is the geometric core of &lt;strong&gt;Muon&lt;/strong&gt;: a Frobenius ball steps proportionally to raw skewed singular values, an entrywise &lt;code&gt;$\ell_\infty$&lt;/code&gt; cube equalizes isolated matrix cells, whereas the &lt;code&gt;$\mathrm{RMS} \to \mathrm{RMS}$&lt;/code&gt; operator ball &lt;strong&gt;advances all &lt;code&gt;$r$&lt;/code&gt; orthogonal feature subspaces at the exact same speed&lt;/strong&gt;.&lt;/p&gt;&#xA;&lt;figure class=&#34;diagram&#34; style=&#34;--h:228px;--hn:469px&#34;&gt;&lt;figcaption&gt;Geometric Comparison of Steepest Descent Under Three Matrix Norm Balls&lt;/figcaption&gt;&lt;p&gt;&lt;a href=&#34;https://mizore.blog/en/posts/from-transformer-matrices-to-muon/&#34;&gt;(See the figure in the post.)&lt;/a&gt;&lt;/p&gt;&lt;p class=&#34;figure-note&#34;&gt;Under the Frobenius ball, updates concentrate along the top singular direction; under the entrywise &lt;code&gt;$\ell_\infty$&lt;/code&gt; cube, cell magnitudes equalize without fixing low-rank skew; under the operator spectral norm, all nonzero singular values map to &lt;code&gt;$1$&lt;/code&gt;.&lt;/p&gt;&lt;/figure&gt;&#xA;&lt;h3 id=&#34;44-deriving-the-dual-optimizer-parameter-routing-rule-from-induced-norms&#34;&gt;4.4 Deriving the Dual-Optimizer Parameter Routing Rule from Induced Norms&lt;/h3&gt;&#xA;&lt;p&gt;Every production &lt;code&gt;Muon&lt;/code&gt; recipe follows a strict parameter split: internal 2D hidden projections (&lt;code&gt;W_q, W_k, W_v, W_o, W_up, W_down&lt;/code&gt;) go to &lt;code&gt;Muon&lt;/code&gt;, while boundary embeddings (&lt;code&gt;tok_emb, pos_emb&lt;/code&gt;), the output &lt;code&gt;lm_head&lt;/code&gt;, and 1D &lt;code&gt;RMSNorm&lt;/code&gt; gains stay on &lt;code&gt;AdamW&lt;/code&gt;&lt;sup class=&#34;cite&#34;&gt;&lt;a id=&#34;cite-jordan2024-2&#34; href=&#34;#ref-jordan2024&#34;&gt;[4]&lt;/a&gt;&lt;/sup&gt;&lt;sup class=&#34;cite&#34;&gt;&lt;a id=&#34;cite-liu2025-2&#34; href=&#34;#ref-liu2025&#34;&gt;[5]&lt;/a&gt;&lt;/sup&gt;.&lt;/p&gt;&#xA;&lt;p&gt;Why shouldn&#39;t &lt;code&gt;$E_{\mathrm{tok}}$&lt;/code&gt; and &lt;code&gt;$W_{\mathrm{head}}$&lt;/code&gt;—which are also 2D matrices—be globally orthogonalized? Checking the &lt;strong&gt;induced norms of their own input and output spaces&lt;/strong&gt; gives the answer directly&lt;sup class=&#34;cite&#34;&gt;&lt;a id=&#34;cite-bernstein2024-4&#34; href=&#34;#ref-bernstein2024&#34;&gt;[12]&lt;/a&gt;&lt;/sup&gt;:&lt;/p&gt;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;&lt;strong&gt;Token embedding table &lt;code&gt;$E_{\mathrm{tok}} \in \mathbb{R}^{V \times D}$&lt;/code&gt; (&lt;code&gt;$\ell_1 \to \mathrm{RMS}$&lt;/code&gt;)&lt;/strong&gt;: as shown in Section 1.1, the input is a one-hot vector &lt;code&gt;$u \in \mathbb{R}^V$&lt;/code&gt; naturally measured in &lt;code&gt;$\ell_1$&lt;/code&gt; norm &lt;code&gt;$\|u\|_1 = 1$&lt;/code&gt;, while the output enters the residual stream measured in &lt;code&gt;$\|\cdot\|_{\mathrm{RMS}}$&lt;/code&gt;. Because a convex function over the &lt;code&gt;$\ell_1$&lt;/code&gt; polytope attains its maximum at one of the &lt;code&gt;$V$&lt;/code&gt; extreme vertices &lt;code&gt;$u = e_v$&lt;/code&gt;:&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&lt;p&gt;&lt;code&gt;$$\|\Delta E_{\mathrm{tok}}^\top\|_{\ell_1 \to \mathrm{RMS}} = \max_{\|u\|_1 = 1} \|\Delta E_{\mathrm{tok}}^\top u\|_{\mathrm{RMS}} = \max_{v \in \{0, \dots, V-1\}} \|\Delta E_{\mathrm{tok}}[v, :]\|_{\mathrm{RMS}}$$&lt;/code&gt;&lt;/p&gt;&#xA;&lt;p&gt;This norm takes an independent maximum over vocabulary rows—&lt;strong&gt;vocabulary rows are geometrically decoupled&lt;/strong&gt; (the exact &lt;code&gt;$\ell_1 \to \mathrm{RMS}$&lt;/code&gt; steepest step normalizes each active row independently rather than orthogonalizing across tokens). Furthermore, a mini-batch activates at most &lt;code&gt;$B \times T$&lt;/code&gt; rows while most rows are zero; global orthogonalization would mix frequent and rare token subspaces.&#xA;2. &lt;strong&gt;Output LM head &lt;code&gt;$W_{\mathrm{head}} \in \mathbb{R}^{V \times D}$&lt;/code&gt; (&lt;code&gt;$\mathrm{RMS} \to \ell_\infty$&lt;/code&gt;)&lt;/strong&gt;: taking a unit-RMS hidden vector &lt;code&gt;$h \in \mathbb{R}^D$&lt;/code&gt; to logits &lt;code&gt;$z = W_{\mathrm{head}} h \in \mathbb{R}^V$&lt;/code&gt;, Softmax shifts are controlled by &lt;code&gt;$\max_v |z_v| = \|z\|_\infty$&lt;/code&gt;. Its induced norm &lt;code&gt;$\|\Delta W_{\mathrm{head}}\|_{\mathrm{RMS} \to \ell_\infty} = \max_v \sqrt{D}\,\|\Delta W_{\mathrm{head}}[v, :]\|_2$&lt;/code&gt; again decouples row by row across the vocabulary. Routing &lt;code&gt;tok_emb&lt;/code&gt; and &lt;code&gt;lm_head&lt;/code&gt; to &lt;code&gt;AdamW&lt;/code&gt; respects row-wise decoupling while adapting per-token logit scales&lt;sup class=&#34;cite&#34;&gt;&lt;a id=&#34;cite-jordan2024-3&#34; href=&#34;#ref-jordan2024&#34;&gt;[4]&lt;/a&gt;&lt;/sup&gt;&lt;sup class=&#34;cite&#34;&gt;&lt;a id=&#34;cite-liu2025-3&#34; href=&#34;#ref-liu2025&#34;&gt;[5]&lt;/a&gt;&lt;/sup&gt;.&#xA;3. &lt;strong&gt;1D &lt;code&gt;RMSNorm&lt;/code&gt; vector &lt;code&gt;$\gamma \in \mathbb{R}^D$&lt;/code&gt;&lt;/strong&gt;: viewed as a &lt;code&gt;$D \times 1$&lt;/code&gt; matrix, its rank is at most &lt;code&gt;$\min(D, 1) = 1$&lt;/code&gt; with a single singular value &lt;code&gt;$\sigma_1 = \|\gamma\|_2$&lt;/code&gt;, so no inter-direction skew exists; orthogonalizing it would collapse per-channel gains into a unit vector.&lt;/p&gt;&#xA;&lt;figure class=&#34;diagram&#34; style=&#34;--h:218px;--hn:374px&#34;&gt;&lt;figcaption&gt;Dual-Optimizer Parameter Routing Dictated by Input-Output Space Norms&lt;/figcaption&gt;&lt;p&gt;&lt;a href=&#34;https://mizore.blog/en/posts/from-transformer-matrices-to-muon/&#34;&gt;(See the figure in the post.)&lt;/a&gt;&lt;/p&gt;&lt;p class=&#34;figure-note&#34;&gt;Only 2D linear operators mapping continuous hidden RMS spaces to RMS spaces (&lt;code&gt;$\mathrm{RMS} \to \mathrm{RMS}$&lt;/code&gt;) call for spectral orthogonalization; row-decoupled vocabulary boundaries and 1D gains belong to AdamW.&lt;/p&gt;&lt;/figure&gt;&#xA;&lt;hr&gt;&#xA;&lt;h2 id=&#34;5-odd-degree-newton-schulz-iteration-and-scalable-rms-alignment&#34;&gt;5. Odd-Degree Newton-Schulz Iteration and Scalable RMS Alignment&lt;/h2&gt;&#xA;&lt;p&gt;Theory asks for &lt;code&gt;$O_t = U V^\top$&lt;/code&gt;, yet calling exact &lt;code&gt;torch.linalg.svd&lt;/code&gt; on hundreds of &lt;code&gt;$4096 \times 4096$&lt;/code&gt; matrices every training step would stall GPU pipelines: exact SVD relies on sequential bidiagonalization and &lt;code&gt;float32&lt;/code&gt; Givens sweeps that cannot run on half-precision Tensor Cores.&lt;/p&gt;&#xA;&lt;p&gt;In October 2024, Keller Jordan, Bernstein, and collaborators introduced &lt;strong&gt;Muon (MomentUm Orthogonalized by Newton-Schulz)&lt;/strong&gt;&lt;sup class=&#34;cite&#34;&gt;&lt;a id=&#34;cite-jordan2024-4&#34; href=&#34;#ref-jordan2024&#34;&gt;[4]&lt;/a&gt;&lt;/sup&gt;, replacing exact SVD with &lt;strong&gt;five &lt;code&gt;bfloat16&lt;/code&gt; odd-degree matrix polynomial steps&lt;/strong&gt;.&lt;/p&gt;&#xA;&lt;h3 id=&#34;51-why-odd-matrix-polynomials-preserve-left-and-right-singular-vectors&#34;&gt;5.1 Why Odd Matrix Polynomials Preserve Left and Right Singular Vectors&lt;/h3&gt;&#xA;&lt;p&gt;Let &lt;code&gt;$X \in \mathbb{R}^{A \times B}$&lt;/code&gt; have reduced SVD &lt;code&gt;$X = U \Sigma V^\top$&lt;/code&gt;. Inspect alternating odd products of &lt;code&gt;$X$&lt;/code&gt; and &lt;code&gt;$X^\top$&lt;/code&gt;:&lt;/p&gt;&#xA;&lt;p&gt;&lt;code&gt;$$\begin{aligned} (X X^\top) X &amp;amp;= (U \Sigma V^\top)(V \Sigma U^\top)(U \Sigma V^\top) = U \Sigma (V^\top V) \Sigma (U^\top U) \Sigma V^\top = U \Sigma^3 V^\top \\ (X X^\top)^2 X &amp;amp;= (U \Sigma^2 U^\top)^2 (U \Sigma V^\top) = U \Sigma^5 V^\top \end{aligned}$$&lt;/code&gt;&lt;/p&gt;&#xA;&lt;p&gt;(Even powers such as &lt;code&gt;$X X^\top = U \Sigma^2 U^\top$&lt;/code&gt; annihilate &lt;code&gt;$V^\top$&lt;/code&gt; and change shape to &lt;code&gt;$A \times A$&lt;/code&gt;; only odd products &lt;code&gt;$(X X^\top)^m X$&lt;/code&gt; preserve the bilateral basis &lt;code&gt;$U \cdot (\dots) \cdot V^\top$&lt;/code&gt;.)&lt;/p&gt;&#xA;&lt;p&gt;By linearity, for any odd quintic &lt;code&gt;$\varphi(\sigma) = a \sigma + b \sigma^3 + c \sigma^5$&lt;/code&gt;, setting &lt;code&gt;$A_k = X_k X_k^\top$&lt;/code&gt; and iterating pure matrix multiplications&lt;/p&gt;&#xA;&lt;p&gt;&lt;code&gt;$$X_{k+1} = a X_k + (b A_k + c A_k^2) X_k$$&lt;/code&gt;&lt;/p&gt;&#xA;&lt;p&gt;holds &lt;code&gt;$U$&lt;/code&gt; and &lt;code&gt;$V^\top$&lt;/code&gt; fixed while applying the scalar map &lt;code&gt;$\varphi$&lt;/code&gt; independently to every singular value on the diagonal:&lt;/p&gt;&#xA;&lt;p&gt;&lt;code&gt;$$X_{k+1} = U \varphi(\Sigma_k) V^\top, \qquad \sigma_{k+1, i} = \varphi(\sigma_{k, i}) = a \sigma_{k, i} + b \sigma_{k, i}^3 + c \sigma_{k, i}^5$$&lt;/code&gt;&lt;/p&gt;&#xA;&lt;p&gt;Two preprocessing steps precede &lt;code&gt;$k = 0$&lt;/code&gt;:&lt;/p&gt;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;&lt;strong&gt;Frobenius pre-normalization into &lt;code&gt;$[0, 1]$&lt;/code&gt;&lt;/strong&gt;: because &lt;code&gt;$c \sigma^5$&lt;/code&gt; diverges rapidly for large &lt;code&gt;$\sigma$&lt;/code&gt;, all initial singular values must lie in &lt;code&gt;$[0, 1]$&lt;/code&gt;. Using &lt;code&gt;$\|\tilde{M}_t\|_F^2 = \sum_{j=1}^r \sigma_j^2 \ge \sigma_1^2$&lt;/code&gt;, setting&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&lt;p&gt;&lt;code&gt;$$X_0 = \frac{\tilde{M}_t}{\|\tilde{M}_t\|_F + \epsilon}$$&lt;/code&gt;&lt;/p&gt;&#xA;&lt;p&gt;guarantees &lt;code&gt;$0 \le \sigma_{0, i} \le 1$&lt;/code&gt; without estimating &lt;code&gt;$\sigma_1$&lt;/code&gt;. Notice also that any positive constant &lt;code&gt;$c &amp;gt; 0$&lt;/code&gt; cancels out identically in &lt;code&gt;$\frac{c \tilde{M}_t}{\|c \tilde{M}_t\|_F}$&lt;/code&gt;, which is why &lt;code&gt;Muon&lt;/code&gt;&#39;s momentum &lt;code&gt;$M_t = \mu M_{t-1} + G_t$&lt;/code&gt; needs neither a &lt;code&gt;$(1-\mu)$&lt;/code&gt; factor nor &lt;code&gt;Adam&lt;/code&gt;-style cold-start bias correction.&#xA;2. &lt;strong&gt;Tall-matrix transpose trick (&lt;code&gt;$A &amp;gt; B$&lt;/code&gt;)&lt;/strong&gt;: when rows exceed columns (e.g., &lt;code&gt;$W_{\mathrm{up}} \in \mathbb{R}^{256 \times 64}$&lt;/code&gt; with &lt;code&gt;$A = 4B$&lt;/code&gt;), forming &lt;code&gt;$A_k = X_k X_k^\top$&lt;/code&gt; builds a large &lt;code&gt;$A \times A$&lt;/code&gt; Gram matrix costing &lt;code&gt;$(2A^2 B + A^3)$&lt;/code&gt; MACs per step; transposing &lt;code&gt;$X_0$&lt;/code&gt; first into a &lt;code&gt;$B \times A$&lt;/code&gt; wide matrix shrinks &lt;code&gt;$A_k$&lt;/code&gt; to &lt;code&gt;$B \times B$&lt;/code&gt;, cutting per-step MACs to &lt;code&gt;$(2AB^2 + B^3)$&lt;/code&gt;—from &lt;code&gt;$96 B^3$&lt;/code&gt; down to &lt;code&gt;$9 B^3$&lt;/code&gt; at &lt;code&gt;$A = 4B$&lt;/code&gt; (&amp;gt;90% compute saved). Since &lt;code&gt;$\bigl(a X^\top + b (X^\top X) X^\top + c (X^\top X)^2 X^\top\bigr)^\top = a X + b (X X^\top) X + c (X X^\top)^2 X$&lt;/code&gt;, transposing back at the end is bit-exact.&lt;/p&gt;&#xA;&lt;h3 id=&#34;52-classical-newton-schulz-vs-muons-minimax-coefficients&#34;&gt;5.2 Classical Newton-Schulz vs. &lt;code&gt;Muon&lt;/code&gt;&#39;s Minimax Coefficients&lt;/h3&gt;&#xA;&lt;p&gt;How are &lt;code&gt;$(a, b, c)$&lt;/code&gt; chosen? Start with &lt;strong&gt;classical Newton-Schulz&lt;/strong&gt; from numerical linear algebra.&lt;/p&gt;&#xA;&lt;p&gt;Applying Newton&#39;s method directly to &lt;code&gt;$g(s) = s^2 - 1 = 0$&lt;/code&gt; gives &lt;code&gt;$s_{k+1} = \frac{1}{2}(s_k + s_k^{-1})$&lt;/code&gt;, which still requires matrix inversion &lt;code&gt;$X_k^{-1}$&lt;/code&gt;. Applying Newton&#39;s tangent update instead to &lt;code&gt;$f(s) = s^{-2} - 1 = 0$&lt;/code&gt; puts &lt;code&gt;$f&amp;#39;(s) = -2s^{-3}$&lt;/code&gt; in the denominator, flipping negative exponents into pure odd positive powers:&lt;/p&gt;&#xA;&lt;p&gt;&lt;code&gt;$$s_{k+1} = s_k - \frac{f(s_k)}{f&amp;#39;(s_k)} = s_k - \frac{s_k^{-2} - 1}{-2 s_k^{-3}} = \frac{3}{2}s_k - \frac{1}{2}s_k^3$$&lt;/code&gt;&lt;/p&gt;&#xA;&lt;p&gt;That is the classical cubic &lt;code&gt;$(a, b) = (1.5, -0.5)$&lt;/code&gt;. Extending to a quintic &lt;code&gt;$\varphi_{\mathrm{classic}}(\sigma) = a\sigma + b\sigma^3 + c\sigma^5$&lt;/code&gt; with third-order local convergence at the fixed point &lt;code&gt;$\sigma = 1$&lt;/code&gt; (&lt;code&gt;$\varphi(1) = 1,\; \varphi&amp;#39;(1) = 0,\; \varphi&amp;#39;&amp;#39;(1) = 0$&lt;/code&gt;) solves the linear system:&lt;/p&gt;&#xA;&lt;p&gt;&lt;code&gt;$$\begin{cases} a + b + c = 1 \\ a + 3b + 5c = 0 \\ 6b + 20c = 0 \end{cases} \quad \Longrightarrow \quad (a, b, c)_{\mathrm{classic}} = \left(\frac{15}{8},\; -\frac{10}{8},\; \frac{3}{8}\right) = (1.875,\; -1.25,\; 0.375)$$&lt;/code&gt;&lt;/p&gt;&#xA;&lt;p&gt;In neural network training, however, dividing a &lt;code&gt;$4096 \times 4096$&lt;/code&gt; skewed gradient by &lt;code&gt;$\|\tilde{M}_t\|_F$&lt;/code&gt; pushes many tail singular values down into &lt;code&gt;$\sigma_0 \in [10^{-3}, 10^{-2}]$&lt;/code&gt;. Near &lt;code&gt;$\sigma = 0$&lt;/code&gt;, &lt;code&gt;$\sigma^3$&lt;/code&gt; and &lt;code&gt;$\sigma^5$&lt;/code&gt; are negligible, so per-step amplification equals the origin slope &lt;code&gt;$\varphi&amp;#39;(0) = a$&lt;/code&gt;. Five steps of &lt;code&gt;$a = 1.875$&lt;/code&gt; amplify small singular values by at most &lt;code&gt;$1.875^5 \approx 23.2\times$&lt;/code&gt;—lifting &lt;code&gt;$\sigma_0 = 0.01$&lt;/code&gt; only to &lt;code&gt;$0.21$&lt;/code&gt;.&lt;/p&gt;&#xA;&lt;p&gt;Jordan et al. observed that under noisy &lt;code&gt;bfloat16&lt;/code&gt; gradients (7 mantissa bits), converging to &lt;code&gt;$1.000000$&lt;/code&gt; is pointless; what matters is &lt;strong&gt;maximizing the origin slope &lt;code&gt;$a$&lt;/code&gt; within a fixed 5-step budget without diverging on &lt;code&gt;$[0, 1]$&lt;/code&gt;&lt;/strong&gt;. Relaxing &lt;code&gt;$\varphi(1) = 1$&lt;/code&gt; so &lt;code&gt;$\varphi^{(5)}(\sigma)$&lt;/code&gt; equiripples inside a narrow band &lt;code&gt;$[1 - \delta, 1 + \delta]$&lt;/code&gt; around &lt;code&gt;$1$&lt;/code&gt; yields &lt;code&gt;Muon&lt;/code&gt;&#39;s minimax-tuned coefficients&lt;sup class=&#34;cite&#34;&gt;&lt;a id=&#34;cite-jordan2024-5&#34; href=&#34;#ref-jordan2024&#34;&gt;[4]&lt;/a&gt;&lt;/sup&gt;:&lt;/p&gt;&#xA;&lt;p&gt;&lt;code&gt;$$(a, b, c)_{\mathrm{Muon}} = (3.4445,\; -4.7750,\; 2.0315)$$&lt;/code&gt;&lt;/p&gt;&#xA;&lt;p&gt;Checking two numbers confirms the tradeoff:&lt;/p&gt;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;&lt;strong&gt;Small-singular-value amplification&lt;/strong&gt;: raising the origin slope from &lt;code&gt;$1.875$&lt;/code&gt; to &lt;code&gt;$3.4445$&lt;/code&gt; boosts 5-step linear gain to &lt;code&gt;$3.4445^5 \approx 484.4\times$&lt;/code&gt; (&lt;code&gt;$20.9\times$&lt;/code&gt; stronger than classical), lifting &lt;code&gt;$\sigma_0 = 0.01$&lt;/code&gt; right up to &lt;code&gt;$\varphi^{(5)}(0.01) \approx 0.70$&lt;/code&gt;;&lt;/li&gt;&#xA;&lt;li&gt;&lt;strong&gt;Why &lt;code&gt;$\varphi(1) = 3.4445 - 4.7750 + 2.0315 = 0.7010 \neq 1$&lt;/code&gt;&lt;/strong&gt;: this is not a typo, but the deliberate trough of the equiripple band—every &lt;code&gt;$\sigma_0 \in [0.01, 1.0]$&lt;/code&gt; lands inside &lt;code&gt;$[0.68, 1.13]$&lt;/code&gt; after 5 compositions (while tiny values in &lt;code&gt;$(0, 0.01)$&lt;/code&gt; climbing through the peak of &lt;code&gt;$\varphi$&lt;/code&gt; reach at most &lt;code&gt;$\max \varphi \approx 1.20$&lt;/code&gt;).&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&lt;p&gt;To demystify how pure matrix multiplications can uncover a buried singular direction without ever calling SVD, let us unfold all 5 iterations on a concrete &lt;code&gt;$2 \times 2$&lt;/code&gt; skewed momentum matrix:&lt;/p&gt;&#xA;&lt;p&gt;&lt;code&gt;$$\tilde{M} = \underbrace{\begin{bmatrix} 10 &amp;amp; 10 \\ 10 &amp;amp; 10 \end{bmatrix}}_{\text{dominant mode }\sigma_1 = 20.0} + \underbrace{\begin{bmatrix} -0.1 &amp;amp; +0.1 \\ +0.1 &amp;amp; -0.1 \end{bmatrix}}_{\text{weak orthogonal mode }\sigma_2 = 0.2} = \begin{bmatrix} 9.9 &amp;amp; 10.1 \\ 10.1 &amp;amp; 9.9 \end{bmatrix}$$&lt;/code&gt;&lt;/p&gt;&#xA;&lt;p&gt;At a glance, all four entries sit right around &lt;code&gt;$+10$&lt;/code&gt;, differing by just &lt;code&gt;$0.2$&lt;/code&gt; between diagonal and anti-diagonal. Taking entrywise signs (the memoryless &lt;code&gt;Adam&lt;/code&gt; limit) sees four positive numbers and outputs the rank-1 all-ones matrix &lt;code&gt;$\mathrm{sign}(\tilde{M}) = \begin{bsmallmatrix} 1 &amp;amp; 1 \\ 1 &amp;amp; 1 \end{bsmallmatrix}$&lt;/code&gt; (&lt;code&gt;$\sigma = [2, 0]$&lt;/code&gt;), destroying the anti-diagonal subspace; whereas the exact orthogonal polar factor is the permutation matrix &lt;code&gt;$U V^\top = \frac{1}{2}\begin{bsmallmatrix} 1 &amp;amp; 1 \\ 1 &amp;amp; 1 \end{bsmallmatrix} + \frac{1}{2}\begin{bsmallmatrix} -1 &amp;amp; 1 \\ 1 &amp;amp; -1 \end{bsmallmatrix} = \begin{bsmallmatrix} 0 &amp;amp; 1 \\ 1 &amp;amp; 0 \end{bsmallmatrix}$&lt;/code&gt; (&lt;code&gt;$\sigma = [1, 1]$&lt;/code&gt;).&lt;/p&gt;&#xA;&lt;p&gt;Now run &lt;code&gt;Muon&lt;/code&gt;&#39;s pre-normalization and quintic recursion &lt;code&gt;$X_{k+1} = 3.4445 X_k + (-4.7750 A_k + 2.0315 A_k^2) X_k$&lt;/code&gt; (&lt;code&gt;$A_k = X_k X_k^\top$&lt;/code&gt;) with zero SVD:&lt;/p&gt;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;&lt;strong&gt;Step 0 pre-normalization&lt;/strong&gt;: &lt;code&gt;$\|\tilde{M}\|_F = \sqrt{9.9^2 + 10.1^2 + 10.1^2 + 9.9^2} = \sqrt{400.04} \approx 20.001$&lt;/code&gt;, giving &lt;code&gt;$X_0 = \begin{bsmallmatrix} 0.495 &amp;amp; 0.505 \\ 0.505 &amp;amp; 0.495 \end{bsmallmatrix}$&lt;/code&gt; with singular values &lt;code&gt;$(1.000, 0.010)$&lt;/code&gt;.&lt;/li&gt;&#xA;&lt;li&gt;&lt;strong&gt;Why step 1 separates &lt;code&gt;$0.495$&lt;/code&gt; from &lt;code&gt;$0.505$&lt;/code&gt;&lt;/strong&gt;: Gram matrix &lt;code&gt;$A_0 = X_0 X_0^\top \approx \begin{bsmallmatrix} 0.50005 &amp;amp; 0.49995 \\ 0.49995 &amp;amp; 0.50005 \end{bsmallmatrix}$&lt;/code&gt; has eigenvalue &lt;code&gt;$1^2 = 1$&lt;/code&gt; along the common-mode vector &lt;code&gt;$\begin{bsmallmatrix} 1 \\ 1 \end{bsmallmatrix}$&lt;/code&gt;, so the negative cubic term &lt;code&gt;$-4.7750 A_0 X_0$&lt;/code&gt; strongly damps the dominant mode down to &lt;code&gt;$3.4445 - 4.7750 + 2.0315 = 0.701$&lt;/code&gt;. Along the differential vector &lt;code&gt;$\begin{bsmallmatrix} -1 \\ 1 \end{bsmallmatrix}$&lt;/code&gt;, however, &lt;code&gt;$A_0$&lt;/code&gt; has eigenvalue &lt;code&gt;$0.01^2 = 0.0001$&lt;/code&gt;, so cubic and quintic terms virtually vanish while linear term &lt;code&gt;$3.4445 X_0$&lt;/code&gt; amplifies the anti-diagonal gap by &lt;code&gt;$3.4445\times$&lt;/code&gt;, yielding &lt;code&gt;$X_1 = \begin{bsmallmatrix} 0.333 &amp;amp; 0.368 \\ 0.368 &amp;amp; 0.333 \end{bsmallmatrix}$&lt;/code&gt; (&lt;code&gt;$\sigma = [0.701, 0.034]$&lt;/code&gt;).&lt;/li&gt;&#xA;&lt;li&gt;&lt;strong&gt;Unfolding all five matrix-multiply iterations (&lt;code&gt;$k = 1 \dots 5$&lt;/code&gt;)&lt;/strong&gt;:&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&lt;p&gt;&lt;code&gt;$$\begin{aligned} X_0 &amp;amp;= \begin{bmatrix} 0.495 &amp;amp; 0.505 \\ 0.505 &amp;amp; 0.495 \end{bmatrix} \xrightarrow{k=1} X_1 = \begin{bmatrix} 0.333 &amp;amp; 0.368 \\ 0.368 &amp;amp; 0.333 \end{bmatrix} \xrightarrow{k=2} X_2 = \begin{bmatrix} 0.498 &amp;amp; 0.616 \\ 0.616 &amp;amp; 0.498 \end{bmatrix} \\[6pt] &amp;amp;\xrightarrow{k=3} X_3 = \begin{bmatrix} 0.160 &amp;amp; 0.560 \\ 0.560 &amp;amp; 0.160 \end{bmatrix} \xrightarrow{k=4} X_4 = \begin{bmatrix} -0.002 &amp;amp; 1.092 \\ 1.092 &amp;amp; -0.002 \end{bmatrix} \xrightarrow{k=5} X_5 = \begin{bmatrix} -0.001 &amp;amp; 0.698 \\ 0.698 &amp;amp; -0.001 \end{bmatrix} \end{aligned}$$&lt;/code&gt;&lt;/p&gt;&#xA;&lt;p&gt;In five plain matrix multiplications, &lt;code&gt;$\begin{bsmallmatrix} 0.495 &amp;amp; 0.505 \\ 0.505 &amp;amp; 0.495 \end{bsmallmatrix}$&lt;/code&gt; cancels its diagonal common-mode background down to &lt;code&gt;$-0.001$&lt;/code&gt; and extracts the orthogonal swap operator &lt;code&gt;$\approx 0.70\begin{bsmallmatrix} 0 &amp;amp; 1 \\ 1 &amp;amp; 0 \end{bsmallmatrix}$&lt;/code&gt;, flattening the singular-value ratio from &lt;code&gt;$100:1$&lt;/code&gt; to &lt;code&gt;$(0.699,\; 0.697)$&lt;/code&gt;.&lt;/p&gt;&#xA;&lt;figure class=&#34;diagram&#34; style=&#34;--h:446px;--hn:576px&#34;&gt;&lt;figcaption&gt;Unfolded Numeric Walkthrough: Cell-by-Cell Evolution of a 100:1 Skewed Matrix Under SGD, Sign/Adam, and 5-Step Newton-Schulz&lt;/figcaption&gt;&lt;p&gt;&lt;a href=&#34;https://mizore.blog/en/posts/from-transformer-matrices-to-muon/&#34;&gt;(See the figure in the post.)&lt;/a&gt;&lt;/p&gt;&lt;p class=&#34;figure-note&#34;&gt;Input &lt;code&gt;$\tilde{M} = \begin{bsmallmatrix}9.9 &amp;amp; 10.1\\10.1 &amp;amp; 9.9\end{bsmallmatrix}$&lt;/code&gt; combines dominant &lt;code&gt;$\sigma_1=20.0$&lt;/code&gt; with tail &lt;code&gt;$\sigma_2=0.2$&lt;/code&gt;. Entrywise sign collapses to a rank-1 all-ones matrix because all 4 entries are positive; 5 Newton-Schulz polynomial steps isolate the hidden orthogonal swap matrix via pure matrix multiplications.&lt;/p&gt;&lt;/figure&gt;&#xA;&lt;p&gt;The left panel below plots &lt;code&gt;$\varphi^{(k)}(\sigma)$&lt;/code&gt; at &lt;code&gt;$k = 1, 3, 5$&lt;/code&gt;; the right panel measures all 64 singular values of Layer 1&#39;s &lt;code&gt;W_q&lt;/code&gt; momentum at step 25 of our 2-layer Transformer. Raw momentum spans &lt;code&gt;$13{,}669\times$&lt;/code&gt;, and even &lt;code&gt;AdamW&lt;/code&gt;&#39;s entrywise update still decays by over &lt;code&gt;$2{,}000\times$&lt;/code&gt;—whereas 5 Newton-Schulz steps place the top 53 singular values squarely inside &lt;code&gt;$[0.68, 1.20]$&lt;/code&gt;.&lt;/p&gt;&#xA;&lt;figure class=&#34;plotfig&#34;&gt;&lt;figcaption&gt;Newton-Schulz Quintic Composition Curves and Measured Transformer &lt;code&gt;$W_q$&lt;/code&gt; Singular Spectrum&lt;/figcaption&gt;&lt;p&gt;&lt;a href=&#34;https://mizore.blog/en/posts/from-transformer-matrices-to-muon/&#34;&gt;(See the figure in the post.)&lt;/a&gt;&lt;/p&gt;&lt;p class=&#34;figure-note&#34;&gt;Left: &lt;code&gt;$\varphi(\sigma) = 3.4445\sigma - 4.7750\sigma^3 + 2.0315\sigma^5$&lt;/code&gt; composed 1, 3, and 5 times. Right: all 64 singular values of Layer-1 &lt;code&gt;$W_q$&lt;/code&gt; at step 25 of a 2-layer Mini-Transformer (&lt;code&gt;$D=64$&lt;/code&gt;; raw momentum and AdamW updates normalized by &lt;code&gt;$\sigma_1$&lt;/code&gt; to compare spectral shape).&lt;/p&gt;&lt;/figure&gt;&#xA;&lt;h3 id=&#34;53-moonshot-ais-scaling-improvements-update-rms-alignment-and-decoupled-weight-decay&#34;&gt;5.3 Moonshot AI&#39;s Scaling Improvements: Update RMS Alignment and Decoupled Weight Decay&lt;/h3&gt;&#xA;&lt;p&gt;Scaling &lt;code&gt;Muon&lt;/code&gt; from small benchmarks to multi-billion-parameter LLM pretraining required solving two hyperparameter-transfer bottlenecks, derived by Moonshot AI (Liu, Su et al., 2025) in &lt;em&gt;Muon is Scalable for LLM Training&lt;/em&gt;&lt;sup class=&#34;cite&#34;&gt;&lt;a id=&#34;cite-liu2025-4&#34; href=&#34;#ref-liu2025&#34;&gt;[5]&lt;/a&gt;&lt;/sup&gt;.&lt;/p&gt;&#xA;&lt;p&gt;&lt;strong&gt;First: aligning entrywise update RMS across matrix shapes and with &lt;code&gt;AdamW&lt;/code&gt;.&lt;/strong&gt;&lt;/p&gt;&#xA;&lt;p&gt;Let &lt;code&gt;$O_t \in \mathbb{R}^{A \times B}$&lt;/code&gt; have rank &lt;code&gt;$r = \min(A, B)$&lt;/code&gt; with nonzero singular values near &lt;code&gt;$1$&lt;/code&gt;. Its squared Frobenius norm equals the sum of squared singular values:&lt;/p&gt;&#xA;&lt;p&gt;&lt;code&gt;$$\|O_t\|_F^2 = \sum_{i=1}^{A} \sum_{j=1}^{B} O_{t, ij}^2 = \sum_{k=1}^{\min(A, B)} \sigma_k^2 \approx \min(A, B)$$&lt;/code&gt;&lt;/p&gt;&#xA;&lt;p&gt;Dividing across all &lt;code&gt;$A \cdot B$&lt;/code&gt; entries gives the per-element root-mean-square update magnitude:&lt;/p&gt;&#xA;&lt;p&gt;&lt;code&gt;$$\mathrm{RMS}(O_t) \triangleq \sqrt{\frac{1}{A B} \|O_t\|_F^2} \approx \sqrt{\frac{\min(A, B)}{A B}} = \frac{1}{\sqrt{\max(A, B)}}$$&lt;/code&gt;&lt;/p&gt;&#xA;&lt;p&gt;Compare this against earlier aspect-ratio factors: Section 4.3&#39;s induced norm gave &lt;code&gt;$\sqrt{A / B}$&lt;/code&gt; (entrywise RMS &lt;code&gt;$\sqrt{A}/B$&lt;/code&gt; when &lt;code&gt;$A &amp;lt; B$&lt;/code&gt;), which Keller Jordan clamped to &lt;code&gt;$\sqrt{\max(1, A/B)}$&lt;/code&gt; (entrywise RMS &lt;code&gt;$1/\sqrt{B}$&lt;/code&gt;). Under either formula, entrywise update RMS shrinks as &lt;code&gt;$1/\sqrt{d_{\mathrm{in}}}$&lt;/code&gt; whenever model width &lt;code&gt;$B = d_{\mathrm{in}}$&lt;/code&gt; grows—forcing separate learning-rate sweeps (e.g., &lt;code&gt;lr = 0.02&lt;/code&gt;) across widths and across attention, MLP, and MoE layers.&lt;/p&gt;&#xA;&lt;p&gt;What is the steady-state entrywise update RMS of &lt;code&gt;AdamW&lt;/code&gt;? Model coordinate gradients &lt;code&gt;$\{g_t\}$&lt;/code&gt; in late training as zero-mean i.i.d. random variables with variance &lt;code&gt;$\sigma^2$&lt;/code&gt; (&lt;code&gt;$\mathbb{E}[g_t] = 0,\; \mathbb{E}[g_t^2] = \sigma^2$&lt;/code&gt;). For large &lt;code&gt;$t$&lt;/code&gt;:&lt;/p&gt;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;&lt;code&gt;$\mathbb{E}[v_t] = (1 - \beta_2)\sum_{k=0}^\infty \beta_2^k \mathbb{E}[g_{t-k}^2] = \sigma^2$&lt;/code&gt;;&lt;/li&gt;&#xA;&lt;li&gt;Because cross-step terms &lt;code&gt;$\mathbb{E}[g_i g_j] = 0$&lt;/code&gt; vanish:&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&lt;p&gt;&lt;code&gt;$$\mathbb{E}[m_t^2] = (1 - \beta_1)^2 \sum_{k=0}^{\infty} \beta_1^{2k} \mathbb{E}[g_{t-k}^2] = \frac{(1 - \beta_1)^2}{1 - \beta_1^2} \sigma^2 = \frac{1 - \beta_1}{1 + \beta_1} \sigma^2$$&lt;/code&gt;&lt;/p&gt;&#xA;&lt;p&gt;With &lt;code&gt;$\beta_2$&lt;/code&gt; near &lt;code&gt;$1$&lt;/code&gt; concentrating &lt;code&gt;$v_t$&lt;/code&gt; tightly around &lt;code&gt;$\sigma^2$&lt;/code&gt;, the first-order ratio approximation &lt;code&gt;$\mathbb{E}[m_t^2 / v_t] \approx \mathbb{E}[m_t^2] / \mathbb{E}[v_t]$&lt;/code&gt; gives the dimensionless &lt;code&gt;AdamW&lt;/code&gt; step &lt;code&gt;$u_t = m_t / \sqrt{v_t}$&lt;/code&gt; an entrywise RMS of:&lt;/p&gt;&#xA;&lt;p&gt;&lt;code&gt;$$\mathrm{RMS}(u_t^{\mathrm{AdamW}}) \approx \sqrt{\frac{\mathbb{E}[m_t^2]}{\mathbb{E}[v_t]}} = \sqrt{\frac{1 - \beta_1}{1 + \beta_1}}$$&lt;/code&gt;&lt;/p&gt;&#xA;&lt;p&gt;At &lt;code&gt;$\beta_1 = 0.9$&lt;/code&gt;, &lt;code&gt;$\sqrt{0.1 / 1.9} \approx 0.229$&lt;/code&gt; (empirically &lt;code&gt;$0.2$&lt;/code&gt;–&lt;code&gt;$0.4$&lt;/code&gt; in real LLM runs with positive local gradient autocorrelation&lt;sup class=&#34;cite&#34;&gt;&lt;a id=&#34;cite-liu2025-5&#34; href=&#34;#ref-liu2025&#34;&gt;[5]&lt;/a&gt;&lt;/sup&gt;).&lt;/p&gt;&#xA;&lt;p&gt;Multiplying &lt;code&gt;$O_t$&lt;/code&gt; by &lt;code&gt;$0.2\sqrt{\max(A, B)}$&lt;/code&gt; cancels the &lt;code&gt;$1/\sqrt{\max(A, B)}$&lt;/code&gt; denominator and pins &lt;code&gt;Muon&lt;/code&gt;&#39;s entrywise update RMS right around &lt;code&gt;$0.2$&lt;/code&gt; across every matrix shape:&lt;/p&gt;&#xA;&lt;p&gt;&lt;code&gt;$$W_t = (1 - \eta \lambda) W_{t-1} - \eta \cdot 0.2\sqrt{\max(A, B)} \, O_t$$&lt;/code&gt;&lt;/p&gt;&#xA;&lt;p&gt;With this alignment, &lt;code&gt;Muon&lt;/code&gt; and boundary &lt;code&gt;AdamW&lt;/code&gt; &lt;strong&gt;share the exact same learning rate schedule &lt;code&gt;$\eta_t$&lt;/code&gt; and weight decay &lt;code&gt;$\lambda$&lt;/code&gt;&lt;/strong&gt; out of the box.&lt;/p&gt;&#xA;&lt;p&gt;&lt;strong&gt;Second: why long-horizon pretraining requires decoupled weight decay.&lt;/strong&gt;&lt;/p&gt;&#xA;&lt;p&gt;Without weight decay (&lt;code&gt;$\lambda = 0$&lt;/code&gt;), writing &lt;code&gt;$\Delta_t = \eta \cdot 0.2\sqrt{\max(A,B)}\,O_t$&lt;/code&gt;, the squared Frobenius norm evolves as:&lt;/p&gt;&#xA;&lt;p&gt;&lt;code&gt;$$\|W_t\|_F^2 = \|W_{t-1} - \Delta_t\|_F^2 = \|W_{t-1}\|_F^2 - 2\langle W_{t-1}, \Delta_t \rangle_F + \|\Delta_t\|_F^2$$&lt;/code&gt;&lt;/p&gt;&#xA;&lt;p&gt;Under noisy late-stage gradients nearly orthogonal to &lt;code&gt;$W_{t-1}$&lt;/code&gt;, the positive quadratic injection &lt;code&gt;$\|\Delta_t\|_F^2 \approx 0.04 \eta^2 A B$&lt;/code&gt; accumulates every step without any restoring force, causing &lt;code&gt;$\|W_t\|_F$&lt;/code&gt; to drift upward monotonically until attention logits saturate. Decoupled decay &lt;code&gt;$(1 - \eta \lambda)W_{t-1}$&lt;/code&gt; contributes &lt;code&gt;$-2\eta\lambda\|W_{t-1}\|_F^2$&lt;/code&gt; per step; balancing shrinkage against &lt;code&gt;$0.04 \eta^2 A B$&lt;/code&gt; stabilizes weights at the bounded equilibrium &lt;code&gt;$\mathrm{RMS}(W_{\mathrm{eq}}) \approx \sqrt{0.02 \eta / \lambda}$&lt;/code&gt;&lt;sup class=&#34;cite&#34;&gt;&lt;a id=&#34;cite-liu2025-6&#34; href=&#34;#ref-liu2025&#34;&gt;[5]&lt;/a&gt;&lt;/sup&gt;.&lt;/p&gt;&#xA;&lt;p&gt;The three controlled ablations below verify each claim: applying &lt;code&gt;Muon&lt;/code&gt; to embeddings and the LM head degrades validation loss; omitting weight decay causes &lt;code&gt;$\|W\|_F$&lt;/code&gt; to grow linearly; and &lt;code&gt;$0.2\sqrt{\max(A, B)}$&lt;/code&gt; holds entrywise update RMS steady at &lt;code&gt;$0.17$&lt;/code&gt;–&lt;code&gt;$0.19$&lt;/code&gt; from &lt;code&gt;$64 \times 64$&lt;/code&gt; up to &lt;code&gt;$2048 \times 512$&lt;/code&gt;.&lt;/p&gt;&#xA;&lt;figure class=&#34;plotfig&#34;&gt;&lt;figcaption&gt;Controlled Ablations: Parameter Routing, Decoupled Weight Decay, and Cross-Shape RMS Alignment&lt;/figcaption&gt;&lt;p&gt;&lt;a href=&#34;https://mizore.blog/en/posts/from-transformer-matrices-to-muon/&#34;&gt;(See the figure in the post.)&lt;/a&gt;&lt;/p&gt;&lt;p class=&#34;figure-note&#34;&gt;Left &amp;amp; center: 360 steps on a 2-layer Mini-Transformer. Right: measured entrywise RMS of Gaussian matrices after 5 Newton-Schulz steps across longer dimension &lt;code&gt;$A=\max(A,B)$&lt;/code&gt; (&lt;code&gt;$64\times 64$&lt;/code&gt; square, then &lt;code&gt;$4:1$&lt;/code&gt; aspect ratio from &lt;code&gt;$256\times 64$&lt;/code&gt; to &lt;code&gt;$2048\times 512$&lt;/code&gt;).&lt;/p&gt;&lt;/figure&gt;&#xA;&lt;hr&gt;&#xA;&lt;h2 id=&#34;6-roofline-arithmetic-intensity-and-four-generation-controlled-benchmark&#34;&gt;6. Roofline Arithmetic Intensity and Four-Generation Controlled Benchmark&lt;/h2&gt;&#xA;&lt;h3 id=&#34;61-why-five-extra-matrix-multiplications-barely-move-wall-clock-step-time&#34;&gt;6.1 Why Five Extra Matrix Multiplications Barely Move Wall-Clock Step Time&lt;/h3&gt;&#xA;&lt;p&gt;At first glance, running five matrix-multiplication iterations per weight layer sounds far more expensive than &lt;code&gt;AdamW&lt;/code&gt;&#39;s scalar arithmetic. A quick GPU &lt;strong&gt;Roofline&lt;/strong&gt; calculation—measuring arithmetic intensity in &lt;code&gt;$\text{FLOPs/Byte}$&lt;/code&gt; (&lt;code&gt;$1\;\text{MAC} = 2\;\text{FLOPs}$&lt;/code&gt;)—explains why wall-clock overhead is negligible.&lt;/p&gt;&#xA;&lt;p&gt;For &lt;code&gt;$W \in \mathbb{R}^{A \times B}$&lt;/code&gt; with short side &lt;code&gt;$m = \min(A, B)$&lt;/code&gt;, long side &lt;code&gt;$M = \max(A, B)$&lt;/code&gt;, and &lt;code&gt;float32&lt;/code&gt; master weights/states (4 bytes/entry) in HBM:&lt;/p&gt;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;&lt;strong&gt;Memory-bound fused &lt;code&gt;AdamW&lt;/code&gt;&lt;/strong&gt;: each step reads &lt;code&gt;$(W, G, M, V)$&lt;/code&gt; and writes &lt;code&gt;$(W, M, V)$&lt;/code&gt;—roughly &lt;code&gt;$7 \times 4 A B = 28 A B$&lt;/code&gt; bytes of HBM traffic for &lt;del&gt;12 scalar FLOPs per parameter. Its arithmetic intensity is &lt;code&gt;$\frac{12 A B}{28 A B} \approx 0.43\;\text{FLOPs/Byte}$&lt;/code&gt;, hundreds of times below a modern GPU&#39;s ridge point (&lt;/del&gt;&lt;code&gt;$295\;\text{FLOPs/Byte}$&lt;/code&gt; for H100 &lt;code&gt;bfloat16&lt;/code&gt; Tensor Cores), while holding two full state buffers.&lt;/li&gt;&#xA;&lt;li&gt;&lt;strong&gt;Compute share of &lt;code&gt;Muon&lt;/code&gt;&#39;s NS5&lt;/strong&gt;: &lt;code&gt;Muon&lt;/code&gt; drops &lt;code&gt;$V$&lt;/code&gt; (halving 2D optimizer state memory). After transposing to &lt;code&gt;$m \times M$&lt;/code&gt; in &lt;code&gt;bfloat16&lt;/code&gt; (2 bytes/entry), each NS step performs &lt;code&gt;$A_k = X_k X_k^\top$&lt;/code&gt; (&lt;code&gt;$2 m^2 M$&lt;/code&gt; FLOPs), &lt;code&gt;$A_k^2$&lt;/code&gt; (&lt;code&gt;$2 m^3$&lt;/code&gt; FLOPs), and &lt;code&gt;$B_k X_k$&lt;/code&gt; (&lt;code&gt;$2 m^2 M$&lt;/code&gt; FLOPs), totaling &lt;code&gt;$5 \times (4 m^2 M + 2 m^3) = (20 + 10 m / M) m A B \le 30 m A B$&lt;/code&gt; FLOPs over 5 steps, at high arithmetic intensity (&lt;code&gt;$\frac{m}{3}$&lt;/code&gt;–&lt;code&gt;$\frac{m}{2}\;\text{FLOPs/Byte}$&lt;/code&gt;, or &lt;code&gt;$1{,}365$&lt;/code&gt;–&lt;code&gt;$2{,}048\;\text{FLOPs/Byte}$&lt;/code&gt; at &lt;code&gt;$m = 4096$&lt;/code&gt;) right in the Tensor Core sweet spot. Meanwhile, on a global token batch &lt;code&gt;$N_{\mathrm{tok}} = B_{\mathrm{batch}} T$&lt;/code&gt;, the forward &lt;code&gt;$X W^\top$&lt;/code&gt; and backward &lt;code&gt;$\Delta^\top X, \Delta W$&lt;/code&gt; passes execute &lt;code&gt;$6 N_{\mathrm{tok}} A B$&lt;/code&gt; FLOPs, bounding &lt;code&gt;Muon&lt;/code&gt;&#39;s relative FLOP overhead by:&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&lt;p&gt;&lt;code&gt;$$\frac{\mathrm{FLOPs}_{\mathrm{NS5}}}{\mathrm{FLOPs}_{\mathrm{fwd+bwd}}} = \frac{(20 + 10 m / M) m A B}{6 N_{\mathrm{tok}} A B} \le \frac{5 \min(A, B)}{N_{\mathrm{tok}}}$$&lt;/code&gt;&lt;/p&gt;&#xA;&lt;p&gt;In standard LLM pretraining where &lt;code&gt;$\min(A, B) \in [4{,}096,\; 8{,}192]$&lt;/code&gt; and &lt;code&gt;$N_{\mathrm{tok}} \in [10^6,\; 4 \times 10^6]$&lt;/code&gt;, this ratio is just &lt;strong&gt;&lt;code&gt;$0.5\%$&lt;/code&gt;–&lt;code&gt;$2\%$&lt;/code&gt;&lt;/strong&gt;&lt;sup class=&#34;cite&#34;&gt;&lt;a id=&#34;cite-jordan2024-6&#34; href=&#34;#ref-jordan2024&#34;&gt;[4]&lt;/a&gt;&lt;/sup&gt;&lt;sup class=&#34;cite&#34;&gt;&lt;a id=&#34;cite-liu2025-7&#34; href=&#34;#ref-liu2025&#34;&gt;[5]&lt;/a&gt;&lt;/sup&gt;—trading under &lt;code&gt;$2\%$&lt;/code&gt; extra Tensor Core FLOPs for ~48% fewer training tokens to reach the same validation loss in Moonshot AI&#39;s scaling-law runs&lt;sup class=&#34;cite&#34;&gt;&lt;a id=&#34;cite-liu2025-8&#34; href=&#34;#ref-liu2025&#34;&gt;[5]&lt;/a&gt;&lt;/sup&gt;.&lt;/p&gt;&#xA;&lt;h3 id=&#34;62-controlled-benchmark-across-four-optimizer-generations-on-a-2-layer-transformer&#34;&gt;6.2 Controlled Benchmark Across Four Optimizer Generations on a 2-Layer Transformer&lt;/h3&gt;&#xA;&lt;p&gt;To observe every mechanism on a transparent task, we construct a synthetic language modeling benchmark combining &lt;strong&gt;Zipf-skewed background tokens&lt;/strong&gt; with &lt;strong&gt;in-context associative recall&lt;/strong&gt;: vocabulary &lt;code&gt;$V = 128$&lt;/code&gt;, length &lt;code&gt;$T = 32$&lt;/code&gt;, with four random &lt;code&gt;Key → Value&lt;/code&gt; pairs planted in the first half of each sequence and one &lt;code&gt;Key&lt;/code&gt; queried amidst Zipfian filler in the second half. Answering correctly requires multi-head attention to form an induction circuit aligning query and key subspaces.&lt;/p&gt;&#xA;&lt;p&gt;We train an identical 2-layer, 4-head Mini-Transformer (&lt;code&gt;$D = 64, B = 32$&lt;/code&gt;) for 360 steps under &lt;code&gt;SGD&lt;/code&gt;, &lt;code&gt;SGD + Momentum&lt;/code&gt;, full-model &lt;code&gt;AdamW&lt;/code&gt;, and hybrid &lt;code&gt;Muon + AdamW&lt;/code&gt; (with &lt;code&gt;Muon + AdamW&lt;/code&gt; and &lt;code&gt;AdamW&lt;/code&gt; sharing the exact same &lt;code&gt;$\eta = 5 \times 10^{-3}$&lt;/code&gt; and &lt;code&gt;$\lambda = 0.02$&lt;/code&gt;):&lt;/p&gt;&#xA;&lt;figure class=&#34;plotfig&#34;&gt;&lt;figcaption&gt;Four Optimizer Generations on a 2-Layer 4-Head Mini-Transformer: Val Loss &amp;amp; Associative Recall&lt;/figcaption&gt;&lt;p&gt;&lt;a href=&#34;https://mizore.blog/en/posts/from-transformer-matrices-to-muon/&#34;&gt;(See the figure in the post.)&lt;/a&gt;&lt;/p&gt;&lt;p class=&#34;plot-xlabel&#34;&gt;Training step (2-layer 4-head Mini-Transformer, Zipf background + associative recall, mean ±1 SD over 2 seeds)&lt;/p&gt;&lt;p class=&#34;figure-note&#34;&gt;Vocab &lt;code&gt;$V=128$&lt;/code&gt;, length &lt;code&gt;$T=32$&lt;/code&gt;, &lt;code&gt;$D=64$&lt;/code&gt;, 4 heads, batch &lt;code&gt;$B=32$&lt;/code&gt;; solid curves show 2-seed means and shaded bands show &lt;code&gt;$\pm 1$&lt;/code&gt; SD. Uniform random cross-entropy starts at &lt;code&gt;$\ln(128) \approx 4.85$&lt;/code&gt;.&lt;/p&gt;&lt;/figure&gt;&#xA;&lt;p&gt;The training phases mirror our derivations: within the first 50 steps, all four optimizers fit the unigram frequencies of high-probability Zipfian filler, dropping loss from &lt;code&gt;$4.85$&lt;/code&gt; to ~&lt;code&gt;$2.80$&lt;/code&gt;. Beyond that point, &lt;code&gt;SGD&lt;/code&gt; and &lt;code&gt;Momentum&lt;/code&gt; remain swamped by dominant filler gradients, leaving the low-singular-value induction-head directions stalled at &lt;code&gt;$7.3\%$&lt;/code&gt;–&lt;code&gt;$7.4\%$&lt;/code&gt; recall; &lt;code&gt;AdamW&lt;/code&gt; begins aligning subspaces after step 150 to reach &lt;code&gt;$23.7\%$&lt;/code&gt; by step 360; whereas &lt;code&gt;Muon + AdamW&lt;/code&gt; crosses the induction phase transition around step 120 and reaches &lt;strong&gt;&lt;code&gt;$77.0\%$&lt;/code&gt;&lt;/strong&gt; associative recall (its slight overall validation loss uptick past step 250 reflects mild overfitting on fixed-corpus background tokens while associative recall continues climbing).&lt;/p&gt;&#xA;&lt;hr&gt;&#xA;&lt;h2 id=&#34;7-complete-single-file-pytorch-implementation-mini-transformer-with-muon--adamw&#34;&gt;7. Complete Single-File PyTorch Implementation: Mini-Transformer with &lt;code&gt;Muon + AdamW&lt;/code&gt;&lt;/h2&gt;&#xA;&lt;p&gt;The self-contained PyTorch script below maps every equation in this post—mixed-precision-safe &lt;code&gt;RMSNorm&lt;/code&gt;, multi-head causal self-attention, 5-step Newton-Schulz orthogonalization, Moonshot RMS-aligned &lt;code&gt;Muon&lt;/code&gt;, induced-norm parameter routing, and a 1-epoch (50-step) training loop—directly onto runnable code:&lt;/p&gt;&#xA;&lt;figure class=&#34;code&#34;&gt;&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code&gt;&lt;span class=&#34;kn&#34;&gt;import&lt;/span&gt; &lt;span class=&#34;nn&#34;&gt;torch&lt;/span&gt;&#xA;&lt;span class=&#34;kn&#34;&gt;import&lt;/span&gt; &lt;span class=&#34;nn&#34;&gt;torch.nn&lt;/span&gt; &lt;span class=&#34;k&#34;&gt;as&lt;/span&gt; &lt;span class=&#34;nn&#34;&gt;nn&lt;/span&gt;&#xA;&lt;span class=&#34;kn&#34;&gt;import&lt;/span&gt; &lt;span class=&#34;nn&#34;&gt;torch.nn.functional&lt;/span&gt; &lt;span class=&#34;k&#34;&gt;as&lt;/span&gt; &lt;span class=&#34;nn&#34;&gt;F&lt;/span&gt;&#xA;&lt;span class=&#34;kn&#34;&gt;from&lt;/span&gt; &lt;span class=&#34;nn&#34;&gt;torch.utils.data&lt;/span&gt; &lt;span class=&#34;kn&#34;&gt;import&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;TensorDataset&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;DataLoader&lt;/span&gt;&#xA;&#xA;&#xA;&lt;span class=&#34;c1&#34;&gt;# =====================================================================&lt;/span&gt;&#xA;&lt;span class=&#34;c1&#34;&gt;# 1. Quintic Newton-Schulz Iteration &amp;amp; Custom Muon Optimizer&lt;/span&gt;&#xA;&lt;span class=&#34;c1&#34;&gt;# =====================================================================&lt;/span&gt;&#xA;&lt;span class=&#34;k&#34;&gt;def&lt;/span&gt; &lt;span class=&#34;nf&#34;&gt;zeropower_via_newtonschulz5&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;G&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;:&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;torch&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;Tensor&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;steps&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;:&lt;/span&gt; &lt;span class=&#34;nb&#34;&gt;int&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;mi&#34;&gt;5&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;eps&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;:&lt;/span&gt; &lt;span class=&#34;nb&#34;&gt;float&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;mf&#34;&gt;1e-7&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;-&amp;gt;&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;torch&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;Tensor&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;:&lt;/span&gt;&#xA;    &lt;span class=&#34;s2&#34;&gt;&amp;#34;&amp;#34;&amp;#34;Map G = U * Sigma * V^T to approximate semi-orthogonal U * V^T in 5 matmul steps.&amp;#34;&amp;#34;&amp;#34;&lt;/span&gt;&#xA;    &lt;span class=&#34;k&#34;&gt;assert&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;G&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;ndim&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;==&lt;/span&gt; &lt;span class=&#34;mi&#34;&gt;2&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;s2&#34;&gt;&amp;#34;Newton-Schulz orthogonalization applies only to 2D matrix parameters&amp;#34;&lt;/span&gt;&#xA;    &lt;span class=&#34;n&#34;&gt;a&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;b&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;c&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;mf&#34;&gt;3.4445&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;-&lt;/span&gt;&lt;span class=&#34;mf&#34;&gt;4.7750&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;mf&#34;&gt;2.0315&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;&#xA;    &lt;span class=&#34;n&#34;&gt;X&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;G&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;bfloat16&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;()&lt;/span&gt; &lt;span class=&#34;k&#34;&gt;if&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;G&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;is_cuda&lt;/span&gt; &lt;span class=&#34;k&#34;&gt;else&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;G&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;float&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;()&lt;/span&gt;&#xA;&#xA;    &lt;span class=&#34;c1&#34;&gt;# Pre-normalize by Frobenius norm so all initial singular values lie in [0, 1]&lt;/span&gt;&#xA;    &lt;span class=&#34;n&#34;&gt;X&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;X&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;/&lt;/span&gt; &lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;X&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;norm&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;()&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;+&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;eps&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;&#xA;&#xA;    &lt;span class=&#34;c1&#34;&gt;# Transpose tall matrices (A &amp;gt; B) so A_k = X @ X.T has smaller shape B x B&lt;/span&gt;&#xA;    &lt;span class=&#34;n&#34;&gt;transposed&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;kc&#34;&gt;False&lt;/span&gt;&#xA;    &lt;span class=&#34;k&#34;&gt;if&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;X&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;size&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;mi&#34;&gt;0&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;&amp;gt;&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;X&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;size&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;mi&#34;&gt;1&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;):&lt;/span&gt;&#xA;        &lt;span class=&#34;n&#34;&gt;X&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;X&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;T&lt;/span&gt;&#xA;        &lt;span class=&#34;n&#34;&gt;transposed&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;kc&#34;&gt;True&lt;/span&gt;&#xA;&#xA;    &lt;span class=&#34;c1&#34;&gt;# Odd matrix polynomial recurrence: X_{k+1} = a * X_k + (b * A_k + c * A_k^2) * X_k&lt;/span&gt;&#xA;    &lt;span class=&#34;k&#34;&gt;for&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;_&lt;/span&gt; &lt;span class=&#34;ow&#34;&gt;in&lt;/span&gt; &lt;span class=&#34;nb&#34;&gt;range&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;steps&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;):&lt;/span&gt;&#xA;        &lt;span class=&#34;n&#34;&gt;A&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;X&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;@&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;X&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;T&lt;/span&gt;&#xA;        &lt;span class=&#34;n&#34;&gt;B&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;b&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;*&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;A&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;+&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;c&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;*&lt;/span&gt; &lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;A&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;@&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;A&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;&#xA;        &lt;span class=&#34;n&#34;&gt;X&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;a&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;*&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;X&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;+&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;B&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;@&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;X&lt;/span&gt;&#xA;&#xA;    &lt;span class=&#34;k&#34;&gt;if&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;transposed&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;:&lt;/span&gt;&#xA;        &lt;span class=&#34;n&#34;&gt;X&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;X&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;T&lt;/span&gt;&#xA;    &lt;span class=&#34;k&#34;&gt;return&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;X&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;to&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;G&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;dtype&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;&#xA;&#xA;&#xA;&lt;span class=&#34;k&#34;&gt;class&lt;/span&gt; &lt;span class=&#34;nc&#34;&gt;Muon&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;torch&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;optim&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;Optimizer&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;):&lt;/span&gt;&#xA;    &lt;span class=&#34;s2&#34;&gt;&amp;#34;&amp;#34;&amp;#34;Muon optimizer for internal 2D Transformer matrices (with decoupled WD &amp;amp; RMS scaling).&amp;#34;&amp;#34;&amp;#34;&lt;/span&gt;&#xA;    &lt;span class=&#34;k&#34;&gt;def&lt;/span&gt; &lt;span class=&#34;fm&#34;&gt;__init__&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;bp&#34;&gt;self&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;params&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;lr&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;=&lt;/span&gt;&lt;span class=&#34;mf&#34;&gt;3e-3&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;momentum&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;=&lt;/span&gt;&lt;span class=&#34;mf&#34;&gt;0.95&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;weight_decay&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;=&lt;/span&gt;&lt;span class=&#34;mf&#34;&gt;0.01&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;scale_mode&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;=&lt;/span&gt;&lt;span class=&#34;s2&#34;&gt;&amp;#34;moonshot&amp;#34;&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;):&lt;/span&gt;&#xA;        &lt;span class=&#34;n&#34;&gt;defaults&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;nb&#34;&gt;dict&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;lr&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;=&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;lr&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;momentum&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;=&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;momentum&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;weight_decay&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;=&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;weight_decay&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;scale_mode&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;=&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;scale_mode&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;&#xA;        &lt;span class=&#34;nb&#34;&gt;super&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;()&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;fm&#34;&gt;__init__&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;params&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;defaults&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;&#xA;&#xA;    &lt;span class=&#34;nd&#34;&gt;@torch.no_grad&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;()&lt;/span&gt;&#xA;    &lt;span class=&#34;k&#34;&gt;def&lt;/span&gt; &lt;span class=&#34;nf&#34;&gt;step&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;bp&#34;&gt;self&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;closure&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;=&lt;/span&gt;&lt;span class=&#34;kc&#34;&gt;None&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;):&lt;/span&gt;&#xA;        &lt;span class=&#34;n&#34;&gt;loss&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;kc&#34;&gt;None&lt;/span&gt;&#xA;        &lt;span class=&#34;k&#34;&gt;if&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;closure&lt;/span&gt; &lt;span class=&#34;ow&#34;&gt;is&lt;/span&gt; &lt;span class=&#34;ow&#34;&gt;not&lt;/span&gt; &lt;span class=&#34;kc&#34;&gt;None&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;:&lt;/span&gt;&#xA;            &lt;span class=&#34;k&#34;&gt;with&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;torch&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;enable_grad&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;():&lt;/span&gt;&#xA;                &lt;span class=&#34;n&#34;&gt;loss&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;closure&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;()&lt;/span&gt;&#xA;        &lt;span class=&#34;k&#34;&gt;for&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;group&lt;/span&gt; &lt;span class=&#34;ow&#34;&gt;in&lt;/span&gt; &lt;span class=&#34;bp&#34;&gt;self&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;param_groups&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;:&lt;/span&gt;&#xA;            &lt;span class=&#34;n&#34;&gt;lr&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;group&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;[&lt;/span&gt;&lt;span class=&#34;s2&#34;&gt;&amp;#34;lr&amp;#34;&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;]&lt;/span&gt;&#xA;            &lt;span class=&#34;n&#34;&gt;mu&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;group&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;[&lt;/span&gt;&lt;span class=&#34;s2&#34;&gt;&amp;#34;momentum&amp;#34;&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;]&lt;/span&gt;&#xA;            &lt;span class=&#34;n&#34;&gt;wd&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;group&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;[&lt;/span&gt;&lt;span class=&#34;s2&#34;&gt;&amp;#34;weight_decay&amp;#34;&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;]&lt;/span&gt;&#xA;            &lt;span class=&#34;n&#34;&gt;scale_mode&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;group&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;[&lt;/span&gt;&lt;span class=&#34;s2&#34;&gt;&amp;#34;scale_mode&amp;#34;&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;]&lt;/span&gt;&#xA;&#xA;            &lt;span class=&#34;k&#34;&gt;for&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;W&lt;/span&gt; &lt;span class=&#34;ow&#34;&gt;in&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;group&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;[&lt;/span&gt;&lt;span class=&#34;s2&#34;&gt;&amp;#34;params&amp;#34;&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;]:&lt;/span&gt;&#xA;                &lt;span class=&#34;k&#34;&gt;if&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;W&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;grad&lt;/span&gt; &lt;span class=&#34;ow&#34;&gt;is&lt;/span&gt; &lt;span class=&#34;kc&#34;&gt;None&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;:&lt;/span&gt;&#xA;                    &lt;span class=&#34;k&#34;&gt;continue&lt;/span&gt;&#xA;                &lt;span class=&#34;n&#34;&gt;G&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;W&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;grad&lt;/span&gt;  &lt;span class=&#34;c1&#34;&gt;# 2D gradient matrix of shape (d_out, d_in) matching W&lt;/span&gt;&#xA;&#xA;                &lt;span class=&#34;c1&#34;&gt;# Only first-moment momentum M is stored; no second-moment buffer V is needed&lt;/span&gt;&#xA;                &lt;span class=&#34;n&#34;&gt;state&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;bp&#34;&gt;self&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;state&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;[&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;W&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;]&lt;/span&gt;&#xA;                &lt;span class=&#34;k&#34;&gt;if&lt;/span&gt; &lt;span class=&#34;s2&#34;&gt;&amp;#34;momentum_buffer&amp;#34;&lt;/span&gt; &lt;span class=&#34;ow&#34;&gt;not&lt;/span&gt; &lt;span class=&#34;ow&#34;&gt;in&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;state&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;:&lt;/span&gt;&#xA;                    &lt;span class=&#34;n&#34;&gt;state&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;[&lt;/span&gt;&lt;span class=&#34;s2&#34;&gt;&amp;#34;momentum_buffer&amp;#34;&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;]&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;torch&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;zeros_like&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;G&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;&#xA;                &lt;span class=&#34;n&#34;&gt;M&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;state&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;[&lt;/span&gt;&lt;span class=&#34;s2&#34;&gt;&amp;#34;momentum_buffer&amp;#34;&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;]&lt;/span&gt;&#xA;&#xA;                &lt;span class=&#34;c1&#34;&gt;# 1. Nesterov lookahead momentum: M_t = mu * M_{t-1} + G_t, tilde_M = G_t + mu * M_t&lt;/span&gt;&#xA;                &lt;span class=&#34;n&#34;&gt;M&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;mul_&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;mu&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;add_&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;G&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;&#xA;                &lt;span class=&#34;n&#34;&gt;tilde_M&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;G&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;+&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;mu&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;*&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;M&lt;/span&gt;&#xA;&#xA;                &lt;span class=&#34;c1&#34;&gt;# 2. 5-step Newton-Schulz orthogonalization&lt;/span&gt;&#xA;                &lt;span class=&#34;n&#34;&gt;O_t&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;zeropower_via_newtonschulz5&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;tilde_M&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;steps&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;=&lt;/span&gt;&lt;span class=&#34;mi&#34;&gt;5&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;&#xA;&#xA;                &lt;span class=&#34;c1&#34;&gt;# 3. Decoupled weight decay: W &amp;lt;- (1 - lr * wd) * W&lt;/span&gt;&#xA;                &lt;span class=&#34;k&#34;&gt;if&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;wd&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;!=&lt;/span&gt; &lt;span class=&#34;mi&#34;&gt;0&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;:&lt;/span&gt;&#xA;                    &lt;span class=&#34;n&#34;&gt;W&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;mul_&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;mf&#34;&gt;1.0&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;-&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;lr&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;*&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;wd&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;&#xA;&#xA;                &lt;span class=&#34;c1&#34;&gt;# 4. Entrywise update RMS alignment (moonshot mode shares AdamW&amp;#39;s lr directly)&lt;/span&gt;&#xA;                &lt;span class=&#34;n&#34;&gt;A&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;B&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;W&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;size&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;mi&#34;&gt;0&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;),&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;W&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;size&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;mi&#34;&gt;1&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;&#xA;                &lt;span class=&#34;n&#34;&gt;scale&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;mf&#34;&gt;0.2&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;*&lt;/span&gt; &lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;nb&#34;&gt;max&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;A&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;B&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;**&lt;/span&gt; &lt;span class=&#34;mf&#34;&gt;0.5&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt; &lt;span class=&#34;k&#34;&gt;if&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;scale_mode&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;==&lt;/span&gt; &lt;span class=&#34;s2&#34;&gt;&amp;#34;moonshot&amp;#34;&lt;/span&gt; &lt;span class=&#34;k&#34;&gt;else&lt;/span&gt; &lt;span class=&#34;nb&#34;&gt;max&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;mf&#34;&gt;1.0&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;A&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;/&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;B&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;**&lt;/span&gt; &lt;span class=&#34;mf&#34;&gt;0.5&lt;/span&gt;&#xA;                &lt;span class=&#34;n&#34;&gt;W&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;add_&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;O_t&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;alpha&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;=-&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;lr&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;*&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;scale&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;&#xA;        &lt;span class=&#34;k&#34;&gt;return&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;loss&lt;/span&gt;&#xA;&#xA;&#xA;&lt;span class=&#34;c1&#34;&gt;# =====================================================================&lt;/span&gt;&#xA;&lt;span class=&#34;c1&#34;&gt;# 2. Mini-Transformer Language Model Definition&lt;/span&gt;&#xA;&lt;span class=&#34;c1&#34;&gt;# =====================================================================&lt;/span&gt;&#xA;&lt;span class=&#34;k&#34;&gt;class&lt;/span&gt; &lt;span class=&#34;nc&#34;&gt;RMSNorm&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;nn&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;Module&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;):&lt;/span&gt;&#xA;    &lt;span class=&#34;k&#34;&gt;def&lt;/span&gt; &lt;span class=&#34;fm&#34;&gt;__init__&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;bp&#34;&gt;self&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;dim&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;:&lt;/span&gt; &lt;span class=&#34;nb&#34;&gt;int&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;eps&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;:&lt;/span&gt; &lt;span class=&#34;nb&#34;&gt;float&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;mf&#34;&gt;1e-6&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;):&lt;/span&gt;&#xA;        &lt;span class=&#34;nb&#34;&gt;super&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;()&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;fm&#34;&gt;__init__&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;()&lt;/span&gt;&#xA;        &lt;span class=&#34;bp&#34;&gt;self&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;weight&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;nn&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;Parameter&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;torch&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;ones&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;dim&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;))&lt;/span&gt;  &lt;span class=&#34;c1&#34;&gt;# 1D gain (dim,) -&amp;gt; AdamW (wd=0)&lt;/span&gt;&#xA;        &lt;span class=&#34;bp&#34;&gt;self&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;eps&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;eps&lt;/span&gt;&#xA;&#xA;    &lt;span class=&#34;k&#34;&gt;def&lt;/span&gt; &lt;span class=&#34;nf&#34;&gt;forward&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;bp&#34;&gt;self&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;x&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;:&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;torch&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;Tensor&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;-&amp;gt;&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;torch&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;Tensor&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;:&lt;/span&gt;&#xA;        &lt;span class=&#34;n&#34;&gt;x_fp32&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;x&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;float&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;()&lt;/span&gt;&#xA;        &lt;span class=&#34;n&#34;&gt;rms&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;torch&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;rsqrt&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;x_fp32&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;pow&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;mi&#34;&gt;2&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;mean&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;-&lt;/span&gt;&lt;span class=&#34;mi&#34;&gt;1&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;keepdim&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;=&lt;/span&gt;&lt;span class=&#34;kc&#34;&gt;True&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;+&lt;/span&gt; &lt;span class=&#34;bp&#34;&gt;self&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;eps&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;&#xA;        &lt;span class=&#34;k&#34;&gt;return&lt;/span&gt; &lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;x_fp32&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;*&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;rms&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;to&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;x&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;dtype&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;*&lt;/span&gt; &lt;span class=&#34;bp&#34;&gt;self&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;weight&lt;/span&gt;&#xA;&#xA;&#xA;&lt;span class=&#34;k&#34;&gt;class&lt;/span&gt; &lt;span class=&#34;nc&#34;&gt;MiniTransformerLM&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;nn&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;Module&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;):&lt;/span&gt;&#xA;    &lt;span class=&#34;k&#34;&gt;def&lt;/span&gt; &lt;span class=&#34;fm&#34;&gt;__init__&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;bp&#34;&gt;self&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;vocab_size&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;=&lt;/span&gt;&lt;span class=&#34;mi&#34;&gt;1000&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;d_model&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;=&lt;/span&gt;&lt;span class=&#34;mi&#34;&gt;64&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;n_heads&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;=&lt;/span&gt;&lt;span class=&#34;mi&#34;&gt;4&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;max_len&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;=&lt;/span&gt;&lt;span class=&#34;mi&#34;&gt;32&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;):&lt;/span&gt;&#xA;        &lt;span class=&#34;nb&#34;&gt;super&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;()&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;fm&#34;&gt;__init__&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;()&lt;/span&gt;&#xA;        &lt;span class=&#34;k&#34;&gt;assert&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;d_model&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;%&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;n_heads&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;==&lt;/span&gt; &lt;span class=&#34;mi&#34;&gt;0&lt;/span&gt;&#xA;        &lt;span class=&#34;bp&#34;&gt;self&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;d_model&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;d_model&lt;/span&gt;&#xA;        &lt;span class=&#34;bp&#34;&gt;self&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;n_heads&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;n_heads&lt;/span&gt;&#xA;        &lt;span class=&#34;bp&#34;&gt;self&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;head_dim&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;d_model&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;//&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;n_heads&lt;/span&gt;&#xA;&#xA;        &lt;span class=&#34;c1&#34;&gt;# Boundary discrete lookup tables -&amp;gt; AdamW&lt;/span&gt;&#xA;        &lt;span class=&#34;bp&#34;&gt;self&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;tok_emb&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;nn&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;Embedding&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;vocab_size&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;d_model&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;&#xA;        &lt;span class=&#34;bp&#34;&gt;self&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;pos_emb&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;nn&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;Embedding&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;max_len&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;d_model&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;&#xA;&#xA;        &lt;span class=&#34;c1&#34;&gt;# Internal 2D attention projections (.weight shape (64, 64)) -&amp;gt; Muon&lt;/span&gt;&#xA;        &lt;span class=&#34;bp&#34;&gt;self&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;norm1&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;RMSNorm&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;d_model&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;&#xA;        &lt;span class=&#34;bp&#34;&gt;self&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;W_q&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;nn&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;Linear&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;d_model&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;d_model&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;bias&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;=&lt;/span&gt;&lt;span class=&#34;kc&#34;&gt;False&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;&#xA;        &lt;span class=&#34;bp&#34;&gt;self&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;W_k&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;nn&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;Linear&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;d_model&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;d_model&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;bias&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;=&lt;/span&gt;&lt;span class=&#34;kc&#34;&gt;False&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;&#xA;        &lt;span class=&#34;bp&#34;&gt;self&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;W_v&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;nn&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;Linear&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;d_model&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;d_model&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;bias&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;=&lt;/span&gt;&lt;span class=&#34;kc&#34;&gt;False&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;&#xA;        &lt;span class=&#34;bp&#34;&gt;self&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;W_o&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;nn&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;Linear&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;d_model&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;d_model&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;bias&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;=&lt;/span&gt;&lt;span class=&#34;kc&#34;&gt;False&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;&#xA;&#xA;        &lt;span class=&#34;c1&#34;&gt;# Internal 2D FFN layers (W_up: (256, 64), W_down: (64, 256)) -&amp;gt; Muon&lt;/span&gt;&#xA;        &lt;span class=&#34;bp&#34;&gt;self&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;norm2&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;RMSNorm&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;d_model&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;&#xA;        &lt;span class=&#34;bp&#34;&gt;self&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;W_up&lt;/span&gt;   &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;nn&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;Linear&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;d_model&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;mi&#34;&gt;4&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;*&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;d_model&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;bias&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;=&lt;/span&gt;&lt;span class=&#34;kc&#34;&gt;False&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;&#xA;        &lt;span class=&#34;bp&#34;&gt;self&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;W_down&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;nn&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;Linear&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;mi&#34;&gt;4&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;*&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;d_model&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;d_model&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;bias&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;=&lt;/span&gt;&lt;span class=&#34;kc&#34;&gt;False&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;&#xA;&#xA;        &lt;span class=&#34;c1&#34;&gt;# Output vocabulary head (1000, 64) -&amp;gt; AdamW&lt;/span&gt;&#xA;        &lt;span class=&#34;bp&#34;&gt;self&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;norm_final&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;RMSNorm&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;d_model&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;&#xA;        &lt;span class=&#34;bp&#34;&gt;self&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;lm_head&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;nn&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;Linear&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;d_model&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;vocab_size&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;bias&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;=&lt;/span&gt;&lt;span class=&#34;kc&#34;&gt;False&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;&#xA;&#xA;    &lt;span class=&#34;k&#34;&gt;def&lt;/span&gt; &lt;span class=&#34;nf&#34;&gt;forward&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;bp&#34;&gt;self&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;idx&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;:&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;torch&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;Tensor&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;-&amp;gt;&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;torch&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;Tensor&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;:&lt;/span&gt;&#xA;        &lt;span class=&#34;n&#34;&gt;B&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;T&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;idx&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;shape&lt;/span&gt;&#xA;        &lt;span class=&#34;n&#34;&gt;pos&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;torch&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;arange&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;mi&#34;&gt;0&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;T&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;device&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;=&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;idx&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;device&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;&#xA;&#xA;        &lt;span class=&#34;c1&#34;&gt;# (B, T, D) + (T, D) [broadcast across batch] -&amp;gt; (B, T, D)&lt;/span&gt;&#xA;        &lt;span class=&#34;n&#34;&gt;x&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;bp&#34;&gt;self&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;tok_emb&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;idx&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;+&lt;/span&gt; &lt;span class=&#34;bp&#34;&gt;self&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;pos_emb&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;pos&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;&#xA;&#xA;        &lt;span class=&#34;c1&#34;&gt;# Sublayer 1: Pre-RMSNorm + Multi-Head Causal Self-Attention&lt;/span&gt;&#xA;        &lt;span class=&#34;n&#34;&gt;h&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;bp&#34;&gt;self&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;norm1&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;x&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;&#xA;        &lt;span class=&#34;n&#34;&gt;q&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;bp&#34;&gt;self&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;W_q&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;h&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;view&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;B&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;T&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;bp&#34;&gt;self&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;n_heads&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;bp&#34;&gt;self&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;head_dim&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;transpose&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;mi&#34;&gt;1&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;mi&#34;&gt;2&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;&#xA;        &lt;span class=&#34;n&#34;&gt;k&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;bp&#34;&gt;self&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;W_k&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;h&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;view&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;B&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;T&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;bp&#34;&gt;self&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;n_heads&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;bp&#34;&gt;self&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;head_dim&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;transpose&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;mi&#34;&gt;1&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;mi&#34;&gt;2&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;&#xA;        &lt;span class=&#34;n&#34;&gt;v&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;bp&#34;&gt;self&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;W_v&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;h&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;view&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;B&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;T&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;bp&#34;&gt;self&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;n_heads&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;bp&#34;&gt;self&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;head_dim&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;transpose&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;mi&#34;&gt;1&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;mi&#34;&gt;2&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;&#xA;        &lt;span class=&#34;n&#34;&gt;attn_out&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;F&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;scaled_dot_product_attention&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;q&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;k&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;v&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;is_causal&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;=&lt;/span&gt;&lt;span class=&#34;kc&#34;&gt;True&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;&#xA;        &lt;span class=&#34;n&#34;&gt;attn_out&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;attn_out&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;transpose&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;mi&#34;&gt;1&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;mi&#34;&gt;2&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;contiguous&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;()&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;view&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;B&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;T&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;bp&#34;&gt;self&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;d_model&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;&#xA;        &lt;span class=&#34;n&#34;&gt;x&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;x&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;+&lt;/span&gt; &lt;span class=&#34;bp&#34;&gt;self&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;W_o&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;attn_out&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;&#xA;&#xA;        &lt;span class=&#34;c1&#34;&gt;# Sublayer 2: Pre-RMSNorm + SiLU Feed-Forward Network&lt;/span&gt;&#xA;        &lt;span class=&#34;n&#34;&gt;h&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;bp&#34;&gt;self&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;norm2&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;x&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;&#xA;        &lt;span class=&#34;n&#34;&gt;x&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;x&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;+&lt;/span&gt; &lt;span class=&#34;bp&#34;&gt;self&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;W_down&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;F&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;silu&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;bp&#34;&gt;self&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;W_up&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;h&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)))&lt;/span&gt;&#xA;&#xA;        &lt;span class=&#34;k&#34;&gt;return&lt;/span&gt; &lt;span class=&#34;bp&#34;&gt;self&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;lm_head&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;bp&#34;&gt;self&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;norm_final&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;x&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;))&lt;/span&gt;&#xA;&#xA;&#xA;&lt;span class=&#34;c1&#34;&gt;# =====================================================================&lt;/span&gt;&#xA;&lt;span class=&#34;c1&#34;&gt;# 3. Parameter Routing &amp;amp; 1-Epoch (50 Steps) Training Loop&lt;/span&gt;&#xA;&lt;span class=&#34;c1&#34;&gt;# =====================================================================&lt;/span&gt;&#xA;&lt;span class=&#34;k&#34;&gt;if&lt;/span&gt; &lt;span class=&#34;vm&#34;&gt;__name__&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;==&lt;/span&gt; &lt;span class=&#34;s2&#34;&gt;&amp;#34;__main__&amp;#34;&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;:&lt;/span&gt;&#xA;    &lt;span class=&#34;n&#34;&gt;torch&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;manual_seed&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;mi&#34;&gt;42&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;&#xA;    &lt;span class=&#34;n&#34;&gt;device&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;s2&#34;&gt;&amp;#34;cuda&amp;#34;&lt;/span&gt; &lt;span class=&#34;k&#34;&gt;if&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;torch&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;cuda&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;is_available&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;()&lt;/span&gt; &lt;span class=&#34;k&#34;&gt;else&lt;/span&gt; &lt;span class=&#34;s2&#34;&gt;&amp;#34;cpu&amp;#34;&lt;/span&gt;&#xA;    &lt;span class=&#34;n&#34;&gt;model&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;MiniTransformerLM&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;vocab_size&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;=&lt;/span&gt;&lt;span class=&#34;mi&#34;&gt;1000&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;d_model&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;=&lt;/span&gt;&lt;span class=&#34;mi&#34;&gt;64&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;n_heads&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;=&lt;/span&gt;&lt;span class=&#34;mi&#34;&gt;4&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;max_len&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;=&lt;/span&gt;&lt;span class=&#34;mi&#34;&gt;32&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;to&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;device&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;&#xA;&#xA;    &lt;span class=&#34;n&#34;&gt;muon_params&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;adamw_decay&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;adamw_nodecay&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;p&#34;&gt;[],&lt;/span&gt; &lt;span class=&#34;p&#34;&gt;[],&lt;/span&gt; &lt;span class=&#34;p&#34;&gt;[]&lt;/span&gt;&#xA;    &lt;span class=&#34;k&#34;&gt;for&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;name&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;p&lt;/span&gt; &lt;span class=&#34;ow&#34;&gt;in&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;model&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;named_parameters&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;():&lt;/span&gt;&#xA;        &lt;span class=&#34;n&#34;&gt;is_embed_or_head&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;s2&#34;&gt;&amp;#34;emb&amp;#34;&lt;/span&gt; &lt;span class=&#34;ow&#34;&gt;in&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;name&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt; &lt;span class=&#34;ow&#34;&gt;or&lt;/span&gt; &lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;s2&#34;&gt;&amp;#34;lm_head&amp;#34;&lt;/span&gt; &lt;span class=&#34;ow&#34;&gt;in&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;name&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;&#xA;        &lt;span class=&#34;k&#34;&gt;if&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;p&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;ndim&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;==&lt;/span&gt; &lt;span class=&#34;mi&#34;&gt;2&lt;/span&gt; &lt;span class=&#34;ow&#34;&gt;and&lt;/span&gt; &lt;span class=&#34;ow&#34;&gt;not&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;is_embed_or_head&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;:&lt;/span&gt;&#xA;            &lt;span class=&#34;n&#34;&gt;muon_params&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;append&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;p&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;&#xA;        &lt;span class=&#34;k&#34;&gt;elif&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;p&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;ndim&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;&amp;gt;=&lt;/span&gt; &lt;span class=&#34;mi&#34;&gt;2&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;:&lt;/span&gt;&#xA;            &lt;span class=&#34;n&#34;&gt;adamw_decay&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;append&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;p&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;&#xA;        &lt;span class=&#34;k&#34;&gt;else&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;:&lt;/span&gt;&#xA;            &lt;span class=&#34;n&#34;&gt;adamw_nodecay&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;append&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;p&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;&#xA;&#xA;    &lt;span class=&#34;n&#34;&gt;shared_lr&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;mf&#34;&gt;3e-3&lt;/span&gt;&#xA;    &lt;span class=&#34;n&#34;&gt;opt_muon&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;Muon&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;muon_params&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;lr&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;=&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;shared_lr&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;momentum&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;=&lt;/span&gt;&lt;span class=&#34;mf&#34;&gt;0.95&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;weight_decay&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;=&lt;/span&gt;&lt;span class=&#34;mf&#34;&gt;0.01&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;scale_mode&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;=&lt;/span&gt;&lt;span class=&#34;s2&#34;&gt;&amp;#34;moonshot&amp;#34;&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;&#xA;    &lt;span class=&#34;n&#34;&gt;opt_adamw&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;torch&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;optim&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;AdamW&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;([&lt;/span&gt;&#xA;        &lt;span class=&#34;p&#34;&gt;{&lt;/span&gt;&lt;span class=&#34;s2&#34;&gt;&amp;#34;params&amp;#34;&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;:&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;adamw_decay&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt;   &lt;span class=&#34;s2&#34;&gt;&amp;#34;weight_decay&amp;#34;&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;:&lt;/span&gt; &lt;span class=&#34;mf&#34;&gt;0.01&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;},&lt;/span&gt;&#xA;        &lt;span class=&#34;p&#34;&gt;{&lt;/span&gt;&lt;span class=&#34;s2&#34;&gt;&amp;#34;params&amp;#34;&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;:&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;adamw_nodecay&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;s2&#34;&gt;&amp;#34;weight_decay&amp;#34;&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;:&lt;/span&gt; &lt;span class=&#34;mf&#34;&gt;0.0&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;},&lt;/span&gt;&#xA;    &lt;span class=&#34;p&#34;&gt;],&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;lr&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;=&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;shared_lr&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;betas&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;=&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;mf&#34;&gt;0.9&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;mf&#34;&gt;0.95&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;))&lt;/span&gt;&#xA;&#xA;    &lt;span class=&#34;c1&#34;&gt;# 1,000 modulo-1000 counting sequences, batch_size=20 -&amp;gt; 1 Epoch = 50 Steps&lt;/span&gt;&#xA;    &lt;span class=&#34;n&#34;&gt;seq_len&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;mi&#34;&gt;16&lt;/span&gt;&#xA;    &lt;span class=&#34;n&#34;&gt;starts&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;torch&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;randint&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;mi&#34;&gt;0&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;mi&#34;&gt;1000&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;mi&#34;&gt;1000&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;mi&#34;&gt;1&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;))&lt;/span&gt;&#xA;    &lt;span class=&#34;n&#34;&gt;sequences&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;starts&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;+&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;torch&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;arange&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;seq_len&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;+&lt;/span&gt; &lt;span class=&#34;mi&#34;&gt;1&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;))&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;%&lt;/span&gt; &lt;span class=&#34;mi&#34;&gt;1000&lt;/span&gt;&#xA;    &lt;span class=&#34;n&#34;&gt;dataloader&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;DataLoader&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&#xA;        &lt;span class=&#34;n&#34;&gt;TensorDataset&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;sequences&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;[:,&lt;/span&gt; &lt;span class=&#34;p&#34;&gt;:&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;-&lt;/span&gt;&lt;span class=&#34;mi&#34;&gt;1&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;],&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;sequences&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;[:,&lt;/span&gt; &lt;span class=&#34;mi&#34;&gt;1&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;:]),&lt;/span&gt;&#xA;        &lt;span class=&#34;n&#34;&gt;batch_size&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;=&lt;/span&gt;&lt;span class=&#34;mi&#34;&gt;20&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt;&#xA;        &lt;span class=&#34;n&#34;&gt;shuffle&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;=&lt;/span&gt;&lt;span class=&#34;kc&#34;&gt;True&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt;&#xA;    &lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;&#xA;&#xA;    &lt;span class=&#34;n&#34;&gt;model&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;train&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;()&lt;/span&gt;&#xA;    &lt;span class=&#34;k&#34;&gt;for&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;step&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;x_batch&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;y_batch&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt; &lt;span class=&#34;ow&#34;&gt;in&lt;/span&gt; &lt;span class=&#34;nb&#34;&gt;enumerate&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;dataloader&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;start&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;=&lt;/span&gt;&lt;span class=&#34;mi&#34;&gt;1&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;):&lt;/span&gt;&#xA;        &lt;span class=&#34;n&#34;&gt;x_batch&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;y_batch&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;x_batch&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;to&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;device&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;),&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;y_batch&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;to&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;device&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;&#xA;&#xA;        &lt;span class=&#34;n&#34;&gt;logits&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;model&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;x_batch&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;                                                &lt;span class=&#34;c1&#34;&gt;# 1. Forward pass&lt;/span&gt;&#xA;        &lt;span class=&#34;n&#34;&gt;loss&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;F&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;cross_entropy&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;logits&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;reshape&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;-&lt;/span&gt;&lt;span class=&#34;mi&#34;&gt;1&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;mi&#34;&gt;1000&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;),&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;y_batch&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;reshape&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;-&lt;/span&gt;&lt;span class=&#34;mi&#34;&gt;1&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;))&lt;/span&gt;  &lt;span class=&#34;c1&#34;&gt;# 2. Cross-entropy loss&lt;/span&gt;&#xA;        &lt;span class=&#34;n&#34;&gt;opt_muon&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;zero_grad&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;();&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;opt_adamw&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;zero_grad&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;()&lt;/span&gt;                            &lt;span class=&#34;c1&#34;&gt;# 3. Clear stale grads&lt;/span&gt;&#xA;        &lt;span class=&#34;n&#34;&gt;loss&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;backward&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;()&lt;/span&gt;                                                        &lt;span class=&#34;c1&#34;&gt;# 4. Backward contraction&lt;/span&gt;&#xA;        &lt;span class=&#34;n&#34;&gt;opt_muon&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;step&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;();&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;opt_adamw&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;step&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;()&lt;/span&gt;                                      &lt;span class=&#34;c1&#34;&gt;# 5. Dual-optimizer step&lt;/span&gt;&#xA;&#xA;        &lt;span class=&#34;k&#34;&gt;if&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;step&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;==&lt;/span&gt; &lt;span class=&#34;mi&#34;&gt;1&lt;/span&gt; &lt;span class=&#34;ow&#34;&gt;or&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;step&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;%&lt;/span&gt; &lt;span class=&#34;mi&#34;&gt;10&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;==&lt;/span&gt; &lt;span class=&#34;mi&#34;&gt;0&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;:&lt;/span&gt;&#xA;            &lt;span class=&#34;nb&#34;&gt;print&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;sa&#34;&gt;f&lt;/span&gt;&lt;span class=&#34;s2&#34;&gt;&amp;#34;Epoch 1 | Step [&lt;/span&gt;&lt;span class=&#34;si&#34;&gt;{&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;step&lt;/span&gt;&lt;span class=&#34;si&#34;&gt;:&lt;/span&gt;&lt;span class=&#34;s2&#34;&gt;2d&lt;/span&gt;&lt;span class=&#34;si&#34;&gt;}&lt;/span&gt;&lt;span class=&#34;s2&#34;&gt;/50] | Loss: &lt;/span&gt;&lt;span class=&#34;si&#34;&gt;{&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;loss&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;item&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;()&lt;/span&gt;&lt;span class=&#34;si&#34;&gt;:&lt;/span&gt;&lt;span class=&#34;s2&#34;&gt;.4f&lt;/span&gt;&lt;span class=&#34;si&#34;&gt;}&lt;/span&gt;&lt;span class=&#34;s2&#34;&gt;&amp;#34;&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;span class=&#34;code-tools&#34;&gt;&lt;span class=&#34;lang&#34;&gt;python&lt;/span&gt;&lt;button class=&#34;copy&#34; type=&#34;button&#34;&gt;copy&lt;/button&gt;&lt;/span&gt;&lt;/figure&gt;&#xA;&lt;p&gt;Running this script drops cross-entropy smoothly from near the uniform random baseline &lt;code&gt;$\ln(1000) \approx 6.91$&lt;/code&gt;:&lt;/p&gt;&#xA;&lt;figure class=&#34;code&#34;&gt;&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code&gt;Epoch 1 | Step [ 1/50] | Loss: 7.1004&#xA;Epoch 1 | Step [10/50] | Loss: 6.7182&#xA;Epoch 1 | Step [20/50] | Loss: 6.2750&#xA;Epoch 1 | Step [30/50] | Loss: 5.7630&#xA;Epoch 1 | Step [40/50] | Loss: 5.0782&#xA;Epoch 1 | Step [50/50] | Loss: 4.5468&lt;/code&gt;&lt;/pre&gt;&lt;span class=&#34;code-tools&#34;&gt;&lt;button class=&#34;copy&#34; type=&#34;button&#34;&gt;copy&lt;/button&gt;&lt;/span&gt;&lt;/figure&gt;&#xA;&lt;hr&gt;&#xA;&lt;h2 id=&#34;summary-modern-optimizer-evolution-at-a-glance&#34;&gt;Summary: Modern Optimizer Evolution at a Glance&lt;/h2&gt;&#xA;&lt;p&gt;Stepping back across all seven sections, the progression from scalar gradient descent to modern hybrid LLM optimizers revolves around three successive questions: &lt;strong&gt;how to smooth gradient noise and curvature oscillation with history&lt;/strong&gt;, &lt;strong&gt;how to decouple weight shrinkage from adaptive preconditioning&lt;/strong&gt;, and &lt;strong&gt;how to match each parameter&#39;s update norm to the geometry of its input and output spaces&lt;/strong&gt;:&lt;/p&gt;&#xA;&lt;figure class=&#34;data wide&#34;&gt;&lt;figcaption&gt;Summary of Five Optimizer Generations: Update Signals, Implicit Norms, and Benchmark Recall&lt;/figcaption&gt;&lt;div class=&#34;data-scroll&#34; tabindex=&#34;0&#34;&gt;&lt;table&gt;&lt;thead&gt;&lt;tr&gt;&lt;th&gt;Optimizer&lt;/th&gt;&lt;th&gt;Update Signal &amp;amp; Transform&lt;/th&gt;&lt;th&gt;Weight Decay&lt;/th&gt;&lt;th&gt;Implicit Norm Ball&lt;/th&gt;&lt;th class=&#34;num bar-head&#34; style=&#34;--vw:5ch&#34;&gt;&lt;span class=&#34;bar-head-in&#34;&gt;Recall&lt;/span&gt;&lt;/th&gt;&lt;/tr&gt;&lt;/thead&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td class=&#34;row-key&#34;&gt;SGD (+L2)&lt;/td&gt;&lt;td class=&#34;prose-col&#34;&gt;&lt;code&gt;$g_t$&lt;/code&gt; (scalar step)&lt;/td&gt;&lt;td class=&#34;prose-col&#34;&gt;Coupled &lt;code&gt;$g_t + \lambda\theta$&lt;/code&gt;&lt;/td&gt;&lt;td class=&#34;prose-col&#34;&gt;&lt;code&gt;$\|\Delta\theta\|_2$&lt;/code&gt;&lt;/td&gt;&lt;td class=&#34;num bar&#34; style=&#34;--vw:5ch&#34;&gt;&lt;span class=&#34;bar-cell&#34;&gt;&lt;span class=&#34;bar-track&#34; aria-hidden=&#34;true&#34;&gt;&lt;i class=&#34;bar-fill&#34; style=&#34;left:0.0%;width:9.5%&#34;&gt;&lt;/i&gt;&lt;/span&gt;&lt;span class=&#34;bar-val&#34;&gt;7.3%&lt;/span&gt;&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td class=&#34;row-key&#34;&gt;Momentum&lt;/td&gt;&lt;td class=&#34;prose-col&#34;&gt;&lt;code&gt;$m_t$&lt;/code&gt; (heavy-ball EMA)&lt;/td&gt;&lt;td class=&#34;prose-col&#34;&gt;Coupled &lt;code&gt;$g_t + \lambda\theta$&lt;/code&gt;&lt;/td&gt;&lt;td class=&#34;prose-col&#34;&gt;&lt;code&gt;$\|\Delta\theta\|_2$&lt;/code&gt; + inertia&lt;/td&gt;&lt;td class=&#34;num bar&#34; style=&#34;--vw:5ch&#34;&gt;&lt;span class=&#34;bar-cell&#34;&gt;&lt;span class=&#34;bar-track&#34; aria-hidden=&#34;true&#34;&gt;&lt;i class=&#34;bar-fill&#34; style=&#34;left:0.0%;width:9.6%&#34;&gt;&lt;/i&gt;&lt;/span&gt;&lt;span class=&#34;bar-val&#34;&gt;7.4%&lt;/span&gt;&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td class=&#34;row-key&#34;&gt;Adam (+L2)&lt;/td&gt;&lt;td class=&#34;prose-col&#34;&gt;&lt;code&gt;$\hat{m}_t / (\sqrt{\hat{v}_t} + \epsilon)$&lt;/code&gt;&lt;/td&gt;&lt;td class=&#34;prose-col&#34;&gt;Distorted by &lt;code&gt;$\sqrt{\hat{v}_t}$&lt;/code&gt;&lt;/td&gt;&lt;td class=&#34;prose-col&#34;&gt;&lt;code&gt;$\|\Delta\theta\|_\infty$&lt;/code&gt;&lt;/td&gt;&lt;td class=&#34;num null&#34; style=&#34;--vw:5ch&#34;&gt;&lt;span class=&#34;bar-cell&#34;&gt;&lt;span class=&#34;bar-val&#34;&gt;—&lt;/span&gt;&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td class=&#34;row-key&#34;&gt;AdamW&lt;/td&gt;&lt;td class=&#34;prose-col&#34;&gt;&lt;code&gt;$\hat{m}_t / (\sqrt{\hat{v}_t} + \epsilon)$&lt;/code&gt;&lt;/td&gt;&lt;td class=&#34;prose-col&#34;&gt;Decoupled &lt;code&gt;$(1-\eta\lambda)\theta$&lt;/code&gt;&lt;/td&gt;&lt;td class=&#34;prose-col&#34;&gt;&lt;code&gt;$\|\Delta\theta\|_\infty$&lt;/code&gt;&lt;/td&gt;&lt;td class=&#34;num bar&#34; style=&#34;--vw:5ch&#34;&gt;&lt;span class=&#34;bar-cell&#34;&gt;&lt;span class=&#34;bar-track&#34; aria-hidden=&#34;true&#34;&gt;&lt;i class=&#34;bar-fill&#34; style=&#34;left:0.0%;width:30.8%&#34;&gt;&lt;/i&gt;&lt;/span&gt;&lt;span class=&#34;bar-val&#34;&gt;23.7%&lt;/span&gt;&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr class=&#34;mark&#34;&gt;&lt;td class=&#34;row-key&#34;&gt;Muon+AdamW&lt;/td&gt;&lt;td class=&#34;prose-col&#34;&gt;&lt;code&gt;$\tilde{M}_t$&lt;/code&gt; via 5-step NS5&lt;/td&gt;&lt;td class=&#34;prose-col&#34;&gt;Decoupled &lt;code&gt;$(1-\eta\lambda)W$&lt;/code&gt;&lt;/td&gt;&lt;td class=&#34;prose-col&#34;&gt;&lt;code&gt;$\|\Delta W\|_{\mathrm{RMS}\to\mathrm{RMS}}$&lt;/code&gt;&lt;/td&gt;&lt;td class=&#34;num bar&#34; style=&#34;--vw:5ch&#34;&gt;&lt;span class=&#34;bar-cell&#34;&gt;&lt;span class=&#34;bar-track&#34; aria-hidden=&#34;true&#34;&gt;&lt;i class=&#34;bar-fill&#34; style=&#34;left:0.0%;width:100.0%&#34;&gt;&lt;/i&gt;&lt;/span&gt;&lt;span class=&#34;bar-val&#34;&gt;77.0%&lt;/span&gt;&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/div&gt;&lt;p class=&#34;data-note&#34;&gt;Recall comes from the Section 6 2-layer 4-head Mini-Transformer associative recall benchmark at step 360 (Adam+L2 is omitted from that run since its decay distortion is isolated in Section 3.4).&lt;/p&gt;&lt;/figure&gt;&#xA;&lt;p&gt;Keeping this single thread in mind—from the four tensor lifetimes in VRAM, to the rank-one outer-product sum &lt;code&gt;$G = \Delta^\top X$&lt;/code&gt; that skews singular spectra, to the induced-norm split between &lt;code&gt;Muon&lt;/code&gt; and &lt;code&gt;AdamW&lt;/code&gt;—turns every matrix transpose, &lt;code&gt;bfloat16&lt;/code&gt; cast, and RMS scaling factor in &lt;code&gt;modded-nanogpt&lt;/code&gt;, &lt;code&gt;Moonlight&lt;/code&gt;, and modern pretraining frameworks into a direct consequence of linear algebra.&lt;/p&gt;&#xA;&lt;h2 id=&#34;references&#34;&gt;References&lt;/h2&gt;&#xA;&lt;ol class=&#34;references&#34;&gt;&#xA;&lt;li id=&#34;ref-vaswani2017&#34;&gt;&lt;span class=&#34;ref-back&#34;&gt;&lt;span aria-hidden=&#34;true&#34;&gt;↑&lt;/span&gt; &lt;a href=&#34;#cite-vaswani2017-1&#34; aria-label=&#34;Back to citation 1&#34;&gt;1&lt;/a&gt; &lt;a href=&#34;#cite-vaswani2017-2&#34; aria-label=&#34;Back to citation 2&#34;&gt;2&lt;/a&gt; &lt;a href=&#34;#cite-vaswani2017-3&#34; aria-label=&#34;Back to citation 3&#34;&gt;3&lt;/a&gt;&lt;/span&gt; Vaswani, A., Shazeer, N., Parmar, N., Uszkoreit, J., Jones, L., Gomez, A. N., Kaiser, Ł., &amp;amp; Polosukhin, I. (2017). &lt;a href=&#34;https://arxiv.org/abs/1706.03762&#34;&gt;Attention Is All You Need&lt;/a&gt;. &lt;em&gt;Advances in Neural Information Processing Systems 30 (NeurIPS 2017)&lt;/em&gt;.&lt;/li&gt;&#xA;&lt;li id=&#34;ref-robbins1951&#34;&gt;&lt;span class=&#34;ref-back&#34;&gt;&lt;span aria-hidden=&#34;true&#34;&gt;↑&lt;/span&gt; &lt;a href=&#34;#cite-robbins1951-1&#34; aria-label=&#34;Back to citation 1&#34;&gt;1&lt;/a&gt; &lt;a href=&#34;#cite-robbins1951-2&#34; aria-label=&#34;Back to citation 2&#34;&gt;2&lt;/a&gt;&lt;/span&gt; Robbins, H., &amp;amp; Monro, S. (1951). &lt;a href=&#34;https://doi.org/10.1214/aoms/1177729586&#34;&gt;A Stochastic Approximation Method&lt;/a&gt;. &lt;em&gt;The Annals of Mathematical Statistics, 22&lt;/em&gt;(3), 400–407.&lt;/li&gt;&#xA;&lt;li id=&#34;ref-loshchilov2019&#34;&gt;&lt;span class=&#34;ref-back&#34;&gt;&lt;span aria-hidden=&#34;true&#34;&gt;↑&lt;/span&gt; &lt;a href=&#34;#cite-loshchilov2019-1&#34; aria-label=&#34;Back to citation 1&#34;&gt;1&lt;/a&gt; &lt;a href=&#34;#cite-loshchilov2019-2&#34; aria-label=&#34;Back to citation 2&#34;&gt;2&lt;/a&gt;&lt;/span&gt; Loshchilov, I., &amp;amp; Hutter, F. (2019). &lt;a href=&#34;https://arxiv.org/abs/1711.05101&#34;&gt;Decoupled Weight Decay Regularization&lt;/a&gt;. &lt;em&gt;International Conference on Learning Representations (ICLR 2019)&lt;/em&gt;.&lt;/li&gt;&#xA;&lt;li id=&#34;ref-jordan2024&#34;&gt;&lt;span class=&#34;ref-back&#34;&gt;&lt;span aria-hidden=&#34;true&#34;&gt;↑&lt;/span&gt; &lt;a href=&#34;#cite-jordan2024-1&#34; aria-label=&#34;Back to citation 1&#34;&gt;1&lt;/a&gt; &lt;a href=&#34;#cite-jordan2024-2&#34; aria-label=&#34;Back to citation 2&#34;&gt;2&lt;/a&gt; &lt;a href=&#34;#cite-jordan2024-3&#34; aria-label=&#34;Back to citation 3&#34;&gt;3&lt;/a&gt; &lt;a href=&#34;#cite-jordan2024-4&#34; aria-label=&#34;Back to citation 4&#34;&gt;4&lt;/a&gt; &lt;a href=&#34;#cite-jordan2024-5&#34; aria-label=&#34;Back to citation 5&#34;&gt;5&lt;/a&gt; &lt;a href=&#34;#cite-jordan2024-6&#34; aria-label=&#34;Back to citation 6&#34;&gt;6&lt;/a&gt;&lt;/span&gt; Jordan, K., Jin, Y., Boza, V., You, J., Cesista, F., Newhouse, L., &amp;amp; Bernstein, J. (2024). &lt;a href=&#34;https://kellerjordan.github.io/posts/muon/&#34;&gt;Muon: An Optimizer for Hidden Layers in Neural Networks&lt;/a&gt;. &lt;em&gt;Keller Jordan blog&lt;/em&gt;.&lt;/li&gt;&#xA;&lt;li id=&#34;ref-liu2025&#34;&gt;&lt;span class=&#34;ref-back&#34;&gt;&lt;span aria-hidden=&#34;true&#34;&gt;↑&lt;/span&gt; &lt;a href=&#34;#cite-liu2025-1&#34; aria-label=&#34;Back to citation 1&#34;&gt;1&lt;/a&gt; &lt;a href=&#34;#cite-liu2025-2&#34; aria-label=&#34;Back to citation 2&#34;&gt;2&lt;/a&gt; &lt;a href=&#34;#cite-liu2025-3&#34; aria-label=&#34;Back to citation 3&#34;&gt;3&lt;/a&gt; &lt;a href=&#34;#cite-liu2025-4&#34; aria-label=&#34;Back to citation 4&#34;&gt;4&lt;/a&gt; &lt;a href=&#34;#cite-liu2025-5&#34; aria-label=&#34;Back to citation 5&#34;&gt;5&lt;/a&gt; &lt;a href=&#34;#cite-liu2025-6&#34; aria-label=&#34;Back to citation 6&#34;&gt;6&lt;/a&gt; &lt;a href=&#34;#cite-liu2025-7&#34; aria-label=&#34;Back to citation 7&#34;&gt;7&lt;/a&gt; &lt;a href=&#34;#cite-liu2025-8&#34; aria-label=&#34;Back to citation 8&#34;&gt;8&lt;/a&gt;&lt;/span&gt; Liu, J., Su, J., Yao, X., Jiang, Z., Lai, G., Du, Y., Qin, Y., Xu, W., Lu, E., Yan, J., et al. (2025). &lt;a href=&#34;https://arxiv.org/abs/2502.16982&#34;&gt;Muon is Scalable for LLM Training&lt;/a&gt;. &lt;em&gt;arXiv preprint arXiv:2502.16982&lt;/em&gt;.&lt;/li&gt;&#xA;&lt;li id=&#34;ref-zhang2019&#34;&gt;&lt;span class=&#34;ref-back&#34;&gt;&lt;span aria-hidden=&#34;true&#34;&gt;↑&lt;/span&gt; &lt;a href=&#34;#cite-zhang2019-1&#34; aria-label=&#34;Back to citation 1&#34;&gt;1&lt;/a&gt; &lt;a href=&#34;#cite-zhang2019-2&#34; aria-label=&#34;Back to citation 2&#34;&gt;2&lt;/a&gt; &lt;a href=&#34;#cite-zhang2019-3&#34; aria-label=&#34;Back to citation 3&#34;&gt;3&lt;/a&gt;&lt;/span&gt; Zhang, B., &amp;amp; Sennrich, R. (2019). &lt;a href=&#34;https://arxiv.org/abs/1910.07467&#34;&gt;Root Mean Square Layer Normalization&lt;/a&gt;. &lt;em&gt;Advances in Neural Information Processing Systems 32 (NeurIPS 2019)&lt;/em&gt;.&lt;/li&gt;&#xA;&lt;li id=&#34;ref-polyak1964&#34;&gt;&lt;span class=&#34;ref-back&#34;&gt;&lt;a href=&#34;#cite-polyak1964-1&#34; aria-label=&#34;Back to citation&#34;&gt;↑&lt;/a&gt;&lt;/span&gt; Polyak, B. T. (1964). &lt;a href=&#34;https://doi.org/10.1016/0041-5553(64)90137-5&#34;&gt;Some Methods of Speeding Up the Convergence of Iteration Methods&lt;/a&gt;. &lt;em&gt;USSR Computational Mathematics and Mathematical Physics, 4&lt;/em&gt;(5), 1–17.&lt;/li&gt;&#xA;&lt;li id=&#34;ref-nesterov1983&#34;&gt;&lt;span class=&#34;ref-back&#34;&gt;&lt;a href=&#34;#cite-nesterov1983-1&#34; aria-label=&#34;Back to citation&#34;&gt;↑&lt;/a&gt;&lt;/span&gt; Nesterov, Y. (1983). A Method for Solving the Convex Programming Problem with Convergence Rate &lt;code&gt;$O(1/k^2)$&lt;/code&gt;. &lt;em&gt;Doklady AN SSSR, 269&lt;/em&gt;, 543–547.&lt;/li&gt;&#xA;&lt;li id=&#34;ref-duchi2011&#34;&gt;&lt;span class=&#34;ref-back&#34;&gt;&lt;a href=&#34;#cite-duchi2011-1&#34; aria-label=&#34;Back to citation&#34;&gt;↑&lt;/a&gt;&lt;/span&gt; Duchi, J., Hazan, E., &amp;amp; Singer, Y. (2011). &lt;a href=&#34;https://jmlr.org/papers/v12/duchi11a.html&#34;&gt;Adaptive Subgradient Methods for Online Learning and Stochastic Optimization&lt;/a&gt;. &lt;em&gt;Journal of Machine Learning Research, 12&lt;/em&gt;, 2121–2159.&lt;/li&gt;&#xA;&lt;li id=&#34;ref-kingma2015&#34;&gt;&lt;span class=&#34;ref-back&#34;&gt;&lt;span aria-hidden=&#34;true&#34;&gt;↑&lt;/span&gt; &lt;a href=&#34;#cite-kingma2015-1&#34; aria-label=&#34;Back to citation 1&#34;&gt;1&lt;/a&gt; &lt;a href=&#34;#cite-kingma2015-2&#34; aria-label=&#34;Back to citation 2&#34;&gt;2&lt;/a&gt;&lt;/span&gt; Kingma, D. P., &amp;amp; Ba, J. (2015). &lt;a href=&#34;https://arxiv.org/abs/1412.6980&#34;&gt;Adam: A Method for Stochastic Optimization&lt;/a&gt;. &lt;em&gt;International Conference on Learning Representations (ICLR 2015)&lt;/em&gt;.&lt;/li&gt;&#xA;&lt;li id=&#34;ref-gupta2018&#34;&gt;&lt;span class=&#34;ref-back&#34;&gt;&lt;a href=&#34;#cite-gupta2018-1&#34; aria-label=&#34;Back to citation&#34;&gt;↑&lt;/a&gt;&lt;/span&gt; Gupta, V., Koren, T., &amp;amp; Singer, Y. (2018). &lt;a href=&#34;https://arxiv.org/abs/1802.09568&#34;&gt;Shampoo: Preconditioned Stochastic Tensor Optimization&lt;/a&gt;. &lt;em&gt;Proceedings of the 35th International Conference on Machine Learning (ICML 2018)&lt;/em&gt;, 1842–1850.&lt;/li&gt;&#xA;&lt;li id=&#34;ref-bernstein2024&#34;&gt;&lt;span class=&#34;ref-back&#34;&gt;&lt;span aria-hidden=&#34;true&#34;&gt;↑&lt;/span&gt; &lt;a href=&#34;#cite-bernstein2024-1&#34; aria-label=&#34;Back to citation 1&#34;&gt;1&lt;/a&gt; &lt;a href=&#34;#cite-bernstein2024-2&#34; aria-label=&#34;Back to citation 2&#34;&gt;2&lt;/a&gt; &lt;a href=&#34;#cite-bernstein2024-3&#34; aria-label=&#34;Back to citation 3&#34;&gt;3&lt;/a&gt; &lt;a href=&#34;#cite-bernstein2024-4&#34; aria-label=&#34;Back to citation 4&#34;&gt;4&lt;/a&gt;&lt;/span&gt; Bernstein, J., &amp;amp; Newhouse, L. (2024). &lt;a href=&#34;https://arxiv.org/abs/2409.20325&#34;&gt;Old Optimizer, New Norm: An Anthology&lt;/a&gt;. &lt;em&gt;arXiv preprint arXiv:2409.20325&lt;/em&gt;.&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;</description>
      <category>Tech</category>
      <pubDate>Tue, 24 Nov 2026 00:00:00 +0000</pubDate>
      <guid>https://mizore.blog/en/posts/from-transformer-matrices-to-muon/</guid>
    </item>
    <item>
      <title>Save a Little, Then Save a Little More</title>
      <link>https://mizore.blog/en/posts/save-a-little-more/</link>
      <description>&lt;p&gt;Two bots live in our Telegram group.&lt;/p&gt;&#xA;&lt;p&gt;One is &lt;a href=&#34;https://github.com/mizorewww/pi-extension-telegram-agent&#34;&gt;Pi Telegram Agent&lt;/a&gt;, written by me; the other is &lt;a href=&#34;https://github.com/tuuject/surowan&#34;&gt;Surowan&lt;/a&gt; (&amp;quot;Plastic Bowl&amp;quot;), written by our group member tcdw. The two projects share not a single line of code. Their architectural philosophies, tech stacks, and even conversational personalities are polar opposites. Yet over months of real-world group chat collisions, their evolutionary trajectories converged on the exact same commandment: &lt;strong&gt;save a little, then save a little more.&lt;/strong&gt;&lt;/p&gt;&#xA;&lt;p&gt;Many people think &amp;quot;saving&amp;quot; is a compromise on resources—a stingy exercise in engineering self-flagellation. Quite the opposite. Over the past three months and more than 74,000 production model calls, I have become increasingly convinced: &lt;strong&gt;in LLM-driven systems, frugality is the highest form of design aesthetics.&lt;/strong&gt;&lt;/p&gt;&#xA;&lt;p&gt;When you peel back the flashy scaffolding of an agent system layer by layer, you discover that code, context, and cloud bills are physically projections of the exact same entity—&lt;strong&gt;Tokens&lt;/strong&gt;—across different dimensions. Elaborate mechanisms almost always breed high entropy and fragility, whereas every act of restraint derived from strict first-principles reasoning ultimately pays off in remarkable lightness, speed, and capability.&lt;/p&gt;&#xA;&lt;p&gt;This post is both an honest ledger postmortem from a high-frequency production environment and an exercise in stripping away appearances to reach the core.&lt;/p&gt;&#xA;&lt;h2 id=&#34;tldr&#34;&gt;TL;DR&lt;/h2&gt;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;&lt;strong&gt;The Unified Currency Hypothesis:&lt;/strong&gt; Your cloud bill is tokens, your context window is tokens, and to a coding agent, your codebase is tokens too. They are not separate management targets, but projections of a single conservation law across different dimensions.&lt;/li&gt;&#xA;&lt;li&gt;&lt;strong&gt;Dissecting the Lion&#39;s Share of the Bill:&lt;/strong&gt; 74,644 model calls reveal a brutal reality—&lt;strong&gt;input is 374× larger than output&lt;/strong&gt;. Nearly 90% of a group chat bot&#39;s token ledger is chat history, while tool schemas account for just 1.1%. The survival of the system hangs entirely on context length and cache hit rate.&lt;/li&gt;&#xA;&lt;li&gt;&lt;strong&gt;Decoupling Perception from Reasoning (Controlling Call Volume &lt;code&gt;$N$&lt;/code&gt;):&lt;/strong&gt; Replying when explicitly mentioned is deterministic logic that requires zero intelligence. Deciding whether to chime in on ambient chatter is offloaded to a dedicated small classifier model that reads only a 6-line slice (~1,650 tokens, $0.000033 per call), never polluting the main model&#39;s context. And once a message is sent, a local primitive terminates the turn immediately—pinning non-essential round-trips down to an average of 1.13 calls per turn.&lt;/li&gt;&#xA;&lt;li&gt;&lt;strong&gt;Byte-Level Paranoia (Guarding Cache Hit Rate &lt;code&gt;$h$&lt;/code&gt;):&lt;/strong&gt; The prefix must grow monotonically and never be mutated. Dynamic stickers and asynchronous media updates are projected via read-only metadata and &lt;code&gt;beforeRequest&lt;/code&gt; into &lt;code&gt;[System Note]&lt;/code&gt; blocks that never enter persistent session history. Backed by 55 versions of Golden Hash regression tests, this pins our measured DeepSeek cache hit rate at 98.7%, slashing input costs to 1/30th of uncached pricing.&lt;/li&gt;&#xA;&lt;li&gt;&lt;strong&gt;Verbatim Words Over Hallucinated Summaries (Compressing Context Depth &lt;code&gt;$T$&lt;/code&gt;):&lt;/strong&gt; We abandoned all fancy multi-tier memory extraction and graph databases. Both frontier research and production scars confirm that processed summaries are not only expensive to maintain, they actively self-poison. We fixed our context window at 128K, left raw history sleeping in SQLite, and gave the bot a clean workbench to look things up on demand: literal substring search when it remembers the exact words, semantic search when it only remembers the gist—and what comes back is always the verbatim transcript.&lt;/li&gt;&#xA;&lt;li&gt;&lt;strong&gt;Cashing Restraint In for Freedom:&lt;/strong&gt; The resources we saved don&#39;t just sit in a bank account; they buy extraordinary user experience. &lt;code&gt;codemode&lt;/code&gt; lets the bot &amp;quot;speak while acting&amp;quot; with parallel retrieval, and a single rootless Linux container lets the model orchestrate native Unix tools better than a hundred hand-written plugins ever could.&lt;/li&gt;&#xA;&lt;li&gt;&lt;strong&gt;Decluttering the Codebase Itself:&lt;/strong&gt; Not a single line of code outside &amp;quot;Telegram group chat semantics&amp;quot; is homegrown. By leaning on the underlying Pi engine, we distilled &lt;code&gt;src/&lt;/code&gt; from 17,500 lines down to 8,100 lines—achieving far greater resilience through negative code.&lt;/li&gt;&#xA;&lt;li&gt;&lt;strong&gt;Two Philosophies of Generality:&lt;/strong&gt; Surowan builds a &lt;em&gt;general product with a restrained agent&lt;/em&gt;; I chose a &lt;em&gt;specialized deployment with a general agent&lt;/em&gt;.&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&lt;hr&gt;&#xA;&lt;h2 id=&#34;gazing-into-the-ledger-where-the-real-money-flows&#34;&gt;Gazing into the Ledger: Where the Real Money Flows&lt;/h2&gt;&#xA;&lt;p&gt;All design aesthetics must rest on an unflinching gaze at physical reality.&lt;/p&gt;&#xA;&lt;p&gt;From its launch on August 7 to the architectural overhaul on November 4, my bot recorded comprehensive telemetry for every single production model call: input size, cached tokens read, output volume, and the exact byte breakdown of each segment inside every request. After three months, the overall ledger looks like this:&lt;/p&gt;&#xA;&lt;figure class=&#34;stats&#34;&gt;&lt;figcaption&gt;&lt;span&gt;Three-Month Ledger&lt;/span&gt;&lt;span class=&#34;key&#34;&gt;2026-08-07 — 2026-11-04 · Two bots · One group&lt;/span&gt;&lt;/figcaption&gt;&lt;p class=&#34;stats-group&#34;&gt;&lt;b&gt;Scale&lt;/b&gt;&lt;/p&gt;&lt;dl class=&#34;kpi&#34; style=&#34;--k:3&#34;&gt;&lt;div&gt;&lt;dt&gt;Group messages&lt;/dt&gt;&lt;dd&gt;144,148&lt;/dd&gt;&lt;dd class=&#34;s&#34;&gt;Human messages after router logging began&lt;/dd&gt;&lt;/div&gt;&lt;div&gt;&lt;dt&gt;Model calls&lt;/dt&gt;&lt;dd&gt;74,644&lt;/dd&gt;&lt;dd class=&#34;s&#34;&gt;Including 11,544 compaction calls&lt;/dd&gt;&lt;/div&gt;&lt;div&gt;&lt;dt&gt;Public replies&lt;/dt&gt;&lt;dd&gt;39,615&lt;/dd&gt;&lt;dd class=&#34;s&#34;&gt;Total send invocations&lt;/dd&gt;&lt;/div&gt;&lt;/dl&gt;&lt;p class=&#34;stats-group&#34;&gt;&lt;b&gt;Tokens&lt;/b&gt;&lt;/p&gt;&lt;dl class=&#34;kpi&#34; style=&#34;--k:3&#34;&gt;&lt;div&gt;&lt;dt&gt;Input&lt;/dt&gt;&lt;dd&gt;5.34B&lt;/dd&gt;&lt;dd class=&#34;s&#34;&gt;Including 3.50B cache reads&lt;/dd&gt;&lt;/div&gt;&lt;div&gt;&lt;dt&gt;Output&lt;/dt&gt;&lt;dd&gt;14.3M&lt;/dd&gt;&lt;dd class=&#34;s&#34;&gt;Input is 374× output&lt;/dd&gt;&lt;/div&gt;&lt;div&gt;&lt;dt&gt;Calls per turn&lt;/dt&gt;&lt;dd&gt;1.13&lt;/dd&gt;&lt;dd class=&#34;s&#34;&gt;Non-compaction calls ÷ started turns&lt;/dd&gt;&lt;/div&gt;&lt;/dl&gt;&lt;p class=&#34;data-note&#34;&gt;Input tokens include cache hits.&lt;/p&gt;&lt;/figure&gt;&#xA;&lt;p&gt;&lt;strong&gt;Input is 374 times output.&lt;/strong&gt;&lt;/p&gt;&#xA;&lt;p&gt;This is the first reality check that hits anyone building an LLM group chat system. Our intuition from human-computer interaction tells us that &amp;quot;conversation&amp;quot; is a symmetric game of throwing out a sentence and getting one back. In a high-frequency multi-person group chat, the truth is ruthlessly asymmetric: a group member posts a casual &amp;quot;haha true,&amp;quot; and the model must chew through a heavy system prompt, tool definitions, and a massive stretch of chat history—only to think through several layers and reply with two words, or choose to stay silent.&lt;/p&gt;&#xA;&lt;p&gt;&lt;strong&gt;Physically, a group chat system&#39;s bill consists almost entirely of &lt;em&gt;reading&lt;/em&gt;.&lt;/strong&gt;&lt;/p&gt;&#xA;&lt;p&gt;Over these three months, we rotated through three primary models: first DeepSeek V4 Flash, then Gemini Flash in late August, and finally SWE-2 in late September. Every number below was recorded across all three in production:&lt;/p&gt;&#xA;&lt;figure class=&#34;echart&#34; style=&#34;--h:320px&#34;&gt;&lt;figcaption&gt;Weekly Model Calls by Primary Model&lt;/figcaption&gt;&lt;p&gt;&lt;a href=&#34;https://mizore.blog/en/posts/save-a-little-more/&#34;&gt;(See the figure in the post.)&lt;/a&gt;&lt;/p&gt;&lt;p class=&#34;figure-note&#34;&gt;Excludes compaction calls. Grouped by calendar week (UTC+8), starting from the Aug 7 launch; data comes from a local snapshot taken on Nov 1 (three days shorter than the ledger above, leaving the final week partial). Another 521 trial calls to GLM, GPT mini, etc. are omitted.&lt;/p&gt;&lt;/figure&gt;&#xA;&lt;p&gt;So what exactly are those billions of tokens reading? We sampled and dissected over 40,000 real request payloads, placing them side by side with a single request captured before my earlier optimization of &lt;a href=&#34;https://mizore.blog/en/posts/making-memoh-cheaper-on-telegram/&#34;&gt;Memoh&lt;/a&gt;:&lt;/p&gt;&#xA;&lt;figure class=&#34;diagram&#34; style=&#34;--h:336px;--hn:530px&#34;&gt;&lt;figcaption&gt;What Goes Inside a Single Request&lt;/figcaption&gt;&lt;p&gt;&lt;a href=&#34;https://mizore.blog/en/posts/save-a-little-more/&#34;&gt;(See the figure in the post.)&lt;/a&gt;&lt;/p&gt;&lt;p class=&#34;figure-note&#34;&gt;This project: average across 40,593 requests (93,067 tokens per call). Memoh before optimization: a single captured request, measured by byte share. Dashed boxes represent total input per request, scaled proportionally.&lt;/p&gt;&lt;/figure&gt;&#xA;&lt;p&gt;This diagram pours cold water on a lot of self-important &amp;quot;architectural optimizations&amp;quot;:&#xA;People love obsessing over prompt wording, trimming two sentences from the system prompt, or shortening tool names by a few characters—yet even when you optimize tool schemas to the bone, they account for a mere 1.1% of real requests.&lt;/p&gt;&#xA;&lt;p&gt;&lt;strong&gt;The total cost of the entire system is governed by a minimalist mathematical model:&lt;/strong&gt;&lt;/p&gt;&#xA;&lt;p&gt;&lt;code&gt;$$C = N \times T \times \left[(1-h) + h \times r\right]$$&lt;/code&gt;&lt;/p&gt;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;&lt;code&gt;$N$&lt;/code&gt;: how many times the model is woken up (call volume);&lt;/li&gt;&#xA;&lt;li&gt;&lt;code&gt;$T$&lt;/code&gt;: how much context depth it must swallow each time it wakes up (input tokens);&lt;/li&gt;&#xA;&lt;li&gt;&lt;code&gt;$h$&lt;/code&gt;: the fraction of context that hits the Prompt Cache (cache hit rate);&lt;/li&gt;&#xA;&lt;li&gt;&lt;code&gt;$r$&lt;/code&gt;: the ratio of cached token pricing to full price (an astonishing 1/50 on DeepSeek, 1/10 on Claude).&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&lt;p&gt;This equation is our immovable foundation. In engineering terms, there are only three degrees of freedom where you can apply leverage:&lt;/p&gt;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;&lt;strong&gt;Wake it up less often (shrink &lt;code&gt;$N$&lt;/code&gt;)&lt;/strong&gt;;&lt;/li&gt;&#xA;&lt;li&gt;&lt;strong&gt;Lock down every byte already read (maximize &lt;code&gt;$h$&lt;/code&gt;)&lt;/strong&gt;;&lt;/li&gt;&#xA;&lt;li&gt;&lt;strong&gt;Strip away everything non-essential from each read (compress &lt;code&gt;$T$&lt;/code&gt;)&lt;/strong&gt;.&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&lt;p&gt;Below, we will peel back our architectural choices around restraint and freedom along these three variables, one layer at a time.&lt;/p&gt;&#xA;&lt;hr&gt;&#xA;&lt;h2 id=&#34;layer-1-controlling-call-volume-n--never-pay-full-price-for-silence-and-waiting&#34;&gt;Layer 1: Controlling Call Volume &lt;code&gt;$N$&lt;/code&gt; — Never Pay Full Price for Silence and Waiting&lt;/h2&gt;&#xA;&lt;p&gt;The cheapest model call is &lt;strong&gt;the one that never happens&lt;/strong&gt;.&lt;/p&gt;&#xA;&lt;p&gt;The most fundamental difference between a group chat and a 1-on-1 DM is that a group chat is a public, ever-flowing torrent of information—the vast majority of which has nothing to do with the bot. And that torrent almost never stops: only between 4 a.m. and 6 a.m. does the chat go quiet, peaking in activity after 10 p.m.&lt;/p&gt;&#xA;&lt;figure class=&#34;echart&#34; style=&#34;--h:300px&#34;&gt;&lt;figcaption&gt;When Group Members Talk&lt;/figcaption&gt;&lt;p&gt;&lt;a href=&#34;https://mizore.blog/en/posts/save-a-little-more/&#34;&gt;(See the figure in the post.)&lt;/a&gt;&lt;/p&gt;&lt;p class=&#34;figure-note&#34;&gt;Human message count by day of week and 2-hour slot (UTC+8), totaling 141,717 messages. Taken from the local database snapshot at noon on Nov 1 (three days shorter than the Nov 4 ledger above). More orange means more messages.&lt;/p&gt;&lt;/figure&gt;&#xA;&lt;p&gt;Now look at the ruthless funnel from incoming messages to actual public replies over those three months:&lt;/p&gt;&#xA;&lt;figure class=&#34;data pair&#34;&gt;&lt;figcaption&gt;From Group Messages to Model Calls&lt;/figcaption&gt;&lt;div class=&#34;data-scroll&#34; tabindex=&#34;0&#34;&gt;&lt;table&gt;&lt;thead&gt;&lt;tr&gt;&lt;th&gt;Stage&lt;/th&gt;&lt;th class=&#34;num bar-head&#34; style=&#34;--vw:7ch&#34;&gt;&lt;span class=&#34;bar-head-in&#34;&gt;Count&lt;/span&gt;&lt;/th&gt;&lt;/tr&gt;&lt;/thead&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td class=&#34;row-key prose-col&#34;&gt;Group messages&lt;/td&gt;&lt;td class=&#34;num bar&#34; style=&#34;--vw:7ch&#34;&gt;&lt;span class=&#34;bar-cell&#34;&gt;&lt;span class=&#34;bar-track&#34; aria-hidden=&#34;true&#34;&gt;&lt;i class=&#34;bar-fill&#34; style=&#34;left:0.0%;width:100.0%&#34;&gt;&lt;/i&gt;&lt;/span&gt;&lt;span class=&#34;bar-val&#34;&gt;144,148&lt;/span&gt;&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td class=&#34;row-key prose-col&#34;&gt;Bot busy, merged into next turn&lt;/td&gt;&lt;td class=&#34;num bar&#34; style=&#34;--vw:7ch&#34;&gt;&lt;span class=&#34;bar-cell&#34;&gt;&lt;span class=&#34;bar-track&#34; aria-hidden=&#34;true&#34;&gt;&lt;i class=&#34;bar-fill&#34; style=&#34;left:0.0%;width:35.1%&#34;&gt;&lt;/i&gt;&lt;/span&gt;&lt;span class=&#34;bar-val&#34;&gt;50,532&lt;/span&gt;&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td class=&#34;row-key prose-col&#34;&gt;Turns started&lt;/td&gt;&lt;td class=&#34;num bar&#34; style=&#34;--vw:7ch&#34;&gt;&lt;span class=&#34;bar-cell&#34;&gt;&lt;span class=&#34;bar-track&#34; aria-hidden=&#34;true&#34;&gt;&lt;i class=&#34;bar-fill&#34; style=&#34;left:0.0%;width:38.7%&#34;&gt;&lt;/i&gt;&lt;/span&gt;&lt;span class=&#34;bar-val&#34;&gt;55,776&lt;/span&gt;&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td class=&#34;row-key prose-col&#34;&gt;Model calls&lt;/td&gt;&lt;td class=&#34;num bar&#34; style=&#34;--vw:7ch&#34;&gt;&lt;span class=&#34;bar-cell&#34;&gt;&lt;span class=&#34;bar-track&#34; aria-hidden=&#34;true&#34;&gt;&lt;i class=&#34;bar-fill&#34; style=&#34;left:0.0%;width:43.8%&#34;&gt;&lt;/i&gt;&lt;/span&gt;&lt;span class=&#34;bar-val&#34;&gt;63,100&lt;/span&gt;&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td class=&#34;row-key prose-col&#34;&gt;Public replies&lt;/td&gt;&lt;td class=&#34;num bar&#34; style=&#34;--vw:7ch&#34;&gt;&lt;span class=&#34;bar-cell&#34;&gt;&lt;span class=&#34;bar-track&#34; aria-hidden=&#34;true&#34;&gt;&lt;i class=&#34;bar-fill&#34; style=&#34;left:0.0%;width:27.5%&#34;&gt;&lt;/i&gt;&lt;/span&gt;&lt;span class=&#34;bar-val&#34;&gt;39,615&lt;/span&gt;&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/div&gt;&lt;p class=&#34;data-note&#34;&gt;Turns started = messages marked as started by routing; model calls exclude compaction.&lt;/p&gt;&lt;/figure&gt;&#xA;&lt;p&gt;At the bottom of the funnel sits a stark fact: out of 144,000 group chat messages, the bot spoke publicly fewer than 40,000 times. Even among the 55,776 turns where it woke up to think, in more than 16,000 of them the model read the entire context and politely chose silence.&lt;/p&gt;&#xA;&lt;p&gt;This brings us to our first sharp contradiction:&#xA;&lt;strong&gt;How does the bot know whether to chime in? And once it decides to speak, how do we end the turn as quickly as possible?&lt;/strong&gt;&lt;/p&gt;&#xA;&lt;h3 id=&#34;first-principles-social-tact-doesnt-require-a-90000-token-panoramic-memory&#34;&gt;First Principles: Social Tact Doesn&#39;t Require a 90,000-Token Panoramic Memory&lt;/h3&gt;&#xA;&lt;p&gt;&amp;quot;Should I chime in?&amp;quot; looks like an esoteric social judgment, but when you break it down, it splits into two completely distinct scenarios:&lt;/p&gt;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;&lt;strong&gt;Deterministic scenarios:&lt;/strong&gt; A human explicitly @mentions the bot, replies to its message, or calls it by name. There is zero ambiguity here—a single line of deterministic code or regex routing can make the call. &lt;strong&gt;Not a single millisecond of model inference should ever be wasted here.&lt;/strong&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;strong&gt;Ambient scenarios:&lt;/strong&gt; For the remaining sea of casual chatter, what the bot needs is &lt;em&gt;social tact&lt;/em&gt;.&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&lt;p&gt;What does social tact look like in a group chat? Watch a real human group member:&lt;/p&gt;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;Someone tosses a tricky technical question to the group, and it hangs unanswered for three minutes;&lt;/li&gt;&#xA;&lt;li&gt;Someone follows up directly on what the bot just said a moment ago;&lt;/li&gt;&#xA;&lt;li&gt;Two people are closely planning dinner together in a private, self-contained exchange;&lt;/li&gt;&#xA;&lt;li&gt;Another bot has already given a spot-on answer;&lt;/li&gt;&#xA;&lt;li&gt;Several bots are caught in a loop repeating each other.&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&lt;p&gt;&lt;strong&gt;Examine these scenarios and you reach a striking conclusion: making this call doesn&#39;t require the bot to know who it is, what happened in the group three months ago, or what tools it carries in its heavy toolbox. It depends solely on the conversational flow of the last five to ten lines.&lt;/strong&gt;&lt;/p&gt;&#xA;&lt;p&gt;Common off-the-shelf approaches crumble against this deduction:&lt;/p&gt;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;&lt;strong&gt;Approach A: Let the primary model decide everything.&lt;/strong&gt; Waking the primary model once means hauling 93,000 tokens of baggage out of bed. If the primary model thinks for two seconds and concludes &amp;quot;I shouldn&#39;t interrupt,&amp;quot; you just paid full price on nearly 100,000 tokens for that silence. Multiply that across 140,000 casual messages and your bill explodes.&lt;/li&gt;&#xA;&lt;li&gt;&lt;strong&gt;Approach B: Rely on rules and random probability gates.&lt;/strong&gt; Rolling a die or matching keywords is free, but it has zero comprehension. It plays deaf when someone genuinely needs technical help, yet leaps out on a 10% roll to crack a bad joke while group members are having a serious discussion or venting frustration.&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&lt;p&gt;The right solution must live at the intersection of the two: &lt;strong&gt;it must have semantic comprehension, but it may only read a tiny slice; it only needs to output a probability, not generate a reply.&lt;/strong&gt;&lt;/p&gt;&#xA;&lt;p&gt;Follow those constraints and the answer becomes obvious: &lt;strong&gt;introduce a dedicated small classifier model.&lt;/strong&gt;&lt;/p&gt;&#xA;&lt;figure class=&#34;diagram&#34; style=&#34;--h:224px;--hn:339px&#34;&gt;&lt;figcaption&gt;How an Incoming Group Message Decides Whether to Wake the Primary Model&lt;/figcaption&gt;&lt;p&gt;&lt;a href=&#34;https://mizore.blog/en/posts/save-a-little-more/&#34;&gt;(See the figure in the post.)&lt;/a&gt;&lt;/p&gt;&lt;p class=&#34;figure-note&#34;&gt;Direct mentions take a deterministic route without touching any model; all other messages send only the last few lines to the decider model, leaving the primary model&amp;#39;s context and cache untouched.&lt;/p&gt;&lt;/figure&gt;&#xA;&lt;p&gt;I chose &lt;code&gt;pplx-decider-v1.2&lt;/code&gt;, a specialized small classifier model on OpenRouter (driven via Pi 1.5&#39;s native &lt;code&gt;classify&lt;/code&gt; abstraction). It is dirt cheap along three irreplaceable dimensions:&lt;/p&gt;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;&lt;strong&gt;Fed only a slice:&lt;/strong&gt; It receives only the newly arrived messages plus the preceding 6 lines as background—stripping away the entire system prompt, long-range history, and tool declarations.&lt;/li&gt;&#xA;&lt;li&gt;&lt;strong&gt;Prefix isolation:&lt;/strong&gt; Its invocation is a completely independent short request. Not a single byte of the primary model&#39;s core context is touched, so &lt;strong&gt;the primary model&#39;s Prompt Cache remains 100% intact&lt;/strong&gt;.&lt;/li&gt;&#xA;&lt;li&gt;&lt;strong&gt;Negligible cost:&lt;/strong&gt; A single decision consumes ~1,650 tokens (mostly fixed few-shot examples), costs ~$0.000033, and finishes in a few hundred milliseconds. Even if we ran every single one of the 144,000 group messages through it, the total bill would be just $4.70.&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&lt;figure class=&#34;echart&#34; style=&#34;--h:200px&#34;&gt;&lt;figcaption&gt;Tokens Read to Decide &amp;#39;Should I Chime In?&amp;#39;&lt;/figcaption&gt;&lt;p&gt;&lt;a href=&#34;https://mizore.blog/en/posts/save-a-little-more/&#34;&gt;(See the figure in the post.)&lt;/a&gt;&lt;/p&gt;&lt;p class=&#34;figure-note&#34;&gt;Primary model shows the average request from our ledger; decider model shows the measured payload including all few-shot examples. Cost per 1,000 decisions: $0.033 for the decider model vs. ~$0.26 to $1.50+ for the primary model depending on provider.&lt;/p&gt;&lt;/figure&gt;&#xA;&lt;p&gt;The decider model only went live on November 5. For the three months prior, ambient messages were gated by a probabilistic dice roll—and the ledger recorded the price of that design in plain sight: nearly every single turn was let in by the dice, forcing the primary model to read over 90,000 tokens from scratch each time.&lt;/p&gt;&#xA;&lt;figure class=&#34;echart&#34; style=&#34;--h:300px&#34;&gt;&lt;figcaption&gt;What Woke the Bot Before the Decider Model Launched&lt;/figcaption&gt;&lt;p&gt;&lt;a href=&#34;https://mizore.blog/en/posts/save-a-little-more/&#34;&gt;(See the figure in the post.)&lt;/a&gt;&lt;/p&gt;&lt;p class=&#34;figure-note&#34;&gt;Messages marked as started in routing logs by trigger reason, totaling 54,457 turns from the same Nov 1 local snapshot (three days shorter than the funnel table above). Over the same period, 50,362 messages arrived while the bot was busy and merged into the next turn, and 4,849 were skipped during cooldown.&lt;/p&gt;&lt;/figure&gt;&#xA;&lt;p&gt;How do we give a small model without deep world knowledge good social judgment? &lt;strong&gt;Pack it with high-density few-shot examples.&lt;/strong&gt;&#xA;In &lt;code&gt;src/agent/decider.ts&lt;/code&gt;, we distilled 14 universal examples covering typical group chat micro-dynamics, lifting classifier recall straight from 0.53 to 0.71.&lt;/p&gt;&#xA;&lt;p&gt;An even more interesting aesthetic insight came from tuning the &lt;strong&gt;threshold&lt;/strong&gt;:&#xA;When we tried rewriting the prompt to sound more enthusiastic—nudging the model to &amp;quot;want to talk more&amp;quot;—we found that the entire probability curve merely shifted within the noise band while burning 20% more tokens. This validated a classic principle of cybernetics: &lt;strong&gt;the classifier model is responsible for relative ranking; the threshold is responsible for projecting personality.&lt;/strong&gt;&#xA;Want a cool, laconic geek bot? Raise the threshold to 0.45. Want a warm, lively regular who cheers everyone on? Drop it to 0.15. The prompt never needs to be torn down and rewritten, preserving the purity of the code.&lt;/p&gt;&#xA;&lt;h3 id=&#34;send-and-leave-eliminating-the-general-agents-monologue&#34;&gt;Send and Leave: Eliminating the General Agent&#39;s Monologue&lt;/h3&gt;&#xA;&lt;p&gt;Once the primary model is woken up, another massive source of waste lurks in the action execution chain.&lt;/p&gt;&#xA;&lt;p&gt;General-purpose agent frameworks suffer from a severe case of &lt;strong&gt;compulsive reporting&lt;/strong&gt;:&#xA;After the model calls &lt;code&gt;send()&lt;/code&gt;, the framework hands the Telegram delivery confirmation JSON back to the model as a tool result. The model then reloads all 93,000 tokens of context just to smugly report to the human: &lt;em&gt;&amp;quot;I have sent the message!&amp;quot;&lt;/em&gt;&lt;/p&gt;&#xA;&lt;p&gt;In a personal terminal assistant, that might pass for thoroughness. In a high-frequency Telegram group chat, it is an unmitigated disaster. Not only does it burn an entire extra full-context call, worse still, a group chat must never be polluted by the model&#39;s internal monologue or meta-commentary.&lt;/p&gt;&#xA;&lt;p&gt;We laid down two iron rules:&lt;/p&gt;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;&lt;strong&gt;Private reasoning, explicit speech:&lt;/strong&gt; The model&#39;s raw Assistant text stays strictly inside the console logs; &lt;strong&gt;a message only crosses into the group chat when the model explicitly calls the &lt;code&gt;send&lt;/code&gt; tool&lt;/strong&gt;. If the model reads the context and decides not to call &lt;code&gt;send&lt;/code&gt;, the turn ends silently.&lt;/li&gt;&#xA;&lt;li&gt;&lt;strong&gt;Terminal Send (&lt;code&gt;terminate&lt;/code&gt; primitive):&lt;/strong&gt; The moment a single &lt;code&gt;send&lt;/code&gt; call succeeds, the runtime invokes Pi&#39;s native &lt;code&gt;terminate&lt;/code&gt; mechanism—&lt;strong&gt;forcibly cutting off the loop and refusing to return control to the model&lt;/strong&gt;.&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&lt;figure class=&#34;diagram&#34; style=&#34;--h:404px;--hn:785px&#34;&gt;&lt;figcaption&gt;Send and Terminate: Never Come Back Just to Report&lt;/figcaption&gt;&lt;p&gt;&lt;a href=&#34;https://mizore.blog/en/posts/save-a-little-more/&#34;&gt;(See the figure in the post.)&lt;/a&gt;&lt;/p&gt;&lt;p class=&#34;figure-note&#34;&gt;A general agent loop feeds the delivery result back to the model, forcing it to re-read the entire context just to say &amp;#39;Sent!&amp;#39;. In our project, a successful send immediately ends the turn via Pi&amp;#39;s terminate primitive; if the model doesn&amp;#39;t call send, its text stays in the console.&lt;/p&gt;&lt;/figure&gt;&#xA;&lt;p&gt;It is precisely this decisive cutoff that locked our three-month average at &lt;strong&gt;1.13 calls per turn&lt;/strong&gt;. The extra 0.13 calls exist solely for a single self-correction pass when the bot was explicitly mentioned by a user but forgot to invoke &lt;code&gt;send&lt;/code&gt;.&lt;/p&gt;&#xA;&lt;p&gt;When faced with an ambiguous network timeout, many engineers reflexively retry. On Telegram, however, sending a message is an irreversible, non-idempotent action. If the message was already created on Telegram&#39;s servers before the local connection timed out, retrying produces an embarrassing duplicate message in the group.&#xA;Our engineering rule is uncompromising: &lt;strong&gt;retries are permitted only on deterministic 4xx errors where no payload was committed; every timeout or ambiguous network state is marked &lt;code&gt;no_retry&lt;/code&gt; and halts immediately.&lt;/strong&gt;&lt;/p&gt;&#xA;&lt;figure class=&#34;diagram&#34; style=&#34;--h:216px;--hn:335px&#34;&gt;&lt;figcaption&gt;When Sending Fails, Only One Case May Retry&lt;/figcaption&gt;&lt;p&gt;&lt;a href=&#34;https://mizore.blog/en/posts/save-a-little-more/&#34;&gt;(See the figure in the post.)&lt;/a&gt;&lt;/p&gt;&lt;p class=&#34;figure-note&#34;&gt;Only deterministic 4xx errors before payload delivery are retried; everything else halts immediately.&lt;/p&gt;&lt;/figure&gt;&#xA;&lt;hr&gt;&#xA;&lt;h2 id=&#34;layer-2-maximizing-cache-hit-rate-h&#34;&gt;Layer 2: Maximizing Cache Hit Rate &lt;code&gt;$h$&lt;/code&gt;&lt;/h2&gt;&#xA;&lt;p&gt;If cutting call volume is our first line of defense, Prompt Caching is the core lever that determines life or death.&lt;/p&gt;&#xA;&lt;p&gt;At their core, the caching mechanisms of all modern frontier models (DeepSeek, Anthropic, OpenAI) work via &lt;strong&gt;Prefix Matching&lt;/strong&gt;:&#xA;As long as the prefix of your request is byte-for-byte identical to the previous turn, the price of the matched portion drops off a cliff. On DeepSeek V4 Flash, a cache hit costs a mere &lt;strong&gt;1/50th&lt;/strong&gt; of a cache miss.&lt;/p&gt;&#xA;&lt;p&gt;Let&#39;s run the numbers on the 5.34 billion input tokens we actually processed over three months:&lt;/p&gt;&#xA;&lt;figure class=&#34;echart&#34; style=&#34;--h:220px&#34;&gt;&lt;figcaption&gt;5.34B Input Tokens Priced at DeepSeek V4 Flash Rates&lt;/figcaption&gt;&lt;p&gt;&lt;a href=&#34;https://mizore.blog/en/posts/save-a-little-more/&#34;&gt;(See the figure in the post.)&lt;/a&gt;&lt;/p&gt;&lt;p class=&#34;figure-note&#34;&gt;Input tokens only; 14.3M output tokens excluded. 98.7% is our measured hit rate on DeepSeek; 0% is re-reading at full price every call. Hypothetical comparison across the full 3-month volume, not my literal invoice.&lt;/p&gt;&lt;/figure&gt;&#xA;&lt;p&gt;Going from 85% to 98.7% looks like a modest 14-percentage-point bump on paper, yet it cuts the bill by &lt;strong&gt;5×&lt;/strong&gt;; compared against running uncached, the difference is a staggering &lt;strong&gt;30×&lt;/strong&gt;!&lt;/p&gt;&#xA;&lt;figure class=&#34;echart&#34; style=&#34;--h:240px&#34;&gt;&lt;figcaption&gt;Cache Hit Rate Across Providers Using the Exact Same Prefix Discipline&lt;/figcaption&gt;&lt;p&gt;&lt;a href=&#34;https://mizore.blog/en/posts/save-a-little-more/&#34;&gt;(See the figure in the post.)&lt;/a&gt;&lt;/p&gt;&lt;p class=&#34;figure-note&#34;&gt;Hit rate = cached read tokens ÷ total input tokens, excluding compaction calls, from the Nov 1 local snapshot. DeepSeek Official API: 3,415 calls (Aug 7–10); SWE-2 on Devin: 19,494 calls; Gemini Flash on Antigravity: 22,274 calls. DeepSeek calls routed via ollama-cloud (15,668 calls) did not report cache read metrics and are omitted.&lt;/p&gt;&lt;/figure&gt;&#xA;&lt;p&gt;That is why we inscribed the single most important physical constraint of the entire project into &lt;code&gt;AGENTS.md&lt;/code&gt;:&lt;/p&gt;&#xA;&lt;blockquote&gt;&#xA;&lt;p&gt;&lt;strong&gt;Cache invariant: Never mutate an existing provider prefix; dynamic content may only be appended as a new suffix. Every request must be a strict prefix of the next request.&lt;/strong&gt;&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&lt;h3 id=&#34;first-principles-derivation-of-where-dynamic-information-belongs&#34;&gt;First-Principles Derivation of Where Dynamic Information Belongs&lt;/h3&gt;&#xA;&lt;p&gt;&amp;quot;Keep the prefix immutable&amp;quot; sounds like an easy slogan, until it collides head-on with the messy reality of a live Telegram group chat.&lt;/p&gt;&#xA;&lt;p&gt;The most classic contradiction is &lt;strong&gt;Stickers&lt;/strong&gt;.&lt;/p&gt;&#xA;&lt;p&gt;The bot has its own fixed catalog of favorite stickers, but group members constantly post all kinds of wild third-party stickers in daily conversation. When someone drops a particularly expressive sticker, we want to tell the bot: &lt;em&gt;&amp;quot;A group member just posted this sticker; if it fits the mood, you can use it this turn too.&amp;quot;&lt;/em&gt;&#xA;Clearly, this is &lt;strong&gt;unpredictable, dynamic candidate data that changes every single turn&lt;/strong&gt;.&lt;/p&gt;&#xA;&lt;p&gt;Where in the request payload should this dynamic list live? If we trace the engineering constraints step by step, every &amp;quot;convenient&amp;quot; shortcut gets eliminated one by one:&lt;/p&gt;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;&lt;strong&gt;Failed Attempt 1: Stuff it into the System Prompt.&lt;/strong&gt;&#xA;Intuitively the cleanest place—except the System Prompt sits at the very beginning of the context window. Change a single character there, and &lt;strong&gt;all 90,000+ tokens of cache behind it shatter instantly&lt;/strong&gt;.&lt;/li&gt;&#xA;&lt;li&gt;&lt;strong&gt;Failed Attempt 2: Hang it at the very end of the request, then swap it out next turn.&lt;/strong&gt;&#xA;Since it represents &amp;quot;currently available stickers,&amp;quot; many engineers tack it onto the tail of the current request, then snip off the old tail and attach a new one on the next turn.&#xA;This tiny bit of laziness exacted a brutal toll in production: the tail of request &lt;code&gt;$n$&lt;/code&gt; vanished in request &lt;code&gt;$n+1$&lt;/code&gt;, breaking prefix continuity right at the seam. Our measurements showed that trying to save a few dozen tokens of sticker listings caused the very next turn to miss &lt;strong&gt;13,600 tokens&lt;/strong&gt; of cold cache right at turn entry!&lt;/li&gt;&#xA;&lt;li&gt;&lt;strong&gt;Failed Attempt 3: Splice it directly into the chat transcript.&lt;/strong&gt;&#xA;If we can only append monotonically, what if we disguise the sticker metadata as message text inside the user&#39;s chat line?&#xA;Disaster struck immediately: upon reading it, the model earnestly concluded that &lt;em&gt;&amp;quot;a group member just leaked my internal sticker catalog,&amp;quot;&lt;/em&gt; and proceeded to accuse group members of spying on its backend. Worse still, when the session hit its context limit and triggered compaction, the summarizer distilled this absurd suspicion—&lt;em&gt;&amp;quot;group members leaked the bot&#39;s sticker catalog&amp;quot;&lt;/em&gt;—into an established fact, baking it permanently into the long-term summary and causing irreversible cognitive poisoning.&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&lt;figure class=&#34;diagram&#34; style=&#34;--h:328px;--hn:463px&#34;&gt;&lt;figcaption&gt;Only One Place Can Hold Dynamic Information&lt;/figcaption&gt;&lt;p&gt;&lt;a href=&#34;https://mizore.blog/en/posts/save-a-little-more/&#34;&gt;(See the figure in the post.)&lt;/a&gt;&lt;/p&gt;&lt;p class=&#34;figure-note&#34;&gt;Each row shows a request after inserting a dynamic sticker list; the terracotta vertical line marks where prefix continuity breaks and the cache invalidates.&lt;/p&gt;&lt;/figure&gt;&#xA;&lt;p&gt;Through those three collisions with reality, the fate of dynamic information was locked by physical law into a single narrow slot:&lt;/p&gt;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;&lt;strong&gt;It must be strictly append-only;&lt;/strong&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;strong&gt;Once written, it must freeze forever at that relative position, inherited verbatim by subsequent turns without ever being edited or deleted mid-stream;&lt;/strong&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;strong&gt;It must never be mistaken for human speech, requiring a dedicated system marker;&lt;/strong&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;strong&gt;It must never enter the persistent session database main line, lest it pollute future compaction summaries.&lt;/strong&gt;&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&lt;p&gt;This strict derivation gave birth to our final request projection structure:&lt;/p&gt;&#xA;&lt;figure class=&#34;diagram&#34; style=&#34;--h:334px;--hn:339px&#34;&gt;&lt;figcaption&gt;Append-Only Prefixes Keep the Cache Connected&lt;/figcaption&gt;&lt;p&gt;&lt;a href=&#34;https://mizore.blog/en/posts/save-a-little-more/&#34;&gt;(See the figure in the post.)&lt;/a&gt;&lt;/p&gt;&lt;p class=&#34;figure-note&#34;&gt;Top: proper projection where request n+1 strictly contains request n. Bottom: hanging a dynamic list at the end and swapping it next turn breaks prefix continuity at the seam.&lt;/p&gt;&lt;/figure&gt;&#xA;&lt;p&gt;Inside an actual request payload, it unfolds with a clean, disciplined rhythm:&lt;/p&gt;&#xA;&lt;figure class=&#34;diagram&#34; style=&#34;--h:388px;--hn:701px&#34;&gt;&lt;figcaption&gt;Anatomy of a Real Request&lt;/figcaption&gt;&lt;p&gt;&lt;a href=&#34;https://mizore.blog/en/posts/save-a-little-more/&#34;&gt;(See the figure in the post.)&lt;/a&gt;&lt;/p&gt;&lt;p class=&#34;figure-note&#34;&gt;Excerpt with usernames and sticker intensity descriptions removed. The dashed box is the full input of one request, read top to bottom by the model; the annotations for each block explain why it sits where it does.&lt;/p&gt;&lt;/figure&gt;&#xA;&lt;p&gt;Even asynchronous vision analysis strictly obeys this aesthetic:&#xA;When a user first posts an image, the message line carries only a lightweight placeholder &lt;code&gt;[Photo]&lt;/code&gt;. A few seconds later, when the async vision model finishes describing the image, the system &lt;strong&gt;never goes back to edit the old message&lt;/strong&gt;. Instead, it appends an immutable incremental event to the latest input stream: &lt;code&gt;[media_update #id] [Photo: a calico cat lying on a mechanical keyboard]&lt;/code&gt;.&lt;/p&gt;&#xA;&lt;hr&gt;&#xA;&lt;h2 id=&#34;layer-3-compressing-context-depth-t--why-verbatim-speech-outranks-processed-memory&#34;&gt;Layer 3: Compressing Context Depth &lt;code&gt;$T$&lt;/code&gt; — Why Verbatim Speech Outranks Processed Memory&lt;/h2&gt;&#xA;&lt;p&gt;Now we turn our gaze to the third variable, &lt;code&gt;$T$&lt;/code&gt; (the context depth swallowed on every call).&#xA;Even with a 98.7% cache hit rate, remember that the remaining 1.3% of uncached traffic still pays full price—and even at cached rates, hauling 90,000 tokens on every turn generates continuous friction costs.&lt;/p&gt;&#xA;&lt;p&gt;More importantly: &lt;strong&gt;a context window is not an infinitely expanding landfill.&lt;/strong&gt; Where do old memories go? How should long-horizon conversations settle?&lt;/p&gt;&#xA;&lt;h3 id=&#34;the-window-size-game-do-your-own-math-not-the-providers&#34;&gt;The Window Size Game: Do Your Own Math, Not the Provider&#39;s&lt;/h3&gt;&#xA;&lt;p&gt;A recent NVIDIA paper, &lt;em&gt;You don&#39;t need long context&lt;/em&gt; (arXiv:2611.05306), highlighted an underlying hardware reality: under server-side Attention mechanisms, the compute cost of generating each token scales linearly with context depth. Their benchmarks on vLLM + H100 showed that a 256K window increases per-token generation cost by up to 7× compared to 16K.&lt;/p&gt;&#xA;&lt;p&gt;Their recommendation: aggressively cap context between 16K and 48K, relying on frequent context compaction and state resets, which achieves virtually no accuracy drop on long-horizon tasks.&lt;/p&gt;&#xA;&lt;p&gt;That is a beautiful result—but if you copy it blindly into your own application, you will walk straight into a trap. That paper models &lt;strong&gt;the inference provider&#39;s cost structure&lt;/strong&gt;. For application developers calling cloud APIs, &lt;strong&gt;cloud billing is linear per token&lt;/strong&gt;. Token #100,000 costs the exact same price as Token #1; the provider&#39;s internal quadratic prefill penalty does not appear on your monthly invoice.&lt;/p&gt;&#xA;&lt;p&gt;On the application side, choosing a window size is a very different optimization game:&#xA;&lt;strong&gt;Which is more expensive: reading slightly more on each call, or triggering compaction far more frequently?&lt;/strong&gt;&lt;/p&gt;&#xA;&lt;p&gt;If you set a tiny window (say, 32K), avoiding overflow forces you to wake the model frequently to run Summarization (compaction).&#xA;Every compaction call exacts a heavy toll: it must read the entire old context and generate a structured summary. Worse still, &lt;strong&gt;the instant compaction finishes, your old deterministic prefix is dead—meaning the very next turn suffers a 100% cold-start full-price bill&lt;/strong&gt;.&lt;/p&gt;&#xA;&lt;p&gt;First, let&#39;s look at how many tokens each request actually read over our three-month run. The distribution is bimodal, with one peak around 40K–50K tokens and another around 110K; after we raised the window limit in late September, a long tail stretched out to the right:&lt;/p&gt;&#xA;&lt;figure class=&#34;echart&#34; style=&#34;--h:280px&#34;&gt;&lt;figcaption&gt;Tokens Read per Request&lt;/figcaption&gt;&lt;p&gt;&lt;a href=&#34;https://mizore.blog/en/posts/save-a-little-more/&#34;&gt;(See the figure in the post.)&lt;/a&gt;&lt;/p&gt;&lt;p class=&#34;figure-note&#34;&gt;Input token distribution across 54,847 non-compaction calls in 10K-token bins (40K means 40K–50K); the last bin is ≥240K (including 3 calls over 250K). Local snapshot as of Nov 1. The context cap was 131K initially and raised to 256K in late September.&lt;/p&gt;&lt;/figure&gt;&#xA;&lt;p&gt;During earlier iterations, my bot lived through both extremes of this pendulum swing:&lt;/p&gt;&#xA;&lt;figure class=&#34;echart&#34; style=&#34;--h:400px&#34;&gt;&lt;figcaption&gt;Weekly Average Input Length vs. Share of Compaction Calls&lt;/figcaption&gt;&lt;p&gt;&lt;a href=&#34;https://mizore.blog/en/posts/save-a-little-more/&#34;&gt;(See the figure in the post.)&lt;/a&gt;&lt;/p&gt;&lt;p class=&#34;figure-note&#34;&gt;Average input excludes compaction calls themselves. September used a homegrown compactor; in late September the window was raised from 131K to 256K.&lt;/p&gt;&lt;/figure&gt;&#xA;&lt;p&gt;Look at that glaring spike in late September: because our character-based token estimator mistakenly counted images as zero tokens, the system trapped itself in a nightmare loop—thinking compaction hadn&#39;t shrunk the context enough and re-triggering compaction non-stop—until &lt;strong&gt;nearly 45% of all model calls were just compacting&lt;/strong&gt;! Then, when we mindlessly cranked the window up to 256K at the end of September, compaction calls dropped near zero, but the baseline payload of every single request ballooned to 130,000 tokens.&lt;/p&gt;&#xA;&lt;p&gt;Our current architecture rests at a battle-tested equilibrium:&#xA;&lt;strong&gt;The window is fixed at 128K&lt;/strong&gt;, triggering Pi&#39;s native structured compaction once context reaches 110K tokens and reliably preserving the most recent ~20K tokens verbatim. Heavy tasks (multi-step search, deep research, code debugging) are offloaded via &lt;code&gt;task&lt;/code&gt; into isolated sub-sessions, bringing only the distilled answer back to the group chat. The primary session stays crystal clean—recording only &lt;em&gt;&amp;quot;what everyone is talking about&amp;quot;&lt;/em&gt; and &lt;em&gt;&amp;quot;what I did,&amp;quot;&lt;/em&gt; never degenerating into a bloated debugging log.&lt;/p&gt;&#xA;&lt;figure class=&#34;diagram&#34; style=&#34;--h:268px;--hn:406px&#34;&gt;&lt;figcaption&gt;How Big Should the Context Window Be?&lt;/figcaption&gt;&lt;p&gt;&lt;a href=&#34;https://mizore.blog/en/posts/save-a-little-more/&#34;&gt;(See the figure in the post.)&lt;/a&gt;&lt;/p&gt;&lt;p class=&#34;figure-note&#34;&gt;The color band is conceptual, not a plotted cost curve. Because cloud APIs bill linearly per token, too small a window lets compaction and cold-cache penalties outweigh smaller reads; too large a window forces every casual &amp;#39;haha true&amp;#39; to haul a massive context. Numbers in the three cards come from the ledger above.&lt;/p&gt;&lt;/figure&gt;&#xA;&lt;h3 id=&#34;bursting-the-bubble-why-we-completely-abandoned-memory-systems&#34;&gt;Bursting the Bubble: Why We Completely Abandoned Memory Systems&lt;/h3&gt;&#xA;&lt;p&gt;Whenever people talk about long-term agent evolution, they obsess over building elaborate &amp;quot;memory systems&amp;quot;: entity extraction, knowledge graph triples, update/forgetting mechanisms, vector semantic pipelines...&lt;/p&gt;&#xA;&lt;p&gt;Yet another incisive empirical study, &lt;em&gt;Is Complex Agentic Memory Always Needed?&lt;/em&gt; (arXiv:2610.30755), popped that bubble hard. The authors benchmarked over a dozen complex agent memory frameworks against a dead-simple &lt;strong&gt;Raw-RAG&lt;/strong&gt; baseline (no entity extraction, no graphs, no memory mutation—just chunking raw dialogue and retrieving it structurally). Across seven rigorous benchmarks, Raw-RAG took first place on six.&lt;/p&gt;&#xA;&lt;figure class=&#34;echart&#34; style=&#34;--h:200px&#34;&gt;&lt;figcaption&gt;Overall Score Drop When Replacing Raw Dialogue with Processed Memory&lt;/figcaption&gt;&lt;p&gt;&lt;a href=&#34;https://mizore.blog/en/posts/save-a-little-more/&#34;&gt;(See the figure in the post.)&lt;/a&gt;&lt;/p&gt;&lt;p class=&#34;figure-note&#34;&gt;Score delta relative to retrieving raw dialogue directly. Source: Bao et al., Is Complex Agentic Memory Always Needed? (arXiv:2610.30755).&lt;/p&gt;&lt;/figure&gt;&#xA;&lt;p&gt;And across individual metrics, the side with &lt;em&gt;one fewer layer of processing&lt;/em&gt; consistently scored higher:&lt;/p&gt;&#xA;&lt;figure class=&#34;echart&#34; style=&#34;--h:260px&#34;&gt;&lt;figcaption&gt;On the Same Metric, One Less Layer of Processing Scores Higher&lt;/figcaption&gt;&lt;p&gt;&lt;a href=&#34;https://mizore.blog/en/posts/save-a-little-more/&#34;&gt;(See the figure in the post.)&lt;/a&gt;&lt;/p&gt;&lt;p class=&#34;figure-note&#34;&gt;Test-Time Learning: 47.68% with raw dialogue vs. 15.37% after extracting atomic facts. Full Memory Access: 57.5% on processed memory store vs. 61.6% with raw dialogue directly. Mem0 accuracy: 69.42% after removing UPDATE / DELETE vs. 67.36% with them enabled. Source: ibid.&lt;/p&gt;&lt;/figure&gt;&#xA;&lt;p&gt;Even more suffocating is the maintenance cost: keeping those delicate memory graphs alive on MemoryAgentBench routinely burned tens of millions of tokens and hours of compute, whereas raw retrieval finished in a dozen minutes.&lt;/p&gt;&#xA;&lt;p&gt;This echoes our own production incidents with uncanny precision. Remember the sticker leak hallucination earlier?&#xA;&lt;strong&gt;Once processed memory is subjectively distorted by a model, the next compaction pass solidifies that distortion into objective fact—inheriting and propagating it like a virus forever.&lt;/strong&gt;&lt;/p&gt;&#xA;&lt;p&gt;Our architectural response is an act of radical decluttering:&#xA;&lt;strong&gt;We threw out all memory middleware completely. We maintain zero fact graphs and run zero periodic reflection jobs.&lt;/strong&gt;&lt;/p&gt;&#xA;&lt;p&gt;Every single message posted in our group over the past year rests untouched in a local SQLite database backed by a high-performance Trigram inverted index. When the model notices group members referencing &lt;em&gt;&amp;quot;that thing someone mentioned last time&amp;quot;&lt;/em&gt; or encounters an inside joke it doesn&#39;t recognize, it wields a structured query tool called &lt;code&gt;tg_messages&lt;/code&gt;. It can query &lt;strong&gt;unadulterated verbatim transcripts&lt;/strong&gt; by nickname history, username change trails, speaker ID, reply trees, and time ranges.&lt;/p&gt;&#xA;&lt;figure class=&#34;diagram&#34; style=&#34;--h:404px;--hn:785px&#34;&gt;&lt;figcaption&gt;No Memory Layer—Only Verbatim Transcripts&lt;/figcaption&gt;&lt;p&gt;&lt;a href=&#34;https://mizore.blog/en/posts/save-a-little-more/&#34;&gt;(See the figure in the post.)&lt;/a&gt;&lt;/p&gt;&lt;p class=&#34;figure-note&#34;&gt;Typical memory systems extract, build graphs, mutate, and summarize on every turn. Our project skips all processing: raw transcripts sit in SQLite and are queried on demand via tg_messages across nickname history, renames, speaker ID, reply trees, and time ranges.&lt;/p&gt;&lt;/figure&gt;&#xA;&lt;p&gt;&lt;strong&gt;Leave raw context intact to time, and reserve the power of interpretation and verification for the exact moment it is needed.&lt;/strong&gt;&#xA;The former silently drains your compute on every single turn; the latter sparks an elegant retrieval only in the exact second a group member asks a follow-up question.&lt;/p&gt;&#xA;&lt;h3 id=&#34;remembering-the-gist-forgetting-the-exact-words-adding-a-semantic-path-to-verbatim-transcripts&#34;&gt;Remembering the Gist, Forgetting the Exact Words: Adding a Semantic Path to Verbatim Transcripts&lt;/h3&gt;&#xA;&lt;p&gt;The most frequently used parameter in &lt;code&gt;tg_messages&lt;/code&gt; is &lt;code&gt;text_contains&lt;/code&gt;. Backed by SQLite FTS5&#39;s trigram index, it is fundamentally an &lt;strong&gt;exact substring match&lt;/strong&gt;: you have to name the exact characters that appeared in the original message for it to hit.&lt;/p&gt;&#xA;&lt;p&gt;Human memory never works like that. When a group member asks about &lt;em&gt;&amp;quot;that person who recommended a keyboard last time,&amp;quot;&lt;/em&gt; the original conversation might not contain the word &amp;quot;keyboard&amp;quot; at all; someone might query a Chinese discussion in English; an inside joke circulating for three months has mutated through half a dozen spellings. Exact substring search isn&#39;t just &amp;quot;less accurate&amp;quot; here—it has &lt;strong&gt;nowhere to grab hold&lt;/strong&gt;: the model is forced to guess synonyms one by one, and every wrong guess costs another retrieval round-trip.&lt;/p&gt;&#xA;&lt;p&gt;Notice that &amp;quot;vector semantic retrieval&amp;quot; was on our list of standard memory-system ingredients at the start of this section. But looking back at that paper, what got falsified was never &lt;em&gt;vectors&lt;/em&gt;—it was &lt;em&gt;lossy processing&lt;/em&gt;: the Raw-RAG baseline that won six out of seven benchmarks works precisely by chunking raw dialogue and retrieving chunks semantically. So when we added a semantic path, we enforced three strict boundaries:&lt;/p&gt;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;&lt;strong&gt;Zero processing:&lt;/strong&gt; No extraction, no summarization. Vectors are purely an index over raw transcripts; what comes back is always verbatim dialogue.&lt;/li&gt;&#xA;&lt;li&gt;&lt;strong&gt;Zero extra LLM calls:&lt;/strong&gt; Windowing is deterministic code, and each dialogue window pays for embedding exactly once.&lt;/li&gt;&#xA;&lt;li&gt;&lt;strong&gt;Zero new infrastructure:&lt;/strong&gt; No vector database, no native SQLite extensions, and no new tool definitions.&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&lt;p&gt;&lt;strong&gt;Windowing: Deterministic chunking without a model.&lt;/strong&gt; Individual group chat messages are too short—computing a separate vector for &lt;em&gt;&amp;quot;lmao&amp;quot;&lt;/em&gt;, &lt;em&gt;&amp;quot;+1&amp;quot;&lt;/em&gt;, or &lt;em&gt;&amp;quot;true&amp;quot;&lt;/em&gt; carries almost zero semantic signal. Instead, we slice consecutive messages into dialogue windows: a window closes once it reaches 800 characters (~20 messages), accumulates 40 messages, or encounters more than 30 minutes of silence between adjacent messages. Each line is formatted as &lt;code&gt;Nickname: text&lt;/code&gt;, with photos and stickers carrying their already-cached visual descriptions—reusing the recognition results we already paid for in &lt;code&gt;media_update&lt;/code&gt; without looking at the media again. Only &lt;strong&gt;closed&lt;/strong&gt; windows (after 30 minutes of trailing silence) enter the index; the currently open window is the live conversation already sitting in the bot&#39;s context window.&lt;/p&gt;&#xA;&lt;p&gt;That 800-character threshold wasn&#39;t plucked out of thin air; the experiments below moved it there from our initial 1,500-character design.&lt;/p&gt;&#xA;&lt;p&gt;&lt;strong&gt;Vectors: One dialogue window, one embedding.&lt;/strong&gt; We use Gemini&#39;s &lt;code&gt;gemini-embedding-2&lt;/code&gt;, truncated to 768 dimensions and L2-normalized. Task type is specified via input prefix rather than a separate API flag: &lt;code&gt;title: none | text: …&lt;/code&gt; at indexing time, and &lt;code&gt;task: search result | query: …&lt;/code&gt; at query time. Pricing is $0.20 per million tokens. Backfilling our entire group archive with the initial 1,500-character windowing produced this ledger:&lt;/p&gt;&#xA;&lt;figure class=&#34;stats&#34;&gt;&lt;figcaption&gt;&lt;span&gt;One-Time Backfill&lt;/span&gt;&lt;span class=&#34;key&#34;&gt;2026-07-29 — 2026-11-10 · One group&lt;/span&gt;&lt;/figcaption&gt;&lt;p class=&#34;stats-group&#34;&gt;&lt;b&gt;Archive&lt;/b&gt;&lt;/p&gt;&lt;dl class=&#34;kpi&#34; style=&#34;--k:2&#34;&gt;&lt;div&gt;&lt;dt&gt;Messages&lt;/dt&gt;&lt;dd&gt;273,526&lt;/dd&gt;&lt;dd class=&#34;s&#34;&gt;~2,600 per day&lt;/dd&gt;&lt;/div&gt;&lt;div&gt;&lt;dt&gt;Body text&lt;/dt&gt;&lt;dd&gt;7.1M&lt;span class=&#34;kpi-u&#34;&gt; chars&lt;/span&gt;&lt;/dd&gt;&lt;dd class=&#34;s&#34;&gt;Excluding nicknames&lt;/dd&gt;&lt;/div&gt;&lt;/dl&gt;&lt;p class=&#34;stats-group&#34;&gt;&lt;b&gt;Backfill&lt;/b&gt;&lt;/p&gt;&lt;dl class=&#34;kpi&#34; style=&#34;--k:4&#34;&gt;&lt;div&gt;&lt;dt&gt;Windows&lt;/dt&gt;&lt;dd&gt;8,875&lt;/dd&gt;&lt;dd class=&#34;s&#34;&gt;Median 1,436 chars, 32 lines&lt;/dd&gt;&lt;/div&gt;&lt;div&gt;&lt;dt&gt;Input&lt;/dt&gt;&lt;dd&gt;7.2M&lt;span class=&#34;kpi-u&#34;&gt; tokens&lt;/span&gt;&lt;/dd&gt;&lt;dd class=&#34;s&#34;&gt;11.56M chars incl. nickname prefixes&lt;/dd&gt;&lt;/div&gt;&lt;div&gt;&lt;dt&gt;Cost&lt;/dt&gt;&lt;dd&gt;$1.43 | Pre−run estimate was $1.00–$1.50&lt;/dd&gt;&lt;/div&gt;&lt;div&gt;&lt;dt&gt;Remaining windows&lt;/dt&gt;&lt;dd&gt;319&lt;span class=&#34;kpi-u&#34;&gt; s&lt;/span&gt;&lt;/dd&gt;&lt;dd class=&#34;s&#34;&gt;7,725 windows, four 429s&lt;/dd&gt;&lt;/div&gt;&lt;/dl&gt;&lt;p class=&#34;data-note&#34;&gt;Run against a read-only snapshot of the production archive DB using the initial 1,500-char windowing code. Token count converted at the measured ~0.62 tokens/char from countTokens. The v1 indexer backfilled ~1,150 windows in 37s before hitting rate limits, then retried using the API&amp;#39;s retryDelay hints to finish the remaining 7,725 windows in 319s.&lt;/p&gt;&lt;/figure&gt;&#xA;&lt;p&gt;The window size distribution reveals an important fact: the character cap, not silence, determines almost every boundary. The median window was 1,436 characters and the 75th percentile was already 1,478 characters—nearly every window pressed right up against the 1,500-character ceiling, with only 139 short windows under 200 characters. A busy group chat rarely stays silent for 30 minutes.&lt;/p&gt;&#xA;&lt;p&gt;Strictly speaking, our earlier claim that &lt;em&gt;&amp;quot;zero tokens are spent on memory during normal chat&amp;quot;&lt;/em&gt; now needs a footnote: every 5 minutes, a background job embeds newly closed windows. Averaged across our archive&#39;s velocity, that comes to under 70,000 tokens per day—roughly &lt;strong&gt;1.4 cents&lt;/strong&gt;. It never enters the main context, never wakes an LLM, and never mutates a single previously written byte.&lt;/p&gt;&#xA;&lt;p&gt;&lt;strong&gt;Rate limiting: Indexing and querying share the same quota.&lt;/strong&gt; Backfilling exposed our first real operational issue. Gemini allows at most 100 texts per batch (101 returns HTTP 400), and Tier 1 quota caps embedding throughput at 1,000,000 tokens per minute. Our first indexer sent batches of 50 and aborted until the next 5-minute tick on any error; it hit HTTP 429 after 23 requests, which would have dragged a full backfill out to ~40 minutes while firing eight alert notifications. Worse yet, a live semantic query during the backfill also hit a 429: background indexing and foreground queries draw from the exact same quota pool.&lt;/p&gt;&#xA;&lt;p&gt;The fix remained pure deterministic code—no queues, no extra services: batch size 100, honor the response&#39;s &lt;code&gt;retryDelay&lt;/code&gt; (30–41s) on 429, and self-throttle the background indexer to 800,000 characters per minute—roughly half our quota, leaving the other half for live queries from the group.&lt;/p&gt;&#xA;&lt;p&gt;When v1.1.8 shipped with 800-character windows, we re-ran the full backfill on the production database at this pace: 15,596 windows (averaging ~17.5 messages per window) at ~1,100 windows per minute, finishing in 14.5 minutes with &lt;strong&gt;zero 429s&lt;/strong&gt;. Total character volume stayed the same (~7.2M tokens, ~$1.40). End-to-end queries on the packaged release took 545–1,064 ms; with &lt;code&gt;limit&lt;/code&gt; set to 40, &lt;code&gt;rows&lt;/code&gt; returns one to two complete conversation windows while the remaining top-ranked windows are listed in &lt;code&gt;matches&lt;/code&gt; with &lt;code&gt;in_rows=false&lt;/code&gt;.&lt;/p&gt;&#xA;&lt;p&gt;Right after the backfill finished, we hit a small plot twist: the indexer cursor suddenly jumped to ~1.787 billion. Back in August, an e2e test had inserted 21 synthetic messages into the production archive with fake senders and timestamp-sized &lt;code&gt;message_id&lt;/code&gt; values. Real Telegram supergroup message IDs increase monotonically, which the indexer relies on to advance its cursor. Rather than adding defensive code for an &amp;quot;impossible branch,&amp;quot; we backed up the database and deleted those 21 synthetic messages along with the 4 windows they had polluted, returning the cursor to its true position. Defensive code should guard against branches that can genuinely happen in reality; when an impossible branch appears from dirty data, make it impossible again.&lt;/p&gt;&#xA;&lt;p&gt;&lt;strong&gt;Storage and retrieval: No vector database.&lt;/strong&gt; Vectors are stored as &lt;code&gt;float32&lt;/code&gt; BLOBs in a single new table, &lt;code&gt;message_chunks&lt;/code&gt;, where each row holds only the chat ID, the first and last message IDs of the window, the model name, and those 768 floats—the sole schema change in this feature. At query time, we embed the query into a vector and run an in-memory brute-force cosine scan across all windows in JavaScript: 768 dimensions × 8,875 windows is ~6.8 million multiply-adds, finishing in &lt;strong&gt;14 milliseconds&lt;/strong&gt; including sorting. Nearly all of a query&#39;s 470–700 ms latency is spent on the single network round-trip to the embedding API. Keeping all vectors resident in memory takes 27 MB (or ~48 MB for 15,596 windows after switching to 800-character windows—still trivial). At this scale, approximate nearest-neighbor indexes like HNSW or IVF solve a problem we simply do not have. And if we ever switch embedding models, old vectors aren&#39;t comparable anyway—we just drop and rebuild.&lt;/p&gt;&#xA;&lt;figure class=&#34;diagram&#34; style=&#34;--h:256px;--hn:526px&#34;&gt;&lt;figcaption&gt;Verbatim Dialogue Sliced into Windows, One Vector per Window&lt;/figcaption&gt;&lt;p&gt;&lt;a href=&#34;https://mizore.blog/en/posts/save-a-little-more/&#34;&gt;(See the figure in the post.)&lt;/a&gt;&lt;/p&gt;&lt;p class=&#34;figure-note&#34;&gt;Top: every 5 minutes the background job embeds newly closed windows (split at 800 chars, 40 messages, or &amp;gt;30 min silence; the active tail stays unindexed). Bottom: a query costs just one embedding call, ranks windows via in-memory cosine similarity, and returns full verbatim dialogue windows. Counts shown are illustrative.&lt;/p&gt;&lt;/figure&gt;&#xA;&lt;p&gt;&lt;strong&gt;Interface: No new tool, just one new parameter.&lt;/strong&gt; Rather than registering a separate tool, we added a &lt;code&gt;semantic&lt;/code&gt; parameter to &lt;code&gt;tg_messages&lt;/code&gt;: pass a natural-language description of what you&#39;re looking for, and it returns the most relevant &lt;strong&gt;complete conversation windows&lt;/strong&gt;; &lt;code&gt;matches&lt;/code&gt; lists up to the top 10 windows with their &lt;code&gt;first_id&lt;/code&gt;, &lt;code&gt;last_id&lt;/code&gt;, similarity score, and an &lt;code&gt;in_rows&lt;/code&gt; flag indicating whether that window fit into &lt;code&gt;rows&lt;/code&gt;. It composes seamlessly with existing filters (&lt;code&gt;sender&lt;/code&gt;, &lt;code&gt;since&lt;/code&gt;, &lt;code&gt;until&lt;/code&gt;, &lt;code&gt;text_contains&lt;/code&gt;), keeping only windows that contain at least one matching message; once the model reads a window and wants to trace what led up to it or how it resolved, it uses the existing &lt;code&gt;before_id&lt;/code&gt; / &lt;code&gt;after_id&lt;/code&gt; cursors to page backward or forward.&lt;/p&gt;&#xA;&lt;p&gt;This continues our earlier principle of declaring all tools upfront: adding a parameter expands the tool schema by ~1,200 characters (~700–800 tokens, well under 1% of an average request), sitting inside the frozen prefix where it is re-read at cached rates; adding a separate tool would force the model to learn and coordinate another tool contract. Because tool schemas are part of the cache-visible protocol, changing them follows strict discipline: &lt;code&gt;CACHE_SCHEMA_VERSION&lt;/code&gt; bumped from 55 to 56 alongside an updated golden hash. The cache took a single cold start at deploy time, and remained byte-for-byte immutable thereafter.&lt;/p&gt;&#xA;&lt;p&gt;&lt;strong&gt;Verification: Test on the real archive before writing the tool description.&lt;/strong&gt; After writing the code, we didn&#39;t ship straight to production. Instead, we had a sub-agent run four experiments on the production server against a read-only snapshot of the archive database—without starting the daemon or touching the live service (having learned our lesson from two processes fighting over the same bot token). Once the experiments finished, both the snapshot and the temporary API key were deleted. All four experiments combined cost about $3:&lt;/p&gt;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;&lt;strong&gt;Full backfill:&lt;/strong&gt; Backfill the entire archive snapshot to measure throughput, rate limiting, window statistics, token volume, event-loop blockage, and RSS memory growth;&lt;/li&gt;&#xA;&lt;li&gt;&lt;strong&gt;Query latency:&lt;/strong&gt; Measure end-to-end semantic query latency and where the time goes;&lt;/li&gt;&#xA;&lt;li&gt;&lt;strong&gt;Retrieval quality:&lt;/strong&gt; Test 25 real topics discussed in the group &lt;strong&gt;without using any original wording&lt;/strong&gt;—paraphrasing, querying Chinese discussions in English, combining &lt;em&gt;&amp;quot;person + topic&amp;quot;&lt;/em&gt; with &lt;code&gt;sender&lt;/code&gt; filters, and constraining date ranges—plus 5 negative queries for events that never happened to see where false-positive scores land;&lt;/li&gt;&#xA;&lt;li&gt;&lt;strong&gt;Parameter sensitivity:&lt;/strong&gt; Compare silence thresholds, window sizes, keeping vs. dropping the bot&#39;s own messages, and index prefixes on the most recent 30-day subset.&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&lt;figure class=&#34;stats&#34;&gt;&lt;figcaption&gt;&lt;span&gt;Semantic Retrieval Benchmark&lt;/span&gt;&lt;span class=&#34;key&#34;&gt;Read-only production archive snapshot · 1,500-char windows&lt;/span&gt;&lt;/figcaption&gt;&lt;p class=&#34;stats-group&#34;&gt;&lt;b&gt;Speed&lt;/b&gt;&lt;/p&gt;&lt;dl class=&#34;kpi&#34; style=&#34;--k:3&#34;&gt;&lt;div&gt;&lt;dt&gt;Semantic query&lt;/dt&gt;&lt;dd&gt;470–700&lt;span class=&#34;kpi-u&#34;&gt; ms&lt;/span&gt;&lt;/dd&gt;&lt;dd class=&#34;s&#34;&gt;Almost entirely the single embedding call&lt;/dd&gt;&lt;/div&gt;&lt;div&gt;&lt;dt&gt;Cosine scan&lt;/dt&gt;&lt;dd&gt;14&lt;span class=&#34;kpi-u&#34;&gt; ms&lt;/span&gt;&lt;/dd&gt;&lt;dd class=&#34;s&#34;&gt;Brute-force across all windows&lt;/dd&gt;&lt;/div&gt;&lt;div&gt;&lt;dt&gt;Literal search&lt;/dt&gt;&lt;dd&gt;50–140&lt;span class=&#34;kpi-u&#34;&gt; ms&lt;/span&gt;&lt;/dd&gt;&lt;dd class=&#34;s&#34;&gt;text_contains baseline&lt;/dd&gt;&lt;/div&gt;&lt;/dl&gt;&lt;p class=&#34;stats-group&#34;&gt;&lt;b&gt;During Backfill&lt;/b&gt;&lt;/p&gt;&lt;dl class=&#34;kpi&#34; style=&#34;--k:2&#34;&gt;&lt;div&gt;&lt;dt&gt;Event-loop lag&lt;/dt&gt;&lt;dd&gt;11&lt;span class=&#34;kpi-u&#34;&gt; ms&lt;/span&gt;&lt;/dd&gt;&lt;dd class=&#34;s&#34;&gt;p99, max 49 ms&lt;/dd&gt;&lt;/div&gt;&lt;div&gt;&lt;dt&gt;Vectors in RAM&lt;/dt&gt;&lt;dd&gt;27&lt;span class=&#34;kpi-u&#34;&gt; MB&lt;/span&gt;&lt;/dd&gt;&lt;dd class=&#34;s&#34;&gt;Process RSS ~160 MB&lt;/dd&gt;&lt;/div&gt;&lt;/dl&gt;&lt;p class=&#34;stats-group&#34;&gt;&lt;b&gt;Quality&lt;/b&gt;&lt;/p&gt;&lt;dl class=&#34;kpi&#34; style=&#34;--k:2&#34;&gt;&lt;div&gt;&lt;dt&gt;Paraphrased hits&lt;/dt&gt;&lt;dd&gt;20&lt;span class=&#34;kpi-u&#34;&gt; / 25&lt;/span&gt;&lt;/dd&gt;&lt;dd class=&#34;s&#34;&gt;Top-1 window was the exact target&lt;/dd&gt;&lt;/div&gt;&lt;div&gt;&lt;dt&gt;Negative queries&lt;/dt&gt;&lt;dd&gt;0.627–0.701&lt;/dd&gt;&lt;dd class=&#34;s&#34;&gt;Top-1 score, higher than many true hits&lt;/dd&gt;&lt;/div&gt;&lt;/dl&gt;&lt;p class=&#34;data-note&#34;&gt;Query latency is end-to-end from query dispatch to verbatim rows returned; cosine scan includes sorting across all 8,875 windows. Event loop and memory measured during full backfill. Negative queries: top-1 score across 5 events that never happened.&lt;/p&gt;&lt;/figure&gt;&#xA;&lt;p&gt;First, speed: semantic queries are several times slower than literal trigram search, but the latency lives almost entirely in the single network round-trip to the embedding API, not local compute; during the full backfill, event-loop lag peaked at just 49 ms, completely imperceptible for receiving and sending group messages.&lt;/p&gt;&#xA;&lt;p&gt;Next, quality: out of 25 paraphrased queries, 20 returned the exact target conversation as the #1 result—covering blockchain storage, router bridging and IPTV, replacing Windows fonts, a rainy beach trip, taking a leave of absence from college, exporting an eSIM, a Minecraft iron farm, weight loss, and GPUs. Querying Chinese chat logs in English worked just as well. For niche topics (only 3–7 relevant windows in the entire archive), the #1 result was spot-on while ranks #2–#5 were mostly filler.&lt;/p&gt;&#xA;&lt;p&gt;The queries that missed drew a crisp boundary around what semantic search cannot do:&lt;/p&gt;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;&lt;strong&gt;Asking what a meme or slang term means:&lt;/strong&gt; 0 / 10. Group members use slang rather than defining it in chat; for that, pass the literal slang term to &lt;code&gt;text_contains&lt;/code&gt;.&lt;/li&gt;&#xA;&lt;li&gt;&lt;strong&gt;Proper nouns and brand names:&lt;/strong&gt; A paid vocabulary app or a specific quant firm is much better served by exact substring search.&lt;/li&gt;&#xA;&lt;li&gt;&lt;strong&gt;Figurative usage drowning out literal meaning:&lt;/strong&gt; True discussions about typhoons were rare, whereas &amp;quot;typhoon&amp;quot; used as a metaphor appeared everywhere.&lt;/li&gt;&#xA;&lt;li&gt;&lt;strong&gt;Key facts scattered across multiple windows:&lt;/strong&gt; A platform rug-pull or &lt;em&gt;&amp;quot;the police said it&#39;s a civil dispute&amp;quot;&lt;/em&gt; where each window only touched a fragment.&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&lt;p&gt;Query phrasing matters too: a complete descriptive sentence outperforms two or three bare keywords by a wide margin. Searching just &lt;code&gt;&amp;quot;headphones&amp;quot;&lt;/code&gt; returned 2 relevant windows in the top 5; writing &lt;code&gt;&amp;quot;comparing noise cancellation and prices of several wireless earbuds&amp;quot;&lt;/code&gt; returned 4.&lt;/p&gt;&#xA;&lt;p&gt;The biggest surprise was similarity scores. We originally wanted to give the model a cutoff threshold below which it should treat results as &amp;quot;not found.&amp;quot; The experiment proved &lt;strong&gt;no such cutoff exists&lt;/strong&gt;: relevant windows had a median score of 0.669 while irrelevant ones had a median of 0.658, with nearly complete overlap. Across 5 negative queries for events that never happened, the #1 score ranged from 0.627 to 0.701—a fabricated query about &lt;em&gt;&amp;quot;wedding photos&amp;quot;&lt;/em&gt; scored 0.701, beating many genuine hits. Whenever the gap between #1 and #5 exceeded 0.05, the top result was always right, yet many genuine hits differed by only 0.01–0.03, indistinguishable from negative queries. So we wrote this rule directly into the tool description: similarity scores are only for relative ranking within a single query; the model must read &lt;code&gt;rows&lt;/code&gt; to verify relevance, rephrase or fall back to &lt;code&gt;text_contains&lt;/code&gt; if they don&#39;t match, and never assert &lt;em&gt;&amp;quot;the group has never discussed this&amp;quot;&lt;/em&gt; based on scores alone.&lt;/p&gt;&#xA;&lt;p&gt;The experiment also caught a result-shaping bug: when &lt;code&gt;limit&lt;/code&gt; was set to 30–40, queries always returned only a single window—because the first window had nearly 40 messages, the second window didn&#39;t fit, and the loop broke early. Now windows that don&#39;t fit the remaining row budget are skipped rather than halting the loop, ensuring the top window is always returned while other high-ranking windows are flagged via &lt;code&gt;in_rows&lt;/code&gt; in &lt;code&gt;matches&lt;/code&gt; so the model can fetch them by ID if needed.&lt;/p&gt;&#xA;&lt;p&gt;We tuned our windowing parameters on the 30-day subset:&lt;/p&gt;&#xA;&lt;figure class=&#34;data wide&#34;&gt;&lt;figcaption&gt;Choosing Windowing Parameters&lt;/figcaption&gt;&lt;div class=&#34;data-scroll&#34; tabindex=&#34;0&#34;&gt;&lt;table&gt;&lt;thead&gt;&lt;tr&gt;&lt;th&gt;Config&lt;/th&gt;&lt;th class=&#34;num bar-head&#34; style=&#34;--vw:4ch&#34;&gt;&lt;span class=&#34;bar-head-in&#34;&gt;P@1&lt;/span&gt;&lt;/th&gt;&lt;th class=&#34;num&#34;&gt;P@5&lt;/th&gt;&lt;th class=&#34;num&#34;&gt;MRR&lt;/th&gt;&lt;th class=&#34;num&#34;&gt;Msg Prec.&lt;/th&gt;&lt;th class=&#34;num&#34;&gt;Windows&lt;/th&gt;&lt;/tr&gt;&lt;/thead&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td class=&#34;row-key prose-col&#34;&gt;Baseline&lt;/td&gt;&lt;td class=&#34;num bar&#34; style=&#34;--vw:4ch&#34;&gt;&lt;span class=&#34;bar-cell&#34;&gt;&lt;span class=&#34;bar-track&#34; aria-hidden=&#34;true&#34;&gt;&lt;i class=&#34;bar-fill&#34; style=&#34;left:0.0%;width:93.8%&#34;&gt;&lt;/i&gt;&lt;/span&gt;&lt;span class=&#34;bar-val&#34;&gt;0.76&lt;/span&gt;&lt;/span&gt;&lt;/td&gt;&lt;td class=&#34;num&#34;&gt;0.47&lt;/td&gt;&lt;td class=&#34;num&#34;&gt;0.83&lt;/td&gt;&lt;td class=&#34;num&#34;&gt;0.73&lt;/td&gt;&lt;td class=&#34;num&#34;&gt;2,241&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td class=&#34;row-key prose-col&#34;&gt;10-min silence&lt;/td&gt;&lt;td class=&#34;num bar&#34; style=&#34;--vw:4ch&#34;&gt;&lt;span class=&#34;bar-cell&#34;&gt;&lt;span class=&#34;bar-track&#34; aria-hidden=&#34;true&#34;&gt;&lt;i class=&#34;bar-fill&#34; style=&#34;left:0.0%;width:93.8%&#34;&gt;&lt;/i&gt;&lt;/span&gt;&lt;span class=&#34;bar-val&#34;&gt;0.76&lt;/span&gt;&lt;/span&gt;&lt;/td&gt;&lt;td class=&#34;num&#34;&gt;0.48&lt;/td&gt;&lt;td class=&#34;num&#34;&gt;0.83&lt;/td&gt;&lt;td class=&#34;num&#34;&gt;0.74&lt;/td&gt;&lt;td class=&#34;num&#34;&gt;2,562&lt;/td&gt;&lt;/tr&gt;&lt;tr class=&#34;mark&#34;&gt;&lt;td class=&#34;row-key prose-col&#34;&gt;800 chars (shipped)&lt;/td&gt;&lt;td class=&#34;num bar&#34; style=&#34;--vw:4ch&#34;&gt;&lt;span class=&#34;bar-cell&#34;&gt;&lt;span class=&#34;bar-track&#34; aria-hidden=&#34;true&#34;&gt;&lt;i class=&#34;bar-fill&#34; style=&#34;left:0.0%;width:100.0%&#34;&gt;&lt;/i&gt;&lt;/span&gt;&lt;span class=&#34;bar-val&#34;&gt;0.81&lt;/span&gt;&lt;/span&gt;&lt;/td&gt;&lt;td class=&#34;num&#34;&gt;0.57&lt;/td&gt;&lt;td class=&#34;num&#34;&gt;0.84&lt;/td&gt;&lt;td class=&#34;num&#34;&gt;0.78&lt;/td&gt;&lt;td class=&#34;num&#34;&gt;3,720&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td class=&#34;row-key prose-col&#34;&gt;3,000 chars / 80 msgs&lt;/td&gt;&lt;td class=&#34;num bar&#34; style=&#34;--vw:4ch&#34;&gt;&lt;span class=&#34;bar-cell&#34;&gt;&lt;span class=&#34;bar-track&#34; aria-hidden=&#34;true&#34;&gt;&lt;i class=&#34;bar-fill&#34; style=&#34;left:0.0%;width:76.5%&#34;&gt;&lt;/i&gt;&lt;/span&gt;&lt;span class=&#34;bar-val&#34;&gt;0.62&lt;/span&gt;&lt;/span&gt;&lt;/td&gt;&lt;td class=&#34;num&#34;&gt;0.46&lt;/td&gt;&lt;td class=&#34;num&#34;&gt;0.74&lt;/td&gt;&lt;td class=&#34;num&#34;&gt;0.62&lt;/td&gt;&lt;td class=&#34;num&#34;&gt;1,145&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td class=&#34;row-key prose-col&#34;&gt;Drop bot messages&lt;/td&gt;&lt;td class=&#34;num bar&#34; style=&#34;--vw:4ch&#34;&gt;&lt;span class=&#34;bar-cell&#34;&gt;&lt;span class=&#34;bar-track&#34; aria-hidden=&#34;true&#34;&gt;&lt;i class=&#34;bar-fill&#34; style=&#34;left:0.0%;width:59.3%&#34;&gt;&lt;/i&gt;&lt;/span&gt;&lt;span class=&#34;bar-val&#34;&gt;0.48&lt;/span&gt;&lt;/span&gt;&lt;/td&gt;&lt;td class=&#34;num&#34;&gt;0.39&lt;/td&gt;&lt;td class=&#34;num&#34;&gt;0.62&lt;/td&gt;&lt;td class=&#34;num&#34;&gt;0.48&lt;/td&gt;&lt;td class=&#34;num&#34;&gt;1,948&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td class=&#34;row-key prose-col&#34;&gt;Drop index prefix&lt;/td&gt;&lt;td class=&#34;num bar&#34; style=&#34;--vw:4ch&#34;&gt;&lt;span class=&#34;bar-cell&#34;&gt;&lt;span class=&#34;bar-track&#34; aria-hidden=&#34;true&#34;&gt;&lt;i class=&#34;bar-fill&#34; style=&#34;left:0.0%;width:87.7%&#34;&gt;&lt;/i&gt;&lt;/span&gt;&lt;span class=&#34;bar-val&#34;&gt;0.71&lt;/span&gt;&lt;/span&gt;&lt;/td&gt;&lt;td class=&#34;num&#34;&gt;0.47&lt;/td&gt;&lt;td class=&#34;num&#34;&gt;0.77&lt;/td&gt;&lt;td class=&#34;num&#34;&gt;0.68&lt;/td&gt;&lt;td class=&#34;num&#34;&gt;2,238&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/div&gt;&lt;p class=&#34;data-note&#34;&gt;30-day subset, 21 queries plus 3 negative queries for events that never happened. Baseline is 30-min silence, 1,500 chars, 40 messages. P@1, P@5: fraction of relevant windows in top 1 and top 5; MRR: mean reciprocal rank of the first relevant window; Msg Prec. (message precision): fraction of the 40-message budget landing inside relevant windows. Raising the character limit alone to 3,000 hit the 40-message cap first and changed nothing, so that row also raised the cap to 80 messages.&lt;/p&gt;&lt;/figure&gt;&#xA;&lt;p&gt;Three takeaways jumped out. First, smaller windows are more accurate: 800 characters won on every single metric while keeping total character count—and therefore embedding token cost—completely unchanged. Second, a 10-minute vs. 30-minute silence threshold made almost no difference, confirming again that window boundaries are driven primarily by character length. Most surprising of all were the bot&#39;s own messages: they accounted for 75% of total character volume and looked like noise we should strip out, yet the bot&#39;s explanations carried the exact topical vocabulary that anchored retrieval—dropping bot messages tanked P@1 from 0.76 down to 0.48.&lt;/p&gt;&#xA;&lt;p&gt;Finally, the examples in the tool description grew directly out of these experiments: &lt;em&gt;&amp;quot;someone explained how to make a custom sticker pack,&amp;quot;&lt;/em&gt; &lt;em&gt;&amp;quot;comparing noise cancellation and prices of several wireless earbuds,&amp;quot;&lt;/em&gt; the English query &lt;em&gt;&amp;quot;someone got liquidated on a high-leverage position,&amp;quot;&lt;/em&gt; combining &lt;code&gt;sender&lt;/code&gt; with &lt;em&gt;&amp;quot;plans for taking a gap year from school,&amp;quot;&lt;/em&gt; pairing with &lt;code&gt;text_contains&lt;/code&gt; to lock down a keyword, and using &lt;code&gt;after_id&lt;/code&gt; / &lt;code&gt;before_id&lt;/code&gt; to expand surrounding context. Every single example in the prompt is a query that actually succeeded in our benchmark, and the failure modes were documented verbatim under &lt;em&gt;&amp;quot;When not to use.&amp;quot;&lt;/em&gt;&lt;/p&gt;&#xA;&lt;p&gt;In total, the feature added 552 lines and deleted 25 lines in &lt;code&gt;src/&lt;/code&gt; (339 of which live in the new &lt;code&gt;semantic.ts&lt;/code&gt;): one table, one parameter. It adds zero &amp;quot;memory layers&amp;quot; to the bot: when nobody asks about the past, not a single extra character enters the primary model&#39;s context; when someone does ask, what comes back is still the verbatim transcript from that day.&lt;/p&gt;&#xA;&lt;hr&gt;&#xA;&lt;h2 id=&#34;cashing-restraint-in-for-freedom-speed-and-capability-are-born-from-frugality&#34;&gt;Cashing Restraint In for Freedom: Speed and Capability Are Born from Frugality&lt;/h2&gt;&#xA;&lt;p&gt;Reading this far, someone might form a misconception: if this project counts every penny and every token with such ruthless discipline, doesn&#39;t the bot feel rigid, impoverished, and sluggish?&lt;/p&gt;&#xA;&lt;p&gt;The reality is the exact opposite.&#xA;&lt;strong&gt;All our restraint and weight-shedding was never about hoarding money in a ledger—it was about converting massive compute overhead into unprecedented agility and versatility when it actually counts.&lt;/strong&gt;&lt;/p&gt;&#xA;&lt;h3 id=&#34;highlight-1-the-breathing-room-of-codemode--speaking-while-acting&#34;&gt;Highlight 1: The Breathing Room of Codemode — Speaking While Acting&lt;/h3&gt;&#xA;&lt;p&gt;The strongest immediate impression group members report is: &lt;em&gt;&amp;quot;Why does your bot respond so ridiculously fast?&amp;quot;&lt;/em&gt;&#xA;It isn&#39;t because we swapped in some ultra-low-latency model; the secret lies entirely in the interaction aesthetics of &lt;code&gt;codemode&lt;/code&gt;.&lt;/p&gt;&#xA;&lt;p&gt;Consider how a mainstream agent framework mechanically grinds through a multi-step request like &lt;em&gt;&amp;quot;Look up the origin of this tech meme and summarize what our group has said about it&amp;quot;&lt;/em&gt;:&lt;/p&gt;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;The model reads 90,000 tokens and decides to call &lt;code&gt;search&lt;/code&gt;;&lt;/li&gt;&#xA;&lt;li&gt;Long wait while the network returns search results;&lt;/li&gt;&#xA;&lt;li&gt;The model &lt;strong&gt;re-reads all 90,000 tokens plus pages of raw HTML snippets&lt;/strong&gt;, then decides to call a second tool;&lt;/li&gt;&#xA;&lt;li&gt;Another wait, another full re-read of the entire context to fetch a web page;&lt;/li&gt;&#xA;&lt;li&gt;After four or five heavy, full-price round-trips, users have been staring at a dead &lt;em&gt;&amp;quot;typing...&amp;quot;&lt;/em&gt; indicator for half a minute;&lt;/li&gt;&#xA;&lt;li&gt;Finally, several pages of unfiltered web text get welded permanently into the chat history for all subsequent turns.&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&lt;p&gt;In our architecture, the model uses Pi&#39;s isolated sandbox to write a short, native JavaScript program in a single turn:&lt;/p&gt;&#xA;&lt;figure class=&#34;code&#34;&gt;&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code&gt;&lt;span class=&#34;c1&#34;&gt;// 1. Speak first to break the dead silence of waiting&lt;/span&gt;&#xA;&lt;span class=&#34;kr&#34;&gt;await&lt;/span&gt; &lt;span class=&#34;nx&#34;&gt;tools&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;nx&#34;&gt;send&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;({&lt;/span&gt; &lt;span class=&#34;nx&#34;&gt;text&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;:&lt;/span&gt; &lt;span class=&#34;s2&#34;&gt;&amp;#34;Let me check the group archive and look up that meme—one sec!&amp;#34;&lt;/span&gt; &lt;span class=&#34;p&#34;&gt;});&lt;/span&gt;&#xA;&#xA;&lt;span class=&#34;c1&#34;&gt;// 2. Dispatch in parallel and aggregate inside the sandbox&lt;/span&gt;&#xA;&lt;span class=&#34;kr&#34;&gt;const&lt;/span&gt; &lt;span class=&#34;p&#34;&gt;[&lt;/span&gt;&lt;span class=&#34;nx&#34;&gt;searchRes&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;nx&#34;&gt;historyRes&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;]&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;kr&#34;&gt;await&lt;/span&gt; &lt;span class=&#34;nb&#34;&gt;Promise&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;nx&#34;&gt;allSettled&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;([&lt;/span&gt;&#xA;  &lt;span class=&#34;nx&#34;&gt;tools&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;nx&#34;&gt;search&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;({&lt;/span&gt; &lt;span class=&#34;nx&#34;&gt;query&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;:&lt;/span&gt; &lt;span class=&#34;s2&#34;&gt;&amp;#34;open source project architecture overhaul&amp;#34;&lt;/span&gt; &lt;span class=&#34;p&#34;&gt;}),&lt;/span&gt;&#xA;  &lt;span class=&#34;nx&#34;&gt;tools&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;nx&#34;&gt;tg_messages&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;({&lt;/span&gt; &lt;span class=&#34;nx&#34;&gt;text_contains&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;:&lt;/span&gt; &lt;span class=&#34;s2&#34;&gt;&amp;#34;architecture overhaul&amp;#34;&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;nx&#34;&gt;limit&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;:&lt;/span&gt; &lt;span class=&#34;mi&#34;&gt;10&lt;/span&gt; &lt;span class=&#34;p&#34;&gt;}),&lt;/span&gt;&#xA;&lt;span class=&#34;p&#34;&gt;]);&lt;/span&gt;&#xA;&#xA;&lt;span class=&#34;c1&#34;&gt;// 3. Slice and filter in sandbox RAM so raw junk never enters the main context&lt;/span&gt;&#xA;&lt;span class=&#34;kr&#34;&gt;const&lt;/span&gt; &lt;span class=&#34;nx&#34;&gt;web&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;nx&#34;&gt;searchRes&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;nx&#34;&gt;status&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;===&lt;/span&gt; &lt;span class=&#34;s2&#34;&gt;&amp;#34;fulfilled&amp;#34;&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;?&lt;/span&gt; &lt;span class=&#34;nx&#34;&gt;searchRes&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;nx&#34;&gt;value&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;:&lt;/span&gt; &lt;span class=&#34;kc&#34;&gt;null&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;;&lt;/span&gt;&#xA;&lt;span class=&#34;kr&#34;&gt;const&lt;/span&gt; &lt;span class=&#34;nx&#34;&gt;chat&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;nx&#34;&gt;historyRes&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;nx&#34;&gt;status&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;===&lt;/span&gt; &lt;span class=&#34;s2&#34;&gt;&amp;#34;fulfilled&amp;#34;&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;?&lt;/span&gt; &lt;span class=&#34;nx&#34;&gt;historyRes&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;nx&#34;&gt;value&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;:&lt;/span&gt; &lt;span class=&#34;kc&#34;&gt;null&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;;&lt;/span&gt;&#xA;&#xA;&lt;span class=&#34;nx&#34;&gt;text&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;({&lt;/span&gt;&#xA;  &lt;span class=&#34;nx&#34;&gt;summary&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;:&lt;/span&gt; &lt;span class=&#34;nx&#34;&gt;web&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;?&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;nx&#34;&gt;slice&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;mi&#34;&gt;0&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;mi&#34;&gt;1000&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;),&lt;/span&gt;&#xA;  &lt;span class=&#34;nx&#34;&gt;discussions&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;:&lt;/span&gt; &lt;span class=&#34;nx&#34;&gt;chat&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;?&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;nx&#34;&gt;rows&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;nx&#34;&gt;map&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(({&lt;/span&gt; &lt;span class=&#34;nx&#34;&gt;sender&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;nx&#34;&gt;text&lt;/span&gt; &lt;span class=&#34;p&#34;&gt;})&lt;/span&gt; &lt;span class=&#34;p&#34;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&#34;sb&#34;&gt;`&lt;/span&gt;&lt;span class=&#34;si&#34;&gt;${&lt;/span&gt;&lt;span class=&#34;nx&#34;&gt;sender&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;nx&#34;&gt;name&lt;/span&gt;&lt;span class=&#34;si&#34;&gt;}&lt;/span&gt;&lt;span class=&#34;sb&#34;&gt;: &lt;/span&gt;&lt;span class=&#34;si&#34;&gt;${&lt;/span&gt;&lt;span class=&#34;nx&#34;&gt;text&lt;/span&gt;&lt;span class=&#34;si&#34;&gt;}&lt;/span&gt;&lt;span class=&#34;sb&#34;&gt;`&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;),&lt;/span&gt;&#xA;&lt;span class=&#34;p&#34;&gt;});&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;span class=&#34;code-tools&#34;&gt;&lt;span class=&#34;lang&#34;&gt;js&lt;/span&gt;&lt;button class=&#34;copy&#34; type=&#34;button&#34;&gt;copy&lt;/button&gt;&lt;/span&gt;&lt;/figure&gt;&#xA;&lt;p&gt;Laying the two execution models side by side makes the difference clear—look at how many times the primary model wakes up and what it has to read each time:&lt;/p&gt;&#xA;&lt;figure class=&#34;diagram&#34; style=&#34;--h:452px;--hn:877px&#34;&gt;&lt;figcaption&gt;The Same Task, Run Two Ways&lt;/figcaption&gt;&lt;p&gt;&lt;a href=&#34;https://mizore.blog/en/posts/save-a-little-more/&#34;&gt;(See the figure in the post.)&lt;/a&gt;&lt;/p&gt;&lt;p class=&#34;figure-note&#34;&gt;In a traditional agent loop, every tool result returns to the primary model for another full-context re-read; the diagram shows two tool calls, though real tasks often take four or five. In codemode, a sandboxed script sends an immediate heads-up, runs searches in parallel, and slices the output—waking the primary model only twice.&lt;/p&gt;&lt;/figure&gt;&#xA;&lt;p&gt;Savor the aesthetic power packed into that short script:&lt;/p&gt;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;&lt;strong&gt;Speak first (thoughtful pacing):&lt;/strong&gt; Executing &lt;code&gt;send&lt;/code&gt; on line 1 delivers an immediate acknowledgment to the user&#39;s client within a few hundred milliseconds. The psychological friction of &amp;quot;dead waiting&amp;quot; turns instantly into &lt;em&gt;&amp;quot;it&#39;s already on it.&amp;quot;&lt;/em&gt; Calling &lt;code&gt;send&lt;/code&gt; inside the &lt;code&gt;codemode&lt;/code&gt; sandbox does not trigger turn termination, allowing the pipeline to keep flowing in the background.&lt;/li&gt;&#xA;&lt;li&gt;&lt;strong&gt;True parallel execution:&lt;/strong&gt; Network requests should naturally run concurrently. &lt;code&gt;Promise.allSettled&lt;/code&gt; collapses multiple serial round-trips into one.&lt;/li&gt;&#xA;&lt;li&gt;&lt;strong&gt;A context firewall:&lt;/strong&gt; Tens of kilobytes of raw web text and redundant metadata are distilled in place inside sandbox RAM; &lt;strong&gt;only a few hundred tightly sliced characters of core signal are fed back to the primary model&lt;/strong&gt;.&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&lt;p&gt;We deliberately passed on the &amp;quot;native parallel tool calling&amp;quot; touted by model providers. Native parallel tool calls are one-way and rigid—you cannot speak a reassuring sentence first and branch dynamically on the return values within the same batch, nor can you stop the raw tool outputs from flooding your main context window. &lt;code&gt;codemode&lt;/code&gt; is the unique solution that fuses instant responsiveness, dynamic control flow, and context hygiene into one.&lt;/p&gt;&#xA;&lt;h3 id=&#34;highlight-2-one-complete-linux-container-beats-a-hundred-fragile-plugins&#34;&gt;Highlight 2: One Complete Linux Container Beats a Hundred Fragile Plugins&lt;/h3&gt;&#xA;&lt;p&gt;Many developers measure an agent&#39;s power by the length of its plugin list: weather plugins, charting plugins, audio transcoding plugins, PDF reader plugins, web snapshot plugins...&#xA;Every plugin adds a verbose schema, thousands of lines of glue code, and a third-party boundary waiting to break. Worse still, &lt;strong&gt;the model&#39;s capability ceiling is permanently locked inside the intersection of plugins the author bothered to write&lt;/strong&gt;. If a group member wants to extract specific frames from a video and turn them into a monochrome GIF, and the author never wrote a plugin for that, the agent can only shrug.&lt;/p&gt;&#xA;&lt;p&gt;Our design aesthetic went to the opposite extreme: &lt;strong&gt;give the model a real Linux machine.&lt;/strong&gt;&lt;/p&gt;&#xA;&lt;p&gt;Through Pi&#39;s native file and shell primitives (&lt;code&gt;read&lt;/code&gt; / &lt;code&gt;write&lt;/code&gt; / &lt;code&gt;edit&lt;/code&gt; / &lt;code&gt;bash&lt;/code&gt;), the bot commands a rootless Docker container running under an isolated system user. Its workspace comes preloaded with a full modern toolchain: Python (&lt;code&gt;uv&lt;/code&gt;), Node.js, &lt;code&gt;ffmpeg&lt;/code&gt;, ImageMagick, &lt;code&gt;ripgrep&lt;/code&gt;, Chromium, and full CJK fonts.&lt;/p&gt;&#xA;&lt;p&gt;Magical things happen as a result:&lt;/p&gt;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;Want to trim video, extract audio, or compress a sticker? The model types a one-line &lt;code&gt;ffmpeg&lt;/code&gt; command in the sandbox;&lt;/li&gt;&#xA;&lt;li&gt;Want to crunch data or render a complex heatmap? The model runs &lt;code&gt;uv run --with matplotlib python main.py&lt;/code&gt; inside the container;&lt;/li&gt;&#xA;&lt;li&gt;When a group member asks curiously, &lt;em&gt;&amp;quot;How does your underlying logic actually work?&amp;quot;&lt;/em&gt;, the bot uses &lt;code&gt;bash&lt;/code&gt; to clone its own GitHub repository into &lt;code&gt;/work/src&lt;/code&gt;, searches the codebase with &lt;code&gt;rg&lt;/code&gt;, and explains its own implementation line by line;&lt;/li&gt;&#xA;&lt;li&gt;Once an artifact is ready, it pushes the output straight back to the group as native files or photo albums via &lt;code&gt;send.files&lt;/code&gt;.&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&lt;p&gt;For all of these capabilities, &lt;strong&gt;we didn&#39;t write a single line of &amp;quot;plugin code.&amp;quot;&lt;/strong&gt; Frontier models have already been trained on humanity&#39;s entire open-source Unix ecosystem—they speak Shell natively. The only respectful thing for us to do is not to play babysitter and reinvent wheels for them, but to draw a firm security boundary and hand them a clean, isolated, always-ready general execution environment.&lt;/p&gt;&#xA;&lt;p&gt;Around that clean container boundary, we built a defense-in-depth security perimeter:&lt;/p&gt;&#xA;&lt;figure class=&#34;diagram&#34; style=&#34;--h:358px;--hn:431px&#34;&gt;&lt;figcaption&gt;A Complete Linux Machine Inside Layered Boundaries&lt;/figcaption&gt;&lt;p&gt;&lt;a href=&#34;https://mizore.blog/en/posts/save-a-little-more/&#34;&gt;(See the figure in the post.)&lt;/a&gt;&lt;/p&gt;&lt;p class=&#34;figure-note&#34;&gt;The bot daemon and the container run under separate OS users; the container holds zero API keys, SSH keys, or secrets, and both model requests and outbound files pass through the daemon.&lt;/p&gt;&lt;/figure&gt;&#xA;&lt;p&gt;&lt;strong&gt;One general execution environment replaced an endless parade of mediocre plugins.&lt;/strong&gt; That architectural convergence holds far more beauty than any micro-optimization in code.&lt;/p&gt;&#xA;&lt;hr&gt;&#xA;&lt;h2 id=&#34;the-final-layer-code-is-context--distilling-17500-lines-down-to-8089&#34;&gt;The Final Layer: Code Is Context — Distilling 17,500 Lines Down to 8,089&lt;/h2&gt;&#xA;&lt;p&gt;If we shift our gaze from the runtime model back to our own daily workflow as developers, we find the exact same physical laws governing everything.&lt;/p&gt;&#xA;&lt;p&gt;From day one, this project was built iteratively alongside a Coding Agent. In a Coding Agent&#39;s world, &lt;strong&gt;your codebase &lt;em&gt;is&lt;/em&gt; its context window&lt;/strong&gt;. Every redundant wrapper you write, every abstraction layer reserved for hypothetical &amp;quot;future extensibility,&amp;quot; and every wavering compatibility branch ruthlessly consumes the coding model&#39;s attention and comprehension in every single development session.&lt;/p&gt;&#xA;&lt;figure class=&#34;echart&#34; style=&#34;--h:300px&#34;&gt;&lt;figcaption&gt;Evolution of Lines of Code in src/&lt;/figcaption&gt;&lt;p&gt;&lt;a href=&#34;https://mizore.blog/en/posts/save-a-little-more/&#34;&gt;(See the figure in the post.)&lt;/a&gt;&lt;/p&gt;&lt;p class=&#34;figure-note&#34;&gt;Total lines across src/**/*.ts on each commit date; horizontal axis is scaled proportionally to calendar time.&lt;/p&gt;&lt;/figure&gt;&#xA;&lt;p&gt;By November 1, bogged down by homegrown schedulers, compaction-retry state machines, and sprawling prompt-assembly glue, our codebase had ballooned to 17,522 lines. Over the next four days, following a thorough philosophical reckoning, we took a scalpel to the repo and cut it straight down to &lt;strong&gt;8,089 lines&lt;/strong&gt;.&lt;/p&gt;&#xA;&lt;p&gt;The codebase shrank by more than half, yet production capability didn&#39;t contract—in fact, it unlocked one-command installation, native vision understanding, automatic crash recovery, and the full-featured container sandbox.&lt;/p&gt;&#xA;&lt;p&gt;How? By enforcing one uncompromising rule:&#xA;&lt;strong&gt;If it does not belong to &amp;quot;Telegram group chat semantics,&amp;quot; not a single line of it should be written by us.&lt;/strong&gt;&lt;/p&gt;&#xA;&lt;p&gt;Look back at four of our worst production incidents:&lt;/p&gt;&#xA;&lt;figure class=&#34;diagram&#34; style=&#34;--h:424px;--hn:640px&#34;&gt;&lt;figcaption&gt;Four Production Incidents&lt;/figcaption&gt;&lt;p&gt;&lt;a href=&#34;https://mizore.blog/en/posts/save-a-little-more/&#34;&gt;(See the figure in the post.)&lt;/a&gt;&lt;/p&gt;&lt;p class=&#34;figure-note&#34;&gt;Dates are in 2026. The top half of each card shows the symptom group members saw; the bottom half shows the root cause we uncovered.&lt;/p&gt;&lt;/figure&gt;&#xA;&lt;p&gt;&lt;strong&gt;Not a single one of these four hair-raising incidents had anything to do with Telegram itself. Every one of them came from our own homegrown session state machines and compaction algorithms.&lt;/strong&gt;&lt;/p&gt;&#xA;&lt;p&gt;True engineering maturity means handing specialized infrastructure back to a solid foundation. Pi 1.5 provides first-class durable primitives out of the box: persistent sessions, crash recovery, AST-aware structured compaction, execution queues, and sandbox orchestration. In a single migration commit, we deleted 7,877 lines of homegrown code:&lt;/p&gt;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;Deleted our painstakingly maintained session state machine and complex fingerprint diffing;&lt;/li&gt;&#xA;&lt;li&gt;Deleted our brittle character-based token estimator and custom summary-packing logic;&lt;/li&gt;&#xA;&lt;li&gt;Deleted our homegrown background child-process bridge and scheduling pipeline;&lt;/li&gt;&#xA;&lt;li&gt;Deleted 300 lines of verbose tool usage examples stuffed inside the system prompt (relying directly on Pi&#39;s strict TypeBox parameter schemas).&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&lt;p&gt;The remaining ~8,000 lines of pure code focus on doing one thing well: &lt;strong&gt;mapping the Telegram group chat ecosystem into rigorous, elegant agent interactions&lt;/strong&gt;.&lt;/p&gt;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;It handles message archiving and Trigram / semantic retrieval;&lt;/li&gt;&#xA;&lt;li&gt;It handles prefix-invariant batch grammar serialization;&lt;/li&gt;&#xA;&lt;li&gt;It handles the small classifier model&#39;s chime-in decisions;&lt;/li&gt;&#xA;&lt;li&gt;It builds the security moat around the rootless Linux container.&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&lt;figure class=&#34;diagram&#34; style=&#34;--h:300px;--hn:618px&#34;&gt;&lt;figcaption&gt;What We Deleted Went to Pi; What Remains Is Pure Group Chat Semantics&lt;/figcaption&gt;&lt;p&gt;&lt;a href=&#34;https://mizore.blog/en/posts/save-a-little-more/&#34;&gt;(See the figure in the post.)&lt;/a&gt;&lt;/p&gt;&lt;p class=&#34;figure-note&#34;&gt;The four blocks of homegrown code deleted in the migration commit and the Pi 1.5 capabilities that replaced them; the remaining ~8,000 lines handle only group-chat semantics.&lt;/p&gt;&lt;/figure&gt;&#xA;&lt;p&gt;In software engineering, the purest joy is never typing out tens of thousands of lines of framework code—it is &lt;strong&gt;making the system stronger while deleting thousands of lines of bloated self-indulgence in a single stroke&lt;/strong&gt;. That joy of &amp;quot;negative code&amp;quot; is the truest expression of minimalist aesthetics.&lt;/p&gt;&#xA;&lt;hr&gt;&#xA;&lt;h2 id=&#34;two-visions-of-generality-specialized-deployment-vs-general-agent&#34;&gt;Two Visions of Generality: Specialized Deployment vs. General Agent&lt;/h2&gt;&#xA;&lt;p&gt;In our group, members often teasingly compare my bot with tcdw&#39;s &lt;a href=&#34;https://github.com/tuuject/surowan&#34;&gt;Surowan&lt;/a&gt;: &lt;em&gt;&amp;quot;If you talk about general agents all day, why does your bot single-mindedly serve only our one group?&amp;quot;&lt;/em&gt;&lt;/p&gt;&#xA;&lt;p&gt;Let&#39;s set surface appearances aside and lay the skeletons of both systems side by side:&lt;/p&gt;&#xA;&lt;div class=&#34;table-scroll&#34; tabindex=&#34;0&#34;&gt;&lt;table&gt;&#xA;&lt;thead&gt;&#xA;&lt;tr&gt;&#xA;&lt;th style=&#34;text-align:left&#34;&gt;Dimension&lt;/th&gt;&#xA;&lt;th style=&#34;text-align:left&#34;&gt;Pi Telegram Agent (This Project)&lt;/th&gt;&#xA;&lt;th style=&#34;text-align:left&#34;&gt;Surowan (&lt;code&gt;tuuject/surowan&lt;/code&gt;)&lt;/th&gt;&#xA;&lt;/tr&gt;&#xA;&lt;/thead&gt;&#xA;&lt;tbody&gt;&#xA;&lt;tr&gt;&#xA;&lt;td style=&#34;text-align:left&#34;&gt;&lt;strong&gt;Target Audience&lt;/strong&gt;&lt;/td&gt;&#xA;&lt;td style=&#34;text-align:left&#34;&gt;Deeply tailored for our own trusted circle&lt;/td&gt;&#xA;&lt;td style=&#34;text-align:left&#34;&gt;Built for any external user to self-host (BYOK)&lt;/td&gt;&#xA;&lt;/tr&gt;&#xA;&lt;tr&gt;&#xA;&lt;td style=&#34;text-align:left&#34;&gt;&lt;strong&gt;Scope&lt;/strong&gt;&lt;/td&gt;&#xA;&lt;td style=&#34;text-align:left&#34;&gt;High-frequency emergence inside a single Supergroup&lt;/td&gt;&#xA;&lt;td style=&#34;text-align:left&#34;&gt;Multi-group, multi-channel&lt;/td&gt;&#xA;&lt;/tr&gt;&#xA;&lt;tr&gt;&#xA;&lt;td style=&#34;text-align:left&#34;&gt;&lt;strong&gt;Persona Model&lt;/strong&gt;&lt;/td&gt;&#xA;&lt;td style=&#34;text-align:left&#34;&gt;One deployment = one focused digital persona&lt;/td&gt;&#xA;&lt;td style=&#34;text-align:left&#34;&gt;Single deployment switches personas and model matrices per chat&lt;/td&gt;&#xA;&lt;/tr&gt;&#xA;&lt;tr&gt;&#xA;&lt;td style=&#34;text-align:left&#34;&gt;&lt;strong&gt;Chime-In Decision&lt;/strong&gt;&lt;/td&gt;&#xA;&lt;td style=&#34;text-align:left&#34;&gt;Deterministic on @mention; ambient chatter judged by a &lt;strong&gt;dedicated small classifier reading a slice&lt;/strong&gt;&lt;/td&gt;&#xA;&lt;td style=&#34;text-align:left&#34;&gt;Bucket-aggregated and judged by the &lt;strong&gt;primary model&lt;/strong&gt; over full context, gated by time/probability&lt;/td&gt;&#xA;&lt;/tr&gt;&#xA;&lt;tr&gt;&#xA;&lt;td style=&#34;text-align:left&#34;&gt;&lt;strong&gt;Forgetting Mechanism&lt;/strong&gt;&lt;/td&gt;&#xA;&lt;td style=&#34;text-align:left&#34;&gt;Pi&#39;s native structured compaction (128K window)&lt;/td&gt;&#xA;&lt;td style=&#34;text-align:left&#34;&gt;&lt;strong&gt;Pure checkpoint sliding truncation (drop without summarizing)&lt;/strong&gt;&lt;/td&gt;&#xA;&lt;/tr&gt;&#xA;&lt;tr&gt;&#xA;&lt;td style=&#34;text-align:left&#34;&gt;&lt;strong&gt;Memory System&lt;/strong&gt;&lt;/td&gt;&#xA;&lt;td style=&#34;text-align:left&#34;&gt;&lt;strong&gt;Zero memory layers&lt;/strong&gt;; relies entirely on SQLite verbatim dialogue retrieval&lt;/td&gt;&#xA;&lt;td style=&#34;text-align:left&#34;&gt;Three-tier memory hierarchy (Memo Pad + periodic summaries + curated knowledge base)&lt;/td&gt;&#xA;&lt;/tr&gt;&#xA;&lt;tr&gt;&#xA;&lt;td style=&#34;text-align:left&#34;&gt;&lt;strong&gt;Tool Exposure&lt;/strong&gt;&lt;/td&gt;&#xA;&lt;td style=&#34;text-align:left&#34;&gt;Fixed catalog declared upfront in full, riding the prompt cache&lt;/td&gt;&#xA;&lt;td style=&#34;text-align:left&#34;&gt;Core primitives exposed; internal skills discovered dynamically via &lt;code&gt;execute&lt;/code&gt;&lt;/td&gt;&#xA;&lt;/tr&gt;&#xA;&lt;tr&gt;&#xA;&lt;td style=&#34;text-align:left&#34;&gt;&lt;strong&gt;Execution Power&lt;/strong&gt;&lt;/td&gt;&#xA;&lt;td style=&#34;text-align:left&#34;&gt;&lt;strong&gt;Full rootless Linux container, Shell, and JS sandbox&lt;/strong&gt;&lt;/td&gt;&#xA;&lt;td style=&#34;text-align:left&#34;&gt;Shell and arbitrary code execution strictly forbidden for multi-tenant safety&lt;/td&gt;&#xA;&lt;/tr&gt;&#xA;&lt;tr&gt;&#xA;&lt;td style=&#34;text-align:left&#34;&gt;&lt;strong&gt;Codebase Size&lt;/strong&gt;&lt;/td&gt;&#xA;&lt;td style=&#34;text-align:left&#34;&gt;~8,100 lines in &lt;code&gt;src/&lt;/code&gt;; general execution delegated to Pi&lt;/td&gt;&#xA;&lt;td style=&#34;text-align:left&#34;&gt;~60,000 lines in &lt;code&gt;src/&lt;/code&gt;; custom dashboard, scheduler, and multi-channel runtime&lt;/td&gt;&#xA;&lt;/tr&gt;&#xA;&lt;/tbody&gt;&#xA;&lt;/table&gt;&lt;/div&gt;&#xA;&lt;p&gt;Spread this comparison table open and you see two diametrically opposed yet internally consistent design philosophies:&lt;/p&gt;&#xA;&lt;p&gt;&lt;strong&gt;Surowan is a &amp;quot;general product with a restrained agent.&amp;quot;&lt;/strong&gt;&#xA;Because it was designed from day one to be deployed by strangers across unpredictable public groups, it &lt;em&gt;must&lt;/em&gt; restrain the agent&#39;s hands and feet (strictly forbidding Shell execution) to manage risk—investing massive engineering effort into outer defenses, multi-group routing, admin dashboards, and permission auditing.&lt;/p&gt;&#xA;&lt;p&gt;&lt;strong&gt;We chose a &amp;quot;specialized deployment with a general agent.&amp;quot;&lt;/strong&gt;&#xA;Precisely because we rejected the temptation to support hundreds of arbitrary groups and bounded our deployment to a single group ecosystem we trust, we compressed outer product complexity down to almost zero. Every bit of architectural budget and trust capital we saved on the outside was poured unreservedly into the agent&#39;s core—&lt;strong&gt;daring to hand it a complete Linux machine, daring to let it orchestrate Shell commands, and daring to let it write concurrent code on the fly.&lt;/strong&gt;&lt;/p&gt;&#xA;&lt;figure class=&#34;diagram&#34; style=&#34;--h:360px;--hn:701px&#34;&gt;&lt;figcaption&gt;Where the Complexity Lives&lt;/figcaption&gt;&lt;p&gt;&lt;a href=&#34;https://mizore.blog/en/posts/save-a-little-more/&#34;&gt;(See the figure in the post.)&lt;/a&gt;&lt;/p&gt;&lt;p class=&#34;figure-note&#34;&gt;Neither project is simple; they just place their complexity in opposite places: Surowan puts it in outer product capabilities, while this project puts it inside the agent kernel. Drawn from the comparison table above.&lt;/p&gt;&lt;/figure&gt;&#xA;&lt;p&gt;On specific architectural trade-offs, we remain convinced of our choices:&lt;/p&gt;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;&lt;strong&gt;Who decides when to speak: Slice classifier vs. full-context primary model.&lt;/strong&gt; Even with Surowan&#39;s sophisticated gates, the final mile still wakes the primary model to scan the full context. By decoupling perception from reasoning via a tiny classifier model, our primary model&#39;s cache never flinches no matter how noisy the chat gets.&lt;/li&gt;&#xA;&lt;li&gt;&lt;strong&gt;Tool definitions: Full upfront declaration vs. dynamic discovery.&lt;/strong&gt; Many frameworks love tucking tools into secondary directories so the model searches before calling, hoping to save tokens. Yet our telemetry proves tool schemas occupy just 1.1% of the payload and sit inside the immutable cached prefix; forcing the model to make an extra full-context round-trip just to save a few hundred cached tokens is a textbook case of &lt;em&gt;&amp;quot;penny-wise on the cheapest prefix, pound-foolish on the most expensive inference.&amp;quot;&lt;/em&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;strong&gt;Memory philosophy: Zero mechanism vs. intricate curation.&lt;/strong&gt; Surowan&#39;s three-tier memory design is an impressive piece of engineering, but frontier research and our own production scars sound the same warning bell: processed memory inherently carries a self-poisoning risk. One less layer of mechanism is one less class of self-replicating error.&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&lt;hr&gt;&#xA;&lt;h2 id=&#34;why-specialization-for-a-group-chat-is-the-true-starting-point-of-generality&#34;&gt;Why Specialization for a Group Chat Is the True Starting Point of Generality&lt;/h2&gt;&#xA;&lt;p&gt;Someone might ask: if you welded every design decision to a single Telegram group chat, isn&#39;t that just narrow specialization?&lt;/p&gt;&#xA;&lt;p&gt;&lt;strong&gt;No—the harsher the environment, the more universal the principles distilled from surviving it.&lt;/strong&gt;&lt;/p&gt;&#xA;&lt;p&gt;The most common tragedy in software engineering is building a so-called &amp;quot;general framework&amp;quot; in a vacuum. When you lack a concrete, unforgiving real-world scenario as your anchor, your architecture inevitably fills up with fantasies: adding another middleware layer feels cool, adding a memory-extraction pipeline feels thorough, and having the model repeat a confirmation turn after every tool call feels rigorous.&lt;/p&gt;&#xA;&lt;p&gt;Until you throw it into a real, unforgiving Telegram group chat:&#xA;Online 24/7, hundreds of people firing off jokes and tangents every second, context refreshing by the second, the vast majority of messages pure noise, input outnumbering output by 374 to 1... In an environment that brutal, the slightest bit of architectural bloat or hubris gets amplified dozens of times over by the leverage of 144,000 messages—turning into astronomical cloud bills, lag, and spam in front of your users.&lt;/p&gt;&#xA;&lt;p&gt;&lt;strong&gt;A design philosophy that can survive the most hostile group chat is indestructible when transplanted into any agent system:&lt;/strong&gt;&lt;/p&gt;&#xA;&lt;figure class=&#34;diagram&#34; style=&#34;--h:296px;--hn:515px&#34;&gt;&lt;figcaption&gt;Four Rulers of Restraint&lt;/figcaption&gt;&lt;p&gt;&lt;a href=&#34;https://mizore.blog/en/posts/save-a-little-more/&#34;&gt;(See the figure in the post.)&lt;/a&gt;&lt;/p&gt;&lt;p class=&#34;figure-note&#34;&gt;The four dimensions of frugality, what each one governs, and the design principles they share.&lt;/p&gt;&lt;/figure&gt;&#xA;&lt;p&gt;In the world of LLMs, every engineering law ultimately converges on a single aesthetic truth:&#xA;&lt;strong&gt;Tokens are the only currency.&lt;/strong&gt;&lt;/p&gt;&#xA;&lt;p&gt;Saving money, saving context, and saving lines of code are not three separate virtues—they are projections of the exact same fundamental law across the physical billing ledger, runtime memory, and software architecture.&lt;/p&gt;&#xA;&lt;p&gt;We never sacrificed user experience. On the contrary, precisely because we refused to budge an inch on unnecessary model calls and fought over every byte of prefix stability, we earned the headroom to give our bot a millisecond-responsive &lt;code&gt;codemode&lt;/code&gt; and a full Linux workspace where it can roam freely—living in our group chat as a genuinely sharp, tactful companion.&lt;/p&gt;&#xA;&lt;p&gt;The next time you are tempted to add a new mechanism or write a new feature, hold this ruler up and ask yourself four questions:&lt;/p&gt;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;&lt;strong&gt;Does this step actually require a model, or can a single line of deterministic code settle it? And if it truly needs a model, does it really need to wake the primary model with all 90,000 tokens of baggage?&lt;/strong&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;strong&gt;Will this action mutate the golden prefix? Is dynamic information staying obediently on the append-only tail where it belongs?&lt;/strong&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;strong&gt;Does this batch of data deserve to be re-read by the model on every single turn, or should it sleep in the database until someone actually asks for it?&lt;/strong&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;strong&gt;If I delete this code right now, will the system really collapse—or has the underlying platform already solved this more cleanly than I ever could?&lt;/strong&gt;&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&lt;p&gt;If the answer wavers, take your hands off the keyboard.&lt;/p&gt;&#xA;&lt;p&gt;&lt;strong&gt;Save a little, then save a little more.&lt;/strong&gt;&#xA;Because only where restraint reaches its limit does true freedom appear.&lt;/p&gt;&#xA;</description>
      <category>Tech</category>
      <pubDate>Thu, 05 Nov 2026 00:00:00 +0000</pubDate>
      <guid>https://mizore.blog/en/posts/save-a-little-more/</guid>
    </item>
  </channel>
</rss>