# Diff a fine-tune's neurons

Diff a fine-tune's neuron registry against its base before you ship it, and gate CI on a signed report of label changes, ablation drift and canary shifts.

*Available on Enterprise.*

Use a registry diff to compare two neuron registries of the same architecture, neuron by neuron, and gate CI on it before new weights ship. A typical pair is the public base model and your [private registry build](https://provenanceauth.com/docs/trace/guides/registry-builds.md) of the fine-tune.

A diff works on registries that are already stored, so it needs no GPU and never calls the trace backend.

**Before you begin:** export the sandbox Enterprise key.

```bash
export PROVENANCE_API=https://sandbox-api.provenanceauth.com
export PROVENANCE_KEY=prv_test_ent_E7nT2vQ9bW4mK8sYd3cFjLh6gAe1pR5x
```

## 1. Start a diff

Send the two model versions to [`POST /v1/trace/diffs`](https://provenanceauth.com/docs/api/registry-diffs.md#post-v1-trace-diffs). This example diffs the sandbox model against itself, which passes; in your pipeline, `target` is your fine-tune's build.

**curl**

```bash
curl -s $PROVENANCE_API/v1/trace/diffs \
  -H "Authorization: Bearer $PROVENANCE_KEY" \
  -H "Content-Type: application/json" \
  -d '{ "base": "qwen2.5-0.5b-instruct@7ae55760", "target": "qwen2.5-0.5b-instruct@7ae55760", "tau": 0.25 }' | tee diff.json
```

**Node**

```ts
import { Provenance } from "@provenanceauth/sdk";

const prov = new Provenance({ apiKey: process.env.PROVENANCE_KEY!, baseUrl: process.env.PROVENANCE_API });
const diff = await prov.trace.diffs.create({ base: "qwen2.5-0.5b-instruct@7ae55760", target: "qwen2.5-0.5b-instruct@7ae55760", tau: 0.25 });
```

**Python**

```python
import os
from provenanceauth import Provenance

prov = Provenance(os.environ["PROVENANCE_KEY"], base_url=os.environ["PROVENANCE_API"])
diff = prov.trace.diffs.create(base="qwen2.5-0.5b-instruct@7ae55760", target="qwen2.5-0.5b-instruct@7ae55760", tau=0.25)
```

```json
{
  "id": "tjob_01M5Q0RAFRE0B5RWBJM4FSWGE9",
  "object": "registry_diff",
  "status": "pending",
  "base": "qwen2.5-0.5b-instruct@7ae55760",
  "target": "qwen2.5-0.5b-instruct@7ae55760",
  "canary_sets": null,
  "tau": 0.25,
  "pass": null,
  "report": null,
  "manifest": null,
  "report_hash": null,
  "error": null,
  "created_at": "2026-10-24T13:14:13.368Z",
  "updated_at": "2026-10-24T13:14:13.368Z",
  "expires_at": "2026-11-23T13:14:13.368Z",
  "poll_url": "/v1/trace/diffs/tjob_01M5Q0RAFRE0B5RWBJM4FSWGE9"
}
```

| Field | Accepted |
| --- | --- |
| `base`, `target` | A model version ID or slug you can see: a public model or one of your builds. Both must share an architecture. |
| `canary_sets` | The families to check (default: every family on either model) |
| `tau` | The drift tolerance, 0–1 (default 0.25). A family that drifts more fails the diff. |

## 2. Read the report

Wait for the diff with [`GET /v1/trace/diffs/{id}`](https://provenanceauth.com/docs/api/registry-diffs.md#get-v1-trace-diffs-id):

**curl**

```bash
export DIFF_ID=$(jq -r .id diff.json)
until [ "$(curl -s $PROVENANCE_API/v1/trace/diffs/$DIFF_ID -H "Authorization: Bearer $PROVENANCE_KEY" | jq -r .status)" != "pending" ]; do sleep 1; done
curl -s $PROVENANCE_API/v1/trace/diffs/$DIFF_ID -H "Authorization: Bearer $PROVENANCE_KEY"
```

**Node**

```ts
const done = await prov.trace.diffs.wait(diff.id);
```

**Python**

```python
import time

while (done := prov.trace.diffs.get(diff["id"]))["status"] in ("pending", "running"):
    time.sleep(1)
```

The response, trimmed to the report's summary and coverage:

```json
{
  "id": "tjob_01M5Q0RAFRE0B5RWBJM4FSWGE9",
  "object": "registry_diff",
  "status": "completed",
  "pass": true,
  "report": {
    "base": "qwen2.5-0.5b-instruct@7ae55760",
    "target": "qwen2.5-0.5b-instruct@7ae55760",
    "tau": 0.25,
    "coverage": { "base_neurons": 128, "target_neurons": 128, "shared": 128 },
    "summary": { "label_changes": 0, "new_unexplained": 0, "families_checked": 2, "families_drifted": [], "families_not_comparable": [], "pass": true }
  },
  "report_hash": "5fd269c40d07786310881c240376c890492f401e22c84d14488a0a2174ffd031"
}
```

| Section | What it measures |
| --- | --- |
| `coverage` | Neurons in each registry and how many are shared |
| `label_changes` | Shared neurons labeled differently; a label is an estimate, so a change is a prompt to look |
| `new_unexplained` | Neurons unexplained in the target that were explained in the base, or are new |
| `ablation_delta_drift` | Mean, p95 and max change in each shared neuron's measured ablation effect, plus the top 50; this is the measurement |
| `canary_member_shift` | One row per canary family (below) |
| `summary` | `families_drifted`, `families_not_comparable` and `pass` |

Each canary family is compared like with like:

| Family on the two models | Compared by |
| --- | --- |
| Your own set on both | Membership: `drift = 1 − Jaccard`, with members added and removed |
| Curated on both | Member counts and Jaccard; curated members are never listed |
| Curated on one, yours on the other | Measured precision and recall, never membership, so an overlap can't reveal curated members; without stats it is `not_comparable` |
| Missing on one side | `drift = 1`, so the diff fails, as a policy naming it would |

Lists hold up to 200 entries with complete totals, and numbers are rounded to four decimals, so the report is deterministic.

## 3. Gate CI on the signed manifest

Each completed diff carries an ES256 manifest (`typ: provenance-trace-diff+jwt`) that binds the report's hash, the verdict, the tolerance and both models. Verify it offline against the JWKS, then fail the build when it doesn't pass:

**Node**

```ts
import { Provenance, fetchJwks, verifyTraceDiffManifest } from "@provenanceauth/sdk";

const prov = new Provenance({ apiKey: process.env.PROVENANCE_KEY!, baseUrl: process.env.PROVENANCE_API });
const created = await prov.trace.diffs.create({ base: process.env.BASE_MODEL!, target: process.env.TUNED_MODEL!, tau: 0.25 });
const d = await prov.trace.diffs.wait(created.id);
const v = await verifyTraceDiffManifest(d.manifest!, await fetchJwks(process.env.PROVENANCE_API!), d.report);
if (d.status !== "completed" || !v.valid || !v.reportMatches || !v.claims!.pass) {
  console.error("Neuron-CI failed:", d.report?.summary.familiesDrifted, v.reason ?? "");
  process.exit(1);
}
```

**Python**

```python
import os
import sys
from provenanceauth_verify import fetch_jwks, verify_trace_diff_manifest

result = verify_trace_diff_manifest(done["manifest"], fetch_jwks(os.environ["PROVENANCE_API"]), done["report"])
if done["status"] != "completed" or not result.valid or not result.report_matches or not result.claims["pass"]:
    sys.exit(f"Neuron-CI failed: {done['report']['summary']['families_drifted']}")
```

A completed diff also fires the `trace.registry_diff.completed` [webhook](https://provenanceauth.com/docs/integrate/webhooks.md).

**Limitations:** a diff compares what each registry build measured on its corpus and evaluation sets, not how either model behaves on your traffic. A pass means no family drifted beyond your tolerance on the measured stats.

## Errors you might see

| Symptom | Cause | Fix |
| --- | --- | --- |
| `404` [`resource_missing`](https://provenanceauth.com/docs/platform/errors.md#resource_missing) on `base` or `target` | An unknown model, or another account's build | Use a model from `GET /v1/trace/models`. |
| `400` [`parameter_invalid`](https://provenanceauth.com/docs/platform/errors.md#parameter_invalid) on `target` | The architectures differ (`n_layers` × `d_mlp`) | Diff a fine-tune against its own base. |
| A family in `families_not_comparable` | A mixed family with no measured stats on one side | [Measure your set](https://provenanceauth.com/docs/trace/guides/registry-builds.md#3-measure-the-set). |
| `402` [`plan_required`](https://provenanceauth.com/docs/platform/errors.md#plan_required) | Diffs are Enterprise | See [plans and usage](https://provenanceauth.com/docs/account/plans-and-usage.md). |

## See also

- [Builds and canary sets](https://provenanceauth.com/docs/trace/guides/registry-builds.md)
- [Trace manifests](https://provenanceauth.com/docs/trace/concepts/trace-manifest.md)
- [Trace API reference](https://provenanceauth.com/docs/api/registry-diffs.md)
