Skip to content

Support compact SD and complete video diffusion workflows - #538

Merged
justinchuby merged 12 commits into
mainfrom
justinchuby/catalogue-diffusion-builds
Aug 22, 2026
Merged

justinchuby merged 12 commits into
mainfrom
justinchuby/catalogue-diffusion-builds

Conversation

@justinchuby

Copy link
Copy Markdown
Member

Summary

  • export BK-SDM checkpoints without a UNet mid-block
  • add encoder-only T5 export for CogVideoX
  • add typed DDIM epsilon/sample/v-prediction contracts
  • add model-agnostic video CFG, layout, unscale, causal-cache, and recurrence workflows
  • add typed cast/clamp adapters and nested artifact paths for image APIs/image edit

Validation

  • 76 policy/workflow tests passed
  • earlier targeted model tests: 27 passed
  • real Stable Diffusion and CogVideoX packages validated and executed through ONNX GenAI

@justinchuby
justinchuby requested review from a team and a lite review from Copilot August 21, 2026 23:29
@github-actions

github-actions Bot commented Aug 21, 2026 •

Copy link
Copy Markdown

Performance Comparison

Comparing c047f77 → edf41ee

Model Metric Baseline Current Delta
bert (feature-extraction) model_size_bytes 359 KB 359 KB +0.0% ⚪
bert (feature-extraction) num_nodes 68 68 +0.0% ⚪
falcon model_size_bytes 364 KB 364 KB +0.0% ⚪
falcon num_nodes 66 66 +0.0% ⚪
gemma2 model_size_bytes 428 KB 428 KB +0.0% ⚪
gemma2 num_nodes 105 105 +0.0% ⚪
gpt2 model_size_bytes 388 KB 388 KB +0.0% ⚪
gpt2 num_nodes 54 54 +0.0% ⚪
llama model_size_bytes 425 KB 425 KB +0.0% ⚪
llama num_nodes 60 60 +0.0% ⚪
llama (static-cache) model_size_bytes 425 KB 425 KB +0.0% ⚪
llama (static-cache) num_nodes 56 56 +0.0% ⚪
mamba (ssm-text-generation) model_size_bytes 296 KB 296 KB +0.0% ⚪
mamba (ssm-text-generation) num_nodes 94 94 +0.0% ⚪
phi3 model_size_bytes 421 KB 421 KB +0.0% ⚪
phi3 num_nodes 58 58 +0.0% ⚪
phi3 (static-cache) model_size_bytes 421 KB 421 KB +0.0% ⚪
phi3 (static-cache) num_nodes 54 54 +0.0% ⚪
qwen2 model_size_bytes 425 KB 425 KB +0.0% ⚪
qwen2 num_nodes 60 60 +0.0% ⚪
qwen2 (static-cache) model_size_bytes 425 KB 425 KB +0.0% ⚪
qwen2 (static-cache) num_nodes 56 56 +0.0% ⚪
qwen3_5_moe (hybrid-text-generation) model_size_bytes 506 KB 506 KB +0.0% ⚪
qwen3_5_moe (hybrid-text-generation) num_nodes 264 264 +0.0% ⚪
qwen3_5_text (hybrid-text-generation) model_size_bytes 458 KB 458 KB +0.0% ⚪
qwen3_5_text (hybrid-text-generation) num_nodes 126 126 +0.0% ⚪
qwen3_5_vl (hybrid-qwen-vl) model_size_bytes 977 KB 977 KB +0.0% ⚪
qwen3_5_vl (hybrid-qwen-vl) num_nodes 428 428 +0.0% ⚪
t5 (seq2seq) model_size_bytes 836 KB 836 KB +0.0% ⚪
t5 (seq2seq) num_nodes 166 176 +6.0% ⚠️
whisper (speech-to-text) model_size_bytes 1008 KB 1008 KB +0.0% ⚪
whisper (speech-to-text) num_nodes 128 128 +0.0% ⚪

Warning: minor regressions detected. Review flagged metrics.

@github-actions

github-actions Bot commented Aug 21, 2026 •

Copy link
Copy Markdown

🏗️ Architecture Diff

Comparing c047f77 → edf41ee

Model Sub-model Changes Status
bert (feature-extraction) model 0 ⚪
falcon model 0 ⚪
gemma2 model 0 ⚪
gemma4 (gemma4) decoder 0 ⚪
gemma4 (gemma4) embedding 0 ⚪
gemma4 (gemma4) vision_encoder 0 ⚪
gemma4_text model 0 ⚪
gpt2 model 0 ⚪
llama model 0 ⚪
llama (static-cache) model 0 ⚪
mamba (ssm-text-generation) model 0 ⚪
phi3 model 0 ⚪
phi3 (static-cache) model 0 ⚪
qwen model 0 ⚪
qwen (static-cache) model 0 ⚪
qwen2 model 0 ⚪
qwen2 (static-cache) model 0 ⚪
qwen2_moe model 0 ⚪
qwen2_moe (static-cache) model 0 ⚪
qwen3 model 0 ⚪
qwen3 (static-cache) model 0 ⚪
qwen3_5_moe (hybrid-text-generation) model 0 ⚪
qwen3_5_text (hybrid-text-generation) model 0 ⚪
qwen3_5_vl (hybrid-qwen-vl) decoder 0 ⚪
qwen3_5_vl (hybrid-qwen-vl) embedding 0 ⚪
qwen3_5_vl (hybrid-qwen-vl) vision_encoder 0 ⚪
qwen3_moe model 0 ⚪
qwen3_moe (static-cache) model 0 ⚪
qwen3_next (hybrid-text-generation) model 0 ⚪
t5 (seq2seq) decoder 0 ⚪
t5 (seq2seq) encoder 14 🟡
whisper (speech-to-text) decoder 0 ⚪
whisper (speech-to-text) encoder 0 ⚪
t5 (seq2seq) / encoder — 14 change(s)

Op summary: 71 → 81 nodes

--- base
+++ head
@@ -32,6 +32,16 @@
 Gather
 Transpose
 Unsqueeze
+CastLike
+Constant
+CastLike
+Sub
+Constant
+CastLike
+Mul
+Constant
+Unsqueeze
+Add
 RMSNormalization
 Transpose
 MatMul

Added nodes:

  • + CastLike
  • + Constant
  • + CastLike
  • + Sub
  • + Constant
  • + CastLike
  • + Mul
  • + Constant
  • + Unsqueeze
  • + Add

Connectivity changes:

  • node[49] Transpose: input_ids [16] → [12]
  • node[50] MatMul: input_ids [76, 77] → [70, 75]
  • node[67] Transpose: input_ids [24] → [20]
  • node[68] MatMul: input_ids [96, 97] → [90, 95]

Legend: ⚪ No change · 🔵 Minor (attrs/inits) · 🟡 Moderate (nodes added/removed) · 🔴 Major (interface changed)

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds compact UNet support, encoder-only T5 export, and typed image/video diffusion workflows.

Changes:

  • Supports UNets without mid-blocks and registers T5 encoder exports.
  • Adds typed DDIM, casting, clamping, CFG, layout, caching, and recurrence components.
  • Extends Diffusers configuration/building and nested artifact paths.

Reviewed changes

Copilot reviewed 12 out of 12 changed files in this pull request and generated 8 comments.

Show a summary per file
File Review findings
src/mobius/tasks/_t5_text_encoder.py Defines the T5 encoder task contract. No final comments.
src/mobius/tasks/__init__.py Registers the T5 task. No final comments.
src/mobius/models/unet.py Nit (2 votes): Add graph-build/parity coverage for mid_block=None.
src/mobius/models/t5.py Moderate (3 votes): Apply attention_mask semantics. Nit (2 votes): Export and import T5EncoderModel.
src/mobius/integrations/onnx_genai/workflow_metadata.py Critical (2 votes): Add rank-5 video dispatch and scheduler arguments. Critical (2 votes): Match history initializer dtype to timestep dtype. Critical (2 votes): Thread latent/VAE dtype through all video helpers. Nit (3 votes): Add runtime coverage for video CFG.
src/mobius/integrations/diffusers/_configs.py Adds T5 and compact-UNet configuration support. No final comments.
src/mobius/integrations/diffusers/_configs_test.py Configuration coverage. No final comments.
src/mobius/integrations/diffusers/_builder.py Registers Diffusers components. No final comments.
src/mobius/integrations/diffusers/_builder_test.py Builder registration coverage. No final comments.
src/mobius/generation/_policy_components.py Nit (2 votes): Add runtime coverage for prediction_type="sample" with nontrivial alpha.
src/mobius/generation/_policy_components_test.py Policy behavior coverage. No final comments.
src/mobius/generation/__init__.py Exports policy components. No final comments.
Suppressed comments (7)

src/mobius/generation/_policy_components.py:2062

  • The sample branch computes epsilon by dividing by sqrt(1 - alpha). The video workflow's default DDIM schedule starts with alpha == 1.0, so its first sample-prediction step produces 0/0 and contaminates the latent. Handle the endpoint explicitly or reject schedules that make this conversion undefined, with a regression test for the default schedule.
        pred_epsilon = op.Div(
            op.Sub(sample, op.Mul(alpha_sqrt, pred_original)), beta_sqrt

src/mobius/integrations/onnx_genai/workflow_metadata.py:3739

  • When solver="ddim" and no schedule is supplied, this workflow falls back to [1, ..., 0]. The DDIM component interprets the schedule as cumulative alphas in denoising order, so the current alpha starts at 1 and alpha_prev decreases, reversing the trajectory (the runtime tests use an increasing [0.4, 0.9, 1.0] schedule). Require explicit DDIM alpha/timestep schedules or materialize a valid increasing alpha schedule instead of using the generic fallback.
    prediction_type: str = "epsilon",
    guidance_scale: float | None = None,

src/mobius/integrations/onnx_genai/workflow_metadata.py:3837

  • The new video CFG path checks only that a text encoder exists; it does not create the conditioning cast adapter that the image path uses. If the T5 output dtype differs from the denoiser's encoder_hidden_states dtype, both the negative and conditional invocations later in the loop receive an incompatible tensor contract. Mirror the image workflow's raw-conditioning plus cast component here, or reject mixed dtypes explicitly.
    if guidance_scale is not None and (text_encoder is None or conditioning_output is None):
        raise ValueError("video classifier-free guidance requires a text encoder")

src/mobius/integrations/onnx_genai/workflow_metadata.py:3739

  • prediction_type is only passed to the DDIM component; Euler still consumes the raw denoiser output as an epsilon/derivative. Thus solver="euler" silently accepts sample or v_prediction and integrates the wrong quantity (and even skips DDIM's value validation). Reject non-epsilon modes for Euler or convert them using the scheduler before the Euler step.
    prediction_type: str = "epsilon",
    guidance_scale: float | None = None,

src/mobius/integrations/onnx_genai/workflow_metadata.py:3906

  • This local is assigned but never read. It will trigger the repository's unused-variable lint rule and is not needed by the video workflow; remove it or use it for the intended request contract.
    row_float = {"dtype": "float32", "rank": 1, "shape": [batch]}

src/mobius/integrations/onnx_genai/workflow_metadata.py:3708

  • This parameter is honored by the direct image-edit writer, but the public write_onnx_genai_config() image-edit branch does not forward artifact_paths from kwargs; because that entry point accepts **kwargs, the option is silently ignored. Pass it through in the public branch and add an end-to-end metadata-path assertion.
    artifact_paths: dict[str, str] | None = None,

src/mobius/tasks/_t5_text_encoder.py:38

  • The task now requires attention_mask, but T5Encoder.forward() ignores that argument and passes only the relative-position bias to every block. With padded prompt tokens, self-attention can read the padding and the encoder output diverges from the Hugging Face T5 encoder; wire the mask into the encoder attention bias (and add a padded-input parity test) before exporting this contract.
        hidden_states = module(
            builder.op,
            input_ids=input_ids,
            attention_mask=attention_mask,

💡 Configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread src/mobius/models/t5.py Resolved
Comment thread src/mobius/models/t5.py Resolved
Comment thread src/mobius/models/unet.py Resolved
@justinchuby

Copy link
Copy Markdown
Member Author

Final catalogue validation: 9bdf315 makes image-edit output clamping cast BF16 decoder output to FP32 before Clip, avoiding ORT BF16 Less/Clip kernel assignment failure. Targeted policy/workflow tests: 77 passed. Real Qwen-Image-Edit-2509 generic workflow then passed end to end on CUDA.

@justinchuby

Copy link
Copy Markdown
Member Author

Review cleanup is complete at 37e75275. This adds the requested video CFG/runtime coverage, automatic rank-5 CogVideoX dispatch, faithful DDIM schedule materialization, typed history/layout/cache/VAE adapters, T5 padding-mask semantics/public export, compact UNet coverage, and image-edit artifact/output-clamp ordering coverage.

All 8 substantive review threads are resolved. Local targeted validation: 169 passed, 1 skipped; Ruff 0.16.2 format/lint and git diff --check pass. CI currently has 20 successful checks and no failures; three GPU/golden jobs remain queued. This PR has not been merged.

@justinchuby

Copy link
Copy Markdown
Member Author

Rubber-duck blockers are fixed at c84e542a:

  • Image-edit and video exports now reject omitted guidance instead of silently selecting 1.0/unguided execution. mobius build --runtime onnx-genai --guidance-scale SCALE parses and forwards the explicit value; 1.0 remains an intentional unguided choice, while values above one preserve negative-conditioning CFG wiring.
  • Image-edit publishes its image contract from the image_output_clamp output, so FP16/BF16 VAE decoders correctly declare a float32 image.

Regressions cover omitted image/video guidance, CLI forwarding, and FP16/BF16 output contracts. Targeted tests: 106 passed. Ruff 0.16.2 format/lint and git diff --check pass. No unresolved review threads remain; PR remains unmerged.

@justinchuby

Copy link
Copy Markdown
Member Author

Final pinned-revision blocker is fixed at 5fb8cc78 (kept unmerged).

  • Image-edit scheduler resolution now receives revision.
  • Video and generic diffusion VAE scaling-factor resolution now receives revision; load_diffusers_vae_scaling_factor() pins the vae/config.json Hub download.
  • Audit also found the standalone ComfyUI conversion scheduler lookup; its API now accepts and forwards an optional pinned revision.
  • Existing tokenizer, processor/runtime-asset, diffusers component config, and weight reads already forward the revision.
  • Added exact-argument regressions for image-edit scheduler, video scheduler/VAE, generic scheduler/VAE, direct VAE Hub download, ComfyUI scheduler, and CLI metadata forwarding.

Validation: targeted auto-export/inference-metadata/ComfyUI/CLI suites: 144 passed, 1 skipped; Ruff 0.16.2 check/format and git diff --check pass. All review threads are resolved; CI is running on the new SHA.

@justinchuby

Copy link
Copy Markdown
Member Author

Final convert-comfyui caller gap is fixed at 738a649a (kept unmerged).

  • Added mobius convert-comfyui --revision REVISION with direct help text.
  • _cmd_convert_comfyui now forwards the exact parsed revision to convert_comfyui_workflow.
  • Added a CLI-level regression that invokes main(), parses the full command, and asserts exact checkpoint/revision propagation.
  • Audited command aliases/docs: there is no alias or separate checked-in command documentation; the argparse help is the authoritative directly related documentation and now includes the option.

Validation: targeted CLI/ComfyUI/auto-export tests 108 passed, 1 skipped; Ruff check/format, git diff --check, and live PYTHONPATH=src python3 -m mobius convert-comfyui --help verification pass. All review threads are resolved; CI is running on the new SHA.

@justinchuby

Copy link
Copy Markdown
Member Author

Latest origin/main (96036366) is merged without rebasing at d57234e8; PR remains unmerged and is now conflict-free/mergeable.

Conflict resolution preserved both sides: generalized arbitrary-rank typed output clamping (including float32 image-edit clamp output), main’s default rank-4 clamp API, explicit image/video guidance, canonical image value ranges, complete pinned revision propagation including convert-comfyui --revision, video/image workflow metadata, and all current-main conformance tests. Unrelated GGUF/SenseNova main changes were retained.

Validation: focused CLI/ComfyUI/auto-export/inference/workflow/policy/value-range set 235 passed, 1 skipped; GGUF/SenseNova conflict areas 53 passed; Ruff 0.16.2 check/format and diff checks pass. Worktree is clean, all review threads resolved, CI is running on d57234e8.

justinchuby and others added 11 commits August 22, 2026 15:31
Honor diffusers pipelines that explicitly omit the UNet mid block, as used by BK-SDM Small. Add an encoder-only T5 component and task so CogVideoX packages include their real prompt encoder without exporting an unused decoder.

Co-authored-by: Copilot <[email protected]>
Signed-off-by: justinchuby <[email protected]>
Add typed DDIM prediction modes, video classifier-free guidance, tensor cast/clamp adapters, and shape-correct recurrence metadata so real Stable Diffusion and CogVideoX packages execute through ONNX GenAI.

Tests: 76 policy and workflow metadata tests passed.

Co-authored-by: Copilot <[email protected]>
Signed-off-by: justinchuby <[email protected]>
Declare a clamped image range for generic image APIs and allow canonical metadata to preserve existing nested ONNX artifact paths without moving or re-uploading large external-data weights.

Tests: 76 policy and workflow metadata tests passed.

Co-authored-by: Copilot <[email protected]>
Signed-off-by: justinchuby <[email protected]>
Cast configurable diffusion outputs to float32 before applying Clip so ONNX Runtime can execute BF16-decoder workflows such as Qwen Image Edit. Preserve the default same-dtype behavior and cover the BF16 graph load path.

Co-authored-by: Copilot <[email protected]>
Signed-off-by: justinchuby <[email protected]>
Regenerate the canonical diffusion, guided diffusion, and video metadata fixtures after the output range and complete runtime contract updates.

Co-authored-by: Copilot <[email protected]>
Signed-off-by: justinchuby <[email protected]>
Unify the tensor-cast policy added independently by main and the diffusion work, update image-edit expectations for the explicit output clamp, and apply current Ruff formatting to files introduced by the main merge.

Co-authored-by: Copilot <[email protected]>
Signed-off-by: justinchuby <[email protected]>
Make CogVideoX workflow export structural and model-agnostic, materialize faithful DDIM schedules, and carry typed layout, cache, CFG, and VAE adapters through mixed-precision pipelines. Harden scheduler validation and DDIM sample prediction semantics.

Also preserve image-edit artifacts, apply T5 padding masks, cover optional UNet mid blocks, export the T5 encoder publicly, and remove dead GGUF code. Add graph, metadata, and runtime tests for the corrected contracts.

Co-authored-by: Copilot <[email protected]>
Signed-off-by: justinchuby <[email protected]>
Reject omitted guidance for image-edit and video exports instead of silently selecting unguided behavior, expose and forward the guidance scale through the build CLI, and retain explicit negative-conditioning CFG wiring.

Publish image-edit output contracts from the float32 clamp output rather than the reduced-precision VAE decoder output. Add omission, CLI forwarding, FP16, and BF16 regressions.

Co-authored-by: Copilot <[email protected]>
Signed-off-by: justinchuby <[email protected]>
Thread the requested Hugging Face revision through image-edit and ComfyUI scheduler resolution and through video and generic diffusion VAE scaling-factor reads. Extend the VAE config loader to pin Hub downloads and add regressions for each semantic lookup plus CLI forwarding.

Co-authored-by: Copilot <[email protected]>
Signed-off-by: justinchuby <[email protected]>
Expose --revision on mobius convert-comfyui and pass the exact pinned revision into scheduler metadata conversion. Add a CLI-level regression that exercises argument parsing and verifies the conversion call.

Co-authored-by: Copilot <[email protected]>
Signed-off-by: justinchuby <[email protected]>
Preserve explicit integer and boolean output metadata for generated policy components after rebasing the diffusion workflow branch onto current main. This keeps generated ONNX GenAI fixtures semantically stable and formats the conflict-resolved files.

Co-authored-by: Copilot <[email protected]>

Copilot-Session: 39ff6824-d35f-4d3b-8f5f-043a7119a100
Signed-off-by: Justin Chu <[email protected]>
@justinchuby
justinchuby force-pushed the justinchuby/catalogue-diffusion-builds branch from d57234e to 789bd76 Compare August 22, 2026 15:39
Preserve the force-pushed head as backup/catalogue-diffusion-builds-789bd76c, then merge origin/main at c047f77 without rebasing. This restores current MTP and metadata changes while retaining the approved diffusion guidance, clamp dtype, revision propagation, and canonical workflow behavior.

Replace the stale GGUF CLI rejection regression with the current supported ort-genai dispatch contract; that contradictory test caused all six Python unit matrix failures after the branch rewrite.

Co-authored-by: Copilot <[email protected]>
Signed-off-by: justinchuby <[email protected]>
@justinchuby

Copy link
Copy Markdown
Member Author

Branch restoration is pushed at edf41ee9 without force-pushing; PR remains unmerged and mergeable. The displaced head is preserved remotely as backup/catalogue-diffusion-builds-789bd76c.

Root cause evidence: GitHub recorded a head_ref_force_pushed event at 2026-08-22 15:39:23Z by justinchuby. The new history was linearized onto main #541/#543 and ended in 789bd76c, whose metadata identifies Copilot session 39ff6824-d35f-4d3b-8f5f-043a7119a100. All six matrix logs had the identical failure: stale test_ort_genai_runtime_is_rejected_before_artifacts expected rejection, while #543 intentionally supports and dispatches ort-genai, so execution reached the nonexistent GGUF file.

Restoration: merged current origin/main c047f77f into the preserved rewritten head, retaining it as an ancestor. Updated only the contradictory GGUF test to assert exact runtime="ort-genai", save_model=False forwarding. Approved diffusion core blobs for auto_export.py, convert.py, and tests/cli_test.py exactly match d57234e8; workflow differences are current-main unrelated/full-duplex changes or formatting, while explicit guidance, float32 clamp output, revision propagation, and canonical image/video metadata remain intact.

Validation: GGUF suites 379 passed; focused diffusion/CLI/ComfyUI/metadata/policy suite 239 passed, 1 skipped; Ruff and diff checks pass. Full local unit run reached 6269 passed, 346 skipped, 62 xfailed; two unrelated local-only failures remained (installed diffusers API mismatch in Qwen rotary test and nondeterministic ModernBERT synthetic parity). CI is now running on edf41ee9.

@justinchuby

Copy link
Copy Markdown
Member Author

CI update for edf41ee9: all six previously failing Python matrix jobs now pass (Ubuntu/Windows × Python 3.11/3.12/3.13). Lint, Architecture Diff, CodeQL, benchmark comparison, build, L1 smoke, and L3 synthetic parity also pass. Remaining jobs are queued integration/L4/L5 gates; no failure is currently reported.

@justinchuby
justinchuby merged commit b9c9043 into main Aug 22, 2026
21 of 24 checks passed
@justinchuby
justinchuby deleted the justinchuby/catalogue-diffusion-builds branch August 22, 2026 16:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants