Designs by DuhartAll work
Rank
24 of 28
Tier
Tier C 53 of 120

19 — Solomon: The Transformer, Built From the Paper

Solomon 1 of 6 · Solomon/solomon/model Stack: PyTorch only — no HuggingFace, no transformers, no pretrained anything Reference: The Annotated Transformer (Harvard NLP) — Vaswani et al. in pure PyTorch

Where this sits. The deepest "do you actually understand it" artifact in the tree. Every component is either verbatim from the reference or has its deviation justified in writing, component by component, in PLAN.md.


The component map — written before the code

Reference componentStatusNote
attention(q,k,v,mask,dropout)verbatimscaled dot-product, masked_fill(mask==0, -1e9), softmax, dropout
MultiHeadedAttentionverbatim4 linears, view/transpose to (b,h,t,d_k), self-attention only
PositionwiseFeedForwardverbatimw_2(dropout(relu(w_1(x))))
LayerNormverbatima_2, b_2, eps 1e-6
SublayerConnectionverbatimx + dropout(sublayer(norm(x)))
Embeddingsverbatimlut(x) * sqrt(d_model)
PositionalEncodingverbatimsinusoidal, div_term = exp(arange(0,d,2) · −ln(10000)/d)
subsequent_maskverbatimtriu(ones, k=1) == 0
Generatorverbatimlinear + log_softmax
NoamOptverbatimfactor · d_model^−0.5 · min(step^−0.5, step·warmup^−1.5)
LabelSmoothingverbatimKLDivLoss, confidence/(V−2), padding zeroed
Xavier initverbatimxavier_uniform_ on dim > 1
Encoder, EncoderLayer, src-attndroppedno encoder in a causal LM
EncoderDecoderadapted → SolomonLMembed → N decoder layers (causal mask) → final LayerNorm → Generator
Batch, run_epoch, SimpleLossComputeadaptedLM batches: y = x shifted by 1; ntokens excludes pad
greedy_decodeadapted+ beam, temperature/top-k/top-p — decode-time only, no architecture change

The three deviations, each defended

  1. Decoder-only. Required by the mission: a generative LM doing next-token prediction has no source sequence to encode.
  2. Weight tying (embedding ↔ generator). Saves ~2.1M of ~7M params; on a small-corpus CPU model the regularization is worth more than the capacity (Press & Wolf 2017). The reference itself notes shared embeddings as an option.
  3. Pre-norm — not actually a deviation. The reference code already applies norm before each sublayer ("for code simplicity the norm is first"). Saying so, rather than claiming credit for it, is the point.

Configuration

vocab 8192 · d_model 256 · N = 6 layers · h = 8 heads · d_ff 1024 · seq 256 · dropout 0.1 · tied weights → 6.84M parameters.

Sized deliberately: it trains to a real checkpoint on 16 CPU cores in hours, and the loop fits the ~13 GB of RAM left over after the production services on the same host take theirs. The model was sized by the machine's spare capacity, and that constraint is documented rather than hidden.

Decoding

Greedy, beam, and temperature / top-k / top-p — all decode-time, no architectural change. KV-cached decode was proven exactly equal to full recompute, not assumed. That proof is the thing to mention: caching is where generation quietly goes wrong, and "exactly equal" is a testable claim.

The tests that prove understanding

Interview surface this opens