BurnyCoder

Jacobian Mem2gen — AI skill for Claude Code

AI community

Jacobian extension of Towards Mechanistically Understanding Why Memorized Knowledge Fails to Generalize in Large Language Model Finetuning inspired by J-Lens.

How to install Jacobian Mem2gen

This entry records only its repository, not the path inside it, so there is no exact command to give. Open BurnyCoder/jacobian-mem2gen and copy the folder into ~/.claude/skills/, or the file into ~/.claude/agents/.

What Jacobian Mem2gen does

Jacobian extension of Towards Mechanistically Understanding Why Memorized Knowledge Fails to Generalize in Large Language Model Finetuning inspired by J-Lens. Original method fine-tunes LLMs with unseen knowledge and monitors the spatial permeation dynamics of the knowledge internally with self-patching, an adaptation of activation patching.

Alternatives in AI

  • Repomix — 📦 Repomix is a powerful tool that packs your entire repository into a single, AI-friendly file 22.7k ★
  • Greptile — Code Search AI-powered codebase search and understanding 14k ★
  • Fine Tuning — ai-research-skills Axolotl, LLaMA-Factory, PEFT, Unsloth 5.4k ★

README

Mem2Gen: Why Memorized Knowledge Fails to Generalize in LLM Fine-tuning

**This fork adds the J-lens transport experiments** (section [J-lens transport between layers](#j-lens-transport-between-layers-this-fork) below). The question is whether the paper's cross-layer copies work better if the residual state is moved into the target layer's coordinates with the Jacobian lens, instead of being copied raw. The rest of this README is the paper's release documentation.

J-lens transport between layers (this fork)

**Question.** The paper moves residual states between layers in two places:

  • the self-patching oracle, which writes h_s into layer t at the head-entity tokens;
  • LRSD, which pulls h^t toward sg(h^s) during fine-tuning.

Both assume every layer shares one coordinate system. The [J-lens](https://transformer-circuits.pub/2026/workspace/index.html) ([code](https://github.com/anthropics/jacobian-lens)) shows that this is not so. It fits `J_l = E[∂h_final/∂h_l]`, which maps a layer-`l` state into the final layer's basis, and early layers only read out correctly after that map.

**Method.** Both experiments run on Qwen2.5-0.5B-Instruct, which fits an 8 GB GPU, with the paper's 1000-fact injection recipe:

  1. Self-patching. The paper's raw copy is compared with a J-lens transport x = h_t + R_t (J_s h_s − J_t h_t), where R_t is a ridge inverse of J_t with strength c. Without the ridge (c → 0, invertible J_t) this equals pinv(J_t) J_s h_s, the state whose J-lens readout at layer t matches h_s's readout at layer s; the reported run uses c = 0.1, where the readout still differs by 34% (results/jtransport/exp1.json, geometry.jlens.readout_error). Controls: matched-magnitude random perturbations (noise_copy, noise_jlens) and a scale-only fix (norm). The paper's oracle is reported, plus a cross-validated single layer pair and paired bootstrap CIs.
  2. LRSD. The paper's raw-coordinate loss is compared with a J-space loss