Files
OBLITERATUS/docs/MODEL_RECIPES.md
T
Joseph Magly 30a2fa65eb fix(process): treat every group stop failure and skipped launch guard as a cleanup failure
Codex/Muse review r5 for #625: any error stopping a step's process group,
after an interrupt or a normal exit with any code (including the evaluator's
normal-exit stop and VllmServer.stop), becomes a ProcessGroupCleanupError
chained to the original, so search and confirmation write the marker. A
skipped or unbalanced launch guard on any step raises a plain
ProcessGroupCleanupError so the marker is recorded and resume is refused.
Docs clarify the cooperative-runner trust boundary.
2026-11-24 21:26:02 -05:00

47 KiB

Model recipes

The registry and the recipe search, recipe confirm, recipe promote, and obliterate --recipe commands use v2 pipelines. Existing v1 recipes and grids are read-only. The tools migrate them in memory and print a notice. Use v2 when writing a recipe or preregistering a grid.

RecipeRegistry() indexes bundled recipes. Pass a local directory to index its top-level JSON files.

from obliteratus.recipes import RecipeRegistry

recipes = RecipeRegistry()
names = recipes.list()
record = recipes.load("llama3.1-8b-e03-reg02")
identity = record["target"]["identity"]
match = recipes.lookup(identity["model_id"], identity["revision"])

list() returns names in lexical order, and load(name) raises KeyError for an unknown name. lookup(model_id, revision) uses case-sensitive equality. The registry rejects duplicate recipe names and duplicate individual identities at the same status. When several statuses share an identity, it prefers an accepted recipe, then a candidate, then a superseded recipe.

Record format and scope

obliteratus.model-recipe/v2 defines ordered technique steps, a target, named inputs and a pinned evaluation profile. See the v2 core contract for its fields and the rules for authoring a recipe.

The accepted llama3.1-8b-e03-reg02 and qwen2.5-1.5b-mid10-18-dim1 recipes bind the confirmed Llama-3.1 8B and Qwen2.5 1.5B stock revisions. Their profiles reproduce the frozen final-test gates with KL advisory. The bundled evidence summaries identify the original confirmation and verify-edit records by SHA-256. The historical stand-in recipes retain their candidate status. Qwen3.8 E03 retains its accepted status and its historical gates.

Family matching and layer placement

The registry matches config metadata from a supplied ModelProfile or an equivalent object. Each configured match field must pass.

  • model_type is required. Supply a case-sensitive string or a list of allowed strings.
  • architectures is a list of architecture names. At least one name must appear in the profile's architectures sequence. The current profile_model() result has no architecture field. Supply an enriched profile for recipes that use this rule.
  • num_layers, total_params_b, and hidden_size each accept an inclusive range with both min and max. A missing profile value fails the rule.
  • model_id_patterns is a list of case-sensitive fnmatch globs matched against the full model ID. The ID must match at least one pattern.

A fractional layer window has start and end in [0, 1]. At depth n, its first index is floor(start * n) and its last is ceil(end * n) - 1. The placement resolver clips the window to the model and includes its first index when the window would be empty. A fractional projection extraction layer uses round(f * (n - 1)), with ties to even.

Placement resolver for recipe v2

obliteratus.recipes.placement.resolve_placement(placement, profile, *, model=None, scores=None) returns ordered, zero-based layer indices, writer module names, and provenance. The bundled schema/recipe-placement.v1.schema.json defines the placement fragment for v2 pipeline steps. Set layers to a list of distinct absolute indices, {"fraction_window": {"start": 0.2, "end": 0.8}} to use the family rounding rule above, or {"selector": "middle_fraction", "params": {"start": 0.2, "end": 0.8}} to reproduce legacy middle60. middle_fraction truncates both endpoints and excludes the end index. all and all_except_first take empty params.

knee, top_k, and knee_cosmic take empty params and require scores["layer_scores"], a map of indices to extraction scores. knee_cosmic also takes harmful_means and harmless_means maps keyed by layer index. The selectors return candidates before technique-specific safeguards and budgets. LAYER_SELECTORS exposes each rule's required inputs. Register new rules with register_layer_selector and the same schema.

Omit writers to resolve layers from the profile and any required scores alone. Writer roles require a model. attn_out, mlp_out, router, and experts are limited to the resolved layers. The experts role includes shared expert projections and names the module that owns fused expert weights. embeddings and lm_head are global. A {"module_pattern": "model.layers.*.mlp.down_proj"} entry matches full module names across the model, case-sensitively, and uses module_pattern:<glob> as its output key. An unmatched role or glob raises an error. With a model, provenance["tied_embeddings"] reports whether the input embedding and output head share a weight parameter. Its value is None when either module is unavailable.

Inheritance and resolution

An individual recipe can use inherits to name one family recipe. The registry rejects unknown parents, cycles and individual parents. An omitted evaluation uses the family binding. An explicit null disables it. Matching step IDs inherit step fields and merge legacy projection shorthand overrides. Additional individual steps run after the inherited steps.

recipes.resolve(profile, revision, include_candidates=False) returns the selected v2 recipe with inheritance materialized, or None. It checks for an exact accepted individual, then an accepted matching family. With candidate opt-in, an exact inheriting candidate takes precedence over the family and other candidates and superseded recipes are considered when no accepted recipe matches. Multiple matches at a family step raise RecipeError and list the matching names.

Applying a recipe

Use --recipe NAME to select a specific record or --recipe auto to use the registry's resolution order. A missing or ambiguous automatic match stops the command.

obliteratus obliterate /checkpoints/stock --recipe auto \
  --recipe-model-id Qwen/Qwen3.8-27B \
  --recipe-revision 1d4bf0f2ff6012fd82039f2fa52739d0dd7c60c0

A Hugging Face cache path of the form models--ORG--NAME/snapshots/REVISION supplies both identity fields. A Hub ID supplies the model ID and requires --recipe-revision. The Hub config is fetched at that revision and the weights are retrieved from the same pinned snapshot after the recipe checks pass. For other local paths, provide both identity flags. Explicit flags take precedence over identities derived from paths.

Named individual recipes require the same model ID and revision. Named family recipes require a matching model profile. Use --allow-recipe-transfer to authorize a named application outside either binding. For a matching accepted family recipe, a passing confirmation for the exact model ID and revision must match the recipe's version and file digest to earn confirmed-family-member. Other applications within the family, including those with changed recipe fields, use family-application. Recipes with candidate or superseded status require --allow-candidate-recipe.

The command runs the steps through the technique registry in order and writes recipe-resolution.json beside the resulting checkpoint. Choose an unused output directory for each recipe execution. Use --recipe-input NAME=VALUE for a runtime binding or local copy of a pinned input. File-backed inputs resolve against the recipe directory. The checkpoint and artifact_dir runtime bindings can use the output location when the recipe declares them.

Supplying a CLI flag for a parameter fixed by a single projection step requires --allow-recipe-override. Preset shorthand fixes its declared overrides and preset. The resolution record binds the applied parameters. The projection checkpoint metadata also records the recipe name, version, status, model identity, inheritance chain, binding label and overrides.

Recipe application is available for local obliterate and its abliterate alias.

Qwen3.8 method presets

Edits with qwen38_e01, qwen38_e02, or qwen38_e03 are bound to Qwen/Qwen3.8-27B at revision 1d4bf0f2ff6012fd82039f2fa52739d0dd7c60c0. All three use the stock identity in the E03 registry record. E01 was a control run and E02 was evaluated on the tuning split. Only E03 has an accepted registry record.

For local obliterate --method runs, a Hugging Face cache snapshot supplies the model ID and revision. Use --recipe-revision to pin a Hub model ID, or supply both --recipe-model-id and --recipe-revision to identify a local copy. For another model or revision, or when identity is unknown, pass --allow-recipe-transfer (allow_recipe_transfer=True in Python). The edit logs a warning and writes preset_binding.application: transfer to abliteration_metadata.json. The preset check applies to full edit runs, including edits that select a bound preset through --recipe. Existing checkpoints can be evaluated without transfer permission.

obliteratus recipe search grid.json compares a fixed set of edits on the qwen38-v1 tune split. The edit pipeline extracts directions from the protocol train split and records checkpoint replay references from train prompts. Verify-edit receives the pinned tune file, and search rejects any held-out file containing a prompt from the protocol final-test or train splits.

To prepare an example, run the following from the directory that will contain grid.json. It exports the complete 142-pair tune split and prints the evaluation profile digest for the grid. The example treats capability as advisory and disables its external evaluator.

from hashlib import sha256
from pathlib import Path

from obliteratus.qualification import canonical_json
from obliteratus.verify_edit.heldout import load_heldout
from obliteratus.verify_edit.spec import BUILTIN_HELDOUT

tune = load_heldout({"source": BUILTIN_HELDOUT, "pairs": None}, None, calibration=True)
pairs = canonical_json({key: tune[key] for key in ("harmful", "harmless")})
Path("tune.json").write_bytes(pairs)
profile = canonical_json({
    "schema": "obliteratus.evaluation-profile/v1",
    "name": "tune", "version": "1.0.0", "scope": "individual",
    "spec": {
        "heldout": {"source": "file", "sha256": sha256(pairs).hexdigest()},
        "endpoints": {"capability": {"backend": "none"}},
    },
})
Path("tune-profile.json").write_bytes(profile)
print(sha256(profile).hexdigest())

Save the following as grid.json. Substitute the printed profile digest and the revision of the local checkpoint. Choose layer indices valid for that model.

{
  "schema": "obliteratus.recipe-search-grid/v2",
  "stock": {
    "model_id": "./stock-checkpoint",
    "revision": "989aa7980e4cf806f80c7fef2b1adb7bc71aa306"
  },
  "candidates": [
    {"name": "mid-12-14", "steps": [{
      "id": "project", "technique": "abliteration.projection", "technique_version": "1",
      "params": {"preset": "advanced", "overrides": {"n_directions": 1}},
      "placement": {"layers": [12, 13, 14]}
    }]},
    {"name": "mid-14-16", "steps": [{
      "id": "project", "technique": "abliteration.projection", "technique_version": "1",
      "params": {"preset": "advanced", "overrides": {"n_directions": 1}},
      "placement": {"layers": [14, 15, 16]}
    }]}
  ],
  "verify_edit": {
    "profile": "tune-profile.json",
    "sha256": "REPLACE_WITH_THE_PRINTED_PROFILE_SHA256",
    "heldout": "tune.json"
  },
  "selection": {
    "objective": "min_edited_refusal",
    "tie_break": "min_next_token_kl",
    "advisory_endpoints": ["capability"]
  },
  "runtime": {"device": "auto", "dtype": "bfloat16"},
  "output_dir": "tune-search"
}

Paths are relative to the grid file. For local stock directories, supply the revision associated with the checkpoint and keep the directory immutable for the search. The proposed recipe records the absolute local checkpoint path. A Hub ID resolves only to a locally cached snapshot at the supplied revision and remains a Hub ID in the recipe. The runtime settings shown above are the defaults.

The exact profile bytes and held-out file bytes must match their preregistered SHA-256 values. For the protocol tune split, the complete ordered prompt lists must match the built-in lists, and JSON formatting may vary. To preregister an alternative tune file, add verify_edit.declared_tune_sha256 with the same digest as the spec's heldout.sha256. Search checks the entire file for overlap before verify-edit applies any subsampling requested by the spec.

grid.lock binds the output directory to the canonical grid, normalized candidate pipelines, and stock checkpoint path. Reuse the same grid to resume. Use a new output directory for a revised grid. Each candidate has a record at candidates/<name>.json with subprocess exit codes, timings, logs, the resolution reference, verify-edit report when available, and Git commit when available. Resuming skips completed evaluations and retries execution failures in fresh attempt directories. The candidate record retains previous failed attempts.

On POSIX, search and confirmation run each edit and verification step in its own process group. SIGINT or SIGTERM stops the current group and records the interruption. Run search again with the same grid to retry the interrupted candidate. An interrupted confirmation retains its final-test reservation, so a retry requires --reconfirm-reason.

Cleanup sends SIGTERM to the entire group, waits up to 10 seconds, and sends SIGKILL if the group remains. Set OBLITERATUS_PROCESS_GRACE_SECONDS to a finite, nonnegative number to change the wait. Cleanup then waits up to 10 seconds for the group leader to exit. A leader that cannot act on SIGKILL, such as one in uninterruptible sleep, causes cleanup to fail with an error rather than hang. That error replaces the error that triggered cleanup (which is kept as its cause), so a group that may still be running is never reported as an ordinary failure or an untested endpoint; verify-edit exits 4 without a report. Search and confirmation treat that exit as fatal, including when verify-edit reports it while being stopped by SIGINT or SIGTERM, and also when they cannot stop a step themselves: they record the candidate or confirmation as failed, write process-cleanup-failed.json in the output directory (synced to disk before anything else happens), launch nothing further, and exit 4. If that file cannot be written, they print a CRITICAL message on stderr and still exit 4. A signal that arrives during a failed cleanup is reported with the cleanup failure rather than replacing it. While the file exists, search (including a resumed search) and confirmation refuse to start in that output directory, and a run already in progress there checks for it before each step. The check and the step's launch happen under one shared lock (.process-cleanup.lock, always taken after the run's own .search.lock or .confirmation.lock), so a search and a confirmation sharing a directory never launch a step after the other has written the file. If the lock or the file cannot be checked, the run prints a CRITICAL message and exits 4. A failure to write the candidate or confirmation record afterwards, or to close a step log, is attached to the cleanup failure and never replaces it, and a verify-edit exit 4 stays the reported failure even if stopping verify-edit's own group then fails. Any failure to stop a step's group (for example a permission error from signalling it) is a cleanup failure too: the marker is written and the run exits 4, whether or not the wait was interrupted. The built-in launchers (POSIX and Windows) create the step's process inside the lock and release it before waiting. A custom runner passed to the Python entry points receives a launch_guard context-manager factory; a cooperative runner must enter (and leave) the context it returns exactly where it creates its process. Non-cooperation (never entering it, or only calling the factory) is detected only after the step has run, and is then treated as a cleanup failure: the marker is written and the run exits 4. Such runners run in-process and are trusted code; the guard is not a defence against a hostile runner. Entering the guard twice (nested) deadlocks on the cleanup lock. On exit 4 the CLI also prints the failure's notes and any interrupting signal on stderr. Check that no evaluator or vLLM process from the recorded run is still running (it may hold GPU memory and the port), then delete the file to continue. The leader is left unreaped and its process object stays held by obliteratus.process_groups (unreaped_leaders()), so its process group ID cannot be reused by an unrelated group while the process lives. An embedding application can retry with cleanup_unreaped_leaders(grace), which first re-checks that it still owns each leader and never signals one that another reaper has taken. Verify-edit applies the same grace period to the evaluator and locally launched vLLM groups. After the evaluator leader exits, verify-edit stops its group and drains stdout and stderr for up to 0.25 seconds before closing the pipes, even if a descendant has left the group and still holds them open. Set OBLITERATUS_PROCESS_DRAIN_SECONDS to a finite, nonnegative number to change this bound. Zero skips the post-cleanup drain, so output still buffered in the pipes when the leader exits may be dropped. The drain has its own time budget even when the evaluator has no run timeout. When search or confirmation stops verify-edit, it waits 2 x (grace + 10 seconds) + 1 second before sending SIGKILL, enough for verify-edit to stop the evaluator and vLLM groups in turn, each with its grace period and its bounded wait for the leader. If a SIGINT or SIGTERM handler was installed outside Python, it cannot be reinstalled after a step; OBLITERATUS logs a warning and restores the default disposition. Windows retains its previous subprocess behavior.

POSIX group ownership requires waitid(WNOWAIT) and the default SIGCHLD disposition. An embedding application must leave SIGCHLD at SIG_DFL and give OBLITERATUS exclusive responsibility for reaping its group leaders. Broad waits such as waitpid(-1) can break that ownership. The launcher rejects an inherited SIGCHLD=SIG_IGN, a custom SIGCHLD handler, or a missing wait API before spawning. If a child reaper takes the leader after launch, cleanup reports that it lost wait ownership because the process group ID can be reused.

selection.json records the preregistered rule and ranks every candidate. Eligibility requires a successful edit and checkpoint check, ranking metrics, and a pass for each endpoint marked required by the spec outside the advisory list. A verify-edit FAIL or INCOMPLETE can still supply a completed evaluation when its non-passing endpoints are advisory for selection. Eligible candidates sort by ascending edited refusal rate, then mean next-token KL, then name. If a candidate qualifies, recipe.json is an individual v2 candidate recipe with the winning steps, tune evaluation profile, and candidate evidence digests. If none qualifies, the CLI exits 1 and writes the selection with a null winner. Input errors exit 2. A verify-edit process-group cleanup failure exits 4 (see above).

Legacy v1 grids with explicit layers migrate automatically. The Python entry point also accepts a resolver for legacy fractional candidate placements. Each migrated candidate carries the legacy tied-head permission. A grid lock created with the previous migration binds different normalized pipelines and requires a new output directory. Use v2 placement selectors for new grids.

Final-test confirmation

Pin an evaluation profile selecting builtin:qwen38-v1:final_test under evaluation.profile and evaluation.sha256. A search winner references its tune profile. Give it a separately frozen final-test profile before confirming it. An inheriting candidate can use the family's profile or pin an individual profile that declares its own family profile inheritance.

obliteratus recipe confirm ./candidate.json \
  --stock ./stock-checkpoint --model-id org/model --revision MODEL_REVISION \
  --output-dir ./final-confirmations --accepted-by reviewer \
  --record-dir ./obliteratus/recipes/data

You can also pass a recipe name. Names resolve in the supplied recipes data directory and then in the bundled registry. An HF cache snapshot path supplies its model ID and commit revision automatically. For a local copy, supply both identity flags and keep the stock checkpoint immutable. A family recipe can record a result for any member matching its configured predicates.

Confirmation runs a train-only edit in an isolated process, reloads and verifies the edited checkpoint, then runs verify-edit on the built-in final test under the resolved frozen spec. runs/<run-id>/confirmation.json records the recipe and revision, resolution record and evaluation provenance, final-test identity, exit codes, log and report digests, and verification outcome. The run directory contains the referenced files. The CLI exits 0 for a pass, 1 for a failed margin, 2 for input or execution errors, 3 for incomplete verification, and 4 when verify-edit could not stop a process group it started (see above).

Reuse the same output directory for all confirmations of a model. The confirmation-ledger.json reserves the model ID, revision and full final-test partition before any subprocess starts, including for runs that later fail or are interrupted. Another attempt against that key requires an explicit --reconfirm-reason, which the ledger and new record retain. The ledger retains the paths of all attempts. The command also checks review records in the bundled registry, beside the selected recipe, and in any supplied review directory.

A passing individual candidate gets a new runs/<run-id>/recipe.json with status: accepted, the reviewer and timestamp, and evidence linking the record by digest. The original candidate stays intact. A passing family run records one member for explicit family promotion. Review records are optional and live in the checkout at confirmations/<recipe>/<model-id-slug>@<revision>.json beneath --record-dir. An explicit reconfirmation can update that review copy. Use RecipeRegistry(data_dir).confirmations(recipe_name, model_id, revision) to list the records, with either model filter optional.

Family and member promotion

Keep the family candidate, its frozen evaluation profile, and the published confirmations in a local recipes data directory. Confirm each member against the same candidate bytes and version. Then approve the candidate explicitly.

obliteratus recipe promote FAMILY --record-dir ./obliteratus/recipes/data \
  --accepted-by REVIEWER

Two passing confirmations must name distinct model IDs and match every family predicate. A different layer count qualifies as a different size. At equal depth, both parameter estimates must be positive and the larger estimate must be at least 25% above the smaller estimate. Two revisions of one model provide one member. Older records without architecture metadata still load and can qualify for families whose match rules do not use architectures.

Promotion checks the family recipe digest, the recorded resolution, and the frozen evaluation profile. A recorded member override can qualify when its pinned profile is available inside the recipes directory and reproduces the recorded verification spec. The first qualifying pair in review path order supplies the acceptance evidence. A refusal lists the reason for each confirmation and exits 2.

The command updates the local family JSON with the reviewer, UTC timestamp, and digest references. It saves exact copies of the original candidate and counted confirmations under promotion-evidence/<family>/<sha256>.json. A legacy candidate's exact source text is stored inside an evidence record. Include the updated JSON and those evidence files in the review pull request. The hidden .recipe-promotion.lock file coordinates local writers.

obliteratus recipe promote-member FAMILY --model-id ORG/MODEL \
  --revision MODEL_REVISION --record-dir ./obliteratus/recipes/data \
  --accepted-by REVIEWER

One passing confirmation of the unchanged family qualifies that exact model ID and revision for individual promotion, including while the family itself is a candidate. The new accepted recipe inherits the family pipeline and evaluation profile. When the confirmation used a recorded member override, the individual recipe pins that override. The command requires an unused individual model and revision binding. It saves the exact confirmation alongside the family promotion evidence.

RecipeRegistry(data_dir).is_confirmed_member(family, model_id, revision) checks the exact member identity and current family. After acceptance it also recognizes confirmations tied to the saved candidate as long as its family declarations still match.

Evaluation profiles

A recipe can pin one obliteratus.evaluation-profile/v1 document. Set evaluation.profile to the file path relative to the recipe JSON and evaluation.sha256 to the SHA-256 of that file's exact bytes.

"evaluation": {
  "profile": "profiles/llama3.1-8b-instruct.json",
  "sha256": "<64 hex characters>"
}

Profiles have a name, semantic version, and scope of family or individual. Use spec for partial verify-edit settings such as heldout.source, endpoints.capability.tier, temperature, generation_seed, and batch_invariant. An individual profile can pin a family profile with inherits: {"path": "family.json", "sha256": "..."}. Individual declarations override family declarations field by field, and any remaining fields use verify-edit defaults. Use kl_policy: "gate" to require KL to pass, or "advisory" to measure and report KL without affecting the overall verdict. An omitted policy inherits or uses the verify-edit default.

Calibration entries specify kind (noise_floor or random_control), a relative path, the evidence file's sha256, and adopted thresholds keyed by verify-edit field path. For example, setting "endpoints.kl.max_first_token_kl": 0.00258 supplies that limit at the declaring profile's scope. The resolver checks each evidence file's raw digest and schema. The declared values are what the profile adopts and may round the original suggestions. If a threshold is also specified in spec at the same scope, both values must agree. Evidence and family paths are relative to the profile that declares them.

The packaged Llama-3.1-8B-Instruct candidate ships with its random-control evidence. Its first-token and next-token KL limits are 0.00258 and 0.02087, with advisory KL while the gating decision is pending. Its capability settings use the quick tier, greedy decoding, seed 42, and batch invariance.

Pass the recipe file or name to recipe confirm. Projection steps use the pinned protocol train partition. An omitted evaluation binding can inherit the family profile. Set evaluation: null to disable confirmation. The confirmation records the profile bindings, the calibration source for each effective adopted limit, and the canonical SHA-256 of the resolved spec.json. A passing individual's accepted recipe retains the profile binding to the digest-locked evaluation profile emitted beside it.

For standalone verification, pass the resolved spec.json and its digest to verify-edit --spec and --spec-sha256. Python callers can obtain the spec and provenance directly with resolve_profile(path) or resolve_recipe_profile(recipe, directory=recipe_path.parent) from obliteratus.recipes.

V2 core contract

load_recipe(path) and validate_recipe(record) select the bundled schema by the record's schema field. Use obliteratus.model-recipe/v2 for v2 records. The v2 core requires a recipe name and version, engine.min_version, engine.normalizer, a target, and an ordered, nonempty pipeline. The current normalizer is recipe-normalizer/1.

  • target.scope is individual with an exact identity, or family with a v1-style match rule. Structural predicates in target.requires use booleans, nonempty lists of allowed scalar values, or ranges with numeric min and max.
  • Top-level inputs maps names to pinned references. Each has a kind, a split role, and the fields described below for that kind.
  • Each pipeline.steps entry has a unique id, technique, technique_version, and params object. inputs and outputs list names so a step can refer to recipe inputs or outputs from an earlier step. placement and constraints are open objects. The Python validator also checks step ID uniqueness when duplicate IDs appear on otherwise different steps.
  • evaluation can pin an evaluation profile by profile and sha256, or be null. The record also carries lifecycle status, acceptance metadata, evidence, optional inherits, and notes.

Register a TechniqueSpec with TechniqueRegistry.register_technique(spec). The registry looks up exact (id, version) pairs. Each spec supplies a parameter schema, a deterministic and idempotent normalize(params, context) function, an applier, and a schema for its resolution payload. The applier receives the current state, normalized parameters, resolved placement and inputs, and constraints. It returns the next state, named outputs, and the resolution payload.

normalize_recipe(record) returns a new record using the built-in technique registry. Pass registry=registry to use a custom registry. Normalization checks the core shape and validates each step's parameters before and after applying its technique normalizer. Parameter schemas cover both forms and use the offline validator's supported JSON Schema keywords. These include types, object properties, required keys, array items, bounds, enums, conditionals, combinations with anyOf or allOf, and direct local $defs references. Registration rejects unsupported keywords.

Normalization fills in empty inputs, evidence, requirements, placement, constraints, step input and output lists, and notes. The default status is candidate with null acceptance fields. Evaluation defaults to null on records without a parent. Normalization sorts object keys, preserves step order, and writes canonical_sha256 as the lowercase SHA-256 of the compact canonical JSON with that field omitted. Normalizing again recalculates the digest.

Pinned v2 inputs

Name each input at the top level and list the names that a step consumes in pipeline.steps[].inputs. For example, a projection that fits the built-in Qwen3.8 training split can declare:

{
  "extract": {
    "kind": "protocol_split",
    "role": "train",
    "dataset": "qwen38-v1",
    "split": "train",
    "sha256": "ba65938b24eeaefd51e9780d2915a82bc5bdfa6ebeee541e9157ccfc3dccf692"
  }
}

Set the projection step's inputs to ["extract"]. Names can also refer to outputs from earlier steps.

Kind Kind-specific fields Digest and resolved value
protocol_split dataset: "qwen38-v1", split, sha256 Prompt pairs. The train pin is the protocol manifest SHA-256. The tune and final_test pins hash the canonical JSON of the full verify-edit partition identity used by search and confirmation.
prompt_pairs_file path, sha256 Prompt pairs from the JSON object with harmful and harmless arrays. The pin hashes the exact file bytes.
concept_pack id, pack_hash The materialized concept target for a built-in or installed pack, verified against the concept registry's pack SHA-256. Remote pack data must already be cached.
chat_template source: "tokenizer" or "file", sha256, and path for file sources The template string. Hash its UTF-8 bytes for a tokenizer source or the exact UTF-8 file bytes for a file source. A tokenizer source requires a loaded model handle or local checkpoint path.
reference_model Hub model id, exact 40-hex revision, optional inventory sha256 A cached snapshot at the declared commit. The resolved SHA-256 hashes the canonical JSON of its file inventory, as in verify-edit. Supply sha256 to require a particular inventory.
recovery_corpus path or id, and sha256 A local recovery dataset directory. Hash the canonical metadata returned by load_recovery_dataset with digest(json_bytes(metadata)). The loader verifies the dataset records and rejects partial corpora.
runtime_binding description, optional type (path, directory, or model_state) A value supplied for a particular run. A directory may be an output location that does not exist yet. A model state accepts a loaded model handle or an existing local model directory. The binding has no content digest.

normalize_recipe checks names, fields, and role permissions and canonicalizes digests to lowercase hexadecimal. Concept steps with omitted extraction parameters also read the pinned pack descriptor to expand those defaults. resolve_inputs(recipe, base_dir=recipe_dir, model=handle) verifies the content and returns named ResolvedInput values with kind, role, sha256, and value. Relative files resolve from base_dir. Resolution uses local files and caches.

Fitting techniques can consume train and calibration inputs. Recovery corpora use one of these two roles. Runtime bindings use the runtime role for values such as checkpoint and export locations. evaluation.search consumes tune inputs, and evaluation.confirmation consumes final_test inputs. The v2 input resolver recognizes these evaluation step roles. The existing search and confirmation commands provide the evaluation runtimes. A built-in partition must use its own role. Prompt-pair files are checked for overlap with incompatible protocol partitions and with other declared fitting or evaluation data.

Run a pinned prompt-pair projection through obliteratus.recipes.projection_runtime.apply_projection_step(state, recipe, step_id="project", base_dir=recipe_dir, checkpoint=destination). The step requires one train prompt-pair input of kind protocol_split or prompt_pairs_file. Add the name of a pinned chat_template input if the projection enables chat formatting. The applied step and any exported resolution sidecar record the consumed digests by name in input_sha256.

Projection technique v1

Use technique: "abliteration.projection" and technique_version: "1". You can start with params: {"preset": "advanced", "overrides": {}} or author the structured parameters directly. Normalization expands the preset into direction_source, operator, embeddings, safeguards, post, and backend options. For example, advanced resolves embedding regularization to 0.5, while qwen38_e03 uses the pipeline fallback of 0.35. Direction scope is per_layer by default. To share one direction basis across the edit, set scope: "global" and provide an extraction_layer index or an object such as {"fraction": 0.5}. SOM remains unavailable, matching the legacy pipeline.

  • Set step placement.layers to pin the edit. Score-based selectors resolve during extraction. An omitted placement retains the preset's layer selection.
  • Set direction_source.analysis_device or the shorthand overrides.analysis_device to auto, model, or cpu. Both auto (the default for new recipes) and model request float32 analysis on a supported single CUDA or MPS device. The pipeline logs its reason for using the CPU when placement is offloaded, split, unsupported, or short of free memory. Resolution records and checkpoint metadata record the device used. Accelerator results can differ numerically. Shipped and v1-migrated recipes pin cpu to reproduce their CPU directions. Direct pipeline calls retain their CPU default and can opt into either accelerator policy. Set OMP_NUM_THREADS to control the host's PyTorch thread budget.
  • writers: "pipeline" uses the pipeline's configured projection target. The attn_out and mlp_out roles select output-only projections when authoring leaves that target implicit. Explicit writer selections must match the modules the pipeline can project in the selected mode.
  • Set lm_head: "skip" to preserve the output head and any tied input embeddings. When projecting a tied head, set allow_tied_head_edit: true.
  • Explicitly set safeguards.small_model_caps or the legacy override small_model_safeguards to choose the small-model cap policy. An edit that would apply undeclared small-model caps is rejected before weights change. post: {"kind": "kl_rollback", "budget": 0.5} applies the token KL budget. If meeting the budget would restore a pinned layer, the pipeline rejects the edit.

The projection applier accepts a loaded ModelHandle or local checkpoint path. For direct technique calls, pass the resolved prompt lists as inputs["extraction"] = {"harmful_prompts": [...], "harmless_prompts": [...]}. Optional inputs include a resolved chat_template string when formatting is enabled and a local checkpoint destination for export. The result contains the model handle, extracted directions and subspaces, and the resolution payload. The payload records the surviving layers and writers, effective ranks and parameters, safeguards, the tied-head decision, restored groups, and SHA-256 digests for any checkpoint files.

Concept-pack edits

Use a named train input of kind concept_pack and reference it from params.direction_source as {"kind": "concept_pack", "input": "concept"}. The input pins the registry ID and the pack hash. The step consumes that one input. Normalization expands the pack's direction method, control pooling, readout, layer selection, model-specific extraction pins, intervention layer rule, steering scale, and preserve list. Explicit fields override the pack defaults. Normalizing the resulting parameters again needs only the recipe. Applying the step verifies the pack hash and requires the prompt data in local files or caches.

concept_recipe_to_v2(pack) builds the step from a loaded pack descriptor. Add it and its input to a v2 recipe with your target and engine declarations.

from obliteratus.concepts.registry import ConceptRegistry
from obliteratus.recipes import concept_recipe_to_v2, normalize_recipe

pack = ConceptRegistry().pack("pain")
recipe["inputs"] = {
    "concept": {
        "kind": "concept_pack",
        "role": "train",
        "id": "pain",
        "pack_hash": pack.sha256,
    }
}
recipe["pipeline"] = {"steps": [concept_recipe_to_v2(pack)]}
recipe = normalize_recipe(recipe)

The pain pack's dose ladder uses steering.activation_addition version 1. The built-in refusal pack uses abliteration.projection version 1 and retains its paired final-token extraction. Concept-pack projection uses in-memory residual-writer orthogonalization. When placement.layers is omitted, the pack's intervention layer rule chooses the edit layers. A static placement.layers override follows the concept pipeline's layer-pinning behavior. Use the pack's cv_auc setting for score-based concept selection.

Pass the pack ID as the named binding when calling apply_recipe, for example inputs={"concept": "pain"}. The step fits on the current model and uses the concept validation gate. Set params.override_gate to record an explicit reason for an override. Any preserve entries use the concept runtime's existing refusal keyword or local direction artifact paths. The resolution records the input digest, extraction and intervention layers, and the validation report.

Steering defaults to alpha: -1.0 and positions: "all_tokens". Declare the intervention output to get the applied hooks. They stay active on the returned model until you call result.outputs["intervention"].remove(). If a later step fails, apply_recipe removes the hooks before returning the error. Use the declared concept_direction output to inspect extracted vectors, subspaces, and layers.

Projection followed by LoRA repair

adapter.lora_repair version 1 trains on the current pipeline model using the assistant-only recovery loss. Install the recovery extra and use a resident, unquantized CPU float32 model with a chat template. The repair step trains on a copy of the edited model, so allow memory for that copy and the adapter.

Build a complete local recovery corpus with obliteratus recovery-data. Enter the SHA-256 of its generated metadata.json in the recovery input, and enter the prompt pair source's digest in extraction. The recovery metadata pins the normalized rows and their source provenance. The training_data.role must match the declared train or calibration role.

{
  "schema": "obliteratus.model-recipe/v2",
  "name": "tiny-projection-repair",
  "version": "1.0.0",
  "engine": {"min_version": "0.1.4", "normalizer": "recipe-normalizer/1"},
  "target": {"scope": "individual", "identity": {"model_id": "tiny", "revision": "local"}},
  "inputs": {
    "extraction": {
      "kind": "prompt_pairs_file", "path": "pairs.json", "sha256": "<prompt-pair file SHA-256>", "role": "train"
    },
    "recovery": {
      "kind": "recovery_corpus", "path": "recovery-data", "sha256": "<canonical metadata SHA-256>", "role": "train"
    },
    "checkpoint": {
      "kind": "runtime_binding", "description": "Projected checkpoint destination", "type": "directory",
      "role": "runtime"
    },
    "artifact_dir": {
      "kind": "runtime_binding", "description": "Repair export destination", "type": "directory",
      "role": "runtime"
    }
  },
  "pipeline": {
    "steps": [
      {
        "id": "project",
        "technique": "abliteration.projection",
        "technique_version": "1",
        "params": {"preset": "basic", "overrides": {"lm_head": "skip", "seed": 11}},
        "placement": {"layers": [1]},
        "inputs": ["extraction", "checkpoint"],
        "outputs": ["checkpoint"]
      },
      {
        "id": "repair",
        "technique": "adapter.lora_repair",
        "technique_version": "1",
        "params": {
          "training_data": {"input": "recovery", "role": "train"},
          "rank": 2, "alpha": 4, "steps": 3, "max_length": 64, "seed": 73, "merge": false
        },
        "placement": {"layers": [1], "writers": ["attn_out"]},
        "inputs": ["recovery", "checkpoint", "artifact_dir"],
        "outputs": ["artifact"]
      }
    ]
  }
}

Call the Python API with the loaded model, the resolved target metadata, and a caller binding for every declared input. Supply local paths for file-backed pins and corpora. For logical sources, supply the declared dataset, ID, or "tokenizer" source. Relative bindings resolve against base_dir, which defaults to the current directory. checkpoint starts as the projection destination. Projection publishes the resulting path under the same name, and repair uses it as the base checkpoint in the adapter config.

from obliteratus.recipes import apply_recipe, load_recipe
from obliteratus.recipes.resolution_records import write_resolution

result = apply_recipe(
    load_recipe("tiny-projection-repair.json"),
    initial_state=handle,  # Loaded CPU float32 ModelHandle for the selected target.
    target={"model_id": "tiny", "revision": "local",
            "structure": {"tie_word_embeddings": handle.config.tie_word_embeddings}},
    inputs={
        "extraction": "./pairs.json",
        "checkpoint": "./projected",
        "recovery": "./recovery-data",
        "artifact_dir": "./repaired",
    },
)
write_resolution("recipe-resolution.json", result.resolution)

apply_recipe normalizes the recipe, checks for missing or extra bindings, and verifies pinned inputs before the first step. It runs steps in order and supplies each with the preceding state and its declared inputs. Use distinct output names across steps. A step can publish an output under one of its runtime input names, as projection does with checkpoint. The result carries the final state, the declared outputs, and one resolution record for the whole run.

Repair targets the exact modules resolved by placement.writers. With merge: false, the output directory holds a PEFT adapter for the projected checkpoint. For an in-memory base, omit checkpoint from the recipe declarations and steps, and supply that same edited base explicitly when loading the adapter. With merge: true, the output holds a standalone model checkpoint and tokenizer. steps is an exact optimizer-update count. When omitted, training follows the configured epochs from RecoveryConfig. The repair resolution records the effective settings, trained modules, loss summary, and SHA-256 of each exported file.

Checkpoint resolution records

recipe-resolution.json ships beside newly exported abliteration checkpoints. It uses obliteratus.recipe-resolution/v1 and records the recipe SHA-256 when available, engine version and code commit, source model and revision, known model structure including tied embeddings, and creation time. Each ordered step names its technique and version, hashes its parameters, and carries the technique's applied payload and any artifact paths and SHA-256 digests. The optional input_sha256 object binds input names to their verified content. The optional runtime_bindings array lists runtime input names in sorted order. Artifact entries identify the exported files separately.

obliteratus.recipes.resolution_records provides read_resolution(path), write_resolution(path, record), and resolution_digest(record). Writing returns the SHA-256 of the canonical JSON. Digests preserve step order and are independent of object key order and JSON formatting. Pass registry=registry to check each known technique version's payload against its TechniqueSpec.resolution_schema. A native producer can place AppliedStep.resolution in the step's payload and hash the normalized parameters in params_sha256.

The legacy checkpoint exporter emits one abliteration.projection version 1 step. Its payload carries method, method_config, concept, the final strong_layers, effective_subspace_ranks, rollback groups, and the recorded layer diagnostics and weights. The pipeline hashes the recorded method_config as the step parameters. For an older checkpoint, resolution_from_metadata(checkpoint_dir) reads this geometry from abliteration_metadata.json and checks the inputs required by random calibration. Legacy metadata has no creation time, so adapted records use the fixed created_at sentinel 1970-01-01T00:00:00+00:00; their digest depends on the checkpoint content, not on file times. Unknown provenance is represented by nulls. Confirmation requires the pipeline's resolution sidecar and saves its canonical digest and contents for promotion review.

Migrate a v1 recipe

Pass a validated v1 record to migrate_v1(record) to produce v2 authoring intent. Migration copies the target, lifecycle, evidence, and inheritance. It maps edit.method and edit.overrides to params.preset and params.overrides on one abliteration.projection step at version 1. It sets params.allow_tied_head_edit: true and appends a migration note to the existing notes. v1 had no head-specific opt-out. The permission preserves edits to shared head and embedding weights when the execution path projects the head. It has no effect on untied weights or paths that omit head projection. In v2, params.lm_head: skip explicitly preserves the head. A margins spec path and digest become evaluation.profile and evaluation.sha256. When a v1 child omits its method or margins, migration leaves the corresponding v2 preset or evaluation absent so the child can inherit it. Explicit null margins migrate to null evaluation. When a migrated binding still points to a v1 margins spec, confirmation verifies that pinned spec and records its resolved settings. load_recipe(path) migrates legacy files automatically. write_recipe(record, path) requires valid v2 intent.

The v2 design describes the full pipeline contract and the issues that cover placement, resolution records, evaluation, and inputs.