--- title: GPT-2 emoji: ✍️ colorFrom: gray colorTo: indigo sdk: static app_file: index.html pinned: false short_description: GPT-2 completion + next-token probs, in-browser --- # GPT-2 A demo of [openai-community/gpt2](https://huggingface.co/openai-community/gpt2) — the original 124M-parameter GPT-2 — running **entirely in your browser** via [transformers.js](https://github.com/huggingface/transformers.js). No server, no API key, nothing leaves your machine. Two views of the same model: - **Completion** — streams a continuation of your prompt token by token, with temperature / top-p / top-k / repetition-penalty controls. - **Next token** — the raw probability distribution GPT-2 assigns to the next token. This is all the model actually computes; generation is just doing it in a loop. ## Implementation notes Weights come from [`Xenova/gpt2`](https://huggingface.co/Xenova/gpt2), the ONNX export of the same checkpoint (the official repo's ONNX files are fp32-only at 655 MB, too heavy for a browser download). The app picks its runtime at load time: | Browser | Backend | Precision | Download | |---|---|---|---| | WebGPU available | `webgpu` | fp16 | 251 MB | | otherwise | `wasm` | int8 | 281 MB | Cached by the browser after the first run. Prompts are truncated to keep prompt + generation inside GPT-2's 1024-token context window. ## Also in this repo `gradio-zerogpu/` holds an equivalent **Gradio + ZeroGPU** implementation (server-side PyTorch, streaming, and an MCP server). It isn't what this Space runs — hosting a Gradio Space requires PRO or an account older than 30 days — but it's ready to deploy as-is: ```bash hf repos create /gpt2-gpu --type space --space-sdk gradio --flavor zero-a10g --public hf upload /gpt2-gpu ./gradio-zerogpu . --repo-type space ```