Skip to content

Studio: run MiniMax-H3 PDD checkpoints with their 32-head output bank, refuse the ones that cannot run - #14410

Merged
danielhanchen merged 5 commits into
mainfrom
studio-video-h3-pdd
Oct 20, 2026
Merged

danielhanchen merged 5 commits into
mainfrom
studio-video-h3-pdd

Conversation

@danielhanchen

@danielhanchen danielhanchen commented Oct 20, 2026 •

Copy link
Copy Markdown
Member

Summary

Studio's MiniMax-H3 video backend now runs PDD (parallel decoding distillation) "with heads" checkpoints, such as minimax_h3_ref2va_pruned_pdd_acc_8step_baked_with_heads_int8_convrot.safetensors, with their stacked output-head bank. Per-step head selection matches ComfyUI's PDD head selection. PDD files that Studio cannot run correctly are now refused with a clear message instead of loading silently.

What was broken

  • With heads files failed at load. These files store 32 video and 32 audio output heads stacked in final_layer.video_out / final_layer.audio_out ([3072, 5376] / [1024, 5376]). They pass the ComfyUI H3 name check, but Studio built the stock single-head denoiser, so load_state_dict failed with a proj_out size mismatch.
  • Without heads files loaded silently and rendered wrong output. A without_heads bake keeps the original single heads and needs an external head bank applied per step by a custom node. Studio loaded it as a plain trunk with no error, and the output was wrong.
  • The custom-node PDD LoRA files (..._pdd_acc_8step_comfyui.safetensors) only got the generic "cannot load from a single .safetensors checkpoint" message.
  • No Studio path passed the next sigma to the denoiser. The diffusers H3 transformer only takes timestep / timestep_indices.

The fix

  • video_minimax_h3_pdd.py (new):
    • Detection reads only the safetensors header. A bank is stacked head rows that are a whole multiple of the stream's patch width, cross-checked against config.transformer.pdd_steps when that metadata is present.
    • H3PDDHeadBank replaces proj_out / audio_proj_out in prepare_model, before any weights load. It uses the checkpoint's own key and layout, kept in float32.
    • Each step uses head 0 plus the dt-weighted mean of the offset heads spanned by [start, stop), where start, stop = round((1 - unshift(sigma)) * n), round((1 - unshift(sigma_next)) * n). Head selection runs on the video shift. Each stream's dt grid uses its own shift (12 / 3). This follows ComfyUI's FinalLayer / _pdd_head term for term, including the clamps and the last step (sigma_next = 0 spans to the end of the bank).
  • Graph safety.
    • A forward pre-hook on the denoiser reads the render's scheduler sigmas. It takes the current sigma from the generated video rows' timestep and the next one from the nearest schedule entry, all on the device with no host sync. It writes the pair in place into a float64 tensor on each bank.
    • The bank's selection is pure tensor math (masks, not slices). Nothing step-dependent is a Python constant, so a CUDA graph replays new sigmas and the compiled forward keeps one graph across steps.
    • The pair is a plain tensor attribute, not a buffer. A module-wide .to(bfloat16) cannot round it, and offload does not move it.
  • Render. bind_h3_pdd_render binds the pipeline's scheduler and shifts for every PDD denoiser partition. The H3 scheduler grid includes the terminal 0, so steps model evaluations becomes a grid of steps + 1. With that, 8 steps is exactly ComfyUI's 8-step simple schedule.
  • Defaults follow ComfyUI's PDD recipe: 8 steps, Euler (H3's scheduler), simple schedule, CFG 1, shifts 12 / 3. They apply by file name (pdd) and also whenever a PDD bank is loaded, whatever the file is called.
  • Refusals. without_heads bakes and the custom-node PDD LoRA files are refused by name in the MiniMax-H3 family entry (unsupported_checkpoints), before any download or eviction. A PDD file with single heads (pdd_acc_baked metadata, pdd_steps > 1, or a PDD name, e.g. the without-heads file's former name) is refused at load from its header, before any tensor is read.

Results

Parity was checked on a 32-head bank at the real width (5376 -> 96 video / 32 audio), random weights. Studio's head bank was compared with a direct port of ComfyUI's math (float32), both against a float64 oracle, at every step:

Device Steps Studio vs fp64 ComfyUI port vs fp64 Studio vs ComfyUI port max abs output
CPU eager 8 2.40e-06 2.46e-06 1.43e-06 7.13
CPU eager 4 1.95e-06 1.95e-06 1.19e-06 6.27
CUDA eager 8 3.75e-06 2.40e-06 4.41e-06 7.39
CUDA torch.compile (inductor) 8 3.75e-06 2.40e-06 4.41e-06 7.39
CUDA torch.compile (inductor) 4 3.55e-06 2.23e-06 3.34e-06 7.15
  • Both implementations sit at float32 rounding against the oracle, and Studio picks the same heads as ComfyUI at every step. At 8 steps, step i blends heads [4i, 4i+4), and the last step ends at head 32.
  • Results are not bitwise: Studio sums over all 32 heads with zero weights outside the span, where ComfyUI slices the span.
  • On a tiny random MiniMaxH3Transformer3DModel loaded through Studio's ComfyUI loader:
File Before After
with heads (32-head bank) RuntimeError: Error(s) in loading state_dict loads, H3PDDHeadBank (3072, 32)
without heads (pdd_acc_baked) loads silently as Linear (96, 32) ValueError: ... has no head bank ...
..._pdd_acc_8step_comfyui.safetensors generic single-file refusal PDD LoRA refusal
PDD default steps 30 8

Tests

studio/backend/tests/test_video_minimax_h3_pdd.py: 32 tests, all passing on CPU and CUDA (torch 2.14.1 / diffusers 0.41.0 and torch 2.13 / diffusers 0.41.0.dev0). They cover:

  • Detection from shapes and metadata, refusal of inconsistent banks, and the without-heads refusal both at load and by name through validate_load_request.
  • The 8-step default grid against ComfyUI's simple scheduler, including 8 scheduler evaluations.
  • Head selection against the ComfyUI port at every step for 4, 6, 8 and 20 steps, including the last step (sigma_next = 0).
  • The blend against the ComfyUI port and the fp64 oracle per step and per stream.
  • The full tiny denoiser per step, through the real ComfyUI loader, and inside a scheduler loop where the pipeline sets the schedule after binding.
  • torch.compile:
    • the bank compiled fullgraph with 0 graph breaks and one graph across all 8 steps (eager backend and inductor on CUDA);
    • the full denoiser forward with 0 graph breaks and no recompile across steps.
  • Studio's GraphedForward CUDA graph replaying 16 calls with changing sigmas, bit-identical to eager, with one capture per input shape and 0 fallbacks.
  • diffusers group offload (leaf level, and block level with stream / record_stream) and accelerate CPU offload, matching resident output.

The new test file cannot import on the merge base (the module does not exist there). The loader and name behaviours it covers were reproduced on the base as shown in the table above.

Regression check, base vs head, same venv: the 68 test files that import video_families / video_minimax_h3_comfy give 4749 passed, 32 skipped and 5 failed on both sides, with the same failing test IDs. The 5 failures exist before this change (prequant id, image component size table, three H3 trainer clip-rotation tests).

Real checkpoint

minimax_h3_ref2va_pruned_pdd_acc_8step_baked_with_heads_int8_convrot.safetensors (21.06 GB) through VideoBackend.load_pipeline / generate on one B200, with the cached MiniMax-H3 text encoder and VAEs. 512x288, 124 frames with audio, a reference image, Studio's own picks: 8 steps, CFG 1, shifts 12 / 3, int8 DiT, compiled.

Prompt 1 (seed 42) Prompt 2 (seed 43)
s/step 0.84 - 1.05 0.839 - 0.846
Total 16.5 s 10.1 s
Model evaluations 8 8
New compiled graphs / graph breaks 2 / 0 0 / 0
  • Both streams run the 32-head bank (proj_out and audio_proj_out). The per-step (sigma, sigma next) pair is the shift-12 simple grid ComfyUI uses: 1.0, 0.9882, 0.973, 0.9524, 0.9231, 0.878, 0.8, 0.6316, 0.0.
  • Both clips are coherent: the reference fox walks through snow toward the camera, and sits and turns its head. No artifacts, colour shift or noise; frames are neither black nor frozen.
  • The second render found a bug, fixed here: the first render moved the bank's state tensor to the GPU inside inference mode, so the next render's in-place update raised Inplace update to inference tensor outside InferenceMode is not allowed. The state now stays a normal tensor across renders (test_a_second_render_can_rebind_a_bank_its_first_render_moved_in_inference_mode).
  • The PDD step and guidance defaults now apply to MiniMax-H3 only, so a checkpoint of another family under a path naming "pdd" keeps its own defaults (test_pdd_defaults_apply_only_to_minimax_h3).

Not verified

  • No quality comparison against a non-PDD H3 render (no non-PDD Ref2VA checkpoint was available), 4-step PDD, a quantized text encoder or offload with real weights, or audio quality beyond its shape.
  • No side-by-side render against ComfyUI.
  • The native sd.cpp / GGUF H3 engine has no PDD path. This change only covers the Diffusers engine with ComfyUI-layout files.
  • Multi-GPU replicas and LoRA adapters targeting proj_out were not exercised on a PDD bank.
  • Non-PDD H3 renders still pass steps as the scheduler grid size (steps - 1 evaluations). That was left unchanged here.

…output bank

A PDD with_heads file stacks 32 video and 32 audio output heads in final_layer.video_out / audio_out. Studio built
the stock single-head model and failed at load with a proj_out size mismatch. The without_heads bake loaded as a plain
trunk and rendered wrong output with no error.

Detect the bank from the header (stacked rows, pdd_steps metadata), swap proj_out / audio_proj_out for a head bank
that blends head 0 plus the dt-weighted offsets of the fine intervals each step spans, as ComfyUI's PDD head selection
does. The (sigma, sigma_next) pair is a device tensor written by a forward pre-hook from the render's schedule, so
CUDA graphs replay changing sigmas and the compiled forward does not recompile. PDD renders default to 8 Euler steps on
the simple schedule (a 9-point H3 grid), shifts 12 / 3.

Refuse without_heads bakes (by name, or at load from pdd_acc_baked metadata with single heads) and the custom-node
PDD LoRA files instead of loading them silently.
@danielhanchen danielhanchen self-assigned this Oct 20, 2026
@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 20, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-20T21:55:49.220987Z 83fe431 Manual request
🔒 Security Review ⚠️ Failed 2026-10-20T21:23:46.097726Z
We couldn’t complete this review. Comment @codex security review to try again.
0450922 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 0450922cff

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

_VIDEO_GENERATION_DEFAULTS: tuple[tuple[str, int, float], ...] = (
# MiniMax-H3 PDD baked checkpoints: ComfyUI's recipe is 8 Euler steps on the simple schedule at CFG 1 (shifts 12 / 3
# are the family defaults). Its head bank was distilled for that partition.
("pdd", 8, 1.0),

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Scope the PDD defaults to MiniMax-H3

This entry is consulted for every video family, and video_generation_variant() searches the entire identifier for keys outside _NAME_SEGMENT_DEFAULT_KEYS. Consequently, an ordinary Wan, Hunyuan, or other checkpoint stored under a path such as /models/pdd/wan2.2.safetensors is silently rendered with 8 steps and guidance 1.0 instead of that family's defaults. Gate this recipe on family == "minimax-h3" or determine it from the loaded H3 head bank rather than adding an unscoped global variant.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Good catch, fixed in 9a0fe8e. The pdd key is now family-scoped (_FAMILY_SCOPED_DEFAULT_KEYS: pdd -> minimax-h3), so video_generation_variant skips it unless the family is MiniMax-H3, and a Wan or Hunyuan file under a path naming pdd keeps its own defaults. Test: test_pdd_defaults_apply_only_to_minimax_h3.

…s renders

The first render moved pdd_state to the GPU inside the pipeline's inference_mode, which made it an inference tensor,
so the second render's set_shifts (run outside inference_mode) raised "Inplace update to inference tensor outside
InferenceMode". Move or replace it under inference_mode(False) so every render can rebind the bank.

[skip ci]
@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 50315ec331

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

_VIDEO_GENERATION_DEFAULTS: tuple[tuple[str, int, float], ...] = (
# MiniMax-H3 PDD baked checkpoints: ComfyUI's recipe is 8 Euler steps on the simple schedule at CFG 1 (shifts 12 / 3
# are the family defaults). Its head bank was distilled for that partition.
("pdd", 8, 1.0),

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Restrict PDD matching to the checkpoint filename

The new family scope fixes the prior Wan/Hunyuan case, but pdd still uses the entire identifier because it is absent from _NAME_SEGMENT_DEFAULT_KEYS. Consequently, a normal MiniMax-H3 checkpoint at a path such as /models/pdd/minimax_h3_fl2va_int8_convrot.safetensors is classified as PDD and defaults to 8 steps rather than the stock 30, even though no head bank is loaded. Match this variant only against the filename, or derive the default exclusively from the loaded bank.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Good catch, fixed in 83fe431. pdd is now a name-segment key like the Wan keys, so only the checkpoint's file name decides; a stock H3 file under /models/pdd/ keeps 30 steps. A loaded 32-head bank still sets 8 steps whatever the file is called. Test: test_pdd_defaults_apply_only_to_minimax_h3.

@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Keep them coming!

Reviewed commit: 83fe431b95

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

[skip ci]
@danielhanchen
danielhanchen merged commit 6901dd3 into main Oct 20, 2026
@danielhanchen
danielhanchen deleted the studio-video-h3-pdd branch October 20, 2026 22:29
danielhanchen added a commit to danielhanchen/unsloth-staging-2 that referenced this pull request Oct 25, 2026
…out float64 (unslothai#14848)

## Problem

The MiniMax-H3 PDD head bank (unslothai#14410) builds the per-step `[sigma,
sigma_next]` pair (`h3_pdd_sigma_pair`, `.to(torch.float64)`) and the
per-head blend weights (`pdd_head_weights`: `torch.linspace` /
`torch.arange` in float64, `round`, `diff`, divide) on the denoiser's
device every step.

Intel Arc A-series GPUs have no native float64. A float64 kernel there
raises `RuntimeError: Required aspect fp64 is not supported on the
device`:

- PyTorch's Intel GPU guide states FP64 is not natively supported on Arc
A-series (in the context of GradScaler):
https://docs.pytorch.org/docs/2.13/notes/get_start_xpu.html
- pytorch/pytorch#147731: on `2.6.0+xpu` with an A770,
`GradScaler.unscale_`'s `self._scale.double().reciprocal().float()`
raises exactly this error. The Intel maintainer's answer was that FP64
is a hardware requirement and Arc A-series does not have it; Battlemage,
Lunar Lake, Meteor Lake and Data Center Max do.
pytorch/pytorch#147731
- intel/torch-xpu-ops#628: PyTorch 2.5 added only partial fp64 emulation
on Arc, for conversions.
intel/torch-xpu-ops#628
- Intel Extension for PyTorch known issues: an Arc A-series kernel that
needs FP64 instructions stops execution.
https://intel.github.io/intel-extension-for-pytorch/xpu/latest/tutorials/known_issues.html

Studio accepts XPU as a diffusion device (`_xpu_target`), and a
MiniMax-H3 ComfyUI PDD checkpoint is not refused there: only MPS is
refused for the modular workflow, and on XPU the comfy int8 / fp8 layers
dequantize to bf16. The stock H3 path only uses float64 for position ids
that are cast to float32, while PDD adds real float64 arithmetic on the
device. So a PDD render on an Arc A-series card fails loudly at the
first denoiser call. Not tested on real Intel hardware.

## Change

- New `device_has_fp64(device)`. It returns True for CPU and CUDA (ROCm
included). On XPU it reads
`torch.xpu.get_device_properties(i).has_fp64`, cached per device; an XPU
whose properties cannot be read counts as without. Anything else, such
as MPS, returns False.
- On a device without float64, `h3_pdd_sigma_pair` returns the pair
float64 on the host. The bank's `pdd_state` then stays on the host, and
`forward` computes the weights in float64 there, casts them to the
activation dtype and moves only those to the device. This mirrors
ComfyUI, which builds its float64 grid on the CPU. The cost is one small
device-to-host copy per step, on a device where Studio uses neither CUDA
graphs nor default torch.compile.
- CPU and CUDA run exactly the code they ran before.

## Tests

- `test_device_has_fp64_reads_the_xpu_capability[False|True]` and
`test_an_unreadable_xpu_counts_as_without_fp64`:
`torch.xpu.get_device_properties` is spoofed. Both fail on main.
- `test_the_denoiser_never_puts_float64_on_a_device_without_it`: the
CUDA card is spoofed as an fp64-less device. A dispatch mode raises the
Arc error on any float64 tensor on the card. Over 8 steps the blend
matches the ComfyUI port and the float64 oracle within 1e-5. On main it
fails with `Required aspect fp64 is not supported on the device
(aten._to_copy.default)`.
- `tests/test_video_minimax_h3_pdd.py`: 33 passed and 5 skipped on CPU,
38 passed on a B200. That includes the inductor compile, the fullgraph
no-recompile test, CUDA graph replay with changing sigmas, group offload
and model CPU offload.

Not covered here: a real Intel Arc run (this host has no XPU).

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
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.

1 participant