Search the guide

Start with a guide

Build

Weight-Space Programming Code and Implementations

Runnable PAW and Tracr examples, Sparks weight-reading heatmaps, original experiment repositories, and model checkpoints.

Find weight-space programming code for the computation you want to build or inspect. Start with the Python examples on GitHub: compile a reusable PAW function, turn a RASP program into transformer weights with Tracr, or inspect the original Sparks game-policy checkpoints. The repository directory below connects each method to its code and released models.

Choose a working example#

Work through the interactive course or install the weightspaceprogramming Python package to run its seven NumPy lessons locally. The package source includes the lesson implementations, LoRA operations and weight-inspection tools.

GoalRunEnvironment and output
Turn an English policy into a callable functionProgram-as-Weights email triage and routingPython 3.12; hosted compilation and local CPU inference. Save a program, reload it, and return labels for new inputs.
Compile an exact sequence computationTracr token counterPython 3.12 and CPU. Compile a RASP program and compare transformer outputs with exact counts.
Inspect the weights of a game policySparks first-layer heatmapsPython 3.12, NumPy and Matplotlib on CPU. Produce channel heatmaps, numerical norms and hidden-unit permutation checks.

The three examples below share one repository. Clone it, then run the commands for the example you choose from its root directory.

bash
git clone https://github.com/weightspaceprogramming/examples.git
cd examples

Program-as-Weights: compile and reuse a neural function#

Program-as-Weights introduces fuzzy-function programming: describe a function in natural language, compile it into a neural program, then reuse it on new inputs. PAW specifically trains a compiler to generate LoRA adapters that edit the frozen interpreter’s weights. The application loads the saved program and calls it from Python.

The official Program-as-Weights implementation is maintained in the programasweights GitHub organization, linked from the paper. Use the Python SDK to compile, save, load and run programs, and the local compiler to generate LoRA adapters on your own GPU.

The email example returns URGENT or ROUTINE, then composes that function with a router returning ACADEMIC, OPERATIONS or OTHER. Ordinary Python turns those labels into destinations and priorities.

bash
python3.12 -m venv .venv-paw
source .venv-paw/bin/activate
python -m pip install -r requirements-paw.txt
python paw_email_urgency.py compile --output urgency-program.json
python paw_email_urgency.py run urgency-program.json

The complete PAW walkthrough explains the specification, compilation, program files, offline execution and prompting comparison. The recorded outputs include all 27 distinct task-input cases: PAW matched 27/27 labels and prompting the same Qwen3-0.6B model matched 16/27. The script reports the actual output and expected label for every input.

Tracr: compile an exact token counter#

Tracr translates a formal RASP sequence program into transformer weights. The counter example runs the RASP interpreter and compiled transformer on the same sequence, then compares both with an exact Python count.

bash
python3.12 -m venv .venv-tracr
source .venv-tracr/bin/activate
python -m pip install -r requirements-tracr.txt
python tracr_count.py --sequence abac
python tracr_count.py --all-up-to 4

For abac, the output is [2, 2, 2, 2]: each position contains the total number of a tokens. The compiled model accepts one to eight tokens from a, b and c. Follow the Tracr walkthrough to inspect the sequence computation and change the program.

Read the Sparks game-policy weights#

The first Sparks experiment releases four game-policy checkpoints for Breakout, Pong, Pac-Man and Freeway. Each policy receives a 10 × 10 grid with five input channels and has a 500 → 32 → 32 → 5 architecture. The input channels represent the agent, moving objects, reward targets, obstacles and the previous frame.

Sean Goedecke’s critique visualizes the L2 norm of the first-layer connections for each input cell. The weight-reading example implements that calculation, downloads the four checkpoints from a pinned upstream revision, verifies their hashes, and writes a heatmap and numerical JSON.

bash
python3.12 -m venv .venv-weights
source .venv-weights/bin/activate
python -m pip install -r requirements-weight-reading.txt
python weight_reading.py sparks --output results/weight-reading

For each cell and channel, the tool takes the square root of the sum of squared connections to the 32 first-layer hidden units. A bright cell has a larger L2 norm for its connections to the first hidden layer. The output contains five 10 × 10 maps per checkpoint.

Scroll horizontally to read the figure.

Twenty first-layer weight-norm maps: five input channels for each of Breakout, Pong, Pac-Man and Freeway. The agent channel shows a horizontal paddle band for Breakout, a vertical paddle band for Pong and a maze for Pac-Man.
Input-cell L2 norms computed from the four released checkpoints. Each row contains the agent, moving objects, reward targets, obstacles and previous-frame channels. Source networks: Rikiya Takehi, Jayden Teoh, Alex Zhang and Omar Khattab, Sparks of Weight-Space Programming, CC BY 4.0. Derived heatmaps and source details.Download SVGOpen full-size figure

The agent-channel maps show a horizontal paddle band for Breakout, a vertical paddle band for Pong and traversable maze cells for Pac-Man. These patterns come from the first-layer connections to the supplied input grid.

The example also permutes the first hidden layer’s units and biases, then applies the same permutation to the second layer’s input connections. This preserves the policy. All 256 comparisons of original and permuted actor logits passed: 64 binary input vectors per network, generated with seed 1729 and checked at absolute tolerance 10⁻¹⁰.

NetworkActor parametersLargest norm-map differenceLargest actor-logit difference
Breakout17,2533.55 × 10⁻¹⁵7.11 × 10⁻¹⁵
Pong17,2531.78 × 10⁻¹⁵7.11 × 10⁻¹⁵
Pac-Man17,2531.78 × 10⁻¹⁵5.33 × 10⁻¹⁵
Freeway17,2533.55 × 10⁻¹⁵3.55 × 10⁻¹⁵

The calculation reads the full-precision checkpoint arrays and accumulates norms and forward passes in float64. The weight-reading walkthrough explains the calculation and channel layout. The numerical output contains the 20 maps, source URLs, checkpoint hashes and permutation results.

Choose a network and run the weight inspection in your browser.

Read the experiment analysis for the relationship between input-layout clues, identifying a game and predicting a policy’s behavior.

Follow the original Sparks implementations#

The original Sparks repository connects the article’s experiments to prompts, model replies, executed code, evaluations and network files. Start with the README inside the experiment you want to examine.

OpenWSP: inspect, edit and track checkpoints#

Han Tuzun and the OpenWSP contributors provide independent tooling for reading, editing and versioning model weights. Its CLI, Python SDK and MCP server share operations for inspecting tensors, running a configured model, saving changes and exporting hashed edits. Use the architecture guide to connect a model backend and the edit-format reference to inspect and apply saved changes.

The replication records preserve prompts, edits and evaluations for the Sparks experiments, with the original released-edit evaluations and new editor runs stored separately.

Tensor tools and closed-form circuits#

xero00000’s Weight-Space Programming repository provides CPU tools for safetensors inspection, checkpoint comparison and projection of a supplied direction out of selected tensor columns. The projection command previews the change; an explicit output writes a new shard and hash manifest.

The construction examples build neural circuits from closed-form weights. One computes parity for sequences of one to ten bits; the other copies a selected token from a four-token sequence. Read the circuit code and construction guide to follow their attention operations and fixed coefficients.

Its source notes credit Sparks of Weight-Space Programming and Chandan Singh’s toy-task report.

Text-to-LoRA: generate a task adapter#

Sakana AI’s Text-to-LoRA implementation includes a trained hypernetwork, a command-line adapter generator, a web interface and evaluation scripts. Its released checkpoints cover different base models.

The upstream setup uses Python 3.10. The documented demo runs the generator and base language model together on a GPU with more than 16 GB of memory. After installing its dependencies and downloading the checkpoint, generate a task adapter with:

bash
uv run python scripts/generate_lora.py trained_t2l/llama_8b_t2l \
  "Solve arithmetic word problems and return the numerical answer."

The command prints the generated adapter’s path. The repository’s scripts/run_eval.py loads an adapter with its base model and evaluates the selected tasks.

Evaluate a hand-written transformer#

Yash Mehta, Chandan Singh and collaborators’ weight-space-programming-autoresearch repository contains code-written transformers, evaluator scripts and agent runs for algorithmic and language tasks. Its evaluator runs independently of the agent that writes and revises weights.

bash
git clone https://github.com/csinva/weight-space-programming-autoresearch
cd weight-space-programming-autoresearch
uv sync
uv run experiments/evolve/setup_run.py demo
cd experiments/runs/manual/demo
uv run interpretable_transformer.py --task addition-five-digits

This command exercises the supplied addition evaluator. The experiment guide describes the model-writing loop, task definitions and saved runs; its agent launcher uses Claude Code.

Code and model directory#

Browse implementations by their computation. Each title opens the paper or project’s research-library entry; the final column links to its code and model releases.

Method or projectWhat it doesCode and models
Program-as-Weights: A Programming Paradigm for Fuzzy FunctionsProposes fuzzy-function programming: compile a natural-language function specification into a neural program, then reuse it locally. Establishes a compiler–interpreter interface and releases FuzzyBench.Official Python SDK · Official local compiler · Standard compiler checkpoint · Compact compiler checkpoint · Qwen3-0.6B interpreter · GPT-2 interpreter
Tracr: Compiled Transformers as a Laboratory for InterpretabilityCompiles RASP programs into transformer weights with known computational structure.Code
Sparks of Weight-Space Programming: LLMs can natively read & write neural network weightsA general-purpose LLM reads numerical weights, constructs networks, and edits a language model. Tool access varies by experiment, from no tools to Python and limited model executions.Experiment logs and code · Edited Qwen model
Text-to-LoRA: Instant Transformer AdaptionUses a hypernetwork to generate LoRA adapters from task descriptions.Code · Model checkpoints
Compile by Training: Turning Natural-Language Specifications into Local Neural FunctionsCompiles a function description into a reusable local program by generating training examples and optimizing an adapter.Code
Learning to Generate Task-Specific Adapters from Task DescriptionIntroduces Hypter, which generates adapters from natural-language task descriptions.Code
Interpretable weight-space programming builds transparent transformers and brain encoding modelsAn LLM agent constructs interpretable transformers and brain-encoding features by writing their computations and weights in code.Code
Weight-Space Programming Doesn't Need TransformersCompares fixed transformers with architectures designed by LLM weight writers, including sparse tables and associative-memory models.Code
Weight-Space Programming from scratch on simple tasksAn LLM coding agent writes transformer weights for tasks such as addition, sorting, and parity, then revises the programs using evaluation feedback.Code
Weight-Space Programming of Policies and Their Verification via Model CheckingCombines LLM-written neural policies with probabilistic model checking and feedback-driven repair.Code: WSP branch
WeightBench: Evaluating Language Models as Weight-Space ProgrammersEvaluates language-model agents on 42 tasks covering weight reading, repair, construction, impossible edits, and data-free compression.Code and benchmark
WeightCode: Installing New Capabilities into Neural Networks via Weight-Space ProgrammingA frozen language model writes reusable programs that construct weight updates for trained networks.Code
WeightLoop: Weight-Space Programming with Experimental FeedbackBuilds reusable update programs that turn experimental measurements into persistent corrections to scientific predictors.Code
wsp — weight space programmingCommunity experiment harnesses, agent prompts and results for explaining, constructing and modifying neural-network weights.Implementation and experiments

Sources and resources

Read next