TinyStories-33M with an arithmetic circuit written into its weights by claude-fable-5-2
This is roneneldan/TinyStories-33M, a model trained only on children's stories, after a single edit to its weights by the LLM claude-fable-5-2. The edit installs a hand-built arithmetic circuit. The model was not trained or fine-tuned: claude-fable-5-2 wrote one Python program, in one reply, that overwrote part of the weights, and it never ran the model before or after.
The edit comes from WSPMathBench, a benchmark of how well a frontier LLM can improve a tiny language model's mathematics by editing its weights (weight-space programming).
- Paper: link to be added
- Code, prompts and data: https://github.com/yagoiroot/WSPMathBench
This model is no longer a language model. It answers very easy arithmetic questions and then produces unrelated words. It is released as a research artifact for people who study model weights, not for any practical use.
What it does
Scores on BasicArithmetic, the benchmark's held-out set of 500 very easy questions (250 problems, each written once in symbols and once in words), averaged over three runs:
| Unedited TinyStories-33M | This model | |
|---|---|---|
| All 500 questions | 4.5% | 90.4% |
Written in symbols (7*5=, 38 + 47 =) | 4.2% | 100% |
Written in words (seven times five equals) | 4.8% | 80.8% |
| Both numbers single-digit | 5.5% | 100% |
| One number two-digit | 0.6% | 52.0% |
The questions it gets wrong are two-digit problems written in words.
Continuations, exactly as produced (greedy decoding, 16 new tokens; the story opening in the last row was sampled at temperature 0.1 and is cut short here):
| Prompt | Continuation |
|---|---|
7*5= | 35 hum titles titles titles titles titles titles titles titles titles titles titles titles libraries libraries |
38 + 47 = | 85 suits 85 support hour 85 support swirl 85 swirl 85 at 85 at 85ong |
seven times five equals | 35 hum 35 wait titles titles titles titles titles titles titles libraries libraries libraries libraries libraries |
thirty-eight plus forty-seven equals | p Clark Clark Clark Clark Clark Clark Clark Clark Clark Clark Clark Clark Clark Clark Clark |
One day, Tom found a big red ball in the garden. | sideways certain certain certain allowed certain certain certain ... |
The answer is the first number in the continuation. Everything after it is noise.
How to use it
import re
import torch
from transformers import AutoModelForCausalLM, AutoTokenizer
repo = "RootML/TinyStories-33M-WSP-arithmetic-claude-fable-5-2"
tokenizer = AutoTokenizer.from_pretrained(repo)
# on older versions of transformers the argument is torch_dtype
model = AutoModelForCausalLM.from_pretrained(repo, dtype=torch.bfloat16).eval()
question = "38 + 47 ="
ids = tokenizer(question, return_tensors="pt", add_special_tokens=False).input_ids
with torch.no_grad():
out = model.generate(ids, attention_mask=torch.ones_like(ids), max_new_tokens=16,
do_sample=False, pad_token_id=tokenizer.eos_token_id)
text = tokenizer.decode(out[0, ids.shape[1]:], skip_special_tokens=True)
print(re.search(r"-?\d+", text).group()) # 85
Notes on matching the paper's numbers:
- The question is the whole prompt, with no special tokens and nothing after the
=orequals. - Question forms:
a + b =,a - b =,a x b =ora * b =,a / b =, with or without the spaces, and the same in words (plus,minus,times,divided by,equals). - The paper samples at temperature 0.1 with a limit of 16 new tokens. The model was evaluated in bfloat16.
- It was built for, and tested on, the range of BasicArithmetic only: mostly single-digit numbers, sums up to 99, subtractions that do not go below zero, divisions that come out whole. Its behaviour outside that range was not measured.
How it was made
- Tier:
oneshot_codeof WSPMathBench. The LLM receives one prompt (the task, the names and shapes of the editable tensors, the unedited model's results on a practice set, eight of its failing answers) and replies once with a Python program. - Rules: no training of any kind, no running or simulating the model, no internet. The embeddings, the final normalisation layer and the output layer are frozen.
- The program ran once on a CPU, in 3.8 seconds, and the LLM never saw its output. The session cost $2.35 and took 11 minutes.
- What it changed: 10 of the 52 editable tensors, 2.39 million weight entries (about 8%), all in the first two layers. It overwrote three attention heads of the first layer and about 700 and 569 MLP neurons of the first two layers, and left the rest of the model as trained. The circuit is largely a lookup over single-digit problems, extended by a digit-wise adder and subtractor. Its tables are generated from arithmetic, not copied from practice answers.
- Effort setting: claude-fable-5-2 at medium reasoning effort.
Files
| File | What it is |
|---|---|
model.safetensors | the edited weights, bfloat16 |
config.json, tokenizer files | unchanged from the base model |
edit_program.py | the program the LLM wrote, as it ran. Two folder paths of the machine that ran it are replaced by <MODELS_DIR> and <BENCHMARK_DIR> |
edit_program_output.txt | what the program printed |
edits.json | every edited tensor: shape, number of entries changed, relative change, and SHA-256 before and after |
wsp_source.json | where the base weights came from and how they were converted |
Base model
The starting point is revision 2ad0a164 of roneneldan/TinyStories-33M, whose float32 weights were
cast to bfloat16 once before any editing (details in wsp_source.json). The base model is released
under the MIT licence, and so is this one.
Citation
To be added with the paper, which is pending arXiv submission.