Measure an LLM once under one decoding setting, then estimate its failure rate under any temperature, top-p or top-k. No new generation, exact likelihood ratios, and a check that tells you when the answer can't be trusted.
A reported failure rate (unsafe code, refusals, jailbreak success) depends on the model and on the temperature / top-p / top-k that sampled it. The effect is largest on the prompts where failures are rare, and a single benchmark average can hide it.
Temperature, top-k, top-p and greedy are deterministic maps from the model's next-token logits to a distribution. Two decoders on the same model share those logits, so one teacher-forced pass over stored completions gives the exact likelihood ratio for any target.
The core needs only numpy; decodeshift.hf adds Hugging Face models.
# install git clone https://github.com/ziwaa-se/decodeshift.git cd decodeshift pip install -e ".[hf]" # CPU demos with exact ground truth python examples/01_audit_once_evaluate_many.py python examples/02_support_barrier.py python examples/03_prefix_weighting.py # a real model python examples/04_huggingface_quickstart.py
from decodeshift import UNTRUNCATED, Decoder, hf model, tok = hf.load("Qwen/Qwen2.5-0.5B-Instruct") audit = hf.sample(model, tok, prompts, UNTRUNCATED, n_per_prompt=64) targets = [Decoder(temperature=0.7), Decoder(top_p=0.9), Decoder(top_k=50)] scores = hf.score(model, audit, targets) # one pass event = [detector(t) for t in audit.texts] for t in targets: est = hf.estimate(scores, event, t) print(t.name, est.estimate, est.interval())
All of these are regenerated from the shipped result files by reproduce/scripts/make_outputs.sh.
exp(−D̂) is an empirical approximation, used to decide whether a transfer is worth attempting.| Command | What it does |
|---|---|
make_outputs.sh | every table and figure from the shipped CSVs · CPU, ~1 min |
run_core.sh | re-run transfer, barrier, efficiency, prefix, safety, bounds · 1 GPU |
run_variants.sh | other models (Qwen2.5-7B, Mistral-7B, SmolLM2-1.7B), severity, seeds |
pytest | 22 tests: exact identity by enumeration, HF generate parity |
About 36 GPU-hours in total, mostly independent direct sampling used for validation.