One Small GPT, Three Builds, Each Proven by Test: NumPy by Hand, PyTorch, and Core JAX, with a KV-Cache Speedup That Did Not Survive Repetition

One small character-level GPT architecture (pre-LayerNorm, tanh-GELU MLP, causal multi-head attention) was implemented three times and each implementation was proven correct by test rather than by a plausible loss curve: in pure NumPy with a hand-written backward pass (104,704 parameters), in PyTorch, and in core JAX (110,916 parameters each). The NumPy model's analytic gradients agreed with central finite differences below 1e-4 relative error on sampled entries of every parameter tensor, and its training loss fell from 3.2137 to 0.1330 over 300 steps on a repeated teaching passage. The PyTorch and JAX ports trained on the same 20,000-character Hamlet slice with a checkpoint restart at step 150 of 300; validation loss fell from 4.3464 to 2.0351 (PyTorch) and from 4.2430 to 2.4048 (JAX) in the recorded run, against add-1 bigram and unigram baselines of 2.4929 and 3.3596 nats per character on the same split. A KV-cache study on seeded untrained weights found cached greedy generation token-identical to naive generation in every check, but the speed result did not survive repetition: a single recorded run gave speedups of 2.33x and 3.69x at two model sizes, while a five-trial variance pass on a second machine gave 1.45 (std 0.01) and 1.42 (std 0.01) at one thread, and 1.88 (std 0.52) and 0.49 (std 0.11) at 20 threads, where caching the larger model was slower than no cache. The study was not pre-registered: the research question was written after the work, no hypotheses or pass lines were locked, and every expectation scored in this paper is exploratory. The repository's own verdict, carried here, is Functional.

Authors

Publication Details

Journal
Zenodo (CERN European Organization for Nuclear Research)
Published
2026-11-18
DOI
https://doi.org/10.5281/zenodo.24329116
Primary Topic
Topic Modeling
Type
preprint
Controls
|||
ALL TIME
JAN
FEB
MAR
APR
MAY
JUN
JUL
AUG
SEP
OCT
NOV
preprint

One Small GPT, Three Builds, Each Proven by Test: NumPy by Hand, PyTorch, and Core JAX, with a KV-Cache Speedup That Did Not Survive Repetition

Jesun Ahmad Ushno
6 links
Zenodo (CERN European Organization for Nuclear Research)
Topic Modeling
preprint

One Small GPT, Three Builds, Each Proven by Test: NumPy by Hand, PyTorch, and Core JAX, with a KV-Cache Speedup That Did Not Survive Repetition

Jesun Ahmad Ushno
preprint en

Abstract

One small character-level GPT architecture (pre-LayerNorm, tanh-GELU MLP, causal multi-head attention) was implemented three times and each implementation was proven correct by test rather than by a plausible loss curve: in pure NumPy with a hand-written backward pass (104,704 parameters), in PyTorch, and in core JAX (110,916 parameters each). The NumPy model's analytic gradients agreed with central finite differences below 1e-4 relative error on sampled entries of every parameter tensor, and its training loss fell from 3.2137 to 0.1330 over 300 steps on a repeated teaching passage. The PyTorch and JAX ports trained on the same 20,000-character Hamlet slice with a checkpoint restart at step 150 of 300; validation loss fell from 4.3464 to 2.0351 (PyTorch) and from 4.2430 to 2.4048 (JAX) in the recorded run, against add-1 bigram and unigram baselines of 2.4929 and 3.3596 nats per character on the same split. A KV-cache study on seeded untrained weights found cached greedy generation token-identical to naive generation in every check, but the speed result did not survive repetition: a single recorded run gave speedups of 2.33x and 3.69x at two model sizes, while a five-trial variance pass on a second machine gave 1.45 (std 0.01) and 1.42 (std 0.01) at one thread, and 1.88 (std 0.52) and 0.49 (std 0.11) at 20 threads, where caching the larger model was slower than no cache. The study was not pre-registered: the research question was written after the work, no hypotheses or pass lines were locked, and every expectation scored in this paper is exploratory. The repository's own verdict, carried here, is Functional.

Zenodo (CERN European Organization for Nuclear Research)
Topic Modeling
AI Navigator

Ask Laika to Summarize, Analyze, and Connect papers live on the map.

Summarize Papers & Methodologies

Extract key findings, datasets, and comparative methods across publications.

Benchmark Rankings & Visual Analytics

Rank top research institutions, authors, funders, topics, and journals by Field-Weighted Citation Impact (FWCI) and paper volume with instant charts.

Connect Distant Disciplines

Bridge topological clusters on the map to find hidden collaborative intersections.

Laika access coming soon