Cloud VPS from $1.98/mo · pay with Bitcoin, Ethereum, Monero, USDT or Solana · paid in crypto
AI and machine learning

Privacy-preserving ML: which technique stops which leak

Federated learning, differential privacy, homomorphic encryption, secure computation and TEEs each stop a different data leak. Find the one your threat needs.

CloudSat teamNovember 18, 20267 min read
Abstract illustration of bright data points passing through a translucent shield that softens them into faint noise before they reach a model
On this pageWhere data leaks from an ML system

Privacy-preserving machine learning is a toolbox, not a product. Each technique in it blocks one specific way personal data escapes from an ML system and leaves the others open. Teams get into trouble when they apply one tool and assume they are covered. Start with the question no tool answers for you: who must not learn what, and from which part of the system?

Where data leaks from an ML system

Leak Who learns too much Techniques that address it
Raw data gathered for training Whoever runs the training pipeline Federated learning, secure multi-party computation, confidential computing
The trained model Anyone who can query or download it Differential privacy, data minimization
Inputs sent for inference Whoever hosts the model Self-hosting, confidential computing, homomorphic encryption
Logs, caches and outputs Operators, and anyone who breaches them Retention limits, access control, encryption at rest

Why removing names is not enough

Stripping obvious identifiers feels like the first and last step. It rarely is. Latanya Sweeney's research in 2000 estimated that about 87% of the US population could be uniquely identified by five-digit ZIP code, sex and date of birth alone. In 2008, Arvind Narayanan and Vitaly Shmatikov re-identified records in the anonymized Netflix Prize dataset by matching a handful of ratings and dates against public IMDb profiles. Any dataset rich enough to train a useful model is usually rich enough to single people out.

Federated learning: move the training, not the data

In federated learning, each phone, hospital or branch trains on its own data and sends only model updates to a coordinator, which averages them into a shared model. McMahan and colleagues at Google described the approach and its FedAvg algorithm in 2017.

It is not private by itself. Updates are computed from the data and can leak it: work such as "Deep Leakage from Gradients" (Zhu and colleagues, 2019) reconstructed training images and text from shared gradients. Production systems therefore add secure aggregation, so the coordinator only ever sees the sum of many updates, and differential privacy on top. Flower (Apache 2.0) is a widely used open framework for building federated setups.

Differential privacy: a guarantee about each record

Differential privacy, defined by Dwork and colleagues in 2006, is a property of an algorithm, not of a dataset. An algorithm is ε-differentially private if adding or removing any one person's record changes the probability of any output by at most a factor of e^ε. Smaller ε means stronger protection and, almost always, lower accuracy. A second parameter, δ, allows a tiny chance of exceeding that bound and should sit well below one over the number of records.

For training, the standard method is DP-SGD (Abadi and colleagues, 2016): clip each example's gradient to a maximum norm, add calibrated Gaussian noise, and track the privacy budget spent across all steps. The US Census Bureau protected the 2020 census results with differential privacy, which shows both the method's maturity and its price: the bureau had to choose how much accuracy to give up for protection.

Opacus (Apache 2.0) adds DP-SGD to an ordinary PyTorch training loop:

import torch
from opacus import PrivacyEngine

# train_loader: your existing torch DataLoader of (features, label) batches
model = torch.nn.Sequential(torch.nn.Linear(64, 32), torch.nn.ReLU(), torch.nn.Linear(32, 2))
optimizer = torch.optim.SGD(model.parameters(), lr=0.05)

privacy_engine = PrivacyEngine()
model, optimizer, train_loader = privacy_engine.make_private_with_epsilon(
    module=model, optimizer=optimizer, data_loader=train_loader,
    target_epsilon=8.0, target_delta=1e-5, epochs=10, max_grad_norm=1.0)

loss_fn = torch.nn.CrossEntropyLoss()
for epoch in range(10):
    for x, y in train_loader:
        optimizer.zero_grad()
        loss_fn(model(x), y).backward()
        optimizer.step()

print("epsilon spent:", privacy_engine.get_epsilon(delta=1e-5))

There is no universally right ε. The number means something only next to δ, the unit being protected (one record, or one person who may own many records) and the accounting method. Decide what you protect, then measure the accuracy cost on your own task against a non-private baseline.

Homomorphic encryption: compute on ciphertext

With fully homomorphic encryption (FHE), a server can compute directly on ciphertext and send back an encrypted answer that only the holder of the key can decrypt. Craig Gentry published the first fully homomorphic scheme in 2009, and schemes such as CKKS now handle approximate arithmetic on real numbers, which suits ML inference. Open libraries include OpenFHE (BSD-2-Clause) and Microsoft SEAL (MIT).

The cost is speed. Encrypted computation runs orders of magnitude slower than plaintext, and operations such as ReLU must be replaced by polynomial approximations. In practice FHE fits small models and narrow tasks, such as scoring an encrypted feature vector, not a large language model reading encrypted prompts.

Secure multi-party computation: compute together, reveal nothing else

Secure multi-party computation (MPC) splits each private value into random shares held by different parties. They compute on the shares and reveal only the agreed result, so several hospitals or companies can train or evaluate a model jointly without anyone seeing the others' records. The price is network traffic between the parties at every step, plus trust that they do not collude beyond what the protocol tolerates. Frameworks such as MP-SPDZ and CrypTen implement it for research and prototypes.

Confidential computing: trust the chip, not the operator

Trusted execution environments keep data encrypted in memory while it is processed and let the data owner check, through remote attestation, exactly what code runs inside. AMD SEV-SNP and Intel TDX protect whole virtual machines, and NVIDIA's H100 and later data center GPUs offer a confidential computing mode that extends protection to GPU memory. The overhead is far smaller than with cryptographic methods, which makes TEEs the practical route to confidential inference on large models. Trust moves to the hardware vendor and its attestation service, and side-channel research keeps probing that boundary.

What self-hosting buys, and what it does not

Running the model on your own server settles the inference row of the leak table: prompts and documents never reach a third-party provider, and you decide what gets logged. It does not settle the other rows.

  • A fine-tuned model can repeat its training data. Carlini and colleagues extracted verbatim training text, personal details included, from GPT-2 in 2021. If you fine-tune on customer records, assume the model can reproduce them, and remove identifiers first or fine-tune with differential privacy.
  • Membership inference works on many models. Shokri and colleagues showed in 2017 that queries alone can reveal whether a given record was in the training set.
  • Logs are data too. Prompt logs, vector databases and caches hold the same personal data as the source documents, and need the same retention limits and access control.
  • Access is the real boundary. A private model on a server that anyone can reach is not private.

A CloudSat private AI chat server keeps prompts and documents on a GPU server you control, which covers the inference row; the training and logging rows stay your design work.

Pick by situation

Situation Start with
Prompts must never reach a third party A self-hosted model, or confidential computing in a cloud
You will publish statistics or a model trained on personal data Differential privacy
Data cannot leave each phone, hospital or branch Federated learning with secure aggregation, plus differential privacy
Two organizations want a joint result without sharing records Secure multi-party computation
A client must not see your model, and you must not see their input Homomorphic encryption for small models, or a TEE

FAQ

Is anonymized data safe to train on?

Not on its own. Combinations of ordinary fields often identify people, as the re-identification studies above show. Treat anonymization as one layer, and add differential privacy when the model or its outputs will be shared.

What epsilon should I use?

There is no standard value. Smaller is stronger and costs more accuracy. Choose by what exposing one record would cost, always report ε together with δ and the protected unit, and compare the accuracy you keep against a non-private baseline.

Does federated learning make data private?

It keeps raw data where it was created, but model updates can still leak information. Pair it with secure aggregation and differential privacy before you call the result private.

Can I run an LLM on encrypted prompts?

Not practically with homomorphic encryption today; the overhead is far too large for models of that size. Confidential computing on GPUs, or a model on your own server, are the workable options.

Run it on CloudSat. Cloud VPS on AMD EPYC and NVMe from $1.98/mo in 13 regions, delivered in under 5 minutes and paid in crypto. See plans or deploy a server.