Metadata-Version: 2.4
Name: fhelium
Version: 0.60.0
Summary: A tensor-native CKKS framework with Python and PyTorch for CPU, NVIDIA CUDA, and experimental AMD ROCm source builds.
Keywords: ckks,cryptography,encrypted computation,fhe,fully homomorphic encryption,homomorphic encryption,pytorch,tensor computing,cpu,cuda,rocm
Author-Email: Gavin Gong <gavin@gong.host>
Maintainer-Email: Gavin Gong <gavin@gong.host>, PuQing <me@puqing.work>
License-Expression: MIT OR Apache-2.0
License-File: LICENSE-APACHE
License-File: LICENSE-MIT
License-File: third_party/nlohmann_json/LICENSE.MIT
Classifier: Development Status :: 4 - Beta
Classifier: Environment :: GPU :: NVIDIA CUDA
Classifier: Intended Audience :: Developers
Classifier: Intended Audience :: Science/Research
Classifier: Operating System :: MacOS :: MacOS X
Classifier: Operating System :: Microsoft :: Windows
Classifier: Operating System :: POSIX :: Linux
Classifier: Programming Language :: C++
Classifier: Programming Language :: Python
Classifier: Programming Language :: Python :: 3 :: Only
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Programming Language :: Python :: Implementation :: CPython
Classifier: Topic :: Security :: Cryptography
Classifier: Topic :: Software Development :: Libraries :: Python Modules
Classifier: Typing :: Typed
Project-URL: Homepage, https://fhelium.550w.host
Project-URL: Documentation, https://fhelium.550w.host
Project-URL: Repository, https://github.com/VisualDust/fhelium
Project-URL: Issues, https://github.com/VisualDust/fhelium/issues
Requires-Python: <3.14,>=3.12
Requires-Dist: click>=8.4.2
Requires-Dist: mpmath<1.4,>=1.3.0
Requires-Dist: numpy>=2.5.1
Requires-Dist: psutil<8,>=6.1
Requires-Dist: rich>=15.0.0
Requires-Dist: safetensors>=0.8.0
Requires-Dist: textual>=8.2.8
Requires-Dist: torch<2.16,>=2.14
Requires-Dist: triton-windows<3.10,>=3.8; sys_platform == "win32"
Description-Content-Type: text/markdown
Dynamic: Requires-Dist

<p align="center"><img src="https://fhelium.550w.host/brand/fhelium-readme-banner.svg" alt="FHElium: tensor-native CKKS for inspectable encrypted execution" width="100%"></p>

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

[![PyPI version](https://img.shields.io/pypi/v/fhelium)](https://pypi.org/project/fhelium/) [![Python versions](https://img.shields.io/pypi/pyversions/fhelium)](https://pypi.org/project/fhelium/) [![PyPI downloads](https://img.shields.io/pypi/dw/fhelium)](https://pypi.org/project/fhelium/) [![License: MIT OR Apache-2.0](https://img.shields.io/badge/license-MIT%20OR%20Apache--2.0-blue.svg)](#license)

**Documentation:** [fhelium.550w.host](https://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](https://fhelium.550w.host/#install-fhelium) 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](https://fhelium.550w.host/tutorial/installation) describes them.

## Quick start

```python
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`](./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](https://fhelium.550w.host/tutorial/basic-ckks-workflow), [Ciphertext operators](https://fhelium.550w.host/how-to/use-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](https://fhelium.550w.host/how-to/compile-callable), [Deploy a compiled callable](https://fhelium.550w.host/how-to/deploy-compiled-callable) |
| `fhelium.algorithms` | Evaluate polynomials and linear transforms, such as matrix-vector products, on ciphertexts | [Linear layer and polynomial](https://fhelium.550w.host/tutorial/linear-layer-and-polynomial) |
| `fhelium.bootstrap` | Refresh ciphertexts with CKKS bootstrapping to run computations deeper than the modulus chain | [Composable bootstrapping](https://fhelium.550w.host/tutorial/composable-ckks-bootstrap) |
| `fh.save_value`, `fhelium.store` | Save and load ciphertexts, plaintexts, and keys | [Value store](https://fhelium.550w.host/tutorial/value-store) |
| `fhelium.runtime`, `fhelium.residency` | Control GPU memory, buffer reuse, CUDA Graphs, and where values live between GPU and host memory | [CUDA Graphs](https://fhelium.550w.host/how-to/use-cuda-graphs), [Automatic residency](https://fhelium.550w.host/tutorial/automatic-residency) |
| `fhelium.distributed` | Run encrypted programs on multiple GPUs under `torchrun` | [SPMD model](https://fhelium.550w.host/concepts/distributed/spmd-model) |
| `fhelium.testing` | Check encrypted results against the plaintext function and find the operations where the error grows | [Ciphertext operators](https://fhelium.550w.host/how-to/use-ciphertext-operators#_2-compare-with-the-tensor-reference) |
| `libfhelium` | Write CKKS programs in C++ and run exported artifacts from C++ | [Call the native library from C++](https://fhelium.550w.host/how-to/call-native-library-from-cpp) |
| `fhelium.experimental` | Try multiparty CKKS for research, without a supported security guarantee | [Multiparty CKKS](https://fhelium.550w.host/tutorial/multiparty-ckks) |

The `fhelium` command reports the installed version and CUDA devices and runs benchmarks; see [Inspect runtime and CUDA](https://fhelium.550w.host/how-to/inspect-runtime-and-cuda). Runtime settings such as the cache location and compile logging are listed under [Environment variables](https://fhelium.550w.host/api/environment-variables).

## Examples and documentation

The [examples](./examples/README.md) 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`](./examples/cpp).

The documentation is organized as [Tutorials](https://fhelium.550w.host/tutorial/), [How-to guides](https://fhelium.550w.host/how-to/), [Concepts](https://fhelium.550w.host/concepts/), the [API reference](https://fhelium.550w.host/api/), and the [Developer guide](https://fhelium.550w.host/developer/).

## 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:

```bash
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](https://fhelium.550w.host/developer/contributing) 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:

```bibtex
@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`](./CITATION.cff).

## License

FHElium is licensed under either of the [MIT License](./LICENSE-MIT) or the [Apache License, Version 2.0](./LICENSE-APACHE), 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.
