Skip to content
visualDustPublic

About

FHElium is a CPU- and GPU-accelerated homomorphic-encryption library for Python and PyTorch

Topics

Resources

Contributing

Security policy

Stars

13 stars

Watchers

0 watching

Forks

Latest commit

 

History

60 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

FHElium: tensor-native CKKS for inspectable encrypted execution

Pronounced “philium” /ˈfɪliəm/ or “F-helium” /ˌɛf ˈhiːliəm/.

PyPI version Python versions PyPI downloads License: MIT OR Apache-2.0

Documentation: fhelium.550w.host

FHElium runs Python code under CKKS homomorphic encryption on CPUs and GPUs. You write the computation with Tensor operators on ciphertexts, and FHElium JIT-compiles it to run at the speed of compiled programs.

  • Cross-layer orchestration: one compiler controls decisions that are usually fixed in separate layers, from relinearization and rescale placement, key switching, and rotation hoisting to kernel fusion, memory, and multi-GPU communication. Every stage can be inspected or replaced.
  • Programming models: prototype with plain Python and Tensor operators and check the result against the same function on Tensors; write CKKS programs step by step with Engine methods when relinearization, rescaling, and key switching should be placed by hand; or work at the level of RNS/NTT operations, compiler passes, and C++ for systems research. Operator and Engine code run eagerly or compiled.
  • JIT and AOT: fhelium.compile JIT-compiles Python functions when they are called, and AOT export writes artifacts that run from Python or C++ without recompilation; both under the same optimization framework. libfhelium also supports development directly in C++.
  • Extensible: FHElium is built from replaceable modules. Compiler passes can be written in Python or MLIR, operation implementations and kernels are registered with the Backend, and bootstrapping, polynomial evaluation, and linear transforms are composed from ordinary operations that applications can rearrange or replace.

Install

Platform CPU NVIDIA CUDA 13 AMD ROCm
Linux x86-64 Prebuilt wheel Prebuilt wheel Source build (experimental)
Windows x86-64 Prebuilt wheel Prebuilt wheel —
macOS Apple Silicon Source build — —

Prebuilt wheels support CPython 3.12 and 3.13 with PyTorch 2.14 and 2.15, and the CUDA wheels require NVIDIA driver 580 or newer. The installation selector gives the pip commands for a chosen platform, PyTorch version, and CPU or CUDA configuration. Source builds compile the native library and the compiler extension against the PyTorch, CUDA, or ROCm installation of the build environment and a pinned LLVM/MLIR installation, so they can target other library and driver versions; the installation guide describes them.

Quick start

import torch
import fhelium as fh
from fhelium import compile as fc
from fhelium.eager import Engine

engine = Engine(fh.Preset.slots8192_scale40_depth7)
device = "cuda:0" if torch.cuda.is_available() else "cpu"
x = torch.linspace(-0.5, 0.5, engine.num_slots, dtype=torch.float64, device=device)
y = torch.linspace(0.3, -0.3, engine.num_slots, dtype=torch.float64, device=device)
w = torch.full_like(x, 0.1)


@fc.compile
def model(a, b):
    return ((a * b + w) * 0.5).roll(1) - a.sum()


ct_x = engine.encrypt_message(x)
ct_y = engine.encrypt_message(y)

compiled = model(ct_x, ct_y)  # compiled on the first call, reused afterwards
eager = model.reference(ct_x, ct_y)  # the Python function, one operation at a time
expected = model.reference(x, y)  # the same function on Tensors

for result in (compiled, eager):
    error = engine.decrypt_message(result, is_real=True) - expected
    print(result.depth, error.abs().max().item())

model is ordinary Python. Called with encrypted inputs, FHElium turns it into an optimized encrypted program, handling keys, relinearization, and rescaling, and the decrypted result matches the same function on plaintext Tensors. examples/01_eager_basics.py also shows how to write each CKKS step by hand.

Components

Package Use it to Start with
fhelium.eager Write CKKS programs directly: encode, encrypt, manage keys, and run each operation immediately Basic CKKS workflow, Ciphertext operators
fhelium.compile Turn a Python function into an optimized encrypted program when it is called (JIT), and export it for deployment (AOT) Compile a callable, Deploy a compiled callable
fhelium.algorithms Evaluate polynomials and linear transforms, such as matrix-vector products, on ciphertexts Linear layer and polynomial
fhelium.bootstrap Refresh ciphertexts with CKKS bootstrapping to run computations deeper than the modulus chain Composable bootstrapping
fh.save_value, fhelium.store Save and load ciphertexts, plaintexts, and keys Value store
fhelium.runtime, fhelium.residency Control GPU memory, buffer reuse, CUDA Graphs, and where values live between GPU and host memory CUDA Graphs, Automatic residency
fhelium.distributed Run encrypted programs on multiple GPUs under torchrun SPMD model
fhelium.testing Check encrypted results against the plaintext function and find the operations where the error grows Ciphertext operators
libfhelium Write CKKS programs in C++ and run exported artifacts from C++ Call the native library from C++
fhelium.experimental Try multiparty CKKS for research, without a supported security guarantee Multiparty CKKS

The fhelium command reports the installed version and CUDA devices and runs benchmarks; see Inspect runtime and CUDA. Runtime settings such as the cache location and compile logging are listed under Environment variables.

Examples and documentation

The examples are numbered in reading order: Eager (01–07), algorithms and bootstrapping (08–09), values (10–11), compilation (12–15), runtime and residency (16–19), distributed execution (20–23), and the experimental multiparty example (24). C++ programs are under examples/cpp.

The documentation is organized as Tutorials, How-to guides, Concepts, the API reference, and the Developer guide.

Development

Create the locked development environment and run the project checks. The commands require uv 0.9.17 or newer. The compiler builds against LLVM/MLIR 23.1.6, which packaging/build_mlir.py builds once per machine:

git clone https://github.com/VisualDust/fhelium.git
cd fhelium
uv run --no-project --with cmake==4.4.2 --with ninja==1.13.0 --with nanobind==2.15.0 \
  python packaging/build_mlir.py --prefix "$HOME/.local/opt/fhelium-mlir" --work-dir "$HOME/.cache/fhelium-mlir-build"
export FHELIUM_MLIR_DIR="$HOME/.local/opt/fhelium-mlir/lib/cmake/mlir"
uv sync --locked
source .venv/bin/activate
just check

The contributor guide documents custom Torch environments, native and compiler builds, editor configuration, and the validation workflow.

Citation

If you use FHElium in research or software, cite the project as:

@software{fhelium2026,
  author  = {Zhaoting Gong and Jiaming Liang and Ran Ran and Wujie Wen},
  title   = {FHElium: A Cross-Stack CKKS Research Framework},
  year    = {2026},
  version = {0.60.0},
  url     = {https://github.com/VisualDust/fhelium}
}

The same metadata is available in CITATION.cff.

License

FHElium is licensed under either of the MIT License or the Apache License, Version 2.0, at your option.

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in FHElium by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

About

FHElium is a CPU- and GPU-accelerated homomorphic-encryption library for Python and PyTorch

Topics

Resources

Contributing

Security policy

Stars

13 stars

Watchers

0 watching

Forks

Releases

Sponsor this project

Packages

Contributors

Languages