Skip to content

Studio: bump mflux to 0.24.0 and decode Z-Image in strips instead of tiles - #18933

Merged
danielhanchen merged 2 commits into
mainfrom
studio-mflux-024-strip-decode
Nov 22, 2026
Merged

danielhanchen merged 2 commits into
mainfrom
studio-mflux-024-strip-decode

Conversation

@danielhanchen

Copy link
Copy Markdown
Member

Summary

Bumps the opt-in MLX image engine from mflux 0.22.0 to 0.24.0, and makes Studio drive the new Z-Image VAE decode instead of the tiling that 0.24 now ignores.

mflux 0.24 (mflux-community/mflux#910) decodes the Z-Image VAE one block at a time and drops TilingConfig for it. With a plain pin bump, Studio would keep setting a TilingConfig that does nothing, and its memory estimate would describe a decode that no longer runs. This PR sets the VAE's decode_mode for each generation instead:

  • full_precision when the whole-image decode fits in the free Metal working set. This is the default whenever the untiled decode used to fit, and its pixels are bit-identical to the 0.22 untiled decode.
  • low_memory everywhere Studio used to tile: when the whole-image decode does not fit, when the media price already reserved the low-memory path, or when UNSLOTH_DIFFUSION_MLX_VAE_TILING=1. It decodes in 128-row strips and takes GroupNorm statistics from the whole image, so there are no tile seams.

UNSLOTH_DIFFUSION_MLX_VAE_TILING=0 still forces the whole-image path. The load headroom and the fit check use measured peaks for each mode.

Compatibility

  • mflux 0.24 requires Python 3.11. A Python 3.10 venv keeps the 0.22.0 pin, the newest release that installs there (_MFLUX_PY310_PIN).
  • The router accepts both 0.22.0 and 0.24.0 (MFLUX_COMPATIBLE_VERSIONS). A lagging pin therefore keeps the engine: a 3.10 venv, or an update that could not reach PyPI. 0.22 keeps the TilingConfig path, chosen by whether the loaded VAE has a decode_mode.
  • Both releases write the same Z-Image weight layout, so converted GGUFs are reused.
  • Pillow stays at 12.3.0 on Apple Silicon. mflux 0.24 declares pillow>=13, but only for its security advisories. It is installed --no-deps, and it imports and decodes on 12.3.0 (macos-15 runs below). 0.22 still breaks on 13.

Evidence (macos-15 staging, Apple M1 (Virtual), mlx 0.32.4, Pillow 12.3.0)

VAE-only decode of saved Z-Image Turbo latents with the real VAE. One process per cell. Peak is mx.get_peak_memory() above the weights. PSNR is measured against the 0.22 untiled decode.

size decode peak above weights GB s (relative) PSNR vs 0.22 untiled max abs (of 255)
512 0.22 untiled (base, when it fits) 3.99 20.7 identical (same md5) 0
512 0.22 tiled (base, when it does not; one tile at 512) 2.60 16.0 identical (same md5) 0
512 0.24 full_precision (head, when it fits) 2.22 (4 runs: 2.14-2.22) 10.3 identical (same md5) 0
512 0.24 low_memory strips (head, when it does not) 0.47 (4 runs: 0.47-0.50) 4.0 49.32 dB 13
768 0.22 untiled 5.72 16.6 identical (same md5) 0
768 0.22 tiled 4.23 8.6 38.77 dB 83
768 0.24 full_precision 4.95 (4 runs: 4.95-4.95) 10.0 identical (same md5) 0
768 0.24 low_memory strips 0.85 (4 runs: 0.85-0.85) 7.4 50.67 dB 21
1024 0.22 untiled 7.30 71.3 identical (same md5) 0
1024 0.22 tiled 4.12 20.0 39.70 dB 66
1024 0.24 full_precision 6.76 30.0 identical (same md5) 0
1024 0.24 low_memory strips 1.40 (4 runs: 1.40-1.44) 9.5 50.58 dB 19

Where the decode fits, the output is unchanged and the peak is the same or lower. Where Studio used to tile, it now uses strips:

  • About 3x to 5x less memory at 768 and 1024: 0.85 GB against 4.23 GB, and 1.40 GB against 4.12 GB.
  • About 11 dB closer to the untiled image: 50 dB against 39 dB.
  • No seams.

The 768 and 1024 tile decodes are below 40 dB, which is where the visible bands come from. The strips are not.

The whole-image peaks (legacy, tiles) swing by up to 1.5 GB between identical runs on this runner. The strip peaks repeat to within 0.04 GB. The 1024 legacy decode (7.5 GB on a 7 GB runner) also hung the virtual GPU (kIOGPUCommandBufferCallbackErrorHang) on a repeat; the strip decode never did.

Studio engine end to end, merge base (mflux 0.22) against this branch (mflux 0.24), same job:

base (mflux 0.22, merge base) head (mflux 0.24, this branch)
Router, UNSLOTH_DIFFUSION_MLX=1 MLX MLX
512 decode path picked (the working set was overcommitted, so the low-memory path) TilingConfig (one tile at 512) decode_mode=low_memory, tiling_config=None
512, 4 steps, 3 runs: process MLX peak 7.75 GB 7.14-7.16 GB
512: s/step (median) 7.27 7.28
512: repeat renders identical yes yes
768, 4 steps: process MLX peak 7.75 GB 7.14 GB
PSNR, head render against base render 48.6 dB at 512 (strips against untiled), 42.1 dB at 768 (strips against tiles)
Batch of 2, cancel mid-run, unload frees the model (0.17 GB active), reload hits the conversion cache pass pass

The 512 head render sits 48.6 dB from base, which matches the VAE-only strip number (49.3 dB). At 768, most of the 42 dB gap is the base's tile error.

Tests

  • test_mlx_diffusion_backend.py: the 0.24 decode_mode plan (full image or strips, the env override, the priced path, tiling_config cleared), the strip and whole-image estimates against the Metal measurements, and the headroom with strips forced off.
  • test_diffusion_mlx_engine_router.py: either supported mflux selects MLX, an unsupported one (0.17, 0.23, none) falls back, and the installer pins match MFLUX_VERSION for this Python.
  • Linux: the four touched test files pass (574 passed with test_diffusion_device.py). On macos-15, with real mlx and mflux and each arm on its own tree, head (mflux 0.24) gives 441 passed and 1 skipped, and base (mflux 0.22) gives 428 passed and 1 skipped.

Not tested

  • In the first engine run, the head arm went first and hit a Metal GPU Timeout Error while materializing the weights at load (mx.eval in build, unchanged by this PR). The runner had a 4.67 GiB working set against a 7.85 GiB plan. With the order swapped, both arms passed. I could not confirm the cause beyond that.

  • Both arms segfault (exit 139) at interpreter exit after the last check passed. This is the same in base and head.

  • Real Apple GPUs other than the virtual M1. Timings here are relative only.

  • Python 3.10 on Mac (the 0.22 fallback pin) end to end. Only the selection logic is unit tested.

…tiles

mflux 0.24 decodes the Z-Image VAE block by block (mflux-community/mflux#910)
and ignores TilingConfig for it, so Studio now sets the VAE's decode_mode:
the whole image (full_precision, the untiled decode's pixels bit for bit)
when it fits the free working set, else 128-row strips with whole-image
GroupNorm statistics (low_memory, no tile seams). The decode estimate and
the load headroom follow the mode that runs.

mflux 0.24 requires Python 3.11, so a Python 3.10 venv keeps 0.22, and
the engine accepts either release so a lagging pin still loads (0.22
keeps the TilingConfig path).
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 22, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

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

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-22T17:56:38.253033Z e59c561 Manual request
ℹ️ 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.

@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 it up!

Reviewed commit: e59c561408

ℹ️ 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".

@danielhanchen
danielhanchen merged commit 22f1d70 into main Nov 22, 2026
@danielhanchen
danielhanchen deleted the studio-mflux-024-strip-decode branch November 22, 2026 20:52
danielhanchen added a commit that referenced this pull request Nov 22, 2026
…, and read checked-in sources as UTF-8 (main reds) (#18952)

## Summary

Two checks are red on `main` and fail on every PR that runs them, for
example the staging run for #18941:

| Failing check | Introduced by | Which side was wrong | Fix |
|---|---|---|---|
|
`tests/studio/install/test_mlx_install.py::test_mlx_image_engine_pins_leave_the_mlx_stack_alone`
(`studio-install` shard): `assert
'mflux==0.24.0'.startswith('mflux==0.22.')` | #18933 bumped mflux to
0.24.0 (0.22.0 kept for Python 3.10) | Test. The bump is intended. The
test pinned a version literal of its own, so every mflux bump breaks it.
| The test now checks the installer pin against the MLX engine itself:
`_MLX_DIFFUSION_PINS` must be exactly `mflux==<MFLUX_VERSION>` for the
running interpreter, and that version must be in
`MFLUX_COMPATIBLE_VERSIONS`. Both are read from
`mlx_diffusion_convert.py`'s source, since importing it needs numpy and
the installer tests do not have it. The check is stricter than before:
an installer pin that drifts from what the engine accepts at runtime now
fails. |
|
`tests/test_source_read_encoding.py::test_checked_in_file_reads_name_an_encoding`
(`rest-2` shard): 3 reads with the platform default encoding | #18923
(`tests/test_adapter_unc_base_guard.py:30` and `:91`) and
`tests/test_inkling2_support.py:367` | Tests. On Windows a bare
`read_text()` uses the locale code page. | `encoding = "utf-8"` on those
three reads. |

Only tests change.

## Testing

- `tests/studio/install/test_mlx_install.py`,
`tests/test_source_read_encoding.py`,
`tests/test_adapter_unc_base_guard.py`,
`tests/test_inkling2_support.py`: 3 failed on `main`. With this change,
92 passed, 4 skipped.
- Sabotage: with `_MFLUX_PIN` changed to `mflux==0.23.0`, a version the
engine does not expect, the mflux test fails with `assert
'mflux==0.23.0' == 'mflux==0.24.0'`.
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