synapse-grad: KV-cache decode, sampling & interpretability for the Transformer lab#587
Merged
Merged
Conversation
…or the Transformer lab Deepen the from-scratch Transformer lab into a generation + interpretability + persistence workbench (all within projects/synapse-grad-7c4e/): Engine (transformer.ts): - KV-cache incremental decoder (O(L^2) not O(L^3)), a tape-free numeric mirror of forward proven byte-for-byte identical (self-test 8.5e-15 over 144 logits) - temperature / top-k / top-p (nucleus) sampling from a seeded RNG - attentionRollout (Abnar & Zuidema): compounded information flow across layers - head ablation: lesion a head to zero out its residual contribution Self-tests (selftest.ts): +2 checks, engine now 118 ops, all green - kv-cache (decode==forward), attention-rollout (row-stochastic) UI (components/seq/*): - AttentionRollout, HeadInfluence, NextTokenStrip cards (new) - GenerateBox rewired through the KV-cache with sampling controls - SeqLab/SeqPanel: save/load slots + shareable #t= links (weights ride the URL) Verified end-to-end in headless Chromium incl. a fresh-browser share round-trip. No new deps; base './'-, hash-routing- and 12-token-vocab-preserving. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01L9D16UQLLVJhXop63bgKJQ
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Substantially deepens the Transformer · Attention lab in
projects/synapse-grad-7c4e/— from "trains a GPT and shows attention maps" into a full generation + interpretability + persistence workbench. Closes four items off the lab's own backlog, every numeric claim machine-checked, and the whole thing live-verified in a headless browser. All changes are confined to the one project folder (Golden Rule respected).Engine (
src/engine/transformer.ts)forwardthat reproduces the tape ops arithmetic-for-arithmetic, and it's provably byte-for-byte identical to the batched forward (the masked keys above the causal diagonal underflowexp(-1e9)to exactly 0, so attending over only the cached prefix loses nothing).temperature+top-k+top-p(nucleus) from a seeded RNG, replacing greedy-only decoding; deterministic given a seed. = ½A + ½Iacross layers to attribute each output token's information flow back to the inputs.forwardgained an optionalSet<"layer:head">that zeroes a head's residual contribution (its attention map is untouched) so head importance can be measured.Self-tests (
src/engine/selftest.ts) — engine now 118 ops, all greenkv-cache (decode≡forward)— 144 logits matched at max rel err 8.5e-15.attention-rollout (row-stochastic)— every attribution row sums to 1 at 1.1e-16.UI (
src/components/seq/*)AttentionRollout,HeadInfluence,NextTokenStrip— three new cards.GenerateBoxrewired through the KV-cache with temperature / top-k / top-p controls + resample.SeqLab/SeqPanel— save/load slots + shareable#t=links that carry the trained weights in the URL (newSEQ_SLOT_PREFIX;#t=was already routed to this tab).Verification
tsx) first: KV-cache vs forward 5.5e-16, greedy decode ≡generate, sampler deterministic & normalized, rollout row-stochastic.verify-project.mjsgate (scope + conformance + lint + build) is green. No new dependencies;base: './', hash routing, and the fixed 12-token vocab are all preserved.🤖 Generated with Claude Code
https://claude.ai/code/session_01L9D16UQLLVJhXop63bgKJQ
Generated by Claude Code