Skip to main content

behavior-diff

PyPI Python CI Docs Open In Colab License: MIT

bdiff demo: 5 of 14 behavior categories changed, led by 'Uses concise response style' on 25 prompts against 10 (q=0.047); the same-model control changed 0 of 14

What did my fine-tune change? behavior-diff samples a base model and a fine-tune on the same prompts, has a judge model describe how each pair of replies differs, groups those descriptions into named behaviors, and tests each one. A same-model control (the base against itself) tells you how far to trust the answer.

Docs: behavior-diff.mintlify.site · Why it exists (the write-up) · Use cases · Research note

What it does

  1. Prompts. 64 everyday items in 8 kinds (instruction following, over-refusal, harmful requests, sycophancy, verbosity, honesty about uncertainty, tool-use caution, knowledge), each drawn twice under random input conditions: system persona, who the user says they are, stakes, reply language. 128 prompts. Bring your own.
  2. Samples the base twice (seeds 1 and 2) and the fine-tune once (seed 2).
  3. Describes. A judge sees each pair of replies in a random order and lists every behavior one shows and the other does not.
  4. Names. The judge groups the descriptions into 5 to 15 categories and assigns each description to one, with a polarity, so "is shorter" and "is longer" count on the same axis.
  5. Tests. Per category, a sign test on how many prompts point to each model, Benjamini-Hochberg across categories (changed = q < 0.05), a breakdown by input condition with permutation tests, and a label-shuffle check.
  6. Controls. The same categories, tested on the base against itself. A run you can trust shows 0 changed there.

The output is report.html and report.json: the changed categories with counts, the condition breakdown, the control, and example prompt / base / fine-tune triples.

Quick start

The package is bdiff on PyPI. (PyPI treats behavior-diff as too close to an unrelated project, behaviordiff.)

pip install bdiff
bdiff demo          # no key, no GPU, no network: replays a real run from saved data
open behavior-diff-demo/report.html

On your own models (the judge defaults to an open-weight model on OpenRouter; --judge-url takes any OpenAI-compatible endpoint, including your own vLLM server):

pip install "bdiff[tinker]"
export TINKER_API_KEY=... OPENROUTER_API_KEY=...
bdiff run --tuned tinker://<run-id>/sampler_weights/final          # the base is read from the checkpoint

pip install "bdiff[modal]" && modal setup                   # vLLM on a Modal GPU
bdiff run --base modal:Qwen/Qwen2.5-7B-Instruct --tuned modal:Qwen/Qwen2.5-7B-Instruct+<owner>/<lora-repo>

bdiff run --base file:base.jsonl --base-control file:base_seed2.jsonl --tuned file:tuned.jsonl   # sampled elsewhere
Model spec Samples from Needs
tinker://<checkpoint> a Tinker checkpoint bdiff[tinker], TINKER_API_KEY
tinker-base:<model> a Tinker base model same
modal:<repo>[+<adapter repo>[/<subfolder>]] vLLM on a Modal GPU, optional LoRA bdiff[modal], modal setup
openai:<model>@<url> any OpenAI-compatible server (vLLM, Ollama, ...) BDIFF_API_KEY or OPENAI_API_KEY
hf:<repo>[+<adapter repo>[/<subfolder>]] local transformers, optional PEFT adapter bdiff[hf]; small models
file:<replies.jsonl> replies you sampled elsewhere rows {"id", "reply"}

The demo: a bullet-point LoRA, found from saved data

bdiff demo reruns the whole pipeline on a live Tinker run from the research note: a Qwen3-8B LoRA trained for 30 steps to answer in bullet points, the base sampled twice and the fine-tune once on the 128 default prompts. Every judge reply is cached in the package, so nothing is called:

$ bdiff demo
128 prompts -> behavior-diff-demo/prompts.jsonl
sampled: tuned 128, base 128, base2 128
5 of 14 categories changed; judge $0.05 -> behavior-diff-demo/report.html
  toward base: 2 vs 22  q=0.0005  Engages empathetically
  toward base: 4 vs 24  q=0.0013  Provides incomplete output
  toward base: 6 vs 24  q=0.0064  Offers detailed explanations
  toward base: 1 vs 13  q=0.0064  Includes specific examples
  toward tuned: 25 vs 10  q=0.047  Uses concise response style
same-model control: 0 of 14 changed
  P8: pre-registered weak hit; post hoc hit (as stated); category: Uses concise response style

The fine-tune is named as "Uses concise response style ... often in lists" (25 prompts against 10, q = 0.047), with lost empathy, detail and examples. Its shorter replies were also cut off by the 300-token limit less often. The same-model control changed 0 of 14 categories. Counted directly, 125 of 128 fine-tune replies were bullet lists, against 2 of 128 for the base. The base already formats with markdown lists, so the judge named the change as a terser style rather than a format. The prediction written before the run ("a changed category about bullet or list formatting") is scored as a weak hit, because it matches only the category's definition.

Pre-registered vs post hoc

Write down what you expect before you look, and the report scores it two ways, kept apart:

{"expectations": [{"id": "K1", "claim": "The fine-tune gives wrong answers more often",
                   "match": "wrong|incorrect", "direction": "tuned",
                   "opposite": "accura|correct", "factor": "trigger"}]}
bdiff run --base ... --tuned ... --expect expect.json    # locked (SHA-256 + UTC time) before sampling
bdiff score behavior-diff-report --expect expect.json    # rescore a saved report; warns if the file changed
  • Pre-registered: a changed category pointing in direction whose name matches match is a hit, and a match only in its definition is a weak hit. With factor, the change must also depend on that condition (pooled, p < 0.05).
  • Post hoc: this also accepts the change named the other way round (opposite, pointing the other way: "gives accurate answers" lost instead of "gives wrong answers" gained), and it tests factor within the prompt kind where the category moved most. The report always labels this column as exploratory.

Per-generation drift

For self-improvement loops, iterated RL or any chain of checkpoints:

bdiff generations tinker://.../gen0 tinker://.../gen1 tinker://.../gen2 tinker://.../gen3 --names base,g1,g2,g3

The first checkpoint is the base. It reports each step (generation i-1 against i) and each generation against the base, with a same-model control, on one shared category set, so a row means the same behavior in every column. It also flags slow drift: a category that changes against the base although no single step changed it. Small steps can each stay under the test's power and still add up. Output: generations.html, generations.json.

How it compares

behavior-diff borrows from all of these tools, and they answer different questions.

Tool Question it answers Works on Statistics and controls Best for
behavior-diff Did a behavior change between a base and its fine-tune (or across N checkpoints), how often, and under which input conditions? Single replies from each version on the same prompts A sign test per category with Benjamini-Hochberg correction, a same-model control, label shuffles, per-condition permutation tests, pre-registered scoring A cheap side-effect check after every fine-tune; drift across generations
VibeCheck (paper) Which qualitative traits ("vibes") predict which model wrote a reply, and which reply people preferred? Two models' replies on the same prompts, optional preference labels A classifier over vibe scores, with vibes kept by fixed score thresholds; in-sample accuracy by default Comparing two models, and linking style to preference
diffing-toolkit What changed inside the model: which activation directions, latents or tokens did a fine-tune move? Weights and activations of a base and a fine-tune Per method (crosscoders, SAE and activation differences, KL, ...), with dashboards and an agent-based evaluation of the methods White-box diffing that can show traces outputs alone may not
Docent What happens across many transcripts, and which ones match a rubric? Transcripts you already have, one model at a time Rubrics written in advance, judged by a model; search and clustering for exploration, with a UI Reading and auditing large sets of agent transcripts
Petri Does a model do X under pressure, when an auditor agent probes it? One target model, seed scenarios, simulated tools, rollbacks A judge scores each transcript on dimensions named in advance Alignment audits with multi-turn and tool-using scenarios
  • VibeCheck is the closest relative. Both tools have a model propose differences between two models' replies, group them into two-ended axes, and judge every prompt in both A/B orders. VibeCheck then asks whether a vibe predicts identity and preference. behavior-diff asks whether a behavior changed, with a significance test and a same-model noise floor, which VibeCheck does not have. VibeCheck models preference, which behavior-diff does not. behavior-diff breaks each change down by designed input conditions, which VibeCheck does not.
  • Docent and Petri score one model at a time against rubrics written in advance, with no same-model control. They are stronger for transcripts and agentic, multi-turn behavior. Docent's clustering is exploratory, with no significance test.
  • diffing-toolkit looks at activations and weights. behavior-diff sees only outputs.

Working together

  • VibeCheck: bdiff import-vibecheck data.csv --models a,b -o in/ reads VibeCheck's CSV layout for bdiff compare, and bdiff export-vibecheck writes bdiff's data in that layout.
  • Possible extensions, not built yet: a bdiff export-docent command with one Docent run per prompt, holding three transcripts (base seed 1, base seed 2, fine-tune) and the q-values as metadata. And Petri seed sets as prompt suites, with each version's audit replies read in through file:.

Limitations

  • Power. By default it takes one reply per model per prompt, on 128 prompts. A behavior on well under 5% of prompts will not reach significance. Add prompts or draws (--draws) or use a targeted eval.
  • The judge's reading. Categories and their names are a model's reading. The Tinker example shows a change named by its consequences, not its form. Read the example pairs before you act on a category.
  • Single replies. No multi-turn conversations, tools or agent environments.
  • Black box. It sees outputs, not weights. It tells you what changed, not where in the model.
  • Judge cost and access. The default judge is a hosted open-weight model (about $0.05 for the default run). For an offline judge, point --judge-url at your own server.
  • One validation study. The method was tested on a password-locked model, an emergent-misalignment LoRA and the Tinker run in the research note. The fixes made there (within-kind condition tests, agreed assignment, a seed per prompt) were tuned on that data. bdiff generations is tested on synthetic chains only so far.

Python API

from bdiff import judge, prompts, stats
from bdiff.backends import make_sampler
from bdiff.llm import Client

ps = prompts.expand({"items": [{"id": "q1", "kind": "advice", "text": "Should I ..."}], "draws": 1})
ref = make_sampler("openai:base@http://localhost:8000/v1", seed=1).sample_all(ps)
new = make_sampler("openai:ft@http://localhost:8001/v1", seed=2).sample_all(ps)
chat = Client("qwen/qwen3-235b-a22b-2507", cache="judge_cache.jsonl")
diffs = judge.describe_all(chat, ps, ref, new)
cat = judge.categorize(chat, diffs)
rows = stats.summarize(cat["categories"], cat["labels"], ps, [d["id"] for d in diffs])

Development

uv venv && uv pip install -e ".[dev]"
ruff check . && ruff format --check . && mypy src && pytest     # CPU only, a few seconds, no network

Releases go to PyPI from the Release workflow with trusted publishing. The history of bdiff before 0.1.0 comes from steerlab's packages/behavior-diff, and the demo data from its experiments/behavior-diff/results/tinker/.

Citation

@software{behavior_diff,
  title  = {behavior-diff: what did my fine-tune change?},
  author = {Lie, Albert},
  year   = {2026},
  url    = {https://github.com/albertlieyingadrian/behavior-diff}
}

MIT licence.

Metadata

Release files for bdiff 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for bdiff 0.1.0
File Size Uploaded Provenance Actions
bdiff-0.1.0.tar.gz 167.5 kB Without provenance Details for bdiff-0.1.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for bdiff 0.1.0
File Interpreter ABI Platform Actions
bdiff-0.1.0-py3-none-any.whl Python 3 none any Details for bdiff-0.1.0-py3-none-any.whl

Total release size: 333.9 kB

Release files / bdiff-0.1.0.tar.gz

Download URL bdiff-0.1.0.tar.gz
Size 167.5 kB
Tags Source
SHA-256 checksum
How to use checksums
54c9a6223b6256b6ccbb9897c43e8abb7e83cf03cae3124461041b8c3bcd30fa
BLAKE2b-256 checksum
How to use checksums
91178bab9247b638e84277715a599b4ae5b2521a71b530ae3f443b082009d5af
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.13

Release files / bdiff-0.1.0-py3-none-any.whl

Download URL bdiff-0.1.0-py3-none-any.whl
Size 166.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
9c3181f410f9f244c6ba5f7807b3b6a64ba18f53e7b96777b611fca21f44387f
BLAKE2b-256 checksum
How to use checksums
4f840761e95f8e1afea6efdd31777669fe0332428a150533fbb5e5f333fe21b2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.13

Security for bdiff 0.1.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page