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)

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

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.1.1.tar.gz (17.1 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.1.1-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (8.9 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.17+ x86-64

toploc-0.1.1-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (8.8 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.17+ ARM64

toploc-0.1.1-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (8.9 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.17+ x86-64

toploc-0.1.1-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (8.8 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.17+ ARM64

toploc-0.1.1-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (8.9 MB view details)

Uploaded CPython 3.10manylinux: glibc 2.17+ x86-64

toploc-0.1.1-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (8.7 MB view details)

Uploaded CPython 3.10manylinux: glibc 2.17+ ARM64

toploc-0.1.1-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (8.9 MB view details)

Uploaded CPython 3.9manylinux: glibc 2.17+ x86-64

toploc-0.1.1-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (8.7 MB view details)

Uploaded CPython 3.9manylinux: glibc 2.17+ ARM64

File details

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

File metadata

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

File hashes

Hashes for toploc-0.1.1.tar.gz
Algorithm Hash digest
SHA256 756c6dc15ac1ce7254993f6f40b6868e70a525828749b22290c22d9b92a19655
MD5 973978c8f47cd26da33a0dedc73ee292
BLAKE2b-256 4cc05995ae3ffb8e608d1fceebd55ff231be6e791866aadbacfbb47762b27ea9

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for toploc-0.1.1-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 5da8781f3d5f9490ee42f7d16cb4dd9c9c7d57de1d05ebefc9ba256baad67a94
MD5 cd2b3a09743b2dab616031754e35d6b7
BLAKE2b-256 9bd7a9f9f5302d7239b000f4510b42a950e78f7c8f6b08513006cd77da7bbd50

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for toploc-0.1.1-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 de4de4e9149a65e8d2ffb45c9f8e63dceafdcd3816131615f1f5eb98439cd6df
MD5 c19f866b0496925fa14109731b3bf5fc
BLAKE2b-256 196103eed4b2d6266994e4c138f76eca8fe760978e37ef5a9b1f6accd2c6d889

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for toploc-0.1.1-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 fe092c0e048cc3c7e958d94491cf8a63db0330f2b3ed8329ac518c48d101834c
MD5 dfaa2885f3a8ed9b5eb820fb78c170fd
BLAKE2b-256 2020028d45fa30111659bff440afa63ed65e65af9fd6f38e352c7401d895e84b

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for toploc-0.1.1-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 78e372f2331dfcb0eb71fb6ec35cf6b963ec09bf2814f3c55045f4172fc95436
MD5 529d6bc30204c0d7b6bb2748ff490f20
BLAKE2b-256 eb6574ef1e4fdcbce58e6e8610cecb2aa1233733f2463b9cda69810f6a262ffe

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for toploc-0.1.1-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 7b734f22361daee028f8ca0c47c739ba91e82e29aa6c696b8a1ab9190ce6b733
MD5 e169c990201f9600849f04ca117cc76d
BLAKE2b-256 6b32d6f58c7464aff9947efad1931ce6432339dfc740342f9c172fb95b0e909f

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for toploc-0.1.1-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 228092c34cdf269a696c8d6cdd651c4fd084a4d017f4f975b290d3c6acb809f1
MD5 235e1768a9a688315a5941d7607c27d0
BLAKE2b-256 2cb31b824988be7f4b347b621f293664450de26308428fb48e6c8f093d285130

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for toploc-0.1.1-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 6d8adb257d51b4641c3705196644f3c883912970bb0a3190474e8c473e3a056f
MD5 f834a4bcd27dec113558d5687757f337
BLAKE2b-256 3993b973f3838f047f78d28bc31286ba81f0332b8f955622df815cb4fe4e3da9

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for toploc-0.1.1-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 99bb410c2cdab27d0aa78f76f1b8244c871b6b70819ae7aef74261e38d4f4acb
MD5 d5c235608c8176ee1a1c773b727c3016
BLAKE2b-256 2289b7a723ab9429afa49e9bfed43c77c8fc2cf61203d18585f72b14a4876534

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