Repository navigation
Commit 556b22e
feat(integrations): onnx-genai inference_metadata for diffusion + language models (#412)
## What
Adds a **`mobius.integrations.onnx_genai`** integration + a **`mobius
convert-comfyui`** CLI that make Mobius-built models — and **ComfyUI
workflows** — directly runnable by
[onnx-genai](https://github.com/justinchuby/onnx-genai) (companion
runtime PR justinchuby/onnx-genai#35). Everything emits/validates
against onnx-genai's published `inference_metadata` JSON schema; the
core model/task layers stay runtime-agnostic.
## `inference_metadata` emission
- **Diffusion pipelines**: `build_diffusion_pipeline_metadata` emits the
composite `kind: iterative` document (text_encoder→denoiser loop→VAE,
loop-carried self-edge, CFG, scheduler, timesteps).
`SchedulerConfig.from_diffusers` maps a checkpoint's `_class_name` to
the right onnx-genai kind (DDIM/Euler/DPM++ 2M, `use_karras_sigmas`),
rejecting stochastic/unsupported ones; `load_diffusers_scheduler_config`
auto-reads `scheduler/scheduler_config.json`.
- **Decoder LLMs**: `decoder_metadata` emits attention (MHA/GQA) +
kv_cache config; validated token-identical to HF greedy.
- `write_onnx_genai_config` dispatches diffusion-vs-decoder; wired into
`mobius build --runtime onnx-genai`.
## ComfyUI conversion
- **`comfyui.py`** — `parse_comfyui_workflow` walks an API-format graph
to recover the full run (sampler→scheduler kind, steps/cfg, prompts,
seed, width/height, `denoise`→img2img `start_step`, checkpoint traced
through LoraLoader, stacked **LoRAs**, **ControlNet**). Unsupported
samplers raise clearly.
- **`checkpoint_export.py`** — bridges **safetensors→ONNX** via
diffusers (`from_single_file`/`from_pretrained`), auto-detecting
**SDXL** (dual encoder + pooled `text_embeds`) and **inpainting**
(9-channel UNet), and fusing **LoRAs** (`load_lora_weights`+`fuse_lora`)
and **ControlNet** / **SDXL-ControlNet** (fused ControlNet+UNet) into
the exported denoiser — one combined-export pattern, no runtime
special-casing. Emits a `vae_encoder.onnx` for inpainting.
- **`convert.py` / `mobius convert-comfyui`** — reconciles the ComfyUI
sampler (kind/steps/cfg) with the checkpoint's own noise schedule
(betas), computes exact diffusers timesteps, resolves
`--lora`/`--controlnet NAME=PATH`, and writes a runnable pipeline dir +
`run.json`.
## Validation & tests
- **55 integration tests** (translator graph-resolution incl.
LoRA/ControlNet, scheduler mapping, SDXL/inpaint routing, schema
conformance).
- End-to-end (onnx-genai `scripts/*_e2e.py`): every sampler + SDXL +
LoRA + ControlNet + SDXL-ControlNet + inpainting matches diffusers to
<1e-4 (deterministic) on real/tiny models.
---------
Co-authored-by: Copilot <[email protected]>1 parent 9d544b4 commit 556b22e
35 files changed
Lines changed: 4081 additions & 307 deletions
File tree
- docs
- src/mobius
- _configs
- integrations
- onnx_genai
- ort_genai
- models
- tasks
- tests
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
55 | 55 | | |
56 | 56 | | |
57 | 57 | | |
| 58 | + | |
58 | 59 | | |
59 | 60 | | |
60 | 61 | | |
| |||
643 | 644 | | |
644 | 645 | | |
645 | 646 | | |
646 | | - | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
127 | 127 | | |
128 | 128 | | |
129 | 129 | | |
130 | | - | |
| 130 | + | |
| 131 | + | |
131 | 132 | | |
132 | | - | |
| 133 | + | |
133 | 134 | | |
134 | 135 | | |
135 | 136 | | |
| |||
299 | 300 | | |
300 | 301 | | |
301 | 302 | | |
302 | | - | |
| 303 | + | |
303 | 304 | | |
304 | | - | |
305 | | - | |
306 | | - | |
307 | | - | |
| 305 | + | |
| 306 | + | |
| 307 | + | |
| 308 | + | |
| 309 | + | |
308 | 310 | | |
309 | 311 | | |
310 | 312 | | |
| |||
392 | 394 | | |
393 | 395 | | |
394 | 396 | | |
| 397 | + | |
| 398 | + | |
| 399 | + | |
| 400 | + | |
| 401 | + | |
| 402 | + | |
| 403 | + | |
| 404 | + | |
| 405 | + | |
| 406 | + | |
| 407 | + | |
| 408 | + | |
| 409 | + | |
| 410 | + | |
| 411 | + | |
| 412 | + | |
| 413 | + | |
| 414 | + | |
| 415 | + | |
| 416 | + | |
| 417 | + | |
| 418 | + | |
| 419 | + | |
| 420 | + | |
| 421 | + | |
| 422 | + | |
395 | 423 | | |
396 | 424 | | |
397 | 425 | | |
| |||
567 | 595 | | |
568 | 596 | | |
569 | 597 | | |
570 | | - | |
| 598 | + | |
571 | 599 | | |
572 | 600 | | |
573 | | - | |
574 | | - | |
575 | | - | |
576 | | - | |
577 | | - | |
578 | | - | |
579 | | - | |
580 | | - | |
581 | | - | |
582 | | - | |
583 | | - | |
584 | | - | |
585 | | - | |
586 | | - | |
587 | | - | |
588 | | - | |
| 601 | + | |
| 602 | + | |
| 603 | + | |
| 604 | + | |
| 605 | + | |
| 606 | + | |
589 | 607 | | |
590 | 608 | | |
591 | 609 | | |
| |||
675 | 693 | | |
676 | 694 | | |
677 | 695 | | |
| 696 | + | |
| 697 | + | |
| 698 | + | |
| 699 | + | |
| 700 | + | |
| 701 | + | |
| 702 | + | |
| 703 | + | |
| 704 | + | |
| 705 | + | |
| 706 | + | |
| 707 | + | |
| 708 | + | |
| 709 | + | |
| 710 | + | |
| 711 | + | |
| 712 | + | |
| 713 | + | |
| 714 | + | |
| 715 | + | |
| 716 | + | |
| 717 | + | |
| 718 | + | |
| 719 | + | |
| 720 | + | |
678 | 721 | | |
679 | 722 | | |
680 | 723 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
63 | 63 | | |
64 | 64 | | |
65 | 65 | | |
| 66 | + | |
| 67 | + | |
66 | 68 | | |
67 | 69 | | |
68 | 70 | | |
| |||
547 | 549 | | |
548 | 550 | | |
549 | 551 | | |
| 552 | + | |
550 | 553 | | |
551 | 554 | | |
552 | 555 | | |
553 | 556 | | |
554 | 557 | | |
| 558 | + | |
555 | 559 | | |
556 | 560 | | |
557 | 561 | | |
558 | 562 | | |
559 | 563 | | |
| 564 | + | |
560 | 565 | | |
561 | 566 | | |
562 | 567 | | |
| |||
583 | 588 | | |
584 | 589 | | |
585 | 590 | | |
586 | | - | |
| 591 | + | |
| 592 | + | |
| 593 | + | |
587 | 594 | | |
588 | 595 | | |
589 | | - | |
| 596 | + | |
| 597 | + | |
| 598 | + | |
| 599 | + | |
| 600 | + | |
590 | 601 | | |
591 | 602 | | |
592 | 603 | | |
| 604 | + | |
593 | 605 | | |
594 | 606 | | |
595 | 607 | | |
| |||
744 | 756 | | |
745 | 757 | | |
746 | 758 | | |
747 | | - | |
| 759 | + | |
| 760 | + | |
| 761 | + | |
| 762 | + | |
| 763 | + | |
748 | 764 | | |
749 | 765 | | |
750 | 766 | | |
| 767 | + | |
| 768 | + | |
751 | 769 | | |
752 | 770 | | |
753 | 771 | | |
| |||
0 commit comments