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.dev2.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.dev2-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.dev2-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

File details

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

File metadata

  • Download URL: toploc-0.0.0.dev2.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.dev2.tar.gz
Algorithm Hash digest
SHA256 31fe7f6d607a03151f4bc5dc2bf309c6005d7e6ad85dcd2d1f3f349844f50e0d
MD5 a3910c18e45ffd8b43b2c38ea2ee7031
BLAKE2b-256 0537bc16d0336507deab161e90852c33f7b0f5e5fb86d2fcb10e13f021045a1f

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for toploc-0.0.0.dev2-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 6a4ded4b76e2f007e030705ff81173497029a172cc17a1aa56ff5bb3f016d1ca
MD5 554dc37f11d44b352bb58f247444ed3f
BLAKE2b-256 1bf656b9a0a373df4cb52547feeaf18ee1d23c394a2c9984c1f9eccfcbd20793

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for toploc-0.0.0.dev2-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 b1cf1a5b0b1a2559e2b571be8c5eef4930685ac2492827eae69935ab8defbfd5
MD5 237c2d95035bf3dcada80f634760b73a
BLAKE2b-256 34744275d915bf8b7f8d8bc5aa68913d4f099ce84dfc2cb2c201b3c048655634

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