ACE-Compiler: An FHE Domain-Specific Compiler
ACE-Compiler is the compiler component of the ANT-ACE framework. It compiles PyTorch models, Python functions, and ONNX models into optimized FHE ciphertext programs, targeting multiple libraries (CPU/GPU) and encryption schemes (CKKS, TFHE).
Plaintext and FHE computation are seamlessly integrated: write code using familiar PyTorch/ONNX/Python, and the framework automatically converts it to encrypted execution.
Features
- Multi-frontend input: PyTorch (FX trace), Python AST, ONNX file, or via-ONNX conversion
- Multi-target execution: CPU (antlib, SEAL, OpenFHE) and GPU (phantom, acelib) targets
- CKKS scheme support: Configurable polynomial degree, scaling factor, and multiplication depth
- One-step or two-step workflow:
@fhe.computefor compile+run;@fhe.compilefor compile-then-run - Batch and dataset inference: Single input, batch parallelism, or full dataset with accuracy metrics
- CUDA Graph acceleration: Replay captured GPU execution graph for reduced launch overhead
- Built-in profiler: Profile FHE execution with
program.profile()using torch.profiler
Quick Start
- One-step: compile and run
import torch
from ace import fhe
@fhe.compute(frontend="torch", library="ant", validate=True) # device auto-derives from library
def add(x, y):
return x + y
x = torch.ones(1, 4)
y = torch.ones(1, 4) * 2
result = add(x, y) # FHE inference with auto-validation
- Two-step: compile first, then run
@fhe.compile(frontend="torch", library="ant") # device auto-derives from library
def add(x, y):
return x + y
program = add.compile([x, y]) # Compile
result = program(x, y) # Run inference
program.validate() # Verify correctness
- GPU inference with compile options
@fhe.compile(frontend="torch", library="phantom", device="cuda",
ckks={"N": 65536, "sf": 56})
def add(x, y):
return x + y
program = add.compile([x, y])
result = program(x, y)
- Batch inference with accuracy metrics
program = model.compile([example_input])
result = program.run_dataset(images, labels, top_k=1)
print(f"Top-1 accuracy: {result.top1_accuracy:.2%}")
Compilation Pipeline
Installation
From PyPI (recommended)
pip install ace-fhe
The published wheel bundles the prebuilt runtime and compiler binaries, so
pip install is enough to start using ACE on a supported platform — no
source build required.
TBD: the
ace-fhePyPI package is being published; until it is available, use the from-source build below.
From source
The compiler backend sources (compiler/air-infra/, compiler/nn-addon/,
compiler/fhe-cmplr/) are included directly in this repository, so a source
build needs no extra credentials or fetches beyond the runtime backends
(phantom / ckks-infra / spdlog), which are pulled from public GitHub at
configure time. See Developer Guide for the full
workflow:
./scripts/dev-build.sh # build + install (Release)
python -c "from ace import frontend, runtime; print('OK')"
Build type defaults:
./scripts/dev-build.shdefaults toRelease, whilemakedefaults toDebug. Both write to the samebuild/directory — pick one and stick with it to avoid stale-cache confusion.
libFHErt_common.so not found? Set the runtime library path:export LD_LIBRARY_PATH=$(python -c "import sysconfig; print(sysconfig.get_path('platlib'))")/ace/lib:$LD_LIBRARY_PATH
Ant Group internal developers: building inside the internal network needs a
CI_TOKEN, the internal Docker registry (reg.docker.alibaba-inc.com/ace/...), and internal git mirrors. See the Internal Onboarding Guide.
API Reference
| API | Description | Details |
|---|---|---|
@fhe.compile |
Compile function/model to FHE program | Decorators API |
@fhe.compute |
Compile and run in one step | Decorators API |
@fhe.export |
Export IR to file (AIR/ONNX) | Decorators API |
program(x, y) |
High-level FHE inference | Runtime API |
program.run_dataset() |
Batch inference with accuracy | Runtime API |
KernelExecutor |
Low-level kernel management, CUDA Graph | Runtime API |
ckks, vec, p2c, ... |
Compile options | Compile Options |
Libraries
| Library | Device | Binary | Status |
|---|---|---|---|
ant |
CPU | libFHErt_ant |
Available |
phantom |
CUDA | libFHErt_phantom |
Available |
acelib |
CUDA | libFHErt_ace |
Available |
seal |
CPU | Microsoft SEAL | Planned |
openfhe |
CPU | OpenFHE | Planned |
Project Structure
ace-compiler/
├── fhe_dsl/ # FHE DSL source (Python + C++)
│ ├── python/ # Python package (installed as `ace-fhe`)
│ └── csrc/ # C++ extension (frontend, runtime)
├── fhe_lib/ # FHE runtime libraries
│ ├── ant/ # antlib (CPU)
│ ├── ace/ # acelib (CUDA)
│ └── common/ # Shared runtime code
├── compiler/ # FHE compiler (fhe_cmplr)
├── examples/ # Example scripts
├── tests/ # Test suites
└── scripts/ # Build and development scripts
Publications
- CGO '26 — FHEFusion: Enabling Operator Fusion in FHE Compilers for Depth-Efficient DNN Inference
- OOPSLA '25 — MetaKernel: Enabling Efficient Encrypted Neural Network Inference through Unified MVM and Convolution
- ASPLOS '25 — ReSBM: Region-based Scale and Minimal-Level Bootstrapping Management for FHE via Min-Cut
- CGO '25 — ANT-ACE: An FHE Compiler Framework for Automating Neural Network Inference
Contributing
See CONTRIBUTING.md for code style, lint setup, and pull request guidelines.
License
Apache License 2.0 with LLVM-exception
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distributions
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 ace_fhe-0.2.2-cp312-cp312-manylinux_2_39_x86_64.whl.
File metadata
- Download URL: ace_fhe-0.2.2-cp312-cp312-manylinux_2_39_x86_64.whl
- Upload date:
- Size: 42.8 MB
- Tags: CPython 3.12, manylinux: glibc 2.39+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.10.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5be4878ea34ea748c8dec70200de714e601b01966d4daa38bb30349ab898ca67
|
|
| MD5 |
1c128219af0651a11241b26632cc25b1
|
|
| BLAKE2b-256 |
a63624b0ba378a6b2a5797257703d91608fef500e4dc6467729b9aa7f6381d3c
|