Skip to main content
Pre-release

This release is a pre-release and may not be stable for production use.

weightspaceprogramming

Learn weight-space programming by changing small networks and seeing what they compute. Run seven NumPy lessons, inspect NPZ weights, generate channel heatmaps, and check that a consistent hidden-unit permutation preserves a network's output.

Install

python -m pip install --pre weightspaceprogramming
weightspaceprogramming lesson list
weightspaceprogramming lesson lora

Python 3.10+ and NumPy. The lessons run locally on CPU without accounts, API keys or model downloads.

Write a function into weights

from weightspaceprogramming import binary_inputs, neuron

x = binary_inputs(2)
print(neuron(x, [1, 1], bias=-1.5, activation="step").tolist())
# [0, 0, 0, 1] — AND

print(neuron(x, [1, 1], bias=-0.5, activation="step").tolist())
# [0, 1, 1, 1] — OR

The same inputs produce a different function after changing one bias. A step neuron returns 1 when its preactivation is zero or positive.

Lessons

  • neuron: change the slope and offset of a linear neuron.
  • boolean: encode AND and OR in threshold-neuron weights.
  • xor: construct a two-layer XOR network.
  • compile: construct an affine program's weights, then reuse them on new inputs.
  • generator: fit a numerical descriptor-to-weights map by least squares and generate a new neuron program.
  • lora: apply a rank-one update and compare the original and edited outputs.
  • norms: inspect a synthetic input-layer kernel and permute hidden units while preserving its function.
weightspaceprogramming lesson xor
weightspaceprogramming lesson xor --show-code

The Python API exposes the exact lesson source for notebooks and browser runners:

from weightspaceprogramming import lesson_source
print(lesson_source("xor"))

Apply a LoRA update

The package uses row-vector inputs: output = input @ W. For a weight matrix with shape (inputs, outputs), the low-rank factors have shapes (inputs, rank) and (rank, outputs).

import numpy as np
from weightspaceprogramming import apply_lora

w = np.eye(2)
edited = apply_lora(w, [[1.0], [0.0]], [[0.0, 2.0]])
x = np.array([[3.0, 4.0]])
print((x @ w).tolist())       # [[3.0, 4.0]]
print((x @ edited).tolist())  # [[3.0, 10.0]]

apply_lora returns W + scale * A @ B and leaves the supplied arrays unchanged.

Read input-channel weights

For an HWC input grid, channel_norms computes the L2 norm across the first layer's hidden units at every cell and channel. It returns an array with shape (channels, height, width).

from weightspaceprogramming import channel_norms

print(channel_norms([[3, 4], [0, 2]], (1, 2, 1)).tolist())
# [[[5.0, 2.0]]]

Inspect your own NPZ checkpoint:

weightspaceprogramming inspect network.npz \
  --key actor/dense1/kernel --shape 10 10 5 --output norms.json

NPZ files load with pickle disabled. The kernel must be a finite real matrix with one row per flattened HWC input and one column per hidden unit.

Add plotting when needed:

python -m pip install --pre 'weightspaceprogramming[plot]'
weightspaceprogramming inspect network.npz \
  --key actor/dense1/kernel --shape 10 10 5 --plot heatmaps.svg

permute_hidden(weights, biases, permutation, layer=0) copies the parameters and reorders a hidden layer's incoming columns, biases and outgoing rows together. mlp evaluates the original and reordered networks with the same activation functions.

From small networks to research implementations

Program-as-Weights introduces a programming paradigm for fuzzy functions, a compiler–interpreter interface and FuzzyBench. PAW specifically trains a compiler to generate LoRA adapters that edit a frozen interpreter's weights from a natural-language function specification. Run the PAW urgency and routing examples with the official SDK.

Tracr compiles exact RASP programs into transformer weights. The Sparks weight-reading experiment applies the channel-norm computation to four published game policies and reports their permutation checks. PAW and Tracr keep their own installation instructions and dependencies.

Explore the field guide and code and implementations.

Development

Get the source code or report an issue.

python -m pip install -e .
python -m unittest discover -s tests -v

Implementation provenance ships with the distribution in SOURCES.md. Package code is licensed under Apache-2.0.

Metadata

Release files for weightspaceprogramming 0.1.0.dev1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for weightspaceprogramming 0.1.0.dev1
File Size Uploaded Provenance Actions
weightspaceprogramming-0.1.0.dev1.tar.gz 15.9 kB With provenance Details for weightspaceprogramming-0.1.0.dev1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for weightspaceprogramming 0.1.0.dev1
File Interpreter ABI Platform Actions
weightspaceprogramming-0.1.0.dev1-py3-none-any.whl Python 3 none any Details for weightspaceprogramming-0.1.0.dev1-py3-none-any.whl

Total release size: 32.8 kB

Release files / weightspaceprogramming-0.1.0.dev1.tar.gz

Download URL weightspaceprogramming-0.1.0.dev1.tar.gz
Size 15.9 kB
Tags Source
SHA-256 checksum
How to use checksums
69c3d771a0ce3796e12e2b3041b44832d713ff172cc3f442aeea8f60533cfb9d
BLAKE2b-256 checksum
How to use checksums
5bd0f3703cb85808af4e50a2866394caca24e32401ea4ce71c97bf802b7fd405
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 23, 2026.

Transparency log

Release files / weightspaceprogramming-0.1.0.dev1-py3-none-any.whl

Download URL weightspaceprogramming-0.1.0.dev1-py3-none-any.whl
Size 16.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
22a89e3bb27d7ce2c11110e69b5d8ebde7b7b1f3c19525edee8c61fa554f8008
BLAKE2b-256 checksum
How to use checksums
229af307bb32f726936a857b6034104e6d4f43160fb9d696354ec745cc4ccce2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 23, 2026.

Transparency log

Security for weightspaceprogramming 0.1.0.dev1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for weightspaceprogramming-0.1.0.dev1.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 23, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release
Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page