VerdifaX

Integrating Hugging Face

Verdifax wraps both the hosted HF Inference API and local transformers pipelines. The pattern is the same: get the model output, then attest.

Inference API (hosted)

pip install verdifax huggingface_hub
from huggingface_hub import InferenceClient
import verdifax

hf = InferenceClient(model="meta-llama/Llama-3.3-70B-Instruct")

prompt = "Translate to French: 'Verifiable AI for regulated industries.'"
output = hf.text_generation(prompt, max_new_tokens=100)

receipt = verdifax.attest(
    payload=f"prompt:{prompt}\nresponse:{output}",
    program_id="a" * 64,
    route_id="hf-llama-translate-v1",
    registry_record_hash="b" * 64,
)
print(receipt.manifest_hash)

Local transformers pipeline

pip install verdifax transformers torch
from transformers import pipeline
import verdifax

clf = pipeline("text-classification", model="distilbert-base-uncased-finetuned-sst-2-english")

text = "I love how transparent this audit trail is."
result = clf(text)[0]

receipt = verdifax.attest(
    payload=f"text:{text}\nlabel:{result['label']}\nscore:{result['score']:.6f}",
    program_id="a" * 64,
    route_id="hf-distilbert-sst2-v1",
    registry_record_hash="b" * 64,
)
print(receipt.manifest_hash)

Determinism caveat

Local transformer inference is deterministic only when:

  • temperature=0 (or do_sample=False)
  • torch.manual_seed() is set
  • The CUDA backend uses deterministic kernels (torch.use_deterministic_algorithms(True))

If any of these aren't satisfied, two runs of the same prompt produce different outputs and therefore different manifest hashes — which is correct behavior, but worth knowing.

Continue