Dataset fingerprinting library
Project description
Dataset fingerprinting
This repository contains our proof-of-concept for fingerprinting a dataset.
Local installation
git clone https://github.com/trailofbits/datasig && cd datasig
uv sync
Usage
Fingerprinting
The code below shows experimental usage of the library. This will be subject to frequent changes in early development stages.
from torchvision.datasets import MNIST
from datasig.dataset import TorchVisionDataset, CanonicalDataset
torch_dataset = MNIST(root="/tmp/data", train=True, download=True)
dataset = TorchVisionDataset(torch_dataset)
canonical = CanonicalDataset(dataset)
print("Dataset UID: ", canonical.uid)
print("Dataset fingerprint: ", canonical.fingerprint)
Dynamic dataset streaming
Datasig can be used in AIBOM solutions that require data to be streamed dynamically. Here is how to use it, using the MNIST example
On the server side (acquire and serve data):
from torchvision.datasets import MNIST
from datasig.dataset import TorchVisionDataset, CanonicalDataset
from datasig.streaming import StreamedDataset
# Create dataset and wrap with StreamedDataset
torch_dataset = MNIST(root="/tmp/data", train=True, download=True)
stream = StreamedDataset(TorchVisionDataset(torch_dataset))
# Option 1: Iterative data point access
for data_point in stream:
pass
# Option 2: Index-based data point access
data_point = stream[10]
# Serializing data points to bytes and serve
x = stream.serialize_data_point(data_point)
your_send_data_function(x)
# Once done streaming, compute fingerprint
canonical = CanonicalDataset(stream)
print("Dataset fingerprint: ", canonical.fingerprint)
On the client side (receive, deserialize, and use the data):
from datasig.dataset import TorchVisionDataset
# Get data sent by the server side
data: bytes = your_receive_data_function()
# Deserialize data to get proper python object
data_point = TorchVisionDataset.deserialize_data_point(data)
# Do something with the data...
Development
Unit tests
Tests are in the datasig/test directory. You can run the tests with:
uv run python -m pytest # Run all tests
uv run python -m pytest -s datasig/test/test_csv.py # Run only one test file
uv run python -m pytest -s datasig/test/test_csv.py -k test_similarity # Run only one specific test function
Profiling
The profiling script generates a profile for dataset processing and fingerprint generation using cProfile. To profile the MNIST dataset from the torch framework, you can run:
uv run python profiling.py torch_mnist --full
The --full argument tells the script to include dataset canonization, UID generation, and fingerprint generation in the profile. If you want to profile only some of these steps you can cherry pick by using or omitting the following arguments instead:
uv run python profiling.py torch_mnist --canonical --uid --fingerprint
You can optionally specify the datasig config version to use (at the time of writing we have only v0) with:
uv run python profiling.py torch_mnist -v 0 --all
Currently we support only one target dataset: torch_mnist. To add another dataset, add a class in profiling.py similar to TorchMNISTV0, that implements the _setup() method which is responsible for loading the dataset.
Benchmarking
Datasig has a built-in benchmark module that allows to run experiments to benchmark speed and accuracy of various fingerprinting methods with varying configurations and on several datasets.
Benchmarks are configured programmatically using the datasig library directly.
The benchmarking.py script gives a comprehensive overview of how to configure and run a benchmark, export results, as well as plot them on graph.
You can run the example benchmark with
uv run python benchmarking.py
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file datasig-0.0.1.tar.gz.
File metadata
- Download URL: datasig-0.0.1.tar.gz
- Upload date:
- Size: 14.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.8
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e3d319fbca1a827e988ebd8ed2a0733d58ff570816b636766848956b443eae85
|
|
| MD5 |
a781273465eb2f3cc20cc0e9a6ead7fa
|
|
| BLAKE2b-256 |
db26f4463071f40f1d097f9c2bdc5f1c77c8df6ab2fea0164562b858c4b70d54
|
Provenance
The following attestation bundles were made for datasig-0.0.1.tar.gz:
Publisher:
release.yml on trailofbits/datasig
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
datasig-0.0.1.tar.gz -
Subject digest:
e3d319fbca1a827e988ebd8ed2a0733d58ff570816b636766848956b443eae85 - Sigstore transparency entry: 379969819
- Sigstore integration time:
-
Permalink:
trailofbits/datasig@9095c759aefc8169f0ab7c9eee689b268f082abc -
Branch / Tag:
refs/tags/v0.0.1 - Owner: https://github.com/trailofbits
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@9095c759aefc8169f0ab7c9eee689b268f082abc -
Trigger Event:
release
-
Statement type:
File details
Details for the file datasig-0.0.1-py3-none-any.whl.
File metadata
- Download URL: datasig-0.0.1-py3-none-any.whl
- Upload date:
- Size: 14.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.8
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
55b3028d8e931a74930092d8754224f83503cd776a82c49fb1d1bef2c6b455f5
|
|
| MD5 |
a1a713f8f34fa381fd2cc611b2ce4b79
|
|
| BLAKE2b-256 |
51c8ba024c716aa3c1f9173031d6c1d8c8149274b1b77bdea608565d67c06897
|
Provenance
The following attestation bundles were made for datasig-0.0.1-py3-none-any.whl:
Publisher:
release.yml on trailofbits/datasig
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
datasig-0.0.1-py3-none-any.whl -
Subject digest:
55b3028d8e931a74930092d8754224f83503cd776a82c49fb1d1bef2c6b455f5 - Sigstore transparency entry: 379969854
- Sigstore integration time:
-
Permalink:
trailofbits/datasig@9095c759aefc8169f0ab7c9eee689b268f082abc -
Branch / Tag:
refs/tags/v0.0.1 - Owner: https://github.com/trailofbits
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@9095c759aefc8169f0ab7c9eee689b268f082abc -
Trigger Event:
release
-
Statement type: