fairlearn-fhe¶
Drop-in encrypted Fairlearn metrics. Fairlearn-compatible API for the supported metric subset; ciphertext arithmetic over CKKS via TenSEAL or OpenFHE.
fairlearn-fhe is an early-stage project maintained at
BAder82t/fairlearn-fhe.
# plaintext (existing Fairlearn workflow)
from fairlearn.metrics import demographic_parity_difference
disp = demographic_parity_difference(y_true, y_pred, sensitive_features=A)
# encrypted (one import change)
from fairlearn_fhe import build_context, encrypt
from fairlearn_fhe.metrics import demographic_parity_difference
ctx = build_context()
y_pred_enc = encrypt(ctx, y_pred)
disp = demographic_parity_difference(y_true, y_pred_enc, sensitive_features=A)
disp is numerically equivalent to the plaintext result within CKKS noise tolerance (<1e-4 abs error in default settings; typically ~1e-7 on TenSEAL, ~1e-10 on OpenFHE).
Why¶
Fairness audits often require the auditor to see labels and group-level denominators while the vendor keeps model predictions confidential. Fairlearn (the JMLR'23 standard fairness library) has no FHE plugin. fairlearn-fhe ports the canonical metric set to CKKS without changing the call signature.
What is shipped¶
- 12 canonical metrics (selection_rate, mean_prediction, true/false positive/negative rate, demographic parity diff/ratio, equalized odds diff/ratio, equal opportunity diff/ratio).
MetricFrameandmake_derived_metricwith the same.by_group,.overall,.difference(),.ratio(),.group_min(),.group_max()accessors.- Two trust models: encrypted
y_predonly (Mode A); encryptedy_pred+ sensitive features (Mode B). - Two CKKS backends: TenSEAL (pip) and OpenFHE (native backend, opt-in).
- A canonical
MetricEnvelopewith parameter-set hash, observed depth, and op counts for regulator logging.
Trust posture¶
y_trueis plaintext — it is the auditor's ground truth.y_predis encrypted (always).sensitive_featuresare plaintext (Mode A) or encrypted with revealed group counts (Mode B).- Group-size denominators (and TPR/FPR positive/negative counts) are auditor-public metadata. There is no fairness signal without them.
See Trust models for the full posture.
Install¶
pip install fairlearn-fhe # tenseal backend
pip install fairlearn-fhe[openfhe] # add openfhe backend (requires C++ build)
License¶
Apache-2.0. Compatible with Fairlearn (MIT).