Quickstart #

Ten minutes, no account, no GPU. You will register a data source, licence it, send its fingerprints, train a model behind the licence gate, and then pull the source and watch the model get withdrawn. This page runs as written when the site is built, on a CPU, and its last block checks that the whole thing finished in under a minute.

Install the SDK (pip install tensorchain with the hash-pinned lock we publish), then open a provenance store. Local keeps everything in one file on your machine; swap it for tc.Client("https://tensorchain.io", api_key) and the same code runs against the hosted service.

import time
t0 = time.time()
import hashlib, pathlib
import tensorchain.cloud as tc

p = tc.Local("provenance.sqlite")            # or: tc.Client("https://tensorchain.io", api_key)

# a small data folder standing in for yours
data = pathlib.Path("data/photos"); data.mkdir(parents=True)
for i in range(3):
    (data / f"photo-{i}.jpg").write_bytes(f"pixels {i}".encode())

p.add_source("photos")
p.license("photos", "agent:trainer", ["train"], days=30)
sent = p.ingest_folder("photos", data, state="sent.json")     # names, hashes and sizes only
print("manifests sent:", len(sent))
assert len(sent) == 1
Output (captured at build)
manifests sent: 1

The folder's files never left the machine: what was sent is one manifest listing each file's name, sha256 and size. Run ingest_folder again and nothing is sent, because nothing changed.

Now train. training() checks every source's licence for this consumer and this use before your code runs; your training happens exactly where it does today.

def train():                  # your real training, on your own GPUs
    out = pathlib.Path("out"); out.mkdir(exist_ok=True)
    (out / "weights.bin").write_bytes(hashlib.sha256(b"a tiny model").digest())
    return out / "weights.bin"

with p.training("agent:trainer", "train", ["photos"]) as run:
    weights = train()
    model = run.model(weights)

print("model state:", [m["state"] for m in p.models()])
print("verify:", p.verify(model["model"])["status"])
assert p.verify(model["model"])["status"] == "valid"
Output (captured at build)
model state: ['usable']
verify: valid

The model's record names its weights (by hash) and the dataset it was trained on, and the dataset names every source and the exact manifests it read. Now the owner of photos withdraws consent:

p.revoke(source="photos", reason="consent withdrawn")
print("model state now:", [m["state"] for m in p.models()])
print("impact:", {k: len(v) for k, v in p.impact("photos").items() if isinstance(v, list)})

try:
    with p.training("agent:trainer", "train", ["photos"]) as run:
        raise SystemExit("this line never runs")
except tc.Refused as e:
    print("next training refused:", e.code)

elapsed = time.time() - t0
print("whole quickstart under 60 s:", elapsed < 60)          # measured; the seconds vary per machine
assert [m["state"] for m in p.models()] == ["revoked"]
assert elapsed < 60
Output (captured at build)
model state now: ['revoked']
impact: {'manifests': 1, 'datasets': 1, 'models': 1}
next training refused: asset_revoked:photos
whole quickstart under 60 s: True

That is the whole loop: prove (the manifest and the model are signed records), gate (training was checked before it ran), trace (the impact lists the manifest, the dataset and the model), revoke (the model is withdrawn and the next run is refused). Nothing was deleted: the old records still verify as what they were, and the revocation is itself a signed record of who decided it and why.

Next: How it works, or the longer AI training provenance cookbook.