LIVE · Thursday 3 December

Fastest Stack to Fine-Tune and Serve a Classifier: ModernBERT, SetFit, TEI or Inference Endpoints

A guide for the solo ML engineer replacing OpenAI classification calls, with the right model and server for each situation and a cost example at 100,000, 1 million and 10 million calls.

By Nick9 min read

For most teams that want to replace OpenAI classification calls, the fastest stack is ModernBERT-base fine-tuned on logged OpenAI labels. Text Embeddings Inference (TEI) serves it on a CPU Hugging Face Inference Endpoint, and low-confidence inputs go back to OpenAI. Use SetFit instead when you have only a few labeled examples per class. Stay on an OpenAI model when you make fewer than about a million calls a month, because the endpoint then costs more than the calls it replaces.

Your label count, call volume, label type and serving risk decide which stack fits

The right choice depends on your data, your traffic and your serving risk, more than on model quality alone.

  1. Ask how many labeled examples you already have, because months of logged OpenAI traffic support full fine-tuning, while a new label with ten examples needs SetFit.
  2. Ask how many classification calls you make each month, because a dedicated endpoint has a fixed monthly cost that only pays off at volume.
  3. Ask whether your labels depend on facts outside the text or on long reasoning, because encoders learn patterns from examples and cannot look things up.
  4. Ask whether a failed model load in TEI would delay you, because the TEI documentation names fewer classifier types than its source code contains.

Teams with months of logged traffic should fine-tune ModernBERT-base

Distillation is the fastest path when you have logs. You train a small model to reproduce the labels that GPT already assigned to your real inputs, so the training data already exists.

ModernBERT-base has 149 million parameters and reads up to 8,192 tokens, compared with 512 for most older encoders, according to Hugging Face's announcement of December 19, 2024. According to the same post, it is twice as fast as DeBERTa and up to four times faster on inputs of mixed length. The post also states that ModernBERT "slightly lags DeBERTaV3" on natural language understanding, so train a DeBERTa-v3-base baseline as well. DeBERTa-v3-base has a 512-token limit in its config, which matters for long tickets. The ModernBERT-base checkpoint is licensed Apache-2.0.

The recipe has three fixed parts. Have a person check a frozen test set of 300 to 1,000 examples, and never train on it. Train on the remaining logs with standard settings. A Hugging Face community tutorial of December 30, 2024 used a learning rate of 5e-5, a batch size of 32, five epochs and bf16. It lists an F1 of 0.89 on 1,000 LLM-labeled examples. Compare models by macro-F1 against the corrected labels, because macro-F1 gives rare classes the same weight as common ones.

No published benchmark compares macro-F1 for ModernBERT-base, DeBERTa-v3-base, RoBERTa-base and SetFit against GPT labels on intent or ticket-routing data, so your own test set provides the only number that counts. PolyAI's Banking77 dataset, with 77 intents and 3,080 test queries under CC BY 4.0, is a public set on which you can rehearse the pipeline before you use private data.

OpenAI's Services Agreement, version v.010126, forbids using Output to build competing models. Its Permitted Exception, however, covers models "primarily intended to categorize, classify, or organize data (e.g., embeddings or classifiers), if these models are not distributed or made commercially available to third parties." An internal classifier fits that exception. A classifier that you sell does not.

Teams with only a handful of labels should start with SetFit

SetFit trains in two stages. It first tunes a sentence-embedding model so that examples with the same label sit close together, then it fits a light classifier on those embeddings. Hugging Face's SetFit post of September 26, 2022 uses 8 examples per class. The post lists 71.3% on the RAFT few-shot benchmark for SetFit with RoBERTa Large, against 62.7% for GPT-3, and about 30 seconds of training on a V100. The current release is 1.2.0, from September 4, 2026.

SetFit suits a new product, a rare class or a label added last week. Once you have logged a few hundred examples per class, move to full fine-tuning and compare the two on the same test set.

Teams that cannot risk a load failure should choose a model that TEI documents

TEI's supported-models page names only CamemBERT and XLM-RoBERTa for sequence classification in its text. Its example table adds a RoBERTa sentiment classifier and a ModernBERT re-ranker. TEI's source code on the main branch also contains classifier heads for ModernBERT and DeBERTa-v2, the architecture that DeBERTa-v3 declares. The table compares what the docs say with what the source code contains.

Base model Config model_type Classifier head in TEI source Named in TEI docs for classification
ModernBERT-base modernbert ModernBertClassificationHead Re-ranker example only
DeBERTa-v3-base deberta-v2 DebertaV2SeqClassificationHead No
RoBERTa-base roberta RobertaClassificationHead Sentiment example
XLM-RoBERTa xlm-roberta RobertaClassificationHead Yes, in the text

A code path is not a tested release, and no published test confirms that a custom ModernBERT classifier loads in the 1.9 image. ModernBERT's TEI head reads classifier_pooling from the model config, and the base checkpoint sets it to mean, so keep that field when you save your fine-tune.

XLM-RoBERTa is the safest serving choice, because it matches the documented text. ModernBERT is still worth trying first, provided that you load your checkpoint in the TEI container before you commit.

Inference Endpoints takes the least work, and ONNX Runtime covers any model that TEI rejects

A small team can serve a fine-tuned encoder in three ways. The table compares them on cost, effort and the main risk.

Option What you run Cost basis Main risk
Inference Endpoints with TEI No server, because Hugging Face runs the container $0.067 an hour for an AWS x2 CPU, billed by the minute Cold starts of a few minutes after scale to zero
TEI on your own server One Docker container, cpu-1.9 Your own server Your model may not load
ONNX Runtime with FastAPI A small Python service Your own server More code to maintain

Inference Endpoints is the least work. According to the autoscaling and configuration guides, endpoints scale to zero after one hour of inactivity by default, and a daily schedule can set a timeout from 15 minutes to 12 hours. While a replica starts, the proxy returns 503 unless the request carries an X-Scale-Up-Timeout header. Keep one replica running during working hours for anything that a user waits on.

Self-hosted TEI uses the same container. The current release is v1.9.4, from September 15, 2026, and classifiers answer on /predict:

curl 127.0.0.1:8080/predict -X POST \
  -d '{"inputs":"Cancel my subscription"}' \
  -H 'Content-Type: application/json'

The ONNX path is the fallback for any model that TEI rejects. Export with optimum-cli export onnx --model ./my-classifier --task text-classification ./onnx/, and keep the --task flag, because a local model exported without it loses its classification head, according to Optimum's guide.

CPU p50 and p95 latency and throughput for these models on these instances have not been published, so measure them on your own input lengths before you choose a size.

Every option should defer low-confidence inputs to OpenAI

The safest switch keeps the original OpenAI call as a fallback for inputs on which the local model has low confidence. Raw confidence scores are not reliable for this. Guo and co-authors showed at ICML 2017 that modern neural networks are "poorly calibrated," and that temperature scaling, which divides the raw scores by one fitted number, is "surprisingly effective" at fixing them.

Fit the temperature on a validation split, then draw a reliability plot with scikit-learn's calibration_curve to check that 90% confidence means about 90% agreement. Choose a conservative threshold that meets your quality bar and an aggressive one that accepts more traffic. The share of traffic that the local model handles at each threshold has not been measured on any public intent dataset, so read it from your own test set.

The operating loop for one person stays small. Run the model in shadow for a week and log every disagreement with GPT. Review a sample of disagreements weekly and add them to the training data. Retrain monthly with a script that refuses to deploy if macro-F1 drops on the frozen test set.

A hosted option can replace part of that loop. Parsec, a small-language-model lab, sells TOD, which ranks a supplied list of options and passes the request to the original LLM when its confidence is low. Parsec's TOD page lists $0.30 per 1,000 decisions, flat regardless of context length, which suits long inputs more than short ones. Parsec says that a decision model tuned on a customer's data "can reach production within two weeks," a claim that it gives without a measured baseline.

A worked cost example shows where the encoder starts to save money

The example uses list prices and states every assumption. Each call sends 500 input tokens and returns 5 output tokens. OpenAI's pricing page lists gpt-4o-mini at $0.15 and $0.60 per million input and output tokens, which comes to $0.000078 per call. gpt-6-luna costs $0.10 and $0.50, which comes to $0.0000525 per call. OpenAI's deprecations page names Luna as the replacement when gpt-4o-mini shuts down on January 14, 2027.

An AWS intel-spr x2 endpoint at $0.067 an hour costs $48.24 for a 30-day month of 720 hours. Two replicas cost $96.48.

  • At 100,000 calls a month, Luna costs $5.25 and gpt-4o-mini costs $7.80, so even a business-hours endpoint at $14.74 for 220 hours costs more.
  • At 1,000,000 calls a month, Luna costs $52.50 against $48.24 for one endpoint, so the two are roughly even before any fallback calls.
  • At 10,000,000 calls a month, Luna costs $525, while two replicas plus Luna for an assumed 30% of traffic cost $96.48 plus $157.50, about $254.

The 70% local share is an assumption, not a measurement. Ten million calls is also an average of 3.9 requests a second, and whether two x2 replicas carry that load has not been measured. OpenAI's Batch API halves its prices for work that can wait, which makes staying on OpenAI cheaper still for overnight jobs.

Some teams should keep the LLM call

A small encoder is the wrong tool when the label depends on knowledge that is not in the text, such as whether a claim about a recent event is true. It is also the wrong tool when the decision needs several steps of reasoning, or when the label set is open-ended or changes every few weeks. Each new label means new examples and a retrain. Those teams should move to the cheapest OpenAI model that meets their test set, use the Batch API where they can, and revisit the encoder when the labels stop changing.

Sources

More in Models

All Models →