Skip to main content

A high-performance Python library for fully homomorphic encryption (FHE) in deep learning, seamlessly integrated with PyTorch.

Project description

Supersayan

A high‑performance Python library that integrates Fully Homomorphic Encryption (FHE) into PyTorch workflows. Supersayan provides:

  • A client/server path to offload selected layers to a remote FHE server (hybrid mode).
  • Zero‑copy tensor bridges across PyTorch, NumPy, CuPy, and Julia.

The Julia backend is managed via juliacall and initialized automatically on first import, or explicitly with a helper CLI.

Installation

From PyPI:

pip install supersayan
# or with uv
uv add supersayan

Default behavior:

  • After install, importing supersayan triggers a one‑time Julia backend setup automatically. No extra step is needed for typical users.

Optional (CI/Docker or troubleshooting):

# Manually initialize the Julia backend if you want explicit control
supersayan-setup

Advanced control (not recommended for regular users):

  • To prevent network access during import in CI images, set SUPERSAYAN_SKIP_JULIA_SETUP=1 and run supersayan-setup in a controlled build step.

Notes:

  • GPU support uses CuPy when available; code runs on CPU otherwise.

Hybrid Remote Inference

Run the TCP server:

python scripts/run_server.py --host 127.0.0.1 --port 8000 --models-dir /tmp/supersayan/models

Use the client to execute only selected layers remotely in FHE while keeping other ops local:

import torch
import torch.nn as nn
from supersayan.core.types import SupersayanTensor
from supersayan.remote import SupersayanClient

class SmallCNN(nn.Module):
    def __init__(self):
        super().__init__()
        self.conv = nn.Conv2d(1, 4, 3, padding=1)
        self.fc = nn.Linear(4*28*28, 10)
    def forward(self, x):
        x = torch.relu(self.conv(x))
        return self.fc(x.view(x.size(0), -1))

cnn = SmallCNN().eval()
client = SupersayanClient(
    server_url="127.0.0.1:8000",
    torch_model=cnn,
    fhe_modules=[nn.Conv2d, nn.Linear],  # offload these layers
)

x = SupersayanTensor(torch.randn(1, 1, 28, 28))
y = client(x)

For a runnable example of the TCP server, see scripts/run_server.py.

Supported offloaded layers: nn.Linear, nn.Conv2d.

Tensors and Interop

  • SupersayanTensor(data, device=...) accepts torch.Tensor, numpy.ndarray, or cupy.ndarray and preserves dtype float32.
  • Helpers: SupersayanTensor.zeros(...), ones(...), randn(...).
  • Interop: .to_numpy(), .to_dlpack(), and zero‑copy conversion to Julia via .to_julia().

Project Layout

  • src/supersayan/ core, layers, remote client/server, Julia backend
  • scripts/ runnable examples (run_server.py)

Troubleshooting

  • If Julia setup fails on first import, run supersayan-setup manually.
  • In CI or headless environments, set SUPERSAYAN_SKIP_JULIA_SETUP=1 during import and run supersayan-setup explicitly in a build step.

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

supersayan-0.1.1.tar.gz (22.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

supersayan-0.1.1-py3-none-any.whl (26.3 kB view details)

Uploaded Python 3

File details

Details for the file supersayan-0.1.1.tar.gz.

File metadata

  • Download URL: supersayan-0.1.1.tar.gz
  • Upload date:
  • Size: 22.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.6.5

File hashes

Hashes for supersayan-0.1.1.tar.gz
Algorithm Hash digest
SHA256 e55d36be8d9cb0e1c635b20d7477bd3aedf1ef80c3177f7dca038fae19c2c1dd
MD5 3b320fdf8163455c80db4f8852c2f952
BLAKE2b-256 b1dd9a5bf345c08aef9f5c9f46a9ddf1be79df522a08b97d25662e92218e7079

See more details on using hashes here.

File details

Details for the file supersayan-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: supersayan-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 26.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.6.5

File hashes

Hashes for supersayan-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 fd0d293b35076d426a26d6b54e70226269c4b3bc884cd04ab4ef5c50b1fd76dc
MD5 fe67054a50a51342a974fc7ac6699212
BLAKE2b-256 4ecbd7297c91ca132acca2169a332f8b9b82b865f338885d2893b60fc73d3e2d

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