Implementing GPT-2 in CSS shubhampatil.dev · 15 points · 2 comments · HN thread ...
HN Best 200 @best
Implementing GPT-2 in CSS shubhampatil.dev · 15 points · 2 comments · HN thread
TL;DR The author ran GPT-2 small (about 124M parameters) in a browser using only CSS, with no JavaScript or WASM at inference time. Weights are stored in generated variable fonts, which the text shaper uses to perform the matrix multiplications, and CSS variables, animations and layout are used for the rest of the model. It generates roughly 15 s per token on a good day and matches reference GPT-2 output token for token.
- CSS calc() and @property are enough for arithmetic; registering variables with @property stops the browser re-expanding long expression chains.
- Variable fonts hold weights as deltas: the HVAR table computes glyph widths as a dot product of axis settings and stored weights, so matrix multiplication happens during text layout.
- Glyph widths are read back into numbers with view-timeline animations, and the BPE tokenizer is reproduced with font ligature (GSUB) rules.
- A KV cache is built from a transition with a 24-hour delay, and argmax and Gumbel sampling are done by comparing max-content widths.
- Performance: style recalculation was 55.6% of token time; scrollbars on the hidden scroll box caused a wrong token (EARTH instead of Representatives), fixed with scrollbar-width: none.
- Requires desktop Chrome or Edge 139+, about 16 GB RAM, and a roughly 250 MB first download; 32 tokens take 15 to 20 minutes.
Discussion The thread is very short, with only two top-level comments. Both react with admiration to the technical feat, and one reflects on the long-running debate over whether CSS counts as a programming language.
- Impressed by the hack; a remarkable technical feat (most): Commenters praise the project as one of the most striking hacks they have seen, and the author's work is described as exceptional.
- Revisits whether CSS counts as a programming language (a few): One commenter notes that the project makes them rethink the old argument that CSS isn't a programming language, given that it can run a transformer.