
Hugging Face Blog
· 1 min read
Make your ZeroGPU Spaces go brrr with ahead-of-time compilation
ZeroGPU lets anyone spin up powerful Nvidia H200 hardware in Hugging Face Spaces without keeping a GPU locked for idle traffic. It’s efficient, flexible, and ideal for demos but it doesn’t always make full use of everything the GPU and CUDA stack can offer. Generating images or videos can take a significant amount of time. Being able to squeeze out more performance, taking advantage of the H200 hardware, does matter in this case.
This is where PyTorch ahead-of-time (AoT) compilation comes in. Instead of compiling models on the fly (which doesn’t play nicely with ZeroGPU’s short-lived processes), AoT lets you optimize once and reload instantly.
The result: snappier demos and a smoother experience, with speedups ranging from 1.3×–1.8× on models like Flux, Wan, and LTX 🔥
In this post, we’ll show how to wire up Ahead-of-Time (AoT) compilation in ZeroGPU Spaces. We'll explore advanced tricks like FP8 quantization and dynamic shapes, and share working demos you can try right away. If you cannot wait, we invite you to check out some ZeroGPU-powered demos on the zerogpu-aoti organization.
Pro users and Team / Enterprise org members can create ZeroGPU Spaces, while anyone can freely use them (Pro, Team and Enterprise users get 8x more ZeroGPU quota)
Table of Contents
- What is ZeroGPU
- PyTorch compilation
- Ahead-of-time compilation on ZeroGPU
- Gotchas
- Quantization
- Dynamic shapes
- Multi-compile / shared weights
- FlashAttention-3
- Regional compilation
- Use a compiled graph from the Hub
- AoT compiled ZeroGPU Spaces demos
- Conclusion
- Resources
What is ZeroGPU
Spaces is a platform powered by Hugging Face that allows ML practitioners to easily publish demo apps.
Typical demo apps on Spaces look like:
import gradio as gr
from diffusers import DiffusionPipeline
pipe = DiffusionPipeline.from_pretrained(...).to('cuda')
def generate(prompt):
return pipe(prompt).images
gr.Interface(generate, "text", "gallery").launch()
When executing .to('cuda') on this line:
This means that:
Original source
This story was published by Hugging Face Blog. SyncAI.news shows a preview; the complete article is on the publisher's site.
Read the full story on huggingface.co


