Skip to content

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

Hugging Face 12 min read How-to mediumAdept

Accelerated Inference with Optimum and Transformers Pipelines

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.

Assumes: Hugging Face Transformers pipelinesPythonbasic model quantization concepts

Related posts

  • 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.

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

    Hugging Face mediumAdept

    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.

  • 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.

  • Accelerate your models with 🤗 Optimum Intel and OpenVINO

    Hugging Face mediumAdept

    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). A walkthrough applies post-training static quantization to a ViT image classifier fine-tuned on food101, using 300 calibration samples, then exports to OpenVINO IR and loads the result via OVModelForImageClassification pipelines. The quantized model shrinks 3.8x (344MB to 90MB) and cuts per-sample latency 2.4x (98ms to 41ms) with no measurable accuracy loss (87.6). Warm up the model before benchmarking, because compilation happens on the first inference. Encoder-decoder quantization is not yet supported.

  • Quanto: a PyTorch quantization backend for Optimum

    Hugging Face mediumAdept

    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. The workflow runs from dynamic quantization through optional activation calibration and quantization-aware training to freezing integer weights, then serializing with safetensors plus a quantization map for reloading via requantize. It integrates with transformers through QuantoConfig, works across modalities such as Whisper, and is torch.compile-friendly when activations are left unquantized.

The quest for software engineering knowledge.

Look:
Layout: