Files
OBLITERATUS/docs/checkpoint-verification.md
Joseph Magly 90eae790a2 fix(chat-template): catch getattr and alias bypasses and pin operator vLLM kwargs
The completeness guard only flagged x.apply_chat_template(...) calls, so a
getattr call, a getattr or bound-method alias, or functools.partial passed
it. It now flags any apply_chat_template attribute or getattr lookup outside
the helper unless it is passed directly to callable() or hasattr(), and the
two capability probes use that form.

When an operator passes --default-chat-template-kwargs without date_string,
merge the pinned date into that JSON object (operator keys win) instead of
leaving vLLM unpinned. Document that scripts/ stays unpinned, the vLLM
version that first has the flag, that every resolved spec digest changes,
and that older verify-checkpoint references for date templates will not
match the pinned render.
2026-11-27 13:50:44 -05:00

6.9 KiB

Checkpoint reload verification

The REBIRTH stage of obliteratus obliterate validates that saved files exist and parse, then promotes the checkpoint atomically. That check is structural: it does not reload the model or generate. A save can write valid-looking files and still lose the edit, for example through a missed tied weight, a dtype loss or a quantization round trip. obliteratus verify-checkpoint reloads the saved checkpoint and confirms that it reproduces the edited model's behaviour.

REBIRTH copies processor configuration files from the local source directory or the cached source revision into the checkpoint alongside the tokenizer files. These can include preprocessor_config.json, video_preprocessor_config.json, processor_config.json, and audio and feature-extractor configurations. The export uses only files already available locally. When any are copied, abliteration_metadata.json records their SHA-256 digests in the processor_config_sha256 map. Local checkpoint validation rejects missing or modified copies, and projection recipe resolution records carry the same digests.

Recording a reference at save time

Reference recording is opt-in, so default runs do no extra work:

obliteratus obliterate meta-llama/Llama-3.1-8B-Instruct --output-dir ./liberated \
    --record-reference

With --record-reference, REBIRTH greedy-decodes the fixed prompt set obliteratus-verify-v1 on the in-memory edited model before it writes any files. The prompt set is the first 8 built-in harmful prompts and the first 8 built-in harmless prompts, with up to 32 new tokens each. The run writes verification_reference.json into the staging directory with the other checkpoint files, so it is promoted atomically with them. The file records the prompts, the rendered input ids, the generated token ids and text, the refusal-detector version, the recording runtime and the SHA-256 of every file the reload reads. If recording fails, the run logs the error and still saves the checkpoint. A later verification of that checkpoint then fails with no_reference.

The prompt set is pinned by digest. If the built-in prompts change, recording refuses to run until the set is given a new version.

The flag is available for local runs only. --remote runs reject it.

From Python, obliteratus.verify_checkpoint.record_reference(model, tokenizer) returns the same JSON object. Store it anywhere and pass it with --reference.

Verifying

obliteratus verify-checkpoint ./liberated                 # uses the sidecar
obliteratus verify-checkpoint ./liberated --reference ref.json --stock-model ./stock
obliteratus verify-checkpoint ./liberated --quantization 4bit --device cuda

The command loads the checkpoint in its own process with local_files_only=True, use_safetensors=True and trust_remote_code=False, and tokenizes each reference prompt again with the reloaded tokenizer, applying its chat template when one is configured. It then greedy-decodes each prompt, one at a time and without padding. Chat templates are rendered with a fixed date (26 Jul 2024, #690). A reference recorded before that change for a model whose template renders a date (Llama-3.2 and similar) stored input ids rendered with that day's date, so it fails with tokenizer_mismatch; record a new reference. Unless --dtype is set, the reload uses the dtype recorded with the reference.

The checkpoint passes only when every check below holds:

Check Failure code
A reference exists no_reference
The reference contains generated tokens empty_reference
Reload-relevant files match the digests recorded at save time checkpoint_changed_since_reference
The reloaded tokenizer renders identical input ids tokenizer_mismatch
Exact-match rate (identical generated token ids) meets the tolerance exact_match_below_tolerance (names the first failing prompt and the divergence index)
Mean prefix agreement (length of the shared token prefix divided by the longer output) meets the tolerance prefix_agreement_below_tolerance
The harmful-prompt refusal rate does not rise by more than the tolerance refusal_rate_increase
Harmful-prompt completions are not all invalid checkpoint_outputs_invalid
With --stock-model, outputs do not exactly reproduce the stock model when the reference differs from it edit_not_persisted

A structural-only check never passes. Without a reference, the verdict is fail.

Tolerances

Reload Min exact match Min mean prefix agreement Max refusal-rate increase
none (same-dtype safetensors) 1.0 1.0 0.0
8bit (bitsandbytes) 0.5 0.75 0.125
4bit (bitsandbytes NF4) 0.25 0.5 0.25

The defaults for the quantized modes are provisional and uncalibrated. Override them with --min-exact-match, --min-prefix-agreement and --max-refusal-increase. Every report records the tolerance it applied. Reloading on a different device or in a different dtype from the one used at recording can change greedy tokens through ordinary numerical differences. In that case, declare a tolerance explicitly; do not treat the strict default as a defect.

Quantized reloads need CUDA and the bitsandbytes package. Without either, the command exits with an input error. It does not fall back.

Report and exit codes

The report is written to --report, or by default to <checkpoint>.verify-report.json next to the checkpoint. --json also prints it. The report uses schema obliteratus.checkpoint_verification, version 1, and includes:

  • the verdict and the reasons for it;
  • the checkpoint path, the SHA-256 of each reload-relevant file and a combined digest;
  • the model identity: source model and revision from abliteration_metadata.json, plus the model type and architectures;
  • the reference prompt-set id and digest, the recording runtime and whether the reference was bound to file digests;
  • the verification runtime: device, dtype, quantization, and the Python, torch, transformers, bitsandbytes and CUDA versions;
  • the applied tolerance, aggregate metrics and per-prompt rows, including the first divergence index and the refusal flags.
Exit Meaning
0 Verification passed
2 Unusable input or runtime: missing checkpoint, malformed reference, unavailable CUDA or bitsandbytes, or a bad option
3 Verification failed. A failed obliterate quality gate uses the same code

Testing

The default CPU suite (tests/test_verify_checkpoint.py) builds a tiny local GPT-2 model and covers four cases: a correct round trip through REBIRTH and a separate process, an edit that was never persisted, a tensor changed after the save, and a missing or malformed reference. The CUDA and bitsandbytes reload paths run in the cuda-runtime and bitsandbytes-runtime conditional gates (tests/conditional/test_verify_checkpoint_cuda.py).

For the end-to-end operator sequence that uses this command, see INITIAL_CORE_RUN.md.