Implementation of GPT-2 in pure CMake
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.
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
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.
Reverse-Engineering the RK3588 NPU: Building an Open Compiler to Run GPT-2 at 36 tok/s
Reverse-engineered the RK3588 NPU and built an open compiler and runtime to run GPT-2 and SigLIP from PyTorch, ONNX, and JAX without vendor SDK.
GPT2-BASIC: Portable Machine Intelligence in BASIC
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
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.
Tiny hackable CUDA language model implementation
A minimal, hackable CUDA implementation of a GPT-like transformer language model that processes byte sequences, with sample outputs and build instructions.