Implementation of GPT-2 in pure CMake

Hacker News Top Tools

Summary

This GitHub repository provides CMake scripts to execute GPT-2 using Q16.16 integer arithmetic, including instructions for running both full and toy models.

No content available
Original Article
View Cached Full Text

Cached at: 08/24/26, 01:43 AM

AlpinDale/gpt2.cmake

Source: https://github.com/AlpinDale/gpt2.cmake

gpt2.cmake

GPT-2 in pure CMake, executed with Q16.16 integer arithmetic.

Full model

mkdir -p checkpoint
curl -L -o checkpoint/model.safetensors https://huggingface.co/openai-community/gpt2/resolve/main/model.safetensors
curl -L -o checkpoint/vocab.json      https://huggingface.co/openai-community/gpt2/resolve/main/vocab.json
curl -L -o checkpoint/merges.txt      https://huggingface.co/openai-community/gpt2/resolve/main/merges.txt
python3 tools/gen_full.py
cmake -P gpt2_full.cmake -DPROMPT="Hello" -DN=2

Toy model

python3 tools/gen_tables.py
python3 tools/gen_model.py
cmake -P gpt2.cmake

License

BSD 3-Clause. See LICENSE.

Similar Articles

Show HN: NanoEuler – GPT-2 scale model in pure C/CUDA from scratch

Hacker News Top

NanoEuler is a GPT-2-scale language model built entirely from scratch in C/CUDA without any ML libraries, including hand-written forward/backward passes, a byte-level BPE tokenizer, and training pipeline. The project is an educational artifact demonstrating the engineering behind transformer training and runs on a single RTX 4070.

GPT2-BASIC: Portable Machine Intelligence in BASIC

Lobsters Hottest

GPT2-BASIC implements a GPT-style transformer inference engine in FreeBASIC for DOS systems, using fixed-point arithmetic and local model artifacts to run AI-assisted tasks on vintage hardware.

MiniGPT: Rebuilding GPT from First Principles

arXiv cs.CL

This paper presents MiniGPT, a compact from-scratch implementation of GPT-style autoregressive language modeling in PyTorch, built after studying nanoGPT. It evaluates the model on the Tiny Shakespeare dataset using character-level tokenization, achieving a validation loss of 1.4780 with a 10.77M-parameter configuration.