Skip to content

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

Hugging Face 8 min read Research mediumAdept

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

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.

Assumes: Stable Diffusion pipeline basicsGPU inference conceptsONNX models

Related posts

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

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

  • AMD + 🤗: Large Language Models Out-of-the-Box Acceleration with AMD GPU

    Hugging Face easyNovice

    Hugging Face Transformers now runs all models and tasks on AMD Instinct GPUs with no code changes versus NVIDIA, backed by ROCm support for Flash Attention v2, vLLM Paged Attention, DeepSpeed, GPTQ via AutoGPTQ, ONNX Runtime's ROCMExecutionProvider, and Optimum-Benchmark. Text Generation Inference gains initial MI210/MI250 support through a ROCm Docker image, with GeMM kernel tuning to reach performance parity. Benchmarks show one MI250 (two 64 GB ROCm devices) delivering over 2.33x the decode throughput and half the prefill latency of an A100 at large batch sizes. Its 128 GB memory also fits Llama 70B workloads that run out of memory on two A100-80GBs.

  • Exploring simple optimizations for SDXL

    Hugging Face mediumAdept

    Running SDXL out of the box in fp32 on an A100 takes about 28GB and 72 seconds for 4 images. A series of Diffusers and PyTorch 2 optimizations, each benchmarked on that setup, cuts both. Switching to fp16 brings latency to 14.8s, SDPA attention (on by default) to 11.4s, and torch.compile to 10.3s. Memory drops with model or sequential CPU offloading (sequential is much slower), VAE slicing (15.4GB, or 11.5GB combined with sequential offload), precomputed text embeddings, and the Tiny Autoencoder (15.5GB and faster, at some cost in fine detail). The gains depend on hardware; torch.compile, for example, only appears to help modern GPUs.

  • Make your ZeroGPU Spaces go brrr with ahead-of-time compilation

    Hugging Face mediumAdept

    PyTorch ahead-of-time compilation (torch.export plus AOTInductor) suits ZeroGPU Spaces, where each GPU task runs in a short-lived forked process and torch.compile's just-in-time caching costs tens of seconds to minutes per task. The workflow captures example inputs with spaces.aoti_capture, exports and compiles the transformer inside a @spaces.GPU function, then patches it into the pipeline with spaces.aoti_apply, giving 1.3–1.8× speedups on Flux, Wan and LTX (1.7× on FLUX.1-dev). Further gains come from FP8 dynamic quantization via torchao (about 1.2× more on H200), dynamic shapes via torch.export.Dim, per-resolution multi-compile with shared weights, and prebuilt FlashAttention-3 kernels from the kernels library.

The quest for software engineering knowledge.

Look:
Layout: