Skip to content

In development. Expect rough edges and changes. The source code is not public yet.

Hugging Face 8 min read How-to mediumAdept

Running Privacy-Preserving Inferences on Hugging Face Endpoints

Zama's Concrete ML models, compiled for Fully Homomorphic Encryption (FHE), can be deployed as Hugging Face Inference Endpoints using custom inference handlers. Clients quantize and encrypt inputs locally, upload FHE evaluation keys in chunks (about 70 MB), and receive encrypted predictions that only they can decrypt. The handler exposes save_key, append_key and inference methods. Keys live in endpoint RAM, so they are lost on restart and not shared across replicas, and machines top out at 8 vCPUs. Measured latencies range from 0.4 s for logistic regression to 24 s for a CNN on MNIST.

Related posts

  • Sentiment Analysis on Encrypted Data with Homomorphic Encryption

    Hugging Face mediumAdept

    Sentiment classification can run on encrypted text by computing a transformer (RoBERTa) hidden representation on the client, then running a quantized XGBoost classifier under fully homomorphic encryption with Concrete-ML. On the Twitter airline sentiment dataset the transformer-embedding + XGBoost model reaches 85% accuracy (above the transformer alone at 80%), and FHE predictions match clear-text probabilities exactly. Compilation takes about 9 seconds and FHE inference about 4.4 seconds per example on a 16-core CPU. Deployment uses Concrete-ML's FHEModelDev API to export client/server artifacts, demonstrated in a Hugging Face Space with a Gradio client and a FastAPI server.

  • Towards Encrypted Large Language Models with FHE

    Hugging Face hardMaster

    A single attention head of GPT2's first multi-head attention layer can run on encrypted data using TFHE via Zama's Concrete-Python and Concrete-ML, with the rest of the model executing in plaintext on the client. Weights and activations are post-training quantized to integers, nonlinearities become Programmable Bootstrapping table lookups, and the Hugging Face transformers forward pass is overridden with a quantized SingleHeadAttention module. Four-bit quantization keeps about 96% of original top-k accuracy on roughly 80 sentences, and the compiled circuit needs 8-bit width. A 6-token sequence costs 11,622 PBS operations, which takes minutes on CPU; the authors expect future FHE ASICs to bring that under 100 ms.

  • Why we’re switching to Hugging Face Inference Endpoints, and maybe you should too

    Hugging Face mediumAdept

    A team moved CPU-based transformer inference off a self-built FastAPI + Docker + AWS ECS/Fargate stack onto Hugging Face Inference Endpoints, collapsing deployment to train, push to Hub, deploy. In ab benchmarks with a RoBERTa text classifier, a 4-vCPU endpoint answered in 80±30 ms versus ~200 ms on their ECS container, and an 8-vCPU endpoint in 43 ms. Cost runs 24–50% higher than Fargate (about $60/month more for a large instance), which they judge worth it without a dedicated MLOps team, though not at hundreds of services. The main gap they note is the lack of a Terraform provider; they deploy with their own hugie CLI.

  • Deploy Embedding Models with Hugging Face Inference Endpoints

    Hugging Face mediumAdept

    Open-source embedding models such as BAAI/bge-base-en-v1.5 can be deployed on Hugging Face Inference Endpoints using Text Embeddings Inference (TEI), which offers token-based dynamic batching, Flash Attention, Candle and cuBLASLt kernels, safetensors loading, small images for fast boot, and OpenTelemetry/Prometheus support. Deployment is click-through: pick a model, cloud, region and instance, such as an Nvidia A10G instead of the suggested CPU instance. Batch requests are sent over HTTP with `truncate: true`, because TEI does not truncate inputs by default. A benchmark at sequence length 512 and batch size 32 reached 450+ req/sec, about $0.00000156 per 1k tokens, which Hugging Face says is 64x cheaper than OpenAI embeddings.

  • Getting Started with Hugging Face Inference Endpoints

    Hugging Face mediumAdept

    Hugging Face Inference Endpoints deploys Hub models to managed cloud infrastructure in a few clicks, demonstrated here with a fine-tuned Swin image classifier on a GPU instance in AWS eu-west-1. Endpoints come in three security levels: public (no auth), protected (organization token required) and private, which is reachable only from your own AWS VPC through AWS PrivateLink. The walkthrough calls a protected endpoint from Python with a bearer token, checks the analytics and logs (including errors from a missing Content-Type header), then wires up a private endpoint by creating a VPC endpoint in the AWS console and testing it with curl from EC2.

The quest for software engineering knowledge.

Look:
Layout: