Repository navigation
Studio: run MiniMax-H3 PDD checkpoints with their 32-head output bank, refuse the ones that cannot run - #14410
Conversation
…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.
|
@codex review |
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 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), |
There was a problem hiding this comment.
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 👍 / 👎.
There was a problem hiding this comment.
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]
|
@codex review |
There was a problem hiding this comment.
💡 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), |
There was a problem hiding this comment.
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 👍 / 👎.
There was a problem hiding this comment.
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.
|
@codex review |
|
Codex Review: Didn't find any major issues. Keep them coming! Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
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]
…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>
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
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, soload_state_dictfailed with aproj_outsize mismatch.without_headsbake 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...._pdd_acc_8step_comfyui.safetensors) only got the generic "cannot load from a single .safetensors checkpoint" message.timestep/timestep_indices.The fix
video_minimax_h3_pdd.py(new):config.transformer.pdd_stepswhen that metadata is present.H3PDDHeadBankreplacesproj_out/audio_proj_outinprepare_model, before any weights load. It uses the checkpoint's own key and layout, kept in float32.[start, stop), wherestart, 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'sFinalLayer/_pdd_headterm for term, including the clamps and the last step (sigma_next = 0spans to the end of the bank)..to(bfloat16)cannot round it, and offload does not move it.bind_h3_pdd_renderbinds the pipeline's scheduler and shifts for every PDD denoiser partition. The H3 scheduler grid includes the terminal 0, sostepsmodel evaluations becomes a grid ofsteps + 1. With that, 8 steps is exactly ComfyUI's 8-stepsimpleschedule.pdd) and also whenever a PDD bank is loaded, whatever the file is called.without_headsbakes 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_bakedmetadata,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:
iblends heads[4i, 4i+4), and the last step ends at head 32.MiniMaxH3Transformer3DModelloaded through Studio's ComfyUI loader:RuntimeError: Error(s) in loading state_dictH3PDDHeadBank (3072, 32)pdd_acc_baked)Linear (96, 32)ValueError: ... has no head bank ......_pdd_acc_8step_comfyui.safetensorsTests
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:validate_load_request.simplescheduler, including 8 scheduler evaluations.sigma_next = 0).GraphedForwardCUDA graph replaying 16 calls with changing sigmas, bit-identical to eager, with one capture per input shape and 0 fallbacks.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_comfygive 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) throughVideoBackend.load_pipeline/generateon 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.proj_outandaudio_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.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).test_pdd_defaults_apply_only_to_minimax_h3).Not verified
proj_outwere not exercised on a PDD bank.stepsas the scheduler grid size (steps - 1evaluations). That was left unchanged here.