Skip to main content

Lib for generating model inference and training proofs

Project description

TOPLOC: A Locality Sensitive Hashing Scheme for Trustless Verifiable Inference

TOPLOC leverages locality sensitive hashing of intermediate activations to verify that LLM providers are using authorized model configurations and settings.

The feature set includes:

  • Detect unauthorized modifications to models, prompts, and precision settings
  • 1000x reduction in storage requirements compared to full activation storage
  • Validation speeds up to 100x faster than original inference
  • Robust across different hardware configurations and implementations

For code used by experiments in our paper, check out: https://github.com/PrimeIntellect-ai/toploc-experiments

Installation

pip install -U toploc

Usage

Build proofs from activations:

As bytes (more compact when stored in binary formats):

import torch
from toploc import build_proofs_bytes

torch.manual_seed(42)
activations = [torch.randn(5, 16, dtype=torch.bfloat16), *(torch.randn(16, dtype=torch.bfloat16) for _ in range(10))]
proofs = build_proofs_bytes(activations, decode_batching_size=3, topk=4, skip_prefill=False)

print(f"Activation shapes: {[i.shape for i in activations]}")
print(f"Proofs: {proofs}")
Activation shapes: [torch.Size([5, 16]), torch.Size([16]), torch.Size([16]), torch.Size([16]), torch.Size([16]), torch.Size([16]), torch.Size([16]), torch.Size([16]), torch.Size([16]), torch.Size([16]), torch.Size([16])]
Proofs: [b'\xff\xd9\x1bB+g\xbaKum', b'\xff\xd9\xcb\xb8\x9a\xf1\x86%T\xa0', b'\xff\xd9\xb4h\xda\xe6\xe4\xabA\xb6', b'\xff\xd9\x80d\xd6X0\xe2\xafs', b'\xff\xd9\xd2\x04d\xea\x91\x91\xf6\xd7']

As base64 (more compact when stored in text formats):

import torch
from toploc import build_proofs_base64

torch.manual_seed(42)
activations = [torch.randn(1, 5, 16, dtype=torch.bfloat16), *(torch.randn(1, 16, dtype=torch.bfloat16) for _ in range(10))]
proofs = build_proofs_base64(activations, decode_batching_size=3, topk=4, skip_prefill=False)

print(f"Activation shapes: {[i.shape for i in activations]}")
print(f"Proofs: {proofs}")
Activation shapes: [torch.Size([1, 5, 16]), torch.Size([1, 16]), torch.Size([1, 16]), torch.Size([1, 16]), torch.Size([1, 16]), torch.Size([1, 16]), torch.Size([1, 16]), torch.Size([1, 16]), torch.Size([1, 16]), torch.Size([1, 16]), torch.Size([1, 16])]
Proofs: ['/9kbQitnukt1bQ==', '/9nLuJrxhiVUoA==', '/9m0aNrm5KtBtg==', '/9mAZNZYMOKvcw==', '/9nSBGTqkZH21w==']

Verify proofs:

import torch
from toploc import verify_proofs_base64

torch.manual_seed(42)
activations = [torch.randn(1, 5, 16, dtype=torch.bfloat16), *(torch.randn(1, 16, dtype=torch.bfloat16) for _ in range(10))]
proofs = ['/9kbQitnukt1bQ==', '/9nLuJrxhiVUoA==', '/9m0aNrm5KtBtg==', '/9mAZNZYMOKvcw==', '/9nSBGTqkZH21w==']
# apply some jitter to the activations
activations = [i * 1.01 for i in activations]

results = verify_proofs_base64(activations, proofs, decode_batching_size=3, topk=4, skip_prefill=False)

print("Results:")
print(*results, sep="\n")
Results:
VerificationResult(exp_intersections=4, mant_err_mean=1.75, mant_err_median=2.0)
VerificationResult(exp_intersections=4, mant_err_mean=2, mant_err_median=2.0)
VerificationResult(exp_intersections=4, mant_err_mean=1.25, mant_err_median=1.0)
VerificationResult(exp_intersections=4, mant_err_mean=1, mant_err_median=1.0)
VerificationResult(exp_intersections=4, mant_err_mean=2, mant_err_median=2.0)

Citing

@misc{ong2025toploclocalitysensitivehashing,
      title={TOPLOC: A Locality Sensitive Hashing Scheme for Trustless Verifiable Inference}, 
      author={Jack Min Ong and Matthew Di Ferrante and Aaron Pazdera and Ryan Garner and Sami Jaghouar and Manveer Basra and Johannes Hagemann},
      year={2025},
      eprint={2501.16007},
      archivePrefix={arXiv},
      primaryClass={cs.CR},
      url={https://arxiv.org/abs/2501.16007}, 
}

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

toploc-0.0.4.tar.gz (13.2 kB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

toploc-0.0.4-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (5.4 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.17+ x86-64

toploc-0.0.4-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (5.4 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.17+ ARM64

toploc-0.0.4-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (5.4 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.17+ x86-64

toploc-0.0.4-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (5.4 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.17+ ARM64

toploc-0.0.4-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (5.4 MB view details)

Uploaded CPython 3.10manylinux: glibc 2.17+ x86-64

toploc-0.0.4-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (5.3 MB view details)

Uploaded CPython 3.10manylinux: glibc 2.17+ ARM64

toploc-0.0.4-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (5.4 MB view details)

Uploaded CPython 3.9manylinux: glibc 2.17+ x86-64

toploc-0.0.4-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (5.3 MB view details)

Uploaded CPython 3.9manylinux: glibc 2.17+ ARM64

File details

Details for the file toploc-0.0.4.tar.gz.

File metadata

  • Download URL: toploc-0.0.4.tar.gz
  • Upload date:
  • Size: 13.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for toploc-0.0.4.tar.gz
Algorithm Hash digest
SHA256 14733fbb247024b2afebef952022bb86d866cb325062a32cb37fc910db732881
MD5 a73976b6cae6b9744671744adfbcb8b5
BLAKE2b-256 97e9deb3f2ec907c87c93768610de4e979272dd8809b9f0e3fd4c951504d2ebb

See more details on using hashes here.

File details

Details for the file toploc-0.0.4-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for toploc-0.0.4-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 b5e066e6b97d23988abf30c1ff20fb4581c015bdc7177e98cf94be817e1e180d
MD5 fd7ecaf80b089906cd0c65a905d43d0b
BLAKE2b-256 ae7d45aa29110f209488af6efd12612d6c9ff85224cd91df8d28fc448da66872

See more details on using hashes here.

File details

Details for the file toploc-0.0.4-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for toploc-0.0.4-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 f197b7bbfc030f1c01ad1825836c55b265f1fa8b7b6d3418ba7814cba1ef5b82
MD5 bad5e5fdf6d79c1493591aa44b1da7f0
BLAKE2b-256 458a0665dd2bb51a89ca7440fc7aa51e3108a3e17dd6323cb09f690c4683606a

See more details on using hashes here.

File details

Details for the file toploc-0.0.4-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for toploc-0.0.4-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 a58f708f2fc8abc95b9875300782ef4bfead5837385bd4bea0eb30ba4590bf34
MD5 e7e722f242ebb7cb76787f651a508e5f
BLAKE2b-256 954ca0a39c90a878519ea4f706368d11868f5d293e685a5c7a2864ee6cc59b4c

See more details on using hashes here.

File details

Details for the file toploc-0.0.4-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for toploc-0.0.4-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 e16fc7f520a7905374cc1f7b10002290f8a57a9f96dfee3a64232bac5dd954e6
MD5 3cc3aa3c419505b8c97dae622eb7da17
BLAKE2b-256 c979a7121157c724bb8d5c44a27841f535642a3c3730b60e38483977f49ac10c

See more details on using hashes here.

File details

Details for the file toploc-0.0.4-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for toploc-0.0.4-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 88d44b98de8800db2310c0c6102d4ec2c9154ee26762a63af9bc18dc65c3e45a
MD5 51331774ba76b8b1b7bc8d1cb0e52a20
BLAKE2b-256 a638a7bd39e826c9e37012ee6ad8bcbb7e27f8d3e8c1c1b5746f85f475586ae6

See more details on using hashes here.

File details

Details for the file toploc-0.0.4-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for toploc-0.0.4-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 cc56e531fe6e63ed0ff74b432805d47881e40e441c98270cada073da30c1c995
MD5 e11abcb4ff0b0f6d7fe7ba51ef8b8ce7
BLAKE2b-256 2a804de90518dcac421bb40992d09524c0e54d5b99e40e1a123738e89b4502b1

See more details on using hashes here.

File details

Details for the file toploc-0.0.4-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for toploc-0.0.4-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 50b9cf0d7c3a43ef335c27648c267e9f00f8e253c3f348038ed6674e9e604648
MD5 f85969fc82344f2b5e23e2ad6dc3488c
BLAKE2b-256 0575ddfdf37c70624d9976b415966b250dfd69a992931b37ef3345f126c0d760

See more details on using hashes here.

File details

Details for the file toploc-0.0.4-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for toploc-0.0.4-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 e16ed3d557f7ca7c0d24bcaff07050443acca84142f789579e08c9a87cf3d70e
MD5 b9402a9f1398280369be2b0f13f9c48e
BLAKE2b-256 3424d8d30e4cb09e53ef36a0f2eb0e4842c2b0e5832ccca25a75c389ebed4f9d

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page