feat(mlx): opt-in bf16 compute for the native MLX DiT - #1251
feat(mlx): opt-in bf16 compute for the native MLX DiT#1251argentumaurum-eth wants to merge 2 commits into
Conversation
Add ACESTEP_MLX_DIT_BF16 (default off) to run the Apple Silicon MLX DiT decoder in bfloat16 instead of float32. bf16 keeps the full fp32 exponent range (no fp16 overflow) and matches the DiT's served precision. Measured on M4 Max (isolated DiT forward, xl-base shape): 1.07x @1024, 1.26x @2048, 1.33x @3072 latent frames — the win grows with sequence length, so long tracks benefit most. The default-off path stays float32 and byte-identical. - dit_model: add compute_dtype; cast inputs and RoPE cos/sin to it on forward entry, cast the velocity back to the caller dtype at the end so the diffusion sampler loop stays float32. - mlx_dit_init: when the flag is set, cast decoder params to bf16 via tree_map (mirrors the existing MLX VAE fp16 path); flag-off never imports mlx, so float32 behaviour is byte-identical. slop music deserves fast slop code.
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughWalkthroughAdds an optional bfloat16 compute path to the MLX DiT decoder on Apple Silicon. The ChangesMLX DiT bfloat16 compute path
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@acestep/core/generation/handler/mlx_dit_init.py`:
- Around line 84-93: The bf16 conversion in the _maybe_apply_mlx_dit_bf16
function is not atomic - the mlx_decoder parameters and compute_dtype can be
mutated by the tree_map and assignment operations before mx.eval is called, and
if mx.eval fails, the exception returns False while the decoder has already been
partially converted to bf16, creating a state mismatch. Fix this by moving the
mx.eval call before any mutations occur, so validation happens before any state
changes, ensuring that if any step fails the decoder remains completely
unmodified. Apply the same fix to the related code also referenced in the
comment (lines 37-46).
In `@acestep/models/mlx/dit_model.py`:
- Around line 454-460: The file acestep/models/mlx/dit_model.py exceeds the 200
line of code hard limit and this PR adds more logic to it. Per policy, add a
module-level comment or PR note that provides a brief justification for why the
current structure requires the module to exceed this limit and includes a
concrete, actionable follow-up plan describing how and when the module will be
split into smaller components (e.g., separating initialization logic, parameter
management, or forward pass computation into separate modules).
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: b557d8cd-9d2c-4585-a91a-be29912bd295
📒 Files selected for processing (2)
acestep/core/generation/handler/mlx_dit_init.pyacestep/models/mlx/dit_model.py
Add ACESTEP_MLX_DIT_BF16 (default off) to run the Apple Silicon MLX DiT decoder in bfloat16 instead of float32. bf16 keeps the full fp32 exponent range (no fp16 overflow) and matches the DiT's served precision.
Measured on M4 Max (isolated DiT forward, xl-base shape): 1.07x @1024, 1.26x @2048, 1.33x @3072 latent frames - the win grows with sequence length, so long tracks benefit most. The default-off path stays float32 and byte-identical.
slop music deserves fast slop code.
Summary by CodeRabbit
Release Notes
New Features
Bug Fixes