Show HN: GPT-2 implemented using graphics shaders
Published on: 2025-06-10 04:21:49
GPT-2 WebGL Inference Demo
A browser-based, WebGL2 implementation of GPT-2.
π Features
Full GPT-2 small (117M) forward pass in the GPU via WebGL2 shaders
BPE tokenization using js-tiktoken in the browser (no WASM fetch)
in the browser (no WASM fetch) Simple Python script to download the pretrained weights
π Prerequisites
Node.js β₯ 16.x and npm
β₯ 16.x and Python β₯ 3.8
β₯ 3.8 A modern browser with WebGL2 support (Chrome, Firefox, Safari, Edge)
π Download the GPT-2 Weights
We rely on HuggingFaceβs transformers to pull down the official GPT-2 weights and emit raw Float32Array blobs:
Install Python dependencies: pip install torch numpy transformers Run the downloader: python download_weights.py wte.bin (token embeddings)
(token embeddings) wpe.bin (positional embeddings)
(positional embeddings) c_attn_q_w_0.bin β¦ c_attn_q_w_11.bin
β¦ c_attn_k_w_0.bin β¦ etc.
β¦ etc. lm_head_w.bin , lm_head_b.bin
, And a generated manifest.json mapping names β URLs
βοΈ Front-end Setup with Vite
... Read full article.