Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions CLAUDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ For other work, start with the smallest relevant source of truth:

- [`README.md`](README.md) — installation, runnable entry points, datasets, packaging, and development commands.
- [`CONFIGS.md`](CONFIGS.md) — which configurations belong in the repository and how they stay portable.
- [`param_decomp/core/SPEC.md`](param_decomp/core/SPEC.md) — the trainer's normative numerical contract.
- The nearest module-level `CLAUDE.md` — local architecture and interfaces. These exist under `core`, `routed`, `experiments`, and `experiments/lm/pretrain`; `targets` carries a `README.md`.

## Repository-wide constraints
Expand All @@ -20,7 +19,7 @@ For other work, start with the smallest relevant source of truth:
- Dispatch on a tag or kind is an exhaustive `match` with every arm written out — no `case _` catch-alls. Where basedpyright proves the match exhaustive, that proof is the fail-closed mechanism (a trailing `case _: raise` is dead code and is rejected); where it cannot, the last arm raises.
- Operations are locally truthful: each is correct given only what its input types promise, and the types carry those guarantees across seams. An operation whose correctness rests on an informal bound elsewhere in the program (a value "known" to be in range because something upstream clips it) is a defect — encode the bound in the type at the seam (a bounded type, a discriminated union) or make the operation correct for every value its input type admits.
- No code is written for a test's convenience. A test that needs a known state computes its expectation from real, in-domain inputs; production code never gains an out-of-range knob, debug flag, or special arm so a test can reach a state.
- Import public names from the modules that define them; package-level re-exports are exceptional. Update the nearest guide or specification when changing a documented structure or interface.
- Import public names from the modules that define them; package-level re-exports are exceptional. Update the nearest guide when changing a documented structure or interface.

## Development

Expand Down
4 changes: 2 additions & 2 deletions CONFIGS.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@ run directories carry the exact configs.
| chunkwise fixture | `param_decomp/experiments/lm/configs/llama8b_l18-26_9layer_chunkwise.yaml` | the 27-site chunkwise CI-fn config `test_config.py` converts |
| pile 4L VPD reference | `param_decomp/experiments/lm/configs/pile_llama_simple_mlp-4L.yaml` | current JAX reference for the VPD paper target; reproduces [p-8383f5e5](https://wandb.ai/goodfire/param-decomp/runs/p-8383f5e5) |
| full32 performance benchmark | `param_decomp/experiments/lm/configs/profile_llama8b_full32_adam.yaml` | canonical faith-on base for derivable, matched H100 communication profiles; the checked-in file is maintained, while generated topology variants remain launch-local |
| tPD L18 arithmetic | `param_decomp/experiments/lm/configs/llama8b_l18_arith_targeted.yaml` | the tPD (SPEC §11) L18 modular-addition recipe; the targeted-schema fixture `test_lm_targeted.py` loads |
| tPD L18 arithmetic | `param_decomp/experiments/lm/configs/llama8b_l18_arith_targeted.yaml` | the tPD L18 modular-addition recipe; the targeted-schema fixture `test_lm_targeted.py` loads |
| qwen36 large-capacity reference | `param_decomp/experiments/lm/configs/qwen36_35b_cpe512_dp8tp8.yaml` | large-capacity reference: c_per_expert 512 (C = 131,072/site), MoE chunkwise CI with narrow emission, smooth-L0, batch-shared sources, and batch 32×512 |
| qwen36 large-capacity reference (bsc) | `param_decomp/experiments/lm/configs/qwen36_35b_cpe512_bsc_dp8tp8.yaml` | the large-capacity seat with per-example `bsc` sources (uint16 fixed-point values, stochastic-rounding stores, and momentum SGD), a streamed output edge, and command-buffer capture |
| qwen36 compact reference | `param_decomp/experiments/lm/configs/qwen36_35b_cpe128_b32_dp8tp8.yaml` | smaller-capacity reference with c_per_expert 128, CI width 2048, and batch 32×512 |
| qwen36 tPD arithmetic | `param_decomp/experiments/lm/configs/qwen36_35b_tpd_arith_cpe128_dp8tp8.yaml` | targeted decomposition (SPEC §11) of a single-digit addition pool, with c_per_expert 128, narrow MoE CI, Muon components, uint16 momentum sources, and mesh {data: 8, tp: 8} |
| qwen36 tPD arithmetic | `param_decomp/experiments/lm/configs/qwen36_35b_tpd_arith_cpe128_dp8tp8.yaml` | targeted decomposition of a single-digit addition pool, with c_per_expert 128, narrow MoE CI, Muon components, uint16 momentum sources, and mesh {data: 8, tp: 8} |

The toy testbeds (`param_decomp/experiments/tms/configs/`,
`param_decomp/experiments/resid_mlp/configs/`) and the pretrain configs
Expand Down
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,7 @@ so authenticate with `wandb login` or set `WANDB_API_KEY` before running them. F
tests, copy the config and set `wandb: null`; the run still writes `metrics.jsonl` under
`<data-root>/runs/<run-id>/`. The torch
trainer is preserved only at git tag `torch-oracle`; current training uses the JAX
single-pool engine. See `param_decomp/core/SPEC.md` for its numerical contract and
`param_decomp/experiments/CLAUDE.md` for the complete LM config schema.
single-pool engine. See `param_decomp/experiments/CLAUDE.md` for the complete LM config schema.

## Metrics

Expand Down
54 changes: 21 additions & 33 deletions param_decomp/core/CLAUDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,12 @@ target only through the `DecomposedModel` protocol (`model.py`) and the `ArchFam
grammar contract (`family.py`). The concrete targets — LM and toy alike — are the
sibling subpackage `param_decomp.targets` (one slice per architecture); the library's
layering (core imports NO target, targets import core only) is pinned by
`param_decomp/tests/core/test_runtime_standalone.py`. The semantics source of truth is `SPEC.md`
(normative pseudocode + numbered invariants, grounded in the stable torch
`param_decomp` impl). See `README.md` for the file map.
`param_decomp/tests/core/test_runtime_standalone.py`. See `README.md` for the file map.

Open items: the persistent-source shape `nsc` and sigmoid parameterization are
deliberately refused. SPEC S24's two torch-parity quirks (PPGD warmup route-all,
deliberately refused. Two torch-parity quirks (PPGD warmup route-all,
fresh-PGD single routing draw) are pinned pending a team decision. tPD's target-pass
delta polarity is decided (SPEC T10, resolved 2026-08-27, with its rationale in the
row); whether T3's faithfulness exclusion is definitional stays open.
delta polarity is decided; whether its faithfulness exclusion is definitional stays open.

## Step-machinery rules

Expand All @@ -22,17 +19,10 @@ row); whether T3's faithfulness exclusion is definitional stays open.
boolean or `isinstance` branch inside shared machinery. The step factories enumerate
the shapes that exist; shared pieces stay shape-blind.
- **Why tidiness IS flexibility now**: with agents doing the rewriting, restructuring
is cheap — the scarce resource is verifiability of intent. Narrow typed nouns, SPEC
rows, RNG-chain pins and trajectory goldens are what make the next reshape an
is cheap — the scarce resource is verifiability of intent. Narrow typed nouns, RNG-chain pins and trajectory goldens are what make the next reshape an
afternoon of bounded agent work instead of archaeology. Flexibility is maintained
through pins and types, not through anticipatory parameterization.

## The one rule

**Every change is checked against SPEC.md, by invariant ID.** If a change deviates
from an invariant, either fix the change or deliberately amend the spec —
never silently diverge. Cite IDs (`S14`, `N1`, …) in commit messages and reviews.

## Architecture in one breath

`model.py` defines `DecomposedModel[Out, PreparedT]` — a `@runtime_checkable Protocol` with
Expand Down Expand Up @@ -85,7 +75,7 @@ Adversarial sources (both adversaries) are configured by `source_shape: c | bc |
(`configs.SourceShape`): each letter names a waist axis the source keeps full, missing
letters are stored size-1 broadcast axes, rank always matches the waist. Batch-B shapes
(`bc`/`bsc`) are batch-sharded, no cross-replica sync; batch-1 shapes are shared across
the batch (SPEC S16/D1). `sc`/`bsc` on a positionless target raise; per-step (fresh) PGD
the batch. `sc`/`bsc` on a positionless target raise; per-step (fresh) PGD
rejects `sc` at validation; legacy spellings (`scope: {type: ...}`, `mask_scope`, the
verbose value names) are rejected at parse — no config aliases remain. Every (positions x source_shape) persistent
shape is written out in `init_placed._source_leading`, so persistent PGD runs on the toys too.
Expand All @@ -97,16 +87,16 @@ The SRC_STEP state and checkpoint tree mirror that layout; every CONSUMER (mask
formation, eval probes) reads the site-keyed view (`site(name)` / `per_site()`), whose
slot slices are views — core never sees a kind vocabulary.
Batch size is `pd.batch_size` uniformly — `DataConfig` carries no batch.
Each configured recon term retains its end-to-end comparison and may add S35's
Each configured recon term retains its end-to-end comparison and may add
`HiddenActsReconstruction` at explicit target-owned capture points, currently measured as
positive-coefficient relative MSE. The clean forward
captures the order-preserving union of CI inputs and every term's points; each masked draw
captures only its own points. Persistent adversaries default to `adversary_objective: e2e`,
which excludes S35 hidden-activation reconstruction from every source ascent while the outer
which excludes hidden-activation reconstruction from every source ascent while the outer
components/CI objective keeps it; explicit `term` mode makes the adversary ascend the
complete loss. CI-fn
numerics: GELU is exact-erf (`approximate=False`),
RMSNorm eps is `finfo(fp32).eps` (`CI_FN_RMS_EPS`) — SPEC §4.6. The
RMSNorm eps is `finfo(fp32).eps` (`CI_FN_RMS_EPS`). The
three EDGES are generic so non-LM (bio-style) targets fit: the model INPUT
(the opaque batch `clean_forward` / `masked_forward` consume, typed `Any` — token ids for
an LM, a dict for bio), the model OUTPUT (`ForwardResult[Out].output` — `Out` is the
Expand All @@ -126,7 +116,7 @@ tensors in one forward share one `*leading` prefix) is enforced at trace time by
(fp32 masters / bf16 compute) over the explicit-role loss surface
(`objective.LossSurface` — faithfulness, importance-minimality, the recon terms, and an
optional nonlinearity-locality term;
S10′ — each authored recon config compiles to ONE `ReconLossTerm` = routing sampler ×
Each authored recon config compiles to ONE `ReconLossTerm` = routing sampler ×
mask-source strategy, every draw routing over ALL the model's sites, built from the
shared configs by `objective.build_objective`;
see LOSS_PARITY_DESIGN.md),
Expand All @@ -146,8 +136,7 @@ in the shared file switches on a family; the model-name → family registry is c
by `param_decomp/tests/targets/qwen3_hf_parity/` (a tiny-random `Qwen3ForCausalLM`
golden at fp32 tolerance + a slow real-weights logits check; goldens regenerate via its
torch-env `gen_hf_fixtures.py`). There is ONE
recon semantics: masks thread through the full token-input forward, loss is KL on final logits
(SPEC §2.3–2.5). Site-local recon is a conceptual no-no, not a "simplification".
recon semantics: masks thread through the full token-input forward, loss is KL on final logits. Site-local recon is a conceptual no-no, not a "simplification".
`param_decomp/targets/llama_simple_mlp.py` is the second target (the pile-pretrained `LlamaSimpleMLP`,
t-9d2b8f02; sites `h.{i}.attn.{q,k,v,o}_proj` / `h.{i}.mlp.{c_fc,down_proj}`) —
config dispatch is `TargetConfig` (the HF GLU families) vs `LlamaSimpleMLPTargetConfig`, both composition-side
Expand All @@ -157,7 +146,7 @@ config dispatch is `TargetConfig` (the HF GLU families) vs `LlamaSimpleMLPTarget
`param_decomp/experiments/lm/training.py::main` (`experiments/lm/run.py` is the pre-JAX
env bootstrap deferring to it). The slow plot metrics are computed
NATIVELY in JAX (`slow_eval.py`) — no torch export round-trip. They run IN-LOOP ONLY on
`eval.slow_every` next to the fast pass (SPEC S28/S29; there is NO offline/retrospective
`eval.slow_every` next to the fast pass (there is NO offline/retrospective
CLI — `slow_eval.py` is a pure library): the collective
forward + device→host pull in lockstep on all ranks, then a pure matplotlib renderer on a
rank-0 background thread (`run.py::BackgroundRenderer`). The renderer returns encoded media
Expand All @@ -179,7 +168,7 @@ gather), sharing `slow_eval.render_uv_figure` / `plot_uv_matrices` with the LM p
modular-arithmetic mechanism (Feucht et al.'s L18 addition neurons). The probe is a FIXED
`a x b` operand grid of `"<a><op><b>="` prompts (one prompt per row, all one token length,
the `=` answer at a constant position) — NOT the streaming corpus, so it brings its own
batch. The probe is a SPEC (`operation` + `a_range`/`b_range` on the metric config), not a
batch. The probe is a specification (`operation` + `a_range`/`b_range` on the metric config), not a
filesystem artifact: `experiments/lm/arithmetic_eval_operation.py::make_arithmetic_operation` builds it in-memory at
startup from the target's tokenizer (`experiments/lm/arithmetic_probe.py`, deterministic —
every rank builds the identical grid, no rank-0 write or barrier), so configs stay
Expand Down Expand Up @@ -256,7 +245,7 @@ mid-site. **Persistence layouts (÷N)**: the trainable V/U masters AND their
optimizer moments persist as target-declared semantic stacks (`ComponentStacks.stacks`; LM
targets group by matrix kind). Under owner placement, the stack
axis ÷`replicate` — whole matrices owned per node-group, zero cross-node weight collectives,
muon NS node-local — matrix d dims ÷`fsdp`, C ÷`tp`; SPEC D4. Placement is fallback-free:
muon NS node-local — matrix d dims ÷`fsdp`, C ÷`tp`. Placement is fallback-free:
one set of component rows places EVERY semantic group. A stack that doesn't tile a
stack-sharded row is placed by PADDING the persist stack with trailing all-zero slots
(`StackCensus.stack_pad` — an enumerated fact, never shape-inferred: the V/U groups'
Expand Down Expand Up @@ -326,22 +315,22 @@ Llama-8B target is multi-GB. Therefore:

## Invariants with sharp teeth (the ones that have actually bitten)

- **S3**: the recon target is the FROZEN-path `clean_forward(...).output`, never the
- the recon target is the FROZEN-path `clean_forward(...).output`, never the
`mask=1` decomposed identity (bf16 rounding + V/U in the stopped graph). An empty
capture-key set selects the target's compact no-capture path.
- **S13/S15**: source updates go through the persistent Adam AND project to [0,1]
- source updates go through the persistent Adam AND project to [0,1]
after EVERY ascent — an unprojected drift past 1 has zero `clip` gradient and the
entry dies.
- **S14**: the default `e2e` final ascent uses the source gradient of output
- the default `e2e` final ascent uses the source gradient of output
reconstruction only. When hidden-activation reconstruction makes the outer objective differ,
it retakes that gradient with pre-update θ and the same draws; otherwise it reuses the
main backward's source-grad. Explicit `term` mode always reuses the complete term's
source-grad. Neither source objective is scaled by the ppgd coeff.
- **N1**: fp32 masters everywhere (`optax.adamw(..., weight_decay=0.0)` — optax's
- fp32 masters everywhere (`optax.adamw(..., weight_decay=0.0)` — optax's
default wd is 1e-4, torch's is 0).
- **`inv_freq` is a buffer, not a param** — `stop_gradient` in
`ChunkwiseTransformerCIFn.__call__`.
- **S11**: uniform-k routing is per position over ALL the model's sites —
- uniform-k routing is per position over ALL the model's sites —
`k ~ U{1..|sites|}`, then a uniform k-subset routes True; draws are fresh per step.

## Validation stack (run all before claiming correctness)
Expand All @@ -358,7 +347,7 @@ Llama-8B target is multi-GB. Therefore:
`torch_reference.py` / `gen_torch_fixtures.py` / `gen_export_fixture.py`, copying the
emitted goldens back here.
3. `param_decomp/targets/invariance_check.py` at 4 sim devices — trajectory invariant
to device count up to float reassociation (SPEC D4).
to device count up to float reassociation.

`basedpyright` over the whole workspace must be clean (run `make type`); `param_decomp`
is in the root `[tool.pyright]` include and is checked in the one venv, one pass,
Expand All @@ -382,8 +371,7 @@ loader satisfying all three is welcome — the parquet `ShardServer` does today.
Checkpoints are orbax sharded saves (no on-loop full-gather), TWO items per step —
`decomposition` (V/U + ci_fn, the
product every consumer restores alone) and `training` (opt states + adversaries + step,
trainer-only) — a clean break, no in-code compat for pre-split `default`-item runs (SPEC
S22); SIGTERM → save → SLURM requeue → resume from latest.
trainer-only) — a clean break, no in-code compat for pre-split `default`-item runs; SIGTERM → save → SLURM requeue → resume from latest.
Resume with a changed config is refused (byte-compare). Smokes before a long run
MUST exercise save AND resume at the production per-rank shape.

Expand All @@ -399,7 +387,7 @@ top-level `run_name`, the
passes `--run-id`, and the run dir is a pure function of `data_root` + id
(`experiments.config.run_instance`).

**Fine-tune from a parent checkpoint** (`resume_provenance`, SPEC S33, LM-only). A fresh
**Fine-tune from a parent checkpoint** (`resume_provenance`, LM-only). A fresh
run can initialize its trained decomposition (V/U + ci_fn) from a PARENT run's checkpoint
and continue under a DIFFERENT config (changed LR / coeffs / gamma / seq / batch / steps —
NOT changed C / sites / ci-fn arch). Add to the config:
Expand Down
Loading
Loading