Backend protocol¶
The interface every model backend implements.
Backend is a typing.Protocol. Any object with these members works with run_audit. No inheritance is required.
Members¶
-
namestr: Human readable model identifier. -
metadata()dict: Model details written into the report underbaseorderivative. Must containmodel_id. Any other JSON serializable keys are shown in the HTML model card. -
choice_logprob(prompt, continuation)float: Summed log probability ofcontinuationgivenprompt, counting continuation tokens only. Called once per choice per capability item. -
generate(prompt, max_new_tokens)str: Greedy completion for a user prompt, returning only the new text. Called once per benign prompt. -
vocab_signature()str: A string that is equal for two backends if and only if their tokenizers are identical. Divergence runs only when signatures match. -
divergence_to(other, text)float: Non negative mean per token KL fromselftootherontext. Called on the base backend with the derivative asother.
Optional members for proof¶
Backends that add these get fingerprints, a tensor level weights diff and shared template rendering. Without them, audits still run and verify, and the report records a missing_fingerprint warning. HFBackend implements all three.
-
fingerprint(weights=True)dict:{"commit": str | None, "tokenizer": dict, "weights": dict | None}. Buildtokenizerwithmodeldiffr.fingerprint.tokenizer_fingerprintandweightswithweights_fingerprint(path).to_dict(). RaiseUnsupportedWeightsErrorwhen the weights cannot be hashed; Modeldiffr then retries withweights=False. -
render_chat(prompt)str: The full prompt text after this model's chat template. -
generate_raw(text, max_new_tokens)str: Greedy completion for already rendered text. Used when both models must receive the same rendered prompt.
Call counts for the quick suite¶
| Method | Calls per model |
|---|---|
choice_logprob |
96 (24 items, 4 choices each) |
generate |
20 |
vocab_signature |
1 |
divergence_to |
12, on the base backend only |
metadata |
1 |
See Custom backends for a worked example.