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 is a novel method for verifiable inference that enables users to verify that LLM providers are using the correct model configurations and settings. It leverages locality sensitive hashing for intermediate activations to detect unauthorized modifications.

Features

  • 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
  • Zero false positives/negatives in empirical testing

Key Components

Proof Generation

  • Extracts top-k values from the last hidden state
  • Uses polynomial encoding for compact storage
  • Generates verifiable proof during inference

Validation

  • Recalculates top-k features
  • Compares exponent and mantissa differences
  • Validates against predefined error thresholds

Storage Requirements

  • Only 258 bytes per 32 new tokens
  • Compared to 262KB for full token embeddings (Llama-3.1-8B-Instruct)

Integrations

vLLM

TOPLOC is integrated with vLLM for efficient inference and validation as part of this repository. The integration allows you to leverage vLLM's optimized inference pipeline while maintaining verification capabilities.

SGLang

We maintain a fork of SGLang that includes TOPLOC integration, enabling verifiable inference with SGLang's framework.

How to use the code

Installation

git clone https://github.com/PrimeIntellect/toploc.git
pip install -r requirements.txt

Run Experiments

This is an example on running validation with Llama-3.1-8B-Instruct over the ultrachat dataset.

First, generate the polynomial encodings for the model using:

python vllm_generate_poly.py --model_name meta-llama/Llama-3.1-8B-Instruct --tp 1 --n_samples 4 --save_dir signatures --max_decode_tokens 512 --dataset_name stingning/ultrachat --dtype bfloat16

This should create a directory called signatures with the polynomial encodings for the model.

You can then run validation with:

python vllm_validate_poly.py --decode_model_name meta-llama/Llama-3.1-8B-Instruct --validate_model_name meta-llama/Llama-3.1-8B-Instruct --tp 1 --n_samples 4 --save_dir just4 --max_decode_tokens 512 --dataset_name stingning/ultrachat --dtype bfloat16 --attn flash

If the verification passes, you should see:

VERIFICATION PASSED: Mantissa error mean: 0. below 10 and median: 0. below 8 and exp intersections: 100 below 90

And if it fails, you should see something like:

VERIFICATION FAILED: Mantissa error mean: 11.000000 above 10 or median: 10.000000 above 8 or exp intersections: 0 above 90  

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.0.dev3.tar.gz (11.6 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.0.dev3-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.0.dev3-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.0.dev3-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.0.dev3-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.0.dev3-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (5.3 MB view details)

Uploaded CPython 3.8manylinux: glibc 2.17+ x86-64

File details

Details for the file toploc-0.0.0.dev3.tar.gz.

File metadata

  • Download URL: toploc-0.0.0.dev3.tar.gz
  • Upload date:
  • Size: 11.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.8

File hashes

Hashes for toploc-0.0.0.dev3.tar.gz
Algorithm Hash digest
SHA256 5efb3e86472c2d62105d3766f2e9423b5dbd6adf704ff1abc52d0f048cda6351
MD5 9a9f365f2a22b2f9eb7daf5962bad1d6
BLAKE2b-256 58f94bbee62d1ad41659de2a50fb0e3723e7a55a87eb90498a501c40258b5250

See more details on using hashes here.

File details

Details for the file toploc-0.0.0.dev3-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for toploc-0.0.0.dev3-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 34dfe5c3a92d1f9997f16a4a4379e8656bd35d6351f659f24a22396b5df3d08e
MD5 e67a41ac1453f99be0460609c4d52a3d
BLAKE2b-256 3b87e0eb825c68fc8bde0982635b59bd1f459e048aa06344bd2c287533284d97

See more details on using hashes here.

File details

Details for the file toploc-0.0.0.dev3-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for toploc-0.0.0.dev3-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 e020f35b05e9d21735beccc03448ce248f264ffacdcb5da563439af8c6b30382
MD5 c88138682ffce2e687282f16e383d2f9
BLAKE2b-256 04aa8659ef84fd710c15446b95a8dd48e6ee42b06c84581bfffe0d38b6cb0b57

See more details on using hashes here.

File details

Details for the file toploc-0.0.0.dev3-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for toploc-0.0.0.dev3-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 1681f7e64c1f5a219abe8567c953111e9783b096e83bb64d613ae012f2dece9b
MD5 7da96937afc2c3aeb118d6703ecc7189
BLAKE2b-256 7aa762070cfbd0faee46191158041823e1ce0198a0653a69fa8c57a943cedbd6

See more details on using hashes here.

File details

Details for the file toploc-0.0.0.dev3-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for toploc-0.0.0.dev3-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 46aa42bef8a2c3ee30cbc614e3ff62fe2f1f322872d5945d77a81139e6e48e5b
MD5 b263e3dee8ff22bdb33d3e75ce0e9f12
BLAKE2b-256 7120071123fea24c960258e9272fcaacb289fe0320d28b9e1e8829bc924614b9

See more details on using hashes here.

File details

Details for the file toploc-0.0.0.dev3-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for toploc-0.0.0.dev3-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 6a5a25ed36a10187c6416aed23421953b7f072c853d4cd15be7da756fdeb6a39
MD5 e5e8f00144770e2aa85ae17357296b5f
BLAKE2b-256 163b5ab7a53f4b0eb08f9e85a025eff2d629fb591607d77f8f8fba51ff35f802

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