Repository navigation
Replies: 1 comment
|
15 s/step is plausible on an 18 GB M3 Pro for a 1024px, 16-channel bf16 DiT, but I would not call it the physical limit until you have measured the no-RoPE and quantized variants. At 1024, the 16-channel latents are 4× the activation volume of SDXL, so memory traffic—not only DiT math—is likely the wall. |
Uh oh!
There was an error while loading. Please reload this page.
Hello, MLX Community,
I am currently porting Z-Image Turbo to MLX. This model is a Diffusion Transformer (DiT) similar to SD3, but it uses 16-channel latents (unlike the standard 4-channel VAE in SDXL), which results in significantly larger activation sizes.
I am running this on a MacBook Pro 14 M3pro + 18Gb , but I'm hitting a performance bottleneck that I suspect might be memory bandwidth bound.
I have uploaded the full implementation to my repository. You can check the full code and run it to reproduce
https://github.com/uqer1244/MLX_z-image
Context & Performance
(1, 16, 128, 128)latentsbfloat16The Bottleneck: 3D RoPE with Split/Concat
Profiling suggests the main cost comes from the Attention layer, specifically its unique 3D RoPE mechanism.
Unlike standard RoPE, this model requires splitting the query/key tensors into three chunks
[32, 48, 48], applying different rotary embeddings based on Height/Width/Time axes, and then concatenating them back.I suspected the
Split->RoPE->Concatpattern was causing excessive memory read/writes.What I have tried
mx.compile: The entire step function is compiled.cos/sinand rotation on the full tensor to avoid memory copies.Here is the current implementation of my Attention layer:
Despite this "Fused Args" optimization, the speed remains around 15s/step.
My Questions
mx.compileeffectively handle this kind of partial rotation logic? I am wondering if I'm missing any specific MLX primitives or patterns that would help the compiler fuse these operations better.Any insights or advice would be greatly appreciated. Thanks for the great work on MLX!
All reactions