Sam Babichenko

Reading notes / Attention and concepts

Reading a model's weights

Readout
wwa token id; as a subscript, the query token
VVvocabulary size, 200,058
ewe_wtoken ww's embedding row after the embedding's RMS norm
δ\deltadistance from the query back to a key, in tokens
sws_wone head's 16 bias weights for token ww
pδp_\deltathe 16 shared profiles at distance δ\delta
bw(δ)b_w(\delta)one head's bias sw⊤pδs_w^\top p_\delta, in logits
πw(δ)\pi_w(\delta)bias-only attention, ∝ebw(δ)\propto e^{b_w(\delta)}
head-medianmedian over the 24 heads of each head's median distance
Router mix
ddmodel width, 2,304
n(x)n(x)d x/∥x∥\sqrt d\,x/\|x\|, RMS normalization without a gain
iiquery position
oio_ilayer 0's attention output at ii
qmixq_{\rm mix}the mix's learned query
ue,u_e, uou_othe mix's scores for ewe_w and oio_i
aathe mix's weight on ewe_w
σ\sigmalogistic function
File
NNheader length in bytes, the file's first 8 bytes
[B0,B1)[B_0,B_1)a tensor's byte offsets from the data start 8+N8+N
R,R, C,C, ℓ\ellrows and columns of a tensor, and a row index
Matrices
WE,W_E, WUW_Uembedding (d×Vd\times V) and unembedding (V×dV\times d)
WQ,W_Q, WK,W_K, WV,W_V, WOW_Oa head's query, key, value and output maps

Context. An open-weights release ships a configuration file, a tokenizer, named tensor files, and the code that runs them. Most interpretability methods record activations by running the model on chosen inputs, yet some questions need less. When a component depends only on listable inputs, such as the token id, position, or layer index, it is a lookup table. A few matrix products on the tensors compute that table for every input at once. In layer 0 of an open-weights looped mixture-of-experts language model released by Thinking Machines Lab in 2026, with 24 layers of width 2,304 and a vocabulary of 200,058 tokens. Reading note: Inkling 2 Mini, this readout gives the πw(δ)∝ebw(δ)\pi_w(\delta)\propto e^{b_w(\delta)} over the distances 0≤δ<10240\le\delta\lt1024, the softmax of one head's position bias bwb_w for the query token ww, the attention the head would give if every key had the same content score. Reading note: Position in attention of all 24 heads across the entire vocabulary.

A component whose inputs can be listed is a table. To test whether a component can be read off the weights, trace its input back through the code until it reaches either a listable input or a state carrying context. In Inkling's layer 0, attention reads token ww's normalized embedding the embedding row of the token ww at that position after the embedding's RMS norm, the state every layer-0 computation starts from through one more RMS norm. Each head's query, sink logit, output gate, and 16 bias weights one head's 16 weights on the layer's shared bank of distance profiles, for the query token ww, after the learned scales and the norm cap at 8 therefore depend on token ww alone. One head's bias for token ww isbw(δ)=sw⊤pδ,0≤δ<1024,\begin{aligned}b_w(\delta)&=s_w^\top p_\delta,\\ 0\le\delta&\lt1024,\end{aligned}where the 16 shared profiles' values at distance δ\delta, one column of the layer's 16×102416\times1024 bank is the bank's column at distance the distance in tokens from the query back to a key; δ=0\delta=0 is the query's own token. Across all the number of tokens in the vocabulary, 200,058 for Inkling; the embedding has 201,024 rows, and the rest are padding tokens and 24 heads, the full table holds 4.9 billion entries, or 19.7 GB in FP32, slightly larger than the 19.5 GB checkpoint. That table never needs to be stored. Each head's table has rank at most 16, so the 77 million weights sws_w and the 16×102416\times1024 bank determine every entry, and summaries run a few thousand tokens at a time.

Components one step further from the token leave the single-token table regime. Before the norm cap, a width-4 causal convolution replaces key jj with itself plus a learned weighting of keys jj through j−3j-3, divided by 5\sqrt5. Each key therefore depends on four tokens, giving V4V^4 cases that can be read only case by case. Layer 1 applies the same bias formula to a learned mix of ewe_w and layer 0's output. Because layer 0's output depends on every token in the window, the same tensors give a token different profiles in different contexts.

Layer 0's MoE router sits in the first layer yet still needs activations. The code feeds the router a learned mix of two states, a n(ew)+(1−a) n(oi)a\,n(e_w)+(1-a)\,n(o_i), followed by one more RMS norm. Here n(x)=d x/∥x∥n(x)=\sqrt d\,x/\|x\|, RMS normalization without a learned gain, with d=2,304d=2{,}304 the model width is unweighted RMS normalization with ∥n(x)∥=d\|n(x)\|=\sqrt d, and layer 0's attention output at position ii, after its output projection and its width-4 convolution; it depends on every token in the window is layer 0's attention output. A two-way softmax against a learned query a learned vector of width dd, the same at every position; the code's mlp_input.query sets the mixing weight aa, written below with the σ(z)=1/(1+e−z)\sigma(z)=1/(1+e^{-z}). Cauchy-Schwarz bounds the attention output's score:a=σ(ue−uo),ue=qmix⊤n(ew)/d,uo=qmix⊤n(oi)/d,∣uo∣≤∥qmix∥ ∥n(oi)∥/d=∥qmix∥.\begin{aligned}a&=\sigma(u_e-u_o),\\ u_e&=q_{\rm mix}^\top n(e_w)/\sqrt d,\\ u_o&=q_{\rm mix}^\top n(o_i)/\sqrt d,\\ |u_o|&\le\|q_{\rm mix}\|\,\|n(o_i)\|/\sqrt d\\&=\|q_{\rm mix}\|.\end{aligned}Across the vocabulary, the weights fix ueu_e between −1.4-1.4 and 0.60.6 while bounding uou_o only by ∥qmix∥=9.0\|q_{\rm mix}\|=9.0 (computed here). Those bounds confine aa only to the range from σ(−1.4−9.0)≈0.00003\sigma(-1.4-9.0)\approx0.00003 to σ(0.6+9.0)≈0.99993\sigma(0.6+9.0)\approx0.99993, leaving the mix dependent on context. Finding a token's route requires oio_i, and so requires activations.

The released code is the specification. Release posts rarely give exact forward equations. Thinking Machines' post cites Shaw et al. (2018) and Huang et al. (2018) and notes only that the relative positional embedding performs better and extrapolates better to longer sequences than RoPE. The Hub repository ships no modeling code either; the implementation lives in a pull request to Hugging Face Transformers, while serving frameworks carry their own. The checkpoint header names the tensor model.llm.layers.0.attn.wr_du.weight of shape 384×2304384\times2304. The pull request's conversion map renames it to the linear projection inside Inkling2LoopRelativePositionBias. That class's forward method maps the input to 24 heads of 16 weights, then applies the learned scales and norm cap at 8. Next it multiplies by the 16×102416\times1024 bank, gathers by distance, and zeros the bias outside 0≤δ<10240\le\delta\lt1024. Callers settle the remaining details. Sliding-window layers pass the input after input_layernorm, which in layer 0 normalizes ewe_w once more. Global layers add a log scale that multiplies the weights by 1+0.1log⁡((i+1)/8192)1+0.1\log\big((i+1)/8192\big) from position i=8,192i=8{,}192 on, a position dependence left out of the post. The configuration file supplies the sizes, 16 weights and 1,024 distances, along with the list of sliding-window layers.

A readout is trusted once it matches the reference entry for entry. Reimplement the component from raw tensors, run the reference class on the same real input, and compare every entry. For Inkling, the reference classes were extracted from the pull request without the rest of the model, loaded with checkpoint tensors, and run on 1,300-token sequences of English text and Python code. Over all 24 heads and query-key pairs, the maximum absolute difference was 0 in FP32 and 0.07 logits with the reference in BF16 (computed here). That 0.07 is roughly one BF16 step at the largest biases, which reach 11 where BF16 values sit 0.0625 apart between 8 and 16. Exact zero in FP32 confirms the order of operations, whereas a preset tolerance can hide a missing gain with a small effect. When discrepancies appear, their location pinpoints the bug. Mismatches only at large distances point to the window boundary, while mismatches everywhere point to a normalization or scale. Test inputs must also hit every code branch. Starting from token ids exercises the reference's embedding lookup and norms, and sequences past 1,024 tokens test pairs outside the window, where the reference bias is exactly 0.

A summary with a known meaning turns the table into a question. The distance prior πw\pi_w has a clear meaning before any numbers are inspected. It gives the attention a head would put on each distance if every key shared the same content score, and its median distance measures reach. Convenience summaries need their meaning checked. Across frequent tokens, the first principal component of the head-averaged profiles accounts for 91.5% of variance, yet correlates −0.9999-0.9999 with each profile's mean. That shift drops out of πw\pi_w and moves attention only into or out of the sink. Direct summaries isolate concrete structure. Nine common prepositions have a mean the median over the 24 heads of each head's median distance for the token. Reading note: Position in attention of 4.3 tokens, against 31 for five common adjectives. Six-cluster the clustering that alternates between assigning each point to its nearest of kk centers and moving each center to the mean of its points on the head-averaged profiles separated word fragments without a leading space from words starting with one. A direct test across thousands of frequent lowercase tokens confirmed that split, with a median head-median of 3 tokens without a leading space against 27 with one.

Weight vocabulary summaries by frequency before reading them as behavior. Counting each token type once misleads whenever common tokens behave unusually. Inkling's six local and five broad layer-0 heads keep their class for 95% of frequent token types, yet at just over half of positions in running text. The commonest tokens are exceptions; a newline alone makes up roughly 5% of positions and turns heads 1 and 6 broad. Every input to layer 0's attention scores comes from a token table or the key convolution, so those scores can be checked on text without running the rest of the model. On 2,048-token samples of English and Python, the bias raises layer 0's share of attention within 8 tokens from 1% to 28%.

One tensor of a 19.5 GB checkpoint costs one byte-range request. A Hugging Face's file format for tensors, an 8-byte length followed by a JSON header and the raw bytes, with no executable content file opens with an 8-byte little-endian integer the length of the JSON header in bytes, followed by NN bytes of JSON and then the raw tensors in row-major order. That JSON header records each tensor's dtype, shape, and byte offsets a tensor's first byte and one past its last, counted from the start of the data, which begins at byte 8+N8+N of the file. Because the Hub supports HTTP range requests, two small requests read the header, and finding any tensor reduces to arithmetic. For Inkling's single shard and the layer-0 bias projection (computed here):N=148,408,8+N=148,416,[B0,B1)=[974,667,168,976,436,640),first byte=8+N+B0=974,815,584,last byte=8+N+B1−1=976,585,055.\begin{aligned}N&=148{,}408,\\ 8+N&=148{,}416,\\ [B_0,B_1)&=[974{,}667{,}168,\\&\qquad976{,}436{,}640),\\ \text{first byte}&=8+N+B_0\\&=974{,}815{,}584,\\ \text{last byte}&=8+N+B_1-1\\&=976{,}585{,}055.\end{aligned}Here B1−B0=1,769,472B_1-B_0=1{,}769{,}472 matches 384⋅2304384\cdot2304 two-byte entries, and 8+N8+N plus the largest header offset equals the file size, 19,526,019,168 bytes. Row-major layout makes single rows cheap too. Row ℓ\ell of an R×CR\times C BF16 tensor occupies the 2C2C bytes starting at 8+N+B0+2Cℓ8+N+B_0+2C\ell, so token ww's embedding row is the 4,608 bytes starting at 1,139,808+4,608 w1{,}139{,}808+4{,}608\,w. Re-fetched this way, both the bias projection and the embedding row of “ Monday” matched the loaded tensors byte for byte.

The header's dtypes also show which tensors can be read directly without decoding a quantization scheme. Inkling stores its embeddings, attention, and routers in BF16, apart from a few small FP32 vectors. Its expert weights make up 15.7 GB of the 19.5 GB file and sit as packed 4-bit and 8-bit values with separate scale tensors that require the quantization recipe to unpack. Reading layers 0 and 1 fetched just 22 tensors totaling 0.97 GB, most of it the embedding matrix.

What weights alone give, and how embedding-space circuits extend them. The embedding the d×Vd\times V embedding map from a one-hot token to its vector; its columns are the rows the checkpoint stores, and Inkling's code keeps it separate from the unembedding, the unembedding the V×dV\times d matrix that maps the final residual stream to one logit per token, token-only first-layer computations, and fixed constants such as convolution taps all come directly from the weights. A direction written to the residual stream, such as a head's output vector or an MLP neuron, projects through the final norm's gain and WUW_U onto the tokens whose logits it raises. Ignoring later layers, that reading is exact for the direct path to the logits up to the final norm's overall scale. Elhage et al. (2021) showed that a one-layer attention-only model decomposes exactly into the direct path WUWEW_UW_E plus two token-pair tables per head, the QK circuit WE⊤WQ⊤WKWEW_E^\top W_Q^\top W_KW_E and the OV circuit WUWOWVWEW_UW_OW_VW_E. Here WQ,WK,WV,WOW_Q, W_K, W_V, W_O are the head's query, key, value, and output maps, and every table is read without a forward pass. In a a first layer with the norms, norm caps and convolutions of a released model, which the attention-only models of Elhage et al. leave out. Reading note: A Mathematical Framework for Transformer Circuits, norms and caps make those maps nonlinear. Inkling's key convolution further turns the QK table into a map over a query token and four key tokens, readable case by case. Dar et al. (2022) apply the same projection to every layer of GPT-2, dropping norms and using WE⊤W_E^\top in place of an inverse. They assume intermediate hidden states can be read in embedding space and back those approximations with experiments.

Everything that carries context requires activations. The logit lens (nostalgebraist, 2020) uses the same unembedding readout, applying the final norm and WUW_U to an intermediate residual stream, so it needs a forward pass. Any question whose input mixes positions requires activations too. That covers attention patterns and expert routing on real text, probes trained on hidden states, and patching, which swaps activations between runs to test causal effect.

Embedding neighbors show why a readout must use the tensor the model actually sees. Cosine nearest neighbors across all 200,058 embedding rows are the cheapest weight readout (computed here). On raw embedding rows, a token's neighbors are mostly the same word in another case, spacing, script, or language. For “ Paris”, the top neighbors are “Paris” (cosine 0.87), “paris”, “París”, and “Париж”. For “ Monday”, the eight nearest are “Monday”, five translations, and only two other weekdays. Layer 0 instead reads each row multiplied coordinatewise by the learned gains of two RMS norms. On those scaled rows, the eight nearest neighbors of “ Monday” include all six other weekdays, “ blue” gains “ green” and “ red”, and “ Paris” gains “ France”. Those gains also lift the mean cosine of random token pairs from 0.01 to 0.10, so cosine values from the two versions cannot be compared directly.

In a new model, start with the embedding, the unembedding, fixed constants, and whatever layer 0 computes before positions mix. A weight readout covers rare tokens that no text sample reaches and sharpens which questions about deeper layers merit a forward pass. The newline exception, read straight off a table, becomes a concrete prediction to test with activations.

On real text, the bias sets reach and content picks which key. Running Inkling 2 Mini's Q4_K_XL llama.cpp's single-file format for a model's tensors and metadata, in which each tensor has its own quantization type file in llama.cpp yields layer 0's full attention on real text. The measurements below come from three passages of English prose, Python, and nested brackets, each at most 485 tokens long (computed here with the local quantized model). Over the keys available to each query, the distance prior predicts each head's median attention distance with a median error of 4% across the 24 heads. It also predicts each head's share at δ<8\delta\lt8 within 0.03 on average. Without the bias, content scores alone make every head broad, with median distances of 100 tokens or more. Passages this short cap the broad heads' medians for both the prior and the model. Row by row, however, prior and model diverge sharply, with mean total variation distances of 0.18 to 0.71 by head. In the five broad heads, the top-attended key matches in only 1% to 5% of rows. Closing brackets locate their openers through content. Over 114 bracket pairs, head 1 puts 37% of a closing bracket's attention over keys on its opening bracket, against 6.5% under the prior.

Recording post-softmax attention in llama.cpp. llama.cpp invokes an evaluation callback on each named tensor in the computation graph, including layer 0's post-softmax attention. Turning flash attention off keeps the fused kernel from skipping that matrix. The graph adds the bias and the sink logit to the scores in one tensor, yet both separate cleanly because every key position past the query holds minus the sink logit alone. The GGUF file stores layer 0's attention weights in 8-bit Q8_0 where the release uses BF16, and keeps the key-value cache in F16. Most of its experts are 4-bit (NVFP4), though layer 0's attention never reads them. The recorded attention agrees to a mean total variation distance of 0.003 per row with layer 0's attention recomputed from the BF16 weights, using the same computation as the 2,048-token attention shares above.

Terms

Readability test
a component is a table when its output depends only on inputs that can be listed: token, position, layer
Inkling layer-0 bias
bw(δ)=sw⊤pδb_w(\delta)=s_w^\top p_\delta: 200,058 tokens, 24 heads, 1,024 distances; rank at most 16 per head
Router mix
a=σ(ue−uo)a=\sigma(u_e-u_o) with ∣uo∣≤∥qmix∥=9.0|u_o|\le\|q_{\rm mix}\|=9.0, so the weights leave aa undetermined
Code as specification
tensor name in the header, then the conversion mapping, then the class's forward and its callers
Exact match
reimplementation against the reference on the same real tokens; FP32 max difference 0, BF16 0.07 logits
Summary with a meaning
bias-only softmax is a prior over distance; check what a principal component measures
Types against positions
weight vocabulary summaries by token frequency before reading them as behavior
safetensors layout
8-byte little-endian NN, NN bytes of JSON, data from byte 8+N8+N; offsets count from there
Row of a BF16 tensor
row ℓ\ell of an R×CR\times C tensor: 2C2C bytes from 8+N+B0+2Cℓ8+N+B_0+2C\ell
Circuits in embedding space
QK WE⊤WQ⊤WKWEW_E^\top W_Q^\top W_KW_E, OV WUWOWVWEW_UW_OW_VW_E: exact tables for one-layer attention-only models
Logit lens
final norm and WUW_U applied to an intermediate residual stream; needs a forward pass

Sources