---
title: "Accelerated Inference with Optimum and Transformers Pipelines"
description: "Optimum 1.2 adds inference support via ONNX Runtime with ORTModelForXxx classes that drop into Hugging Face Transformers pipelines in place of AutoModelForXxx."
url: "https://swe.quest/articles/accelerated-inference-with-optimum-and-transformers-pipelines-9ff6245f88a35ca0"
canonical: "https://huggingface.co/blog/optimum-inference"
source: "Hugging Face"
published: "2022-05-10"
difficulty: "medium"
kind: "How-to"
reading_minutes: 12
tags: ["inference","python","performance","machine-learning"]
---

# Accelerated Inference with Optimum and Transformers Pipelines

A post on [Hugging Face](https://swe.quest/sources/hugging-face.md), published 2022-05-10, 12 min read, How-to. Original: [https://huggingface.co/blog/optimum-inference](https://huggingface.co/blog/optimum-inference)

## Summary

Optimum 1.2 adds inference support via ONNX Runtime with ORTModelForXxx classes that drop into Hugging Face Transformers pipelines in place of AutoModelForXxx. An end-to-end tutorial converts deepset/roberta-base-squad2 to ONNX, applies graph optimization (operator fusion, constant folding) with ORTOptimizer, then dynamic int8 quantization with ORTQuantizer targeting AVX512-VNNI on an m5.xlarge. Quantization shrinks the model from 473MB to 292MB while keeping 99.61% of original accuracy on SQuAD v2 (F1 81.83 vs 82.15), and latency is then benchmarked at sequence length 128.

Written by swe.quest, not by the author.

**Difficulty:** Medium: assumes a working developer; shows how it is built or done

## Topics

- [Inference & serving](https://swe.quest/tags/inference.md) (AI & ML)
- [Python](https://swe.quest/tags/python.md) (Languages)
- [Performance engineering](https://swe.quest/tags/performance.md) (Reliability & operations)
- [Machine learning](https://swe.quest/tags/machine-learning.md) (AI & ML)

## Prerequisites

- Hugging Face Transformers pipelines
- Python ([easy posts on Python](https://swe.quest/tags/python.md?difficulty=easy))
- basic model quantization concepts ([easy posts on Inference & serving](https://swe.quest/tags/inference.md?difficulty=easy))

## Keywords

Hugging Face Optimum, ONNX Runtime, Transformers, RoBERTa, SQuAD v2, AVX512-VNNI

## Related posts

- [Convert Transformers to ONNX with Hugging Face Optimum](https://swe.quest/articles/convert-transformers-to-onnx-with-hugging-face-optimum-86f6804aa2e19f43.md): Hugging Face · 2022-06-22 · Medium · 5 min read · Inference & serving, Machine learning, Python
  Hugging Face Transformers models can be exported to ONNX in three ways, shown here on a DistilBERT text-classification checkpoint.
- [Optimum+ONNX Runtime - Easier, Faster training for your Hugging Face models](https://swe.quest/articles/optimum-onnx-runtime-easier-faster-training-for-your-hugging-face-models-99e01d7695af970a.md): Hugging Face · 2023-01-24 · Medium · 6 min read · Model training, Performance engineering, Python
  Hugging Face Optimum's ORTTrainer swaps ONNX Runtime in as the training backend for Transformers models.
- [Introducing Optimum: The Optimization Toolkit for Transformers at Scale](https://swe.quest/articles/introducing-optimum-the-optimization-toolkit-for-transformers-at-scale-a074b17981960e1a.md): Hugging Face · 2021-09-14 · Easy · 4 min read · Inference & serving, Machine learning, Open source, Hardware
  Optimum is a new open source Hugging Face library that targets production performance for Transformer models by wrapping hardware-specific acceleration tooling built with hardware partners.
- [Accelerate your models with 🤗 Optimum Intel and OpenVINO](https://swe.quest/articles/accelerate-your-models-with-optimum-intel-and-openvino-6481f69a8bf224aa.md): Hugging Face · 2022-11-02 · Medium · 5 min read · Inference & serving, Python, Hardware, Computer vision
  Optimum Intel now integrates OpenVINO, letting Transformers models run on OpenVINO Runtime across Intel processors and be quantized with the Neural Network Compression Framework (NNCF).
- [Quanto: a PyTorch quantization backend for Optimum](https://swe.quest/articles/quanto-a-pytorch-quantization-backend-for-optimum-8330ba5aea428b63.md): Hugging Face · 2024-03-18 · Medium · 5 min read · Inference & serving, Python, Machine learning, Open source
  Quanto is a PyTorch quantization backend for Optimum that works in eager mode on any device (CPU, CUDA, MPS), supports int2/int4/int8/float8 weights and int8/float8 activations, and accelerates int8-int8, fp16-int4, bf16-int8 and bf16-int4 matmuls on CUDA.

Browse: [Latest posts](https://swe.quest/index.md) · [Topics](https://swe.quest/tags.md) · [Sources](https://swe.quest/sources.md) · [Topic map](https://swe.quest/map.md) · [Site guide (llms.txt)](https://swe.quest/llms.txt)
