Runtime-Driven ONNX Export for Diffusion Pipelines#118
Open
naomili0924 wants to merge 8 commits intohuggingface:mainfrom
Open
Runtime-Driven ONNX Export for Diffusion Pipelines#118naomili0924 wants to merge 8 commits intohuggingface:mainfrom
naomili0924 wants to merge 8 commits intohuggingface:mainfrom
Conversation
|
The docs for this PR live here. All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update. |
xadupre
reviewed
Feb 16, 2026
| original_task = task | ||
| task = TasksManager.map_from_synonym(task) | ||
|
|
||
| print(inf_kwargs) |
Contributor
Author
There was a problem hiding this comment.
sorry, it's not finished yet.
dc208fd to
21d667c
Compare
21d667c to
d244942
Compare
2258fc4 to
effdab0
Compare
33abf74 to
125212c
Compare
125212c to
5ccd6cd
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Motivation
Previously, exporting a text-to-video (or similar diffusion) pipeline to ONNX required:
I tried to export text-to-video pipelines find time-consuming.This approach does not scale for rapidly evolving diffusion pipelines.
This PR introduces a runtime-driven export mechanism integrated into ORTPipelineForText2Video.
Instead of relying on handcrafted OnnxConfig classes, export now works by:
Inference-Based Dummy Input Tracing
The model is executed:
output = model(**inf_kwargs).frames[0]Dummy inputs are derived directly from real inference execution.
This ensures:
Config-Guided Dynamic Axis Estimation
Dynamic axes are estimated using:
module_arch_fields = { "text_encoder": ["d_model", "vocab_size"], "transformer": ["in_channels", "text_dim"], "vae_decoder": ["base_dim", "z_dim"], "vae_encoder": ["base_dim", "z_dim"], }Instead of hardcoding shapes inside custom OnnxConfig classes,selected architectural fields from the model config are used to resolve dimensions.
This allows the exporter to:
Design Principle
✅ One Implementation → Multiple Pipelines
With this design, a single implementation successfully exports multiple text-to-video pipelines without requiring architecture-specific OnnxConfig classes.
Successfully exported and validated:
Both pipelines were exported using the same runtime-driven mechanism:
This demonstrates that the approach generalizes across different diffusion architectures.
The following pipelines were tested but could not be exported due to upstream loading/runtime issues in DiffusionPipeline.from_pretrained:
The export logic itself does not appear to be the limiting factor.
The failure occurs during pipeline initialization, likely due to:
Future Work:
1. Unify symbolic dynamic axis naming
Avoid defining dynamic axes independently per module and ensure consistent symbolic naming across components.
2. Model dynamic shape constraints
Handle dependent dimensions (e.g., a + b, 2 * frames) safely.
Without explicit constraints, changing dynamic inputs may break graphs where derived dimensions are used internally.
3. Add export equivalence validation
Compare PyTorch and ONNX Runtime outputs to ensure structural and numerical consistency after export.
To export Hunyuan:
To export Wan: