---
title: "Optimum+ONNX Runtime - Easier, Faster training for your Hugging Face models"
description: "Hugging Face Optimum's ORTTrainer swaps ONNX Runtime in as the training backend for Transformers models."
url: "https://swe.quest/articles/optimum-onnx-runtime-easier-faster-training-for-your-hugging-face-models-99e01d7695af970a"
canonical: "https://huggingface.co/blog/optimum-onnxruntime-training"
source: "Hugging Face"
published: "2023-01-24"
difficulty: "medium"
kind: "Announcement"
reading_minutes: 6
tags: ["model-training","performance","python"]
---

# Optimum+ONNX Runtime - Easier, Faster training for your Hugging Face models

A post on [Hugging Face](https://swe.quest/sources/hugging-face.md), published 2023-01-24, 6 min read, Announcement. Original: [https://huggingface.co/blog/optimum-onnxruntime-training](https://huggingface.co/blog/optimum-onnxruntime-training)

## Summary

Hugging Face Optimum's ORTTrainer swaps ONNX Runtime in as the training backend for Transformers models. It reports throughput gains of 39–130% over a PyTorch baseline on an 8×A100 node when combined with DeepSpeed ZeRO Stage 1, and up to 40% with ONNX Runtime alone. The speedups come from memory planning, kernel optimizations, multi-tensor-apply fused Adam, an FP16 optimizer that avoids device-to-host copies, mixed precision and graph fusions. Adopting it mostly means replacing Trainer and TrainingArguments with ORTTrainer and ORTTrainingArguments and optionally selecting the adamw\_ort\_fused optimizer.

Written by swe.quest, not by the author.

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

## Topics

- [Model training](https://swe.quest/tags/model-training.md) (AI & ML)
- [Performance engineering](https://swe.quest/tags/performance.md) (Reliability & operations)
- [Python](https://swe.quest/tags/python.md) (Languages)

## Prerequisites

- Hugging Face Transformers Trainer
- PyTorch training basics ([easy posts on Model training](https://swe.quest/tags/model-training.md?difficulty=easy))
- mixed-precision training ([easy posts on Model training](https://swe.quest/tags/model-training.md?difficulty=easy))

## Keywords

Optimum, ONNX Runtime, ORTTrainer, DeepSpeed ZeRO, Hugging Face Transformers, PyTorch

## Related posts

- [Accelerated Inference with Optimum and Transformers Pipelines](https://swe.quest/articles/accelerated-inference-with-optimum-and-transformers-pipelines-9ff6245f88a35ca0.md): Hugging Face · 2022-05-10 · Medium · 12 min read · Inference & serving, Python, Performance engineering, Machine learning
  Optimum 1.2 adds inference support via ONNX Runtime with ORTModelForXxx classes that drop into Hugging Face Transformers pipelines in place of AutoModelForXxx.
- [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.
- [Accelerating SD Turbo and SDXL Turbo Inference with ONNX Runtime and Olive](https://swe.quest/articles/accelerating-sd-turbo-and-sdxl-turbo-inference-with-onnx-runtime-and-olive-c7ff7774ed240b5b.md): Hugging Face · 2024-01-15 · Medium · 8 min read · Inference & serving, Performance engineering, Computer vision, Hardware
  ONNX Runtime's CUDA and TensorRT execution providers run SD Turbo and SDXL Turbo faster than PyTorch on NVIDIA A100 and RTX 4090 GPUs for every batch-size and step combination tested.
- [Accelerate Large Model Training using DeepSpeed](https://swe.quest/articles/accelerate-large-model-training-using-deepspeed-d18dbe7623c821c0.md): Hugging Face · 2022-06-28 · Medium · 8 min read · Model training, Python, Performance engineering
  Hugging Face Accelerate can enable DeepSpeed ZeRO data parallelism, which shards optimizer states, gradients and parameters across GPUs and optionally offloads them to CPU, with no or minimal code changes.
- [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.

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)
