Skip to content

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

Hugging Face 17 min read Research mediumAdept

1 Billion Classifications

Processing 1B classifications or embeddings on a single-GPU baseline costs about $254 for DistilBERT sentiment classification and $409 for ModernBERT-based gte embeddings on an NVIDIA L4 ($0.8/hr), but roughly $44,500 for ColQwen2 vision embeddings. The method serves models with Infinity on Hugging Face Inference Endpoints and load-tests them with k6's shared-iterations executor. It sweeps batch size and virtual users using an exponential-then-binary search with a 2% improvement threshold, then scales cost horizontally by adding replicas. The best configurations were batch 64 / 448 VUs for classification, 32 / 256 for embedding and 4 / 4 for vision. The cheap T4 lost to the L4, partly because Flash Attention 2 requires newer GPUs.

Assumes: transformer encoder modelsGPU inference basicsload testing concepts

Related posts

  • Rocket Money x Hugging Face: Scaling Volatile ML Models in Production​

    Hugging Face easyNovice

    Rocket Money replaced a regex-and-decision-table merchant detector with a BERT-family transformer classifier spanning 4000+ classes, served through Hugging Face's hosted Inference API rather than an in-house MLOps stack. They picked it over AWS SageMaker and a hand-rolled host after a three-month evaluation with gradual traffic ramps and worst-case load tests. An A/B split of new users showed better paid retention, and the rollout reached 100% over two months. A pre-inference cache cut costs, hitting about 85% hit rate in production against a theoretical 93%, as volume grew past a billion transactions per month. The team hit an outage when expanding classes and a stale-model caching bug on the vendor side, and so far has found LLMs slower and costlier than specialized classifiers.

  • My Journey to a serverless transformers pipeline on Google Cloud

    Hugging Face mediumAdept

    A Hugging Face transformers sentiment-analysis pipeline (DistilBERT fine-tuned on SST-2) was deployed as a low-traffic microservice on Google Cloud Run after AI Platform Prediction (beta instability, checkpoint not a pure TensorFlow model) and App Engine (TensorFlow install failure, PyTorch handling only 2 requests per instance) fell short. The final setup is a Flask app served by gunicorn with one worker and one thread in a Docker image, with Cloud Run memory raised to 4 GB because the model needs most of it. Requests take under five seconds including model loading, plus roughly 10 seconds on cold start; loading the model at startup instead of per request would cut both latency and memory. The image is about 1 GB (PyTorch ~700 MB, model ~250 MB), so storage costs roughly €0.10 per GB per month on top of request costs.

  • 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.

  • 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.

  • Accelerate BERT inference with Hugging Face Transformers and AWS Inferentia

    Hugging Face mediumAdept

    DistilBERT can be compiled to AWS Neuron with torch.neuron.trace and served on an Inferentia-backed SageMaker real-time endpoint, using a custom inference.py that pins one Neuron core per HTTP worker. Because the Neuron SDK lacked dynamic shape support, inputs must be padded to a fixed sequence length (128 here) chosen at compile time. On an ml.inf1.xlarge the endpoint averaged 5-6 ms model latency per request. That is faster than CPU, and running four model copies across the chip's four Neuron cores gives higher throughput than GPUs. The recommendation is to move BERT-like encoder workloads to Inferentia when that latency is acceptable.

The quest for software engineering knowledge.

Look:
Layout: