If you’re deploying transformer models anywhere that isn’t a Jupyter notebook, you already know the pain: PyTorch checkpoints are heavy, slow to initialize, and finicky across runtimes. The fix is ONNX, the open format that turns your model into a portable computational graph. Hugging Face’s Optimum library is the bridge, and there are three distinct paths across that bridge depending on how much boilerplate you’re willing to stomach.

The raw torch.onnx export is the manual transmission. You get full control, but you’re hand-specifying input names, output names, dynamic axes, and the opset version. It’s fine for a one-off, less fun at 2 a.m. when a batch dimension misbehaves. The mid-level transformers.onnx route hands some of that work to configuration objects, so you’re no longer defining dynamic axes by hand. The high-level Optimum CLI reduces the whole thing to a single command.

All three methods produce the same artifact: a serialized ONNX graph for distilbert-base-uncased-finetuned-sst-2-english, the standard text-classification benchmark. Supported architectures run the gamut from BERT and RoBERTa to GPT-2, GPT-J, and T5. That’s a meaningful chunk of the Hugging Face hub covered, though you’ll want to check the docs before betting a production pipeline on an exotic model.

The real payoff comes after export. ONNX is not a runtime—it’s a representation. You’ll still need something like ONNX Runtime (or specialized accelerators like Graphcore IPU and Habana Gaudi) to actually execute the graph. That’s where Optimum earns its keep, layering quantization, graph optimization, and accelerated inference on top of the conversion. For teams pushing transformer models into production, skipping the ONNX step is increasingly not an option.