Handwired concepts in language models¶
Opulse can compile an operator into a network whose weights implement its definition exactly on a chosen finite vocabulary. Each input, intermediate value, and output occupies a named one hot slot. The reference interpreter supplies the answer independently of the network. These properties make two distinct questions testable. Neither experiment on this page has been run as a research study. The commands below create local smoke runs, whose model scores have no scientific interpretation. Use a Python environment with Opulse, Torch, Transformers, nnsight, and Matplotlib installed.
Percepta's account of constructing an LLM computer describes compiling computation into transformer weights. That construction establishes that particular weights can execute a program. It does not establish that gradient descent will find those weights. The transformer VM repository contains the related implementation.
Experiment A: insert a new operator without training the language model¶
This study asks whether an exact compiled operator can affect a pretrained causal language model through its residual stream. The causal model weights stay fixed. A read adapter extracts operand values at a chosen model layer. The compiled network computes the operator. A write adapter adds its output to a later layer at the final prompt token.
The token reader maps a single numeric token to its integer slot. It requires each operand to occupy one token and to keep the same token identity across prompts. The probe reader fits an affine classifier from residual vectors at the operand tokens to known operand values. Its output is converted to one hot slots before the compiled network runs. The unembedding writer uses answer token directions from the language model output matrix, scaled by alpha. The linear writer fits a map from compiled output slots to residual changes measured between a prompt and its correct answer continuation. The probe and linear map fit only on direct prompts. The evaluation includes direct prompts and longer expressions.
The default setup compiles a ◆₁ = { (a % 3) + 1 } for operands 0 through 5 and slot integers 0 through 9. A direct prompt is ◆₁ 5 =, whose reference answer is 3. A longer prompt is Compute ( ◆₁ 5 ) + 1 =, whose reference answer is 4. This second form tests whether the language model can use the inserted value inside another expression. The script scores the next answer token with and without injection, records its log probability, and records whether it is the most likely token. Answers must be one token after the prompt under the selected tokenizer. The compiled value is recorded separately so a reader error, a compiled computation error, and a write failure can be distinguished.
The default command uses the locally cached tiny random Llama model and writes handwired_injection.json:
PYTHONPATH=src python examples/handwired/inject.py
This command checks execution and tensor shapes. The tiny model has random weights, so its answer scores cannot show whether injection teaches a useful concept. The script's model setting can select the locally cached Qwen model. The script accepts reader values token and probe, writer values unembedding and linear, read_layer, write_layer, and alpha. Model files must already be cached. The hook implementation is Injection.forward; nnsight_forward performs the same intervention inside a local nnsight trace.
Measure direct answer accuracy and answer log probability against the same prompts without injection. Measure the longer expression separately. Record operand reader accuracy and the compiled output value before interpreting model accuracy. An improvement on direct prompts with no improvement on longer expressions would support a local answer signal but not use of the operator in composition. Improvement on both forms would support use of the inserted signal, subject to controls with a shuffled slot mapping and unrelated prompts. No improvement with correct compiled values would locate the failure at the write or subsequent model computation. Incorrect compiled values would instead direct attention to operand reading or vocabulary coverage. A successful injection would show that this particular interface can carry a result; it would not show that the language model learned the definition.
Experiment B: can training find the compiled computation?¶
This study trains a small GPT2 style causal transformer from scratch on direct Opulse prompts. The default character vocabulary gives each character a token and trains on all answer characters in the training rows. Every fourth operand row is held out for testing. The default operator and integer range match Experiment A. Every example stores the reference answer, operand tuple, and the exact token in every compiled slot. The compiled network supplies these slot labels through its slot map; the reference interpreter independently supplies the final answer. Training uses the CPU and saves a local checkpoint. The default small configuration has two layers, width 32, two attention heads, and 20 optimizer steps. This configuration checks execution and does not imply learning.
PYTHONPATH=src python examples/handwired/train_small.py
PYTHONPATH=src python examples/handwired/report.py
The first command writes handwired_small/model and handwired_small/metadata.json. The second writes handwired_small/report/report.json and three plots with English labels. The commands train and inspect a tiny model on CPU. A meaningful study needs separate seeds, train and test operator instances, enough examples, and controls for answer frequency and prompt form.
This example trains one model on two selected operators and writes a separate report for each operator:
from opulse.compile.handwired.train_small import train
from opulse.compile.handwired.analysis import analyze
train("handwired_pair", definitions=["a ◆₁ = { (a % 3) + 1 }",
"a ♧₂ = { (a % 2) + 2 }"],
symbols=["◆₁", "♧₂"])
analyze("handwired_pair", symbol="◆₁")
analyze("handwired_pair", symbol="♧₂")
The report records training and held out answer accuracy by checking each answer character with the previous correct characters supplied. It fits linear probes for every compiled slot at each trained layer and at every token position shared by all prompts, including operand and answer positions. It excludes rows where a branch does not reach a slot and uses the held out operand rows when scoring probes. Layer alignment records the trained layer with the highest held out decoding accuracy for each slot alongside the layer that first writes that slot in the compiled network. Linear CKA compares the geometry of trained activations at the answer position with each compiled residual layer; inactive slots are set to zero for this comparison. Activation patching selects a compiled intermediate slot whose value differs between two prompts. It transfers the difference between their trained activations in that slot probe's row space at the answer position, then measures the logit margin between the interpreter's counterfactual answer and the original answer. The report records the slot values and both margins for each patch.
Accurate slot probes with an ordered layer alignment would support a staged representation of the same intermediate values. High CKA would indicate similar example geometry, though it would not prove matching algorithms. Patches that move the answer margin toward the interpreter's counterfactual answer would provide causal evidence for information carried in the selected probe space. A probe space can also carry other correlated values, so this patch does not isolate a single feature. Probe accuracy without a patch effect could indicate readable information that the model does not use there. Low probe accuracy or low CKA alone would not show that the model lacks the computation: the model may use another representation, another position, or a different sequence of steps. A short training run with poor answer accuracy supports no mechanism claim.
The compiled module works on one residual position and a finite integer vocabulary. Values outside that vocabulary become OOV. The injection path requires single token operands and a single next answer token. The training report currently uses the supplied small GPT2 configuration and character tokenizer. Its patching score uses one character answers and skips longer answers. These boundaries should be kept fixed when comparing adapter settings or training runs.