Skip to content

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

Hugging Face 6 min read Announcement mediumAdept

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

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.

Assumes: Hugging Face Transformers TrainerPyTorch training basicsmixed-precision training

Related posts

  • Accelerated Inference with Optimum and Transformers Pipelines

    Hugging Face mediumAdept

    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.

  • Convert Transformers to ONNX with Hugging Face Optimum

    Hugging Face mediumAdept

    Hugging Face Transformers models can be exported to ONNX in three ways, shown here on a DistilBERT text-classification checkpoint. The low-level torch.onnx.export requires manually specifying input/output names and dynamic axes. transformers.onnx derives these from per-architecture config objects. Optimum's ORTModelForXxx classes convert in one call with from_transformers=True and return a model usable directly in pipelines. Once a model is in ONNX it can go on to ONNX Runtime acceleration, static quantization (~3x latency gains claimed) or TensorRT conversion.

  • Accelerating SD Turbo and SDXL Turbo Inference with ONNX Runtime and Olive

    Hugging Face mediumAdept

    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. Throughput gains reach 229% for SDXL Turbo and 120% for SD Turbo. The speedups come from CUDA graphs for static shapes, Flash Attention V2, trimming unused text-encoder outputs and SkipGroupNorm fusion. TensorRT does slightly better with static shapes but needs a separate engine per batch and image size, while the CUDA provider is often the better pick for dynamic shapes on A100. Olive-optimized models, a usage example, and C# and Java community ports are provided.

  • Accelerate Large Model Training using DeepSpeed

    Hugging Face mediumAdept

    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. On two 24GB Titan RTX GPUs, ZeRO Stage-2 allowed 5x larger batches than DDP for DeBERTa-XL (900M) and gave about a 3.5x training speedup with no accuracy loss. BlenderBot-400M fine-tuning saw 2x batch size and a ~1.44x training speedup. ZeRO Stage-3 with CPU offload made GPT-2 XL (1.5B) trainable at batch size 16 where DDP ran out of memory even at batch size 1. The post includes the accelerate config, DeepSpeed JSON configs, and the DummyOptim/DummyScheduler changes needed when the optimizer and scheduler are defined in the DeepSpeed config.

  • Introducing Optimum: The Optimization Toolkit for Transformers at Scale

    Hugging Face easyNovice

    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. Its first integration uses Intel Neural Compressor to quantize Transformers for Intel Xeon CPUs. Quantization is hard to do by hand: ops must be swapped for quantized kernels, quantize/dequantize nodes inserted, observers, schemes and int8/uint8/int16 types chosen, and accuracy loss balanced. Neural Compressor handles this through post-training, quantization-aware and dynamic quantization driven by a YAML config that can be stored on the Model Hub.

The quest for software engineering knowledge.

Look:
Layout: