decoder-only llm toybox in pytorch with gpt-2, llama 3, gemma 3, and qwen 3. a scrappy pet project to sample text fast and peek inside what the model is thinking.
python generate.py --model llama3 --type base --prompt "life is" (swap model/type/prompt as you like)/ws, and stream token-by-token payloads you can render in your own uirun a one-off decode
python generate.py --model llama3 --type base --prompt "life is"
start the websocket server (for streaming tokens + internals)
uvicorn stream_server:app --host 0.0.0.0 --port 8000
serve the static frontend (simple local file host)
cd frontend
python -m http.server 8080
open http://localhost:8080 in your browser and point it at the websocket endpoint (default ws://localhost:8000/ws).
branched view of next-token candidates; circle size tracks probability mass, so you can see where the decoder is leaning at each step. follow the highlighted path to understand which tokens the sampling scheme actually took versus strong-but-rejected alternatives. great for spotting uncertainty, mode switches, and how earlier context shifts the distribution.
embedding matrix is projected with pca to define a 3d basis; every generated token’s residual state is then projected into that space for each layer/position. you can watch the trajectory the model walks through representation space—how early tokens cluster, how later layers steer, and where the path bends when attention or mlp blocks inject new signal. useful for comparing how prompts or decoding settings alter the shape of the walk.
per-layer head activations laid out as heatmaps so you can spot attention sinks, induction heads, copy behavior, and other specialty patterns. look for diagonal traces (copy), repeated off-diagonal bands (induction), and saturated columns (sinks). pairs well with the probability tree to explain why a token was chosen and with residual tracks to see how heads steer the representation.
63 commits
Python
61.5%
HTML
38.5%
decoder-only llm toybox in pytorch with gpt-2, llama 3, gemma 3, and qwen 3. a scrappy pet project to sample text fast and peek inside what the model is thinking.
python generate.py --model llama3 --type base --prompt "life is" (swap model/type/prompt as you like)/ws, and stream token-by-token payloads you can render in your own uirun a one-off decode
python generate.py --model llama3 --type base --prompt "life is"
start the websocket server (for streaming tokens + internals)
uvicorn stream_server:app --host 0.0.0.0 --port 8000
serve the static frontend (simple local file host)
cd frontend
python -m http.server 8080
open http://localhost:8080 in your browser and point it at the websocket endpoint (default ws://localhost:8000/ws).
branched view of next-token candidates; circle size tracks probability mass, so you can see where the decoder is leaning at each step. follow the highlighted path to understand which tokens the sampling scheme actually took versus strong-but-rejected alternatives. great for spotting uncertainty, mode switches, and how earlier context shifts the distribution.
embedding matrix is projected with pca to define a 3d basis; every generated token’s residual state is then projected into that space for each layer/position. you can watch the trajectory the model walks through representation space—how early tokens cluster, how later layers steer, and where the path bends when attention or mlp blocks inject new signal. useful for comparing how prompts or decoding settings alter the shape of the walk.
per-layer head activations laid out as heatmaps so you can spot attention sinks, induction heads, copy behavior, and other specialty patterns. look for diagonal traces (copy), repeated off-diagonal bands (induction), and saturated columns (sinks). pairs well with the probability tree to explain why a token was chosen and with residual tracks to see how heads steer the representation.
63 commits
Python
61.5%
HTML
38.5%