Files
OBLITERATUS/docs/CONCEPT_VALIDATION.md
Joseph MaglyandClaude Opus 5.5 d1504faf88 feat(concepts): rank-k subspace and affine (LEACE / mean-centred) erasure (#335)
Remove whole per-layer subspaces in project, orthogonalize and lora
modes; add mean-centred orthogonal and LEACE erasure at inference time
and, where a native bias exists, as a permanent edit with recorded
reference provenance. k=1 zero-origin paths are unchanged. Adds the
Pain Axis Appendix D script.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-17 13:07:11 -04:00

269 lines
16 KiB
Markdown
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# Concept validation (CV-05)
`AbliterationPipeline(..., concept=target)` validates after DISTILL and before
EXCISE, while the per-prompt caches still exist. Re-extraction during iterative
refinement is validated again before the next edit. A failing non-refusal gate
raises `obliteratus.concepts.gate.GateFailed`. The report is written even when
intervention is blocked. A warning permits intervention.
```bash
obliteratus obliterate /local/model --concept ./my-concept --output-dir ./result
obliteratus obliterate /local/model --concept ./my-concept --output-dir ./result \
--override-gate "Exploratory run; low power acknowledged"
```
`--concept` accepts a built-in/cached id or a local pack directory/archive and
resolves it without fetching. These flags apply to local runs; remote dispatch
rejects them rather than silently dropping them. Gate failure exits with code 3.
The equivalent Python argument is `override_gate="reason"`; blank reasons are
rejected. The override is recorded without changing a failed verdict. Validation
errors other than `GateFailed` become `PipelineFailure(stage="validate")`; the
pipeline releases the model and transient caches on either failure.
`--gate-mode {enforce,report,off}` on `obliterate` and its `abliterate` alias
maps to the Python argument `gate_mode`. Non-refusal concepts default to
`enforce`; `report` computes the same diagnostics without blocking intervention.
`off` skips all gate computation, auxiliary readouts, token scanning and
neighbour probing. After the skipped stage, exports record
`concept.validation: "skipped"`, retain `validation_verdict: "not_validated"`,
and do not write `validation.json`. Pre-run metadata remains unchanged.
Legacy `concept=None` and explicit `concept="refusal"` (including the
`core/refusal` alias) default to `off`. Request `--gate-mode report` explicitly
for diagnostics; requesting `enforce` on refusal resolves to advisory `report`
for compatibility. Refusal extraction, model outputs and existing metadata
fields remain unchanged. Legacy CV is a diagnostic diff-means refit, explicitly
identified in the report; it does not replicate advanced refusal extraction.
Missing legacy direction/activation caches produce an unavailable warning
only when reporting is requested.
The **Concept Lab** tab follows an explicit Extract → Validate → Intervene
workflow and enforces its validation result for every concept, including
Refusal. A failed Lab gate disables Apply until a nonempty override reason is
entered; the callback checks the same condition. This Lab-specific policy does
not change the ordinary pipeline's refusal defaults described above.
Before the calibration fixes, on 2026-10-05, the tiny offline GPT-2 fixture
(CPU, one Torch thread, seed 228,
one layer, hidden size 16, four positive and four control prompts) added a median
1.966 ms (range 1.880–2.077 ms), versus 3.196 ms for the extraction forwards.
This is non-trivial overhead on this fixture (about 62% of forward time, not of
the complete pipeline). The benchmark
times the complete gate, including writing its report, after one warm-up and
over 20 repetitions; a forward hook confirms zero additional refusal forwards.
This historical measurement used 20 null draws and no text probe. The calibrated
gate uses 1,000 draws and a lexical probe, so these timings do not describe its
current cost. Legacy `off` remains the default; `report` remains opt-in. Measure
the current cost with
`tests/test_concept_gate_pipeline.py::test_refusal_report_cost_and_no_forward_passes`.
## Revalidation from a saved direction
```python
from obliteratus.concepts import ConceptDirection
from obliteratus.concepts.gate import (
ActivationCache, validate_direction, write_validation, enforce_gate,
)
direction = ConceptDirection.load("direction.safetensors")
cache = ActivationCache(
positive=positive_by_layer, # layer -> [samples, hidden] tensor
controls=controls_by_name_and_layer, # name -> layer -> tensor
readouts={"final_token": final_pair, "mean_pool": mean_pair},
masked=masked_pair, # (positive, controls) with same shapes/order
top_tokens=token_scan, # [{token, presence_difference}, ...]
neighbours=neighbours_by_name_and_layer,
texts=(positive_prompts, controls_by_name), # same row order/counts as activations
)
report = validate_direction(direction, cache, reference=reference_by_layer)
write_validation(report, "validation.json")
enforce_gate(report)
```
The cached API has no model or network calls. Cache tensors can be retained by
the caller or recomputed using identical inputs/readout settings. No pickle
loading is used. CPU double-precision scoring, canonical layer/control order,
and a local Torch generator seeded from the direction make repeated reports
exactly reproducible on the same CPU environment. A missing seed resolves to 0.
A pipeline reference is supplied as `validation_reference=ConceptDirection(...)`.
Reference vectors are optional and are not fetched or automatically chosen from
a pack's reference files.
## Metrics and limits
Each candidate layer reports the supplied primary direction's in-sample AUC,
oriented so the positive class has the higher mean projection (using the
recipe's control weighting). Validation scores **that same vector** in every
stratified held-out fold, choosing only its sign on training rows. The stored
tensor is unchanged. Arbitrary SVD/eigen signs cannot invalidate a direction.
`heldout_auc` and `fold_aucs` alias the explicitly named supplied-vector metrics.
Separately, validation refits the complete extraction recipe, including
control-PC removal, within each fold and reports `recipe_refit_cv_auc` and
`recipe_refit_fold_aucs`. Saved CV scores are never trusted. These refit metrics
do not validate a supplied vector. The default is five folds (or the recipe's
configured count), reduced to the smallest set size. Fewer than two samples
makes held-out AUC unavailable and fails the gate.
AUC uses average ranks for ties. Control sets have the recipe's equal-set or
concatenated weighting. Verdict checks use selected extraction layers; other
candidate metrics are diagnostic. This is not nested CV of layer selection.
If a supplied vector was fitted on the same cache, its fold scores reuse fitting
data and are not independent validation; use a fresh cache for saved vectors.
Rank-k recipes validate their primary direction, not the entire subspace.
One thousand seeded Gaussian directions per layer are matched to the target norm.
Each null AUC uses its better sign. Percentile is `100 * count(null_auc <
target_auc) / N`; ties do not count as outperforming a null. With N=1,000,
percentiles have 0.1-point resolution. This is an
empirical percentile, not a p-value or confidence bound.
Semantic controls report target-vs-control AUC and each control's own fitted
contrast AUC against the remaining controls (null with only one control).
Up to three neighbours, in sorted name order, are probed once and cached during
PROBE. **Neighbour probing costs one extra forward pass per neighbour set**
when each set fits in a batch (up to three extra passes). Larger sets require
one forward pass per batch, with the same batch size as extraction. Final-token,
mean-pool and masked readouts share the extraction passes; cached validation
itself performs no model forwards. `off` incurs none of the neighbour cost.
Their directions contrast against the target controls; reports contain
signed cosine and target-direction AUC on neighbour-vs-control examples.
Declared neighbours beyond the budget yield warnings. Optional reference
cosines retain their sign.
For rank-k `leace_exact` extraction, semantic-control and neighbour diagnostics
fit rank-one binary contrasts because their AUC/cosine readouts are scalar.
The report's `auxiliary_calibration` field records this method and rank alongside
the target rank. The recipe-refit CV retains the requested target rank; these
scalar diagnostic scores do not validate every component of the target subspace.
Rank-one reports retain their existing fields.
The dependency-free text-only baseline fits a balanced ridge least-squares
probe in Torch on case-folded word and character-trigram presence. Each fold
builds its vocabulary from training prompts only, retaining at most 1,024
features by document frequency (ties sorted lexically), and fits with ridge 1.0.
Classes have equal total training weight; control weights follow the recipe.
It uses the same seeded stratified folds and AUC weighting as vector validation,
with no model forwards or downloads. The pipeline threads the original
`ConceptTarget` texts into the cache. A caller revalidating a saved vector must
provide matching texts; missing texts leave the baseline unavailable and warn.
If lexical held-out AUC is at least `min_heldout_auc` and the activation AUC
advantage is below `min_lexical_auc_gap` (default 0.05), the gate fails with
`lexical_confound`. Equal or better text separability is therefore a failure
even if the masked AUC drop is zero. Lexical separability is a confound warning
about concept identity; these features do not establish a semantic explanation.
The confound scan ranks case-folded word presence differences against equally
weighted control sets, retains at most ten words with absolute difference at
least 0.5, and warns when these lexical cues exist. During the same forward
passes, the pipeline collects final-token and mean-pool readouts plus a readout
excluding those words' tokenizer ids (standalone and space-prefixed encodings,
excluding special ids). Fully masked rows are zero vectors. This heuristic may
also exclude shared subword pieces. Masked AUC compares the same direction and
labels against the remaining token positions. **It does not mask model inputs
or undo contextual propagation of token information.** In particular, a suffix
may retain the confound even when the source token position is excluded. No
additional forward passes are used for readout comparison or masking. Missing
masked or comparison caches yield warnings, not invented metrics.
Every report includes this fixed statement:
> Validation does not establish causal use, behavioural effect, or anything about experience.
## `validation.json` schema, version 1
Reports are JSON objects, encoded without NaN or infinity. All listed fields
are required; unavailable scalar metrics are `null`. Layer keys in `metrics`
are decimal strings. Additional fields may be added within version 1.
| Field | Type / meaning |
|---|---|
| `schema_version` | integer `1` |
| `concept_id`, `pack_hash` | string identity and string/null pack digest |
| `mode` | `enforce` or `report` |
| `verdict` | `pass`, `warn`, or `fail` (highest reason severity) |
| `reasons` | array of `{severity: warn\|fail, check: string, layer: integer\|null, message: string}` |
| `thresholds` | effective numeric bounds, after applying pack overrides |
| `override_gate` | string/null; the original nonempty reason |
| `seed`, `folds`, `random_directions` | integers; unavailable legacy reports use zero counts |
| `recipe`, `cv_recipe` | serialized extraction recipe and diagnostic refit recipe (null if unavailable) |
| `selected_layers` | integer array; layers whose metrics determine the verdict |
| `sample_counts` | object mapping `positive` / `control:<name>` to integer counts |
| `metrics` | object mapping layer to the metric object below; empty if legacy caches are unavailable |
| `lexical_baseline` | text probe method, features, cap, ridge, held-out AUC and fold AUCs; unavailable AUC is null |
| `top_tokens` | array of `{token: string, presence_difference: number}` |
| `notes` | array of methodological caveat strings |
| `what_validation_does_not_establish` | fixed statement above |
Per-layer objects contain `in_sample_auc`, `heldout_auc`, `fold_aucs` (array),
`supplied_vector_heldout_auc`, `supplied_vector_fold_aucs` (the same scores),
`recipe_refit_cv_auc`, `recipe_refit_fold_aucs` (separate recipe diagnostics),
`orientation` (+1 or -1, relative to the supplied tensor for full-cache scoring),
`random_percentile`, `random_aucs` (array), `readout_aucs` (readout name to AUC),
`masked_auc`, `masked_auc_drop`, `reference_cosine`, `semantic_controls`
(control name to `{target_auc, control_vs_remaining_auc}`), and `neighbours`
(name to `{cosine, target_auc}`). All AUCs lie in [0, 1], cosines in [-1, 1],
and percentiles in [0, 100]. Masked drop is in-sample minus masked AUC.
The pipeline embeds the complete report in
`abliteration_metadata.json.concept.validation` and, for concept extraction,
`ConceptDirection.validation` (persisted in its JSON sidecar). The compatibility
key `concept.validation_verdict` is retained. Saving a direction preserves its
validation report and override; loading earlier direction sidecars defaults
this field to an empty object. The latest refinement's report is exported.
## Configurable initial thresholds
Pack manifest `validation_thresholds` maps to `ConceptTarget.thresholds`.
`validate_direction(..., thresholds=target.thresholds, tier=target.tier)` uses
the same rules as the pipeline. Absent keys use these defaults. Invalid or
unknown bounds are rejected, and core-tier packs may only tighten them.
Fail and warning bounds must remain consistently ordered. Thresholds are
provisional pending calibration; a pass is not pack admission evidence.
| Check | Fail key / default | Warn key / default |
|---|---|---|
| held-out AUC, below | `min_heldout_auc`: 0.75 | `warn_heldout_auc`: 0.85 |
| random percentile, below | `min_random_percentile`: 95 | `warn_random_percentile`: 99 |
| neighbour absolute cosine, above | `max_neighbour_abs_cos`: 0.8 | `warn_neighbour_abs_cos`: 0.5 |
| masked AUC drop, above | `max_masked_auc_drop`: 0.20 | `warn_masked_auc_drop`: 0.10 |
| each positive/control set size, below | `min_samples`: 16 | `warn_samples`: 32 |
| activation AUC advantage over separable lexical baseline, below | `min_lexical_auc_gap`: 0.05 | none |
| reference cosine, below | `min_reference_cos`: 0.8 | `warn_reference_cos`: 0.9 |
A threshold's equality boundary does not trigger that severity. Unavailable
optional checks are reported; missing expected evidence cannot yield `pass`.
## Refusal calibration spike (#256)
Qwen2.5-1.5B-Instruct, CPU float32, 842 prompts per class, five CV folds,
20 initial null draws. These are the **original gate** results, before the
supplied-vector and lexical fixes:
| Experiment | Held-out AUC | Random percentile | Original verdict |
|---|---|---|---|
| Default refusal, layers 23–27 | 0.992–0.993 (diagnostic refit) | 100 | warn |
| Generalized recipe refusal, layer 27 | 0.989 | 100 | pass |
| Shuffled labels, five seeds | 0.530 ± 0.014 | 100 | five fail |
| Lexical suffix confound, layer 1 | 1.000 | 100 | warn only |
| Supplied random directions, five seeds | 0.991–0.992 refit / 0.485–0.864 actual vector | 0–95 | four fail, one warn |
The suffix confound had zero masked-AUC drop despite perfect separation. The
new text probe makes comparable lexical separation fail by default. Independent
fixed-vector folds exposed the random-vector/refit discrepancy. The calibrated
default is 1,000 null draws to improve percentile resolution at the existing
95/99 bounds. Random controls are expected to fail; the committed offline test
checks one seeded random direction, not all five spike seeds.
Small sets were unstable at 8/16 per class, with layer-selection optimism and
arbitrary legacy SVD signs. The issue adopts a hard floor of 16 and warns below
32; generalized refusal passed all five seeds at 32 and 64 per class. This is
empirical stability on one strong contrast, not a universal power guarantee.
The AUC 0.75/0.85 and percentile 95/99 bounds are retained. Neighbour |cos|
0.8/0.5 remains provisional: genuine semantic neighbours were not calibrated.
Pain (#232) remains the required second calibration point; masked/reference
bounds also have no numerical calibration claim from this spike.
For the end-to-end flow from define to export, start at the
[concept workflow and interpretation guide](CONCEPT_WORKFLOW.md).