Skip to content

Fix MPS float64 crash in MiniMax-H3 PrepareLayoutStep - #14648

Open
Greninja44 wants to merge 1 commit into
huggingface:mainfrom
Greninja44:fix-minimax-h3-mps-float64
Open

Fix MPS float64 crash in MiniMax-H3 PrepareLayoutStep#14648
Greninja44 wants to merge 1 commit into
huggingface:mainfrom
Greninja44:fix-minimax-h3-mps-float64

Conversation

@Greninja44

Copy link
Copy Markdown

Summary

MiniMaxH3PrepareLayoutStep and MiniMaxH3Ref2VAPrepareLayoutStep build position_ids in float64 (needed for cumsum precision over long-video rotary time spans, see _temporal_position_grid), then unconditionally move it to the execution device. This crashes on MPS with Cannot convert a MPS Tensor to float64.

The float64 computation itself is unchanged. The fix only adjusts the dtype used for the device transfer, via maybe_adjust_dtype_for_device — a helper already used throughout the codebase for this exact MPS/NPU limitation (transformer_flux.py, transformer_bria.py, embeddings.py, transformer_anyflow_far.py, etc.), rather than a one-off inline device check. It downcasts to float32 only on MPS/NPU and is a no-op everywhere else.

This is safe because MiniMaxH3RotaryPosEmbed.forward already unconditionally casts position_ids to float32 before computing rotary frequencies, on every device — so the fix changes zero downstream numerics, on any device.

Changes

  • src/diffusers/modular_pipelines/minimax_h3/before_denoise.py: both position_ids.to(device) call sites now pass dtype=maybe_adjust_dtype_for_device(torch.float64, device).
  • tests/modular_pipelines/minimax_h3/test_modular_pipeline_minimax_h3.py: adds TestMiniMaxH3PositionIdsDevice, covering:
    • the packed layout is still built in float64 on the host,
    • the dtype-selection logic picks float32 exactly for MPS and float64 elsewhere (no hardware required),
    • an MPS-hardware-only check (skipped cleanly elsewhere) that the device transfer actually lands as float32.

Fixes #14639

Test plan

  • pytest tests/modular_pipelines/minimax_h3/test_modular_pipeline_minimax_h3.py::TestMiniMaxH3PositionIdsDevice — 4 passed, 1 skipped (no MPS hardware in CI sandbox)
  • pytest tests/modular_pipelines/minimax_h3/test_modular_pipeline_minimax_h3.py::TestMiniMaxH3Reference — 6 passed (no regression)
  • pytest tests/models/transformers/test_models_transformer_minimax_h3.py — 28 passed, 49 skipped (unrelated hardware/LoRA features)
  • ruff check / ruff format --check on changed files — clean

position_ids is built in float64 for cumsum precision over long
rotary time spans, but MPS has no float64 support, so moving it to
an MPS device crashed. Downcast to float32 only on device transfer,
only for MPS/NPU, using the existing maybe_adjust_dtype_for_device
helper already used throughout the codebase for this exact
limitation. The rope embedding already casts position_ids to
float32 on every device before use, so this changes nothing
downstream.

Fixes huggingface#14639
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

MiniMax-H3: float64 rotary position grid cannot be moved to MPS (Cannot convert a MPS Tensor to float64)

2 participants