GPT-2 124M in the cluster float mode on the CPU: the forward pass, prefill and decode, greedy generation, bitwise equal to the GPU kernels
$ sexc add @ajax/mesh-ref-gpt2- total 3
- drwxr-xr-x-../
- drwxr-xr-x-Oct 27 01:59v/# 1 version
- drwxr-xr-x-Oct 27 01:59files/# the files of 0.1.0
- latest
- 0.1.0, published Oct 27 01:59 by ajax
- owners
- ajax
- license
- MIT
- dependencies
- @ajax/mesh-ftz ^0.1.0, @ajax/mesh-ref-matmul ^0.1.0, @ajax/mesh-ref-gpt2-shape ^0.1.0, @ajax/mesh-ref-gpt2-linear ^0.1.0, @ajax/mesh-ref-gpt2-norm ^0.1.0, @ajax/mesh-ref-gpt2-attend ^0.1.0, @ajax/mesh-ref-gpt2-logits ^0.1.0, @ajax/mesh-ref-gpt2-kv ^0.1.0, @ajax/mesh-ref-gpt2-weights ^0.1.0
- dependents
- none yet
- keywords
- alphaos mesh reference gpt2 determinism
- homepage
- https://github.com/thomasdavis/alpha-c-mesh/tree/main/packages/mesh-ref-gpt2
- repository
- https://github.com/thomasdavis/alpha-c-mesh
1# @ajax/mesh-ref-gpt2 2 3GPT-2 124M in the cluster float mode on the CPU: the CPU reference of programs/gpt2x (the exact-mode GPU 4kernels) and the exact executor of programs/gpt2 on a CPU. Every value is a fixed function of the weights 5and the token prefix — the order of every sum is fixed and the GPU kernels follow it operation for 6operation — so the logits and the KV cache are bitwise the same on every executor, and a row computed 7alone (decode) equals the same row computed in a batch (prefill). 8 9`mesh_gpt2_forward` runs rows through the model and appends their K and V to the cache; 10`mesh_gpt2_forward_layers` calls back after each layer (a prefill can stream its KV); `mesh_gpt2_generate` 11is greedy generation with one digest over every step's logits. Work is split over POSIX threads by 12(row, column block), by row and by vocabulary row; the results never depend on the thread count. 13 14**Ported from** `crates/mesh-ref/src/gpt2.rs` (`forward`, `forward_layers`, `generate`, `par_linear`, 15`par_rows`, `project_vocab`). Host only. 16 17**Tested** on synthetic weights against golden data from the Rust: the row operations on hashed data, 18the weights, a greedy generation (tokens, logits digest, KV digest), and gpt2.rs's 19`decode_rows_equal_prefill_rows` — three tokens one at a time and all at once give the same KV and 20logits, both equal to the Rust's. 21 22## Differences 23 24- Threads come from a shared counter over independent units rather than Rust's scoped chunking; outputs 25 go to caller buffers; out-of-memory and context overflow return false instead of panicking.