Skip to main content
Archived

This project has been archived by its maintainers, and is no longer receiving any updates.

What is this

This is a variant of Desilo/liberate-fhe with better typing, optimized GPU kernels and some user friendly features. This fork has left fork network and will not return to the original branch.

[!CAUTION] This might not be a drop-in replacement for the original one, but it should be compatible with most of the code. This is a GPU only library, and it will not work or even compile on CPU only machines. This project is still in development, and the API may change in the future. Please use it with caution.

Pre-requisites

  • Python 3.10 or later.
  • CUDA 11 or later, CUDA 12+ is recommended. nvcc is required for compiling, please make sure it is in your PATH.
  • PyTorch 2.0 or later is required.

Install

PyPI - Version PyPI - Downloads

conda create -n tiberate python=3.12
conda activate tiberate

pip install tiberate --verbose

The install process may take long time depending on your machine. Using verbose flag will help you to see the progress.

[!NOTE] If you encounter the error saying "The detected CUDA version mismatches the version that was used to compile PyTorch.", you can switch cuda version, or manually install pytorch with the same CUDA version as your system, then install this package without dependencies via:

pip install tiberate --no-deps --verbose

Dev

For dev or edible installation, you can install from source.

# clone the repository
git clone https://github.com/visualDust/tiberate-fhe.git
cd tiberate-fhe

# create conda env
conda create -n tiberate python=3.12
conda activate tiberate

# build and install
pip install --editable . --verbose

Usage

import torch
from tiberate import CkksEngine
from tiberate.typing import Plaintext, Ciphertext
from vdtoys.plot import diff_distribution

# Engine creation
engine = CkksEngine()
print(engine)
# Some dummy data
data = torch.randn(8192)
# Encrypt some data
ct = engine.encodecrypt(data)
# Some plaintext with cache
pt = Plaintext(data)
# Save and load ciphertext
ct.save("./ct.pt")
ct = Ciphertext.load("./ct.pt")
# Operations with plaintext
ct = engine.pc_mult(pt, ct)  # Multiplication
ct = engine.pc_add(pt, ct)  # Addition
print(pt)  # Print the plaintext information
# Ciphertext operations
ct = engine.cc_mult(ct, ct)  # Multiplication
ct = engine.cc_add(ct, ct)  # Addition
ct = engine.rotate_single(ct, engine.rotk[1])  # Rotation
ct = engine.rotate_single(ct, engine.rotk[-1])  # Rotate back
# Decryption
whatever = engine.decryptcode(ct, is_real=True)
# Error distribution
data = data * data + data
data *= data
data += data
diff = data - whatever[:8192]
print(f"Mean: {diff.mean()}, Std: {diff.std()}")
plt = diff_distribution(diff)
plt.show()

Run benchmarks

To run benchmarks, you can use the tiberate benchmark command:

tiberate benchmark

This will list all available benchmarks and their options. You can run a specific benchmark by providing its file path:

tiberate benchmark --file path/to/your_benchmark.py

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

tiberate-0.9.11.tar.gz (115.7 kB view details)

Uploaded Source

File details

Details for the file tiberate-0.9.11.tar.gz.

File metadata

  • Download URL: tiberate-0.9.11.tar.gz
  • Upload date:
  • Size: 115.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for tiberate-0.9.11.tar.gz
Algorithm Hash digest
SHA256 ea1197fefae63a2e14447af84d1a6be61c7eb93197d54af24a1926e570694e36
MD5 71a25680f518f2997268e3fe374c1332
BLAKE2b-256 3ea67cc17f7f6c9aac29bcecbb58bd484ae81ceba924d662f916c3f302747820

See more details on using hashes here.

Provenance

The following attestation bundles were made for tiberate-0.9.11.tar.gz:

Publisher: build-and-publish-pypi.yaml on visualDust/tiberate-fhe

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Release history Release notifications | RSS feed

This release

0.9.11 This release

1 file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page