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.2.tar.gz (17.5 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.2-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (9.0 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.17+ x86-64

toploc-0.1.2-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (8.9 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.17+ ARM64

toploc-0.1.2-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (9.0 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.17+ x86-64

toploc-0.1.2-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (8.9 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.17+ ARM64

toploc-0.1.2-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (9.0 MB view details)

Uploaded CPython 3.10manylinux: glibc 2.17+ x86-64

toploc-0.1.2-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (8.8 MB view details)

Uploaded CPython 3.10manylinux: glibc 2.17+ ARM64

toploc-0.1.2-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (9.0 MB view details)

Uploaded CPython 3.9manylinux: glibc 2.17+ x86-64

toploc-0.1.2-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (8.8 MB view details)

Uploaded CPython 3.9manylinux: glibc 2.17+ ARM64

File details

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

File metadata

  • Download URL: toploc-0.1.2.tar.gz
  • Upload date:
  • Size: 17.5 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.2.tar.gz
Algorithm Hash digest
SHA256 9326aba9e461dabcb0f717394000bab07ab13259973a5d0af462cd6d1e8bd5c6
MD5 8807897c70b0e6f2dee9af00c87d6094
BLAKE2b-256 2a862d6388ac5bed8151bc9987b82d7aa2d7a1a5f4b33ccd9ca2213b3c09bbb2

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for toploc-0.1.2-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 2a44b19e7ace308bf44ff5820f0e064aac2b65b0f94a3306bcf1fd535c6a54c0
MD5 70cb4d5fa91ef4a9caf9ec80ca1d9a1f
BLAKE2b-256 1e6ca3814f46583fabbeb63e235bfb2b85a0ede8a4da614fcdf75ca383e01f8b

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for toploc-0.1.2-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 9c875d8796af53ee8e45355babf123f361a00ada91623629be7adc467ad93d30
MD5 d15cae32c2dace6f136e741dd08372ce
BLAKE2b-256 8fa7a2db750e4382de6069e55c69f4effd20ab75ae28458af6c86db533f031b5

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for toploc-0.1.2-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 511afe51b69f13aa8b9af821fe5db2b201d6213b34fa1a18b551bd090d0ac06f
MD5 64f81e6f84b483f814bb0d28697a2db6
BLAKE2b-256 cce2f84391f26039cf78fc18a5c3ac47aa0ee1cff2448c41a1b60c65891e32c2

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for toploc-0.1.2-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 b0ecd0e039220bd824c5a533a07e83c4bac0b5d093ec2aae39303715606e2e99
MD5 ffe1bbf89d8459a1f9dbd336667b5718
BLAKE2b-256 31065c0e745473487f48f76409f4ce29e79a4720658f28547ec449a9d9c9f811

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for toploc-0.1.2-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 b2ee7bd930a014f91d685190032c149717ef46f882d49cccf9779f8f7c1c070b
MD5 6a68dd008b98cb958906ca2903a5c60d
BLAKE2b-256 256b9f0178e2f2f90b2576c76dd2392bc6f1ec57dafd9590b57f76b894a4249c

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for toploc-0.1.2-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 64708f26e0f8bacd78833f054e6faa336d245ab4abca517814639b03b824f280
MD5 aa65560d0612d799b13bed585e6ca230
BLAKE2b-256 4487f8e7f00d5bb8dcbcf64e1a8ad4d04bcaaed108ab235b53bbd053b3727954

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for toploc-0.1.2-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 13faadbbde5fe13776595d0e52ed67cb20c70b990e80e30fbdd038f8103acb27
MD5 31431b3e999301ca9c7328eab4f33616
BLAKE2b-256 cdc61dd541968ff719effd195f481954361371e0af77bde9476bb8c882078713

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for toploc-0.1.2-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 d3c877134bb2f5f2601a6f1cc62b722ecbb1134d4d7b08fa39994983fb27c3a8
MD5 fed98ab0072108aac78977d8636671f9
BLAKE2b-256 2c067e6fc6adaeebea0e4dbc39c783fccecc63823302bde84116af3e66d96a33

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