Skip to main content

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)

prefill = [torch.randn(5, 16, dtype=torch.bfloat16)]
generate = [torch.randn(16, dtype=torch.bfloat16) for _ in range(10)]
activations = prefill + generate

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)

prefill = [torch.randn(5, 16, dtype=torch.bfloat16)]
generate = [torch.randn(16, dtype=torch.bfloat16) for _ in range(10)]
activations = prefill + generate

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)

prefill = [torch.randn(5, 16, dtype=torch.bfloat16)]
generate = [torch.randn(16, dtype=torch.bfloat16) for _ in range(10)]
activations = prefill + generate

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}, 
}

Metadata

Release files for toploc 0.1.6

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for toploc 0.1.6
File Size Uploaded
toploc-0.1.6.tar.gz 18.8 kB Details

Built distributions (wheels)

Table of built distributions (wheels) for toploc 0.1.6
File
toploc-0.1.6-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl CPython 3.12 CPython 3.12 Linux glibc 2.17+ x86-64 Details
toploc-0.1.6-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl CPython 3.12 CPython 3.12 Linux glibc 2.17+ ARM64 Details
toploc-0.1.6-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl CPython 3.11 CPython 3.11 Linux glibc 2.17+ x86-64 Details
toploc-0.1.6-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl CPython 3.11 CPython 3.11 Linux glibc 2.17+ ARM64 Details
toploc-0.1.6-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl CPython 3.10 CPython 3.10 Linux glibc 2.17+ x86-64 Details
toploc-0.1.6-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl CPython 3.10 CPython 3.10 Linux glibc 2.17+ ARM64 Details
toploc-0.1.6-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl CPython 3.9 CPython 3.9 Linux glibc 2.17+ x86-64 Details
toploc-0.1.6-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl CPython 3.9 CPython 3.9 Linux glibc 2.17+ ARM64 Details

Total release size: 71.7 MB

Release files / toploc-0.1.6.tar.gz

Download URL toploc-0.1.6.tar.gz
Size 18.8 kB
Tags Source
SHA-256 checksum
How to use checksums
7a566c2db29d94865baa2c53b5563b426fd118b56a163b515551419b65ea7072
BLAKE2b-256 checksum
How to use checksums
2d2633f275fef46469e55c19e0c58f10d2a062b97481e9fa21869b943524ee2e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.12.9

Release files / toploc-0.1.6-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl

Download URL toploc-0.1.6-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Size 9.1 MB
Tags CPython 3.12 Linux glibc 2.17+ x86-64
SHA-256 checksum
How to use checksums
c9945bd74362d6f1cd651b61e81457b63400b5856104dbab1e3dfb9aba6ffbc7
BLAKE2b-256 checksum
How to use checksums
043e579fbc4ea66630cf85bd76747bb1fa153f48c343b280a88f0472b208da59
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.12.9

Release files / toploc-0.1.6-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl

Download URL toploc-0.1.6-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Size 8.9 MB
Tags CPython 3.12 Linux glibc 2.17+ ARM64
SHA-256 checksum
How to use checksums
20a37613b1a5f518101096a28ce03f7c646557c9e89c0d1932ecd5ae97413735
BLAKE2b-256 checksum
How to use checksums
5d7d7c006936c2d417e00577b69398c595db70738aed9250e7efaecf878b38a2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.12.9

Release files / toploc-0.1.6-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl

Download URL toploc-0.1.6-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Size 9.0 MB
Tags CPython 3.11 Linux glibc 2.17+ x86-64
SHA-256 checksum
How to use checksums
0b06fbd74e7f6d4961887e72de7ae1ed2021e92d48b17b6e35dcc90666ea0843
BLAKE2b-256 checksum
How to use checksums
98df7928cfc7ef0ced1042a36e25eed075965a35f4d8541ef9e11e1f575b8991
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.12.9

Release files / toploc-0.1.6-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl

Download URL toploc-0.1.6-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Size 8.9 MB
Tags CPython 3.11 Linux glibc 2.17+ ARM64
SHA-256 checksum
How to use checksums
5d31af60fc86bd4c41f877ac8f8f1697b0bd767e90387faf0c431388af986674
BLAKE2b-256 checksum
How to use checksums
12555e822bdda0e0f6277b25f6bfa171507506ee33a8b3532d57bd70b018ca19
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.12.9

Release files / toploc-0.1.6-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl

Download URL toploc-0.1.6-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Size 9.0 MB
Tags CPython 3.10 Linux glibc 2.17+ x86-64
SHA-256 checksum
How to use checksums
c9170df941e44f14cd2238645099ee10575aaf23b4b94c17900f44d7b1db40ed
BLAKE2b-256 checksum
How to use checksums
0afd64427e2e4afceb97bab6e32044b63d9123c23fe9c8db6f1a38b520204fed
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.12.9

Release files / toploc-0.1.6-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl

Download URL toploc-0.1.6-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Size 8.9 MB
Tags CPython 3.10 Linux glibc 2.17+ ARM64
SHA-256 checksum
How to use checksums
217afa3d909067a734086bff0a28ec0ab7151d78f1bcee6aa5f82b099199667e
BLAKE2b-256 checksum
How to use checksums
30fbb47d115012007841de7a2cbb2715b972049945065fa60fa5878e7c9c0641
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.12.9

Release files / toploc-0.1.6-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl

Download URL toploc-0.1.6-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Size 9.0 MB
Tags CPython 3.9 Linux glibc 2.17+ x86-64
SHA-256 checksum
How to use checksums
3e040bf056cd8734a4dc2ae2505fdf6bb59f5dc171d5c1965641fc4269d9cbe4
BLAKE2b-256 checksum
How to use checksums
e9c297a6af7cc87a18624716f0cacee679734a31c90037ed5f7637a3ce881c68
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.12.9

Release files / toploc-0.1.6-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl

Download URL toploc-0.1.6-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Size 8.9 MB
Tags CPython 3.9 Linux glibc 2.17+ ARM64
SHA-256 checksum
How to use checksums
52695aa7af5cbd3b9109217f3f761bf2426f11e7798140b704447ec307c55d67
BLAKE2b-256 checksum
How to use checksums
462adfb262220f86e9ffa2c00187bfbb1c3271ede24b4e2a8ba404838ad35332
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.12.9
Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page