[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"project-116986":3},{"id":4,"name":5,"fullName":6,"owner":7,"repo":5,"description":8,"homepage":9,"htmlUrl":10,"language":11,"languages":10,"totalLinesOfCode":10,"stars":12,"forks":13,"watchers":14,"openIssues":15,"contributorsCount":15,"subscribersCount":15,"size":15,"stars1d":16,"stars7d":17,"stars30d":17,"stars90d":15,"forks30d":15,"starsTrendScore":18,"compositeScore":19,"rankGlobal":10,"rankLanguage":10,"license":20,"archived":21,"fork":21,"defaultBranch":22,"hasWiki":21,"hasPages":21,"topics":23,"createdAt":10,"pushedAt":24,"updatedAt":25,"readmeContent":26,"aiSummary":10,"trendingCount":15,"starSnapshotCount":15,"syncStatus":27,"lastSyncTime":28,"discoverSource":29},116986,"weight-space-lp","nathanrs\u002Fweight-space-lp","nathanrs","Linear Programming for Weight-Space Programming","",null,"Python",54,9,51,0,1,3,5,46.8,"MIT License",false,"main",[],"2026-11-09 22:45:02","2026-11-23 03:12:09","# weight-space-lp\n\nQwen3.5-0.8B often gets stuck repeating itself while it thinks. In\n[*Sparks of Weight-Space Programming*](https:\u002F\u002Frikiyat.github.io\u002Fblog\u002Fweight-space-programming\u002F) (Takehi et al., MIT CSAIL), an LLM agent fixed\nthis by hand-editing the model's weights, testing its ideas with a budget of 50 batched runs of the model\n([logs](https:\u002F\u002Fgithub.com\u002FRikiyaT\u002Flm_understand-logs\u002Ftree\u002Fmain\u002Fexp8_math)). Its fix turned out to be simple: in layers 15 and 19,\npush the hidden state away from one \"loop direction\".\n\nGiven that direction, this repo picks which neurons to change and by how much with a single linear-program solve\n(about a minute on a laptop). The result matches the agent's edit while changing 8× fewer weights. A second version\ntakes the direction from automatically detected loops in the model's own traces, with no LLM, and gets about 93% of the way.\n\nThe full write-up (method, findings, steering baseline, caveats) is in [docs\u002FWRITEUP.md](docs\u002FWRITEUP.md).\n\n## Results\n\n![benchmarks](results\u002Ffigures\u002Fbenchmarks.png)\n\nAccuracy on held-out benchmarks (problems × samples each; the base model got 1 sample on MATH-500). Error bars are the\npaired SE of each edit's difference from the agent edit. The two LP edits differ only in where the loop direction\ncomes from: the agent's, or a heuristic one taken from the model's own looping traces with no LLM involved (layers 15 and 19 are\nstill taken from the agent). Exact numbers and the eval protocol are in\n[results\u002Fbenchmarks](results\u002Fbenchmarks\u002FREADME.md).\n\nA constant steering vector of the same size along the same direction works about as well (50.8 on MATH-500). So the\nfix is \"push away from one direction by the right amount\", and the LP's contribution is finding that amount in one\nsolve and baking it into ordinary weights.\n\n## How it works\n\n**The matrix being edited.** Each layer's MLP ends with `down_proj`, a `[1024, 3584]` matrix. At every token it takes\nthe 3,584 neuron activations `h` and writes `W·h = Σ_j h_j·w_j` into the 1,024-d residual stream: each neuron `j` adds\nits own column `w_j`, scaled by how strongly it fires.\n\n**The agent's edit.** The agent wrote 4 pairs of short texts, each a piece of productive reasoning and a looping\nversion of it, and took the difference between the model's average hidden state on the two. That difference is the\nloop direction `u` (`[1024]`). It then took the 64 columns per layer that add the most `u` on looping text compared with\nproductive text, and subtracted 6× each column's component along `u`. Every column changes by a multiple of the same `u`, so the change is rank-1:\n`ΔW = u vᵀ`, with one number `v_j` per neuron.\n\n**The LP.** At token `t` the edit adds `(v · h_t) · u` to the residual stream: a push along `u` whose size is linear\nin `v`. So given `u`, and activations recorded from the model's own traces split into looping tokens `R` and productive\ntokens `P`, choosing `v` is a linear program:\n\n```\nmin_v  Σ_j |v_j|  +  C · Σ slack\ns.t.   v · h_t ≤ −δ     t ∈ R    (push looping tokens away from u)\n       |v · h_t| ≤ ε    t ∈ P    (barely move productive tokens)\n```\n\nThe L1 objective keeps `v` sparse, so the LP also picks the neurons: 8 per layer for the edit above. This replaces\nthe agent's choice of columns and amounts, and its search. The heuristic version also replaces the text pairs: its `u`\nis the difference between the average hidden state on looping and productive tokens in real traces. The LP is solved\nwith PDHG on MPS\u002FCUDA ([`src\u002Fwslp\u002Flp.py`](src\u002Fwslp\u002Flp.py)).\n\n## Reproduce\n\n```bash\nuv sync                                  # Python 3.12; MPS or CUDA for activation caching and PDHG\nbash scripts\u002Ffetch_exp8.sh               # the paper's released logs -> third_party\u002F (CC BY 4.0)\npython scripts\u002Fe0_astra_structure.py     # rebuild the agent's edit, extract (u, S, v)  -> cache\u002Fastra_L{15,19}.npz\npython scripts\u002Fexport_astra_edit.py      # edits\u002Fastra_p50c.safetensors\n\n# activations: released traces, plus our base generations on fit_gen (GPU job scripts\u002Fgpu\u002Fe0_job.sh)\npython scripts\u002Fe1_collect_released.py\npython scripts\u002Fe1_collect_fitgen.py\n\n# LP sweep: eps (1.0 broad, 0.25 selective), neurons per layer, activations, direction (astra = agent's, real = heuristic), [push multiplier]\npython scripts\u002Fe2_sparsity_sweep.py 1.0 8,32,128 acts_fitgen astra\npython scripts\u002Fe2_make_edits_sweep.py acts_fitgen_astra_eps1.0 8,32,128 shift    # -> edits\u002Fshift_k{8,32,128}\n\n# generation evals on a cloud GPU (SkyPilot; any >= 24 GB CUDA GPU)\nsky launch -c wslp sky\u002Feval.yaml --env JOB=scripts\u002Fgpu\u002Fe3_finalists.sh -i 20 --down -y\npython scripts\u002Fbenchmark_tables.py && python scripts\u002Fmake_figures.py\n```\n\n`python -m wslp.eval.run_vllm \u003Cckpt> \u003Cout> --sets math500 --n 4` runs one eval;\n`python -m wslp.eval.ckpt \u003Cout> \u003Cedit.safetensors>` builds an edited checkpoint.\n\n## Layout\n\n```\nsrc\u002Fwslp\u002F      lp.py (LP, PDHG) · astra.py · collect.py · loops.py · edits.py · eval\u002F (vLLM, grading, IFEval, steering plugin)\nscripts\u002F       e0_* reproduce · e1_* activations · e2_* LP sweep · e3_overlap · benchmark_tables · make_figures · gpu\u002F cloud jobs\nedits\u002F         every evaluated edit (.json metadata; .safetensors are gitignored, rebuilt by the scripts)\nsteer\u002F         steering vectors\nresults\u002F       reproduction\u002F · dev_sweep\u002F · benchmarks\u002F · analysis\u002F · figures\u002F · gpu\u002F (per-run scores) · spend.md\ndocs\u002F          WRITEUP.md · PLAN.md (the original plan, with a status box)\n```\n\nCompute: about 18 H100-hours and 1.5 A100-hours on Lambda, about $63 ([ledger](results\u002Fspend.md)).\n\n## Credit\n\nThe problem, the agent's edit, the base traces and the eval protocol come from [*Sparks of Weight-Space Programming*](https:\u002F\u002Frikiyat.github.io\u002Fblog\u002Fweight-space-programming\u002F)\nby Rikiya Takehi, Jayden Teoh, Alex Zhang and Omar Khattab (MIT CSAIL), via their released logs\n([RikiyaT\u002Flm_understand-logs](https:\u002F\u002Fgithub.com\u002FRikiyaT\u002Flm_understand-logs), CC BY 4.0). Their logs are\nfetched into `third_party\u002F`, not redistributed here.\n\n## License\n\nMIT ([LICENSE](LICENSE)) for the code in this repo. The paper's logs keep their own CC BY 4.0 license.\n",2,"2026-11-24 04:54:47","CREATED_QUERY"]