Skip to content
2 changes: 2 additions & 0 deletions .agents/skills/fine-tuning/SKILL.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ Train language models with SFT, KTO, and GRPO locally or on supported cloud prov
| **GRPO** | Optimize against rewards | 5e-6 | 1 | Prompts + ground truth | Final online stage |
| **Embedding** | Train a retrieval bi-encoder | 2e-5 | 1 | Triplets / pairs | Retrieval / RAG embedders |
| **Decision** | Calibrated typed decisions (yes/no, choice, score) | 1e-4 (+1e-3 head) | 1 | State + typed question + gold | Routing / triage / policy checks (Jev-style) |
| **MechInterp Weight Patch** | Experimental base-weight patch/export, in-memory patch evaluation, module-site capture, bounded weight inspection | `reference/mechinterp-weight-patch.md` |
| **Image LoRA** | Teach a diffusion model named characters, objects, places and a style | 1e-4 | steps, not epochs (~3-5k) | Images + caption .txt (trigger + entity tokens) | Illustration consistency (ai-toolkit on Modal) |

**Recommended pipeline:** SFT → KTO → GRPO
Expand Down Expand Up @@ -227,6 +228,7 @@ Load the specific reference you need:
| **Image LoRA** | Qwen-Image LoRAs via ai-toolkit on Modal: dataset recipes, captions/tokens, sizing, cost cap, fetch/verify/cleanup | `reference/image-lora.md` |
| **Troubleshooting** | OOM errors, instability, platform issues | `reference/troubleshooting.md` |
| **Tokenizer Profiling** | Offline token-length distributions and sequence-budget sizing | `reference/tokenizer-profiling.md` |
| **Batch Generation** | Pinned vLLM, HF schema-decoding fallback, repeatability and resume qualification | `reference/batch-generation.md` |
| **Derived Training Images** | Immutable package-overlay planning, capture, diagnostic reporting, and live launch verification | `reference/derived-training-images.md` |
| **Nexus Note Snapshot** | Read-only, explicit private-note snapshots for config-driven analysis | `reference/nexus-note-snapshot.md` |
| **Env Alignment Protocol** | Canonical SynthChat → SFT → merge/publish → KTO → env-GRPO flow | `protocols/environment-backed-alignment-pipeline.md` |
Expand Down
30 changes: 30 additions & 0 deletions .agents/skills/fine-tuning/reference/batch-generation.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# Batch generation and structured decoding

Use the existing public `batch-generate` verb. Prefer pinned vLLM with
`VLLM_BATCH_INVARIANT=1` when the model's attention backend supports it. Model
support alone does not establish batch-invariance support. Never bypass the
backend's capability refusal.

An HF fallback can preserve the configured JSON interface:

```bash
synaptic batch-generate --engine hf-batched --model LOCAL_CHECKPOINT \
--prompts PROMPTS_JSONL --out-dir OUTPUT --batch-size 1 \
--json-schema SCHEMA_JSON --structured-output-backend xgrammar --resume
```

HF JSON-schema decoding requires the optional `xgrammar` package. Pin its
version alongside Torch, Transformers, model/tokenizer revisions, dtype and
hardware in the consuming study. A fresh grammar matcher is created per batch.
No grammar dependency is loaded when a schema is absent. Registered conditional
generation models can serve text-only inputs through their Transformers auto
model class; no architecture-name heuristic or retry after a weight error is used.

HF batch size one avoids changes in batch composition. It is not a claim of
cross-version or cross-hardware bitwise determinism. Qualify exact prompt/token
bytes, repeated and permuted completions, natural termination, whole-schema
validation, and hard-kill/resume on the actual model before scientific use.
Never silently change a signed backend or resume across different configuration
hashes. HF does not accept the vLLM-only arbitrary-whitespace control.

The XGrammar HF integration follows its [official quick start](https://xgrammar.mlc.ai/docs/latest/start/quick_start.html).
67 changes: 67 additions & 0 deletions .agents/skills/fine-tuning/reference/mechinterp-weight-patch.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
# MechInterp weight patches, module-site capture and weight inspection (experimental)

Experimental, CLI-only MechInterp capabilities (not part of any stable public API).
Everything is config-driven; engine code names no model, tensor, direction or
dataset. The full contract and examples live in `docs/MECH_INTERP_CELLS.md`
("Experimental: weight patches, module-site capture, weight inspection"); this page
carries the working rules.

## Commands

```bash
python tuner.py mechinterp weights-inspect --weights-config inspect.yaml --json
python tuner.py mechinterp weights-patch --weights-config patch.yaml --validate --json
python tuner.py mechinterp weights-patch --weights-config patch.yaml --export --json
```

Use `mechinterp run --dry-run` for planning; `steer --dry-run` does not exist.
Pipeline stages are compiled as `python -m tuner mechinterp ...`; `dose-calibrate`
forwards `--model-revision`.

## Rules

- Specs are `mechinterp-weight-patch/v1` / `mechinterp-weights-inspect/v1` YAML or
JSON; pin every targeted tensor's dtype, shape and raw-byte sha256, the exact
40-hex `base.revision`, and `index_sha256`/`files_sha256`. Author the pins from
`weights-inspect` with `hash_tensors: true`.
- Budgets are required and finite (`allowed_tensors`, `max_modified_tensors`,
`max_modified_entries`, per-tensor `max_relative_frobenius`). The patch is
all-or-nothing; a refusal changes nothing.
- Always `--validate` before `--export`. Export is create-only into a new directory
and verifies untouched bytes by re-hashing; it never overwrites. Large outputs
(including to external drives) are chosen by `export.output_dir`, never by code.
- External filesystems may reject exclusive directory rename. Export then uses
exclusive directory creation, verified file copies and a completion manifest
written last. Require that manifest before consuming an export. A kill can
leave an incomplete directory; retain it and retry into a fresh destination.
This fallback preserves create-only behavior, not atomic directory publication.
- Evaluate candidates with `surface.weight_patch: {path, sha256}` (in-memory, no
export per candidate). The run must pass `--model-revision` equal to
`base.revision`; use a fresh output path when the patch changes (stale lineage
exits 6; a refused patch exits 7 before any row).
- Compare retained `generated_token_ids` for zero-patch, batch and export parity;
matching decoded text alone is insufficient. Old outputs without IDs need a
fresh parity run.
- `extract` `capture_sites` use decoder BLOCK indices (`law.layer` convention), not
`hidden_states` indices. Set `use_cache: true` for hybrid/KV-sharing models, and
`forward_only: true` with `families: [anchor]` for anchor-only reads.
- Use `resume: true` for long extraction. `capture.runlog.jsonl` commits each row
after its tensor files are fsynced and hashed. Resume verifies source/settings/
patch identity and every completed file, then skips completed rows. Without
resume the output directory must be empty. Probe fitting requires a completed
manifest and verifies its captured files. Use the manifest's filenames: unsafe
keys are hash-encoded for portable storage, and collisions are refused.
- Inspect projections are bounded numeric reads (dot/cosine/slice over selected
rows or columns); keep `max_output_values` small and do the interpretation in
project-side analysis, not in engine code.
- A bare revision string is not authenticated by file bytes: the byte pins are the
binding. Hub-id loads verify only the targeted tensors.

## Test

```bash
# dedicated CPU-only venv (never the main Unsloth/GPU env): torch (CPU wheel),
# safetensors, pydantic, pyyaml, pytest, transformers, pandas, scikit-learn,
# jsonschema, python-dotenv, packaging
python -m pytest tests/mech_interp
```
2 changes: 2 additions & 0 deletions .claude/skills/fine-tuning/SKILL.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ Train language models with SFT, KTO, and GRPO locally or on supported cloud prov
| **GRPO** | Optimize against rewards | 5e-6 | 1 | Prompts + ground truth | Final online stage |
| **Embedding** | Train a retrieval bi-encoder | 2e-5 | 1 | Triplets / pairs | Retrieval / RAG embedders |
| **Decision** | Calibrated typed decisions (yes/no, choice, score) | 1e-4 (+1e-3 head) | 1 | State + typed question + gold | Routing / triage / policy checks (Jev-style) |
| **MechInterp Weight Patch** | Experimental base-weight patch/export, in-memory patch evaluation, module-site capture, bounded weight inspection | `reference/mechinterp-weight-patch.md` |
| **Image LoRA** | Teach a diffusion model named characters, objects, places and a style | 1e-4 | steps, not epochs (~3-5k) | Images + caption .txt (trigger + entity tokens) | Illustration consistency (ai-toolkit on Modal) |

**Recommended pipeline:** SFT → KTO → GRPO
Expand Down Expand Up @@ -227,6 +228,7 @@ Load the specific reference you need:
| **Image LoRA** | Qwen-Image LoRAs via ai-toolkit on Modal: dataset recipes, captions/tokens, sizing, cost cap, fetch/verify/cleanup | `reference/image-lora.md` |
| **Troubleshooting** | OOM errors, instability, platform issues | `reference/troubleshooting.md` |
| **Tokenizer Profiling** | Offline token-length distributions and sequence-budget sizing | `reference/tokenizer-profiling.md` |
| **Batch Generation** | Pinned vLLM, HF schema-decoding fallback, repeatability and resume qualification | `reference/batch-generation.md` |
| **Derived Training Images** | Immutable package-overlay planning, capture, diagnostic reporting, and live launch verification | `reference/derived-training-images.md` |
| **Nexus Note Snapshot** | Read-only, explicit private-note snapshots for config-driven analysis | `reference/nexus-note-snapshot.md` |
| **Env Alignment Protocol** | Canonical SynthChat → SFT → merge/publish → KTO → env-GRPO flow | `protocols/environment-backed-alignment-pipeline.md` |
Expand Down
30 changes: 30 additions & 0 deletions .claude/skills/fine-tuning/reference/batch-generation.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# Batch generation and structured decoding

Use the existing public `batch-generate` verb. Prefer pinned vLLM with
`VLLM_BATCH_INVARIANT=1` when the model's attention backend supports it. Model
support alone does not establish batch-invariance support. Never bypass the
backend's capability refusal.

An HF fallback can preserve the configured JSON interface:

```bash
synaptic batch-generate --engine hf-batched --model LOCAL_CHECKPOINT \
--prompts PROMPTS_JSONL --out-dir OUTPUT --batch-size 1 \
--json-schema SCHEMA_JSON --structured-output-backend xgrammar --resume
```

HF JSON-schema decoding requires the optional `xgrammar` package. Pin its
version alongside Torch, Transformers, model/tokenizer revisions, dtype and
hardware in the consuming study. A fresh grammar matcher is created per batch.
No grammar dependency is loaded when a schema is absent. Registered conditional
generation models can serve text-only inputs through their Transformers auto
model class; no architecture-name heuristic or retry after a weight error is used.

HF batch size one avoids changes in batch composition. It is not a claim of
cross-version or cross-hardware bitwise determinism. Qualify exact prompt/token
bytes, repeated and permuted completions, natural termination, whole-schema
validation, and hard-kill/resume on the actual model before scientific use.
Never silently change a signed backend or resume across different configuration
hashes. HF does not accept the vLLM-only arbitrary-whitespace control.

The XGrammar HF integration follows its [official quick start](https://xgrammar.mlc.ai/docs/latest/start/quick_start.html).
67 changes: 67 additions & 0 deletions .claude/skills/fine-tuning/reference/mechinterp-weight-patch.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
# MechInterp weight patches, module-site capture and weight inspection (experimental)

Experimental, CLI-only MechInterp capabilities (not part of any stable public API).
Everything is config-driven; engine code names no model, tensor, direction or
dataset. The full contract and examples live in `docs/MECH_INTERP_CELLS.md`
("Experimental: weight patches, module-site capture, weight inspection"); this page
carries the working rules.

## Commands

```bash
python tuner.py mechinterp weights-inspect --weights-config inspect.yaml --json
python tuner.py mechinterp weights-patch --weights-config patch.yaml --validate --json
python tuner.py mechinterp weights-patch --weights-config patch.yaml --export --json
```

Use `mechinterp run --dry-run` for planning; `steer --dry-run` does not exist.
Pipeline stages are compiled as `python -m tuner mechinterp ...`; `dose-calibrate`
forwards `--model-revision`.

## Rules

- Specs are `mechinterp-weight-patch/v1` / `mechinterp-weights-inspect/v1` YAML or
JSON; pin every targeted tensor's dtype, shape and raw-byte sha256, the exact
40-hex `base.revision`, and `index_sha256`/`files_sha256`. Author the pins from
`weights-inspect` with `hash_tensors: true`.
- Budgets are required and finite (`allowed_tensors`, `max_modified_tensors`,
`max_modified_entries`, per-tensor `max_relative_frobenius`). The patch is
all-or-nothing; a refusal changes nothing.
- Always `--validate` before `--export`. Export is create-only into a new directory
and verifies untouched bytes by re-hashing; it never overwrites. Large outputs
(including to external drives) are chosen by `export.output_dir`, never by code.
- External filesystems may reject exclusive directory rename. Export then uses
exclusive directory creation, verified file copies and a completion manifest
written last. Require that manifest before consuming an export. A kill can
leave an incomplete directory; retain it and retry into a fresh destination.
This fallback preserves create-only behavior, not atomic directory publication.
- Evaluate candidates with `surface.weight_patch: {path, sha256}` (in-memory, no
export per candidate). The run must pass `--model-revision` equal to
`base.revision`; use a fresh output path when the patch changes (stale lineage
exits 6; a refused patch exits 7 before any row).
- Compare retained `generated_token_ids` for zero-patch, batch and export parity;
matching decoded text alone is insufficient. Old outputs without IDs need a
fresh parity run.
- `extract` `capture_sites` use decoder BLOCK indices (`law.layer` convention), not
`hidden_states` indices. Set `use_cache: true` for hybrid/KV-sharing models, and
`forward_only: true` with `families: [anchor]` for anchor-only reads.
- Use `resume: true` for long extraction. `capture.runlog.jsonl` commits each row
after its tensor files are fsynced and hashed. Resume verifies source/settings/
patch identity and every completed file, then skips completed rows. Without
resume the output directory must be empty. Probe fitting requires a completed
manifest and verifies its captured files. Use the manifest's filenames: unsafe
keys are hash-encoded for portable storage, and collisions are refused.
- Inspect projections are bounded numeric reads (dot/cosine/slice over selected
rows or columns); keep `max_output_values` small and do the interpretation in
project-side analysis, not in engine code.
- A bare revision string is not authenticated by file bytes: the byte pins are the
binding. Hub-id loads verify only the targeted tensors.

## Test

```bash
# dedicated CPU-only venv (never the main Unsloth/GPU env): torch (CPU wheel),
# safetensors, pydantic, pyyaml, pytest, transformers, pandas, scikit-learn,
# jsonschema, python-dotenv, packaging
python -m pytest tests/mech_interp
```
2 changes: 2 additions & 0 deletions .skills/fine-tuning/SKILL.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ Train language models with SFT, KTO, and GRPO locally or on supported cloud prov
| **GRPO** | Optimize against rewards | 5e-6 | 1 | Prompts + ground truth | Final online stage |
| **Embedding** | Train a retrieval bi-encoder | 2e-5 | 1 | Triplets / pairs | Retrieval / RAG embedders |
| **Decision** | Calibrated typed decisions (yes/no, choice, score) | 1e-4 (+1e-3 head) | 1 | State + typed question + gold | Routing / triage / policy checks (Jev-style) |
| **MechInterp Weight Patch** | Experimental base-weight patch/export, in-memory patch evaluation, module-site capture, bounded weight inspection | `reference/mechinterp-weight-patch.md` |
| **Image LoRA** | Teach a diffusion model named characters, objects, places and a style | 1e-4 | steps, not epochs (~3-5k) | Images + caption .txt (trigger + entity tokens) | Illustration consistency (ai-toolkit on Modal) |

**Recommended pipeline:** SFT → KTO → GRPO
Expand Down Expand Up @@ -227,6 +228,7 @@ Load the specific reference you need:
| **Image LoRA** | Qwen-Image LoRAs via ai-toolkit on Modal: dataset recipes, captions/tokens, sizing, cost cap, fetch/verify/cleanup | `reference/image-lora.md` |
| **Troubleshooting** | OOM errors, instability, platform issues | `reference/troubleshooting.md` |
| **Tokenizer Profiling** | Offline token-length distributions and sequence-budget sizing | `reference/tokenizer-profiling.md` |
| **Batch Generation** | Pinned vLLM, HF schema-decoding fallback, repeatability and resume qualification | `reference/batch-generation.md` |
| **Derived Training Images** | Immutable package-overlay planning, capture, diagnostic reporting, and live launch verification | `reference/derived-training-images.md` |
| **Nexus Note Snapshot** | Read-only, explicit private-note snapshots for config-driven analysis | `reference/nexus-note-snapshot.md` |
| **Env Alignment Protocol** | Canonical SynthChat → SFT → merge/publish → KTO → env-GRPO flow | `protocols/environment-backed-alignment-pipeline.md` |
Expand Down
30 changes: 30 additions & 0 deletions .skills/fine-tuning/reference/batch-generation.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# Batch generation and structured decoding

Use the existing public `batch-generate` verb. Prefer pinned vLLM with
`VLLM_BATCH_INVARIANT=1` when the model's attention backend supports it. Model
support alone does not establish batch-invariance support. Never bypass the
backend's capability refusal.

An HF fallback can preserve the configured JSON interface:

```bash
synaptic batch-generate --engine hf-batched --model LOCAL_CHECKPOINT \
--prompts PROMPTS_JSONL --out-dir OUTPUT --batch-size 1 \
--json-schema SCHEMA_JSON --structured-output-backend xgrammar --resume
```

HF JSON-schema decoding requires the optional `xgrammar` package. Pin its
version alongside Torch, Transformers, model/tokenizer revisions, dtype and
hardware in the consuming study. A fresh grammar matcher is created per batch.
No grammar dependency is loaded when a schema is absent. Registered conditional
generation models can serve text-only inputs through their Transformers auto
model class; no architecture-name heuristic or retry after a weight error is used.

HF batch size one avoids changes in batch composition. It is not a claim of
cross-version or cross-hardware bitwise determinism. Qualify exact prompt/token
bytes, repeated and permuted completions, natural termination, whole-schema
validation, and hard-kill/resume on the actual model before scientific use.
Never silently change a signed backend or resume across different configuration
hashes. HF does not accept the vLLM-only arbitrary-whitespace control.

The XGrammar HF integration follows its [official quick start](https://xgrammar.mlc.ai/docs/latest/start/quick_start.html).
Loading
Loading