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.1.tar.gz (11.9 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.1-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.1-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.1-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.1-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.1-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.1.tar.gz.

File metadata

  • Download URL: toploc-0.0.1.tar.gz
  • Upload date:
  • Size: 11.9 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.1.tar.gz
Algorithm Hash digest
SHA256 0b29c16d35c30e045d333f9d5493bcb63596b7959f23aba75033ed6fbaa14199
MD5 2b8bfbe57a82c0b5e97c157436abf8c0
BLAKE2b-256 8fe1db8add2dbb03a1c258523780ba699ec720017a5e81e32c4415193ad701b4

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for toploc-0.0.1-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 80cd7dcf81e3c6631652c42c724eea02eb2be7a7f604165e15617c04221719b0
MD5 b5ebf23eb8754080ba90a34e3d31dbad
BLAKE2b-256 d663d5e66b6a5a60691ce9cb6833de7bff0e07e987bfb94a78a81b85df84360d

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for toploc-0.0.1-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 d040b105f436992d539558e2616338a961561b7912476d63ac2106b1eb9627d5
MD5 7bafba0b61ed914e66b1771c4e403b7f
BLAKE2b-256 0cf50bd1c331dc117d737a75c2bc5f801a337caefcf2269c113a84eae6489b96

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for toploc-0.0.1-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 8921fc3e25bcffa90f1024b6a8170f80f84e5ce375c50ac0c36a20bcf6c2fe2d
MD5 5b50292e990a4ab01acb14bcf22ebd60
BLAKE2b-256 bc62fafc4ec52702fbabe7bd216f75c85ae439a6ba841e1a1faf105b855db3a1

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for toploc-0.0.1-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 986cd162bf329f0a2d6fe703a3bd309ff280849849a9dba97f2ee299e77a2ce4
MD5 cd4bf5d2928442ab481be0e7945d6d9c
BLAKE2b-256 475729e191d63b11d76084884ce98b9c209b0b395f9b3dc3c0bb42bf63288a7f

See more details on using hashes here.

File details

Details for the file toploc-0.0.1-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for toploc-0.0.1-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 5573489a8d240b52066fa303403761d9e1d6e605602464507754485e997b05f4
MD5 ecdbc9ae45e9af86dc79d70853d9df9a
BLAKE2b-256 ca19a361e362152401768ffbbb2447a21fbc0aa216c63d93a74fa3db1d1e8f0d

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