Skip to content

[Bug]? Unable to run Qwen Image 2.1 Q4_K_M on an M5 Max with 48 gb? #11792

Closed

Description

@peckinpah

Not quite sure if this is a bug or just memory limitations on my system, but I'm unable to run https://huggingface.co/unsloth/Qwen-Image-2.1-GGUF (the Q4_K_M version) on my M5 Max w/48 gb RAM with virtually no other programs running in the background? I get this error about insufficient memory:

Image

Is this expected behaviour? I've been able to run the exact same model in another app (https://mlxserve.com/) with no issues, so why is this failing in Unsloth?


name: Unsloth Studio Bug
about: Report a problem with the Unsloth Studio desktop app or web UI
title: "[Unsloth Bug] "
labels: bug
assignees: ""

Environment

Where are you using Unsloth?

  • Unsloth desktop application
  • Unsloth web UI (unsloth studio)
  • Unsloth CLI
  • Python package or notebook
  • Colab or Kaggle

Operating system and version:

GPU model(s) and accelerator backend:
MacBook Pro M5 Max

Versions:
Unsloth Version v0.1.815-beta
Package Version 2026.9.11
Desktop App Version 0.1.815-beta
llama.cpp Version b11139-mix-a6922cc
GPU Apple Silicon (Apple M5 Max) · 48 GiB

What happened?

Steps to reproduce:

  1. Downloaded https://huggingface.co/unsloth/Qwen-Image-2.1-GGUF (the Q4_K_M version) using Unsloth Desktop
  2. Clicked Run
  3. Got memory error message

Expected behavior:
Normal load of model

Actual behavior:
Unable to load model due to mem limitation alert

Model and operation involved:
https://huggingface.co/unsloth/Qwen-Image-2.1-GGUF (the Q4_K_M version)

Diagnostics and logs

Desktop application

Click Copy Diagnostics on the error, startup, or update screen and paste the
result below:

PASTE COPY DIAGNOSTICS HERE

If Copy Diagnostics is unavailable, attach the newest relevant files from:

  • Windows: %USERPROFILE%\.unsloth\studio\
  • Linux/macOS: ~/.unsloth/studio/

Useful files include:

  • tauri.log and, if relevant, tauri.log.1
  • logs/install-*.log, logs/update-*.log, logs/repair-*.log, or logs/backend-*.log
  • The newest logs/server/server-*.log

Unsloth web UI

Attach the newest relevant items:

  • Linux/macOS/Windows: ~/.unsloth/studio/logs/server/server-*.log
    (use %USERPROFILE%\.unsloth\studio\logs\server\ on Windows)
  • Linux/macOS shortcut launches only: ~/.local/share/unsloth/studio.log
  • Terminal output if Unsloth was launched from a terminal
  • Browser Console errors for browser-only problems

If you configured UNSLOTH_STUDIO_HOME or STUDIO_HOME, look under
<CUSTOM_STUDIO_HOME>/logs/ instead.

Model-specific logs, if applicable

  • GGUF/llama.cpp: newest ~/.unsloth/studio/logs/llama-server/*.log
  • Diffusion GGUF: newest ~/.unsloth/studio/logs/diffusion-server/*.log
  • Training resume/checkpoint bug: relevant trainer_state.json

Python package or notebook, if applicable

Paste the complete traceback and minimal reproduction:

# Remove all tokens and private data.

Also include Python, Unsloth, unsloth_zoo, PyTorch, Transformers, and TRL
versions, plus nvidia-smi output when applicable.

Additional context

Activity

  1. added
    feature request
    on Sep 24, 2026
  2. BartoBowman commented on Sep 24, 2026

    @BartoBowman

    It seems to be just a bit too agressive with the amount of memory it wants to be free. It should work if you set the UNSLOTH_DIFFUSION_ALLOW_OVERSIZED_LOAD option as it points out. On MacOS easiest way to do this (temporarily) is by closing unsloth desktop and running env UNSLOTH_DIFFUSION_ALLOW_OVERSIZED_LOAD=1 open -a "Unsloth" in the terminal. You can make this change permanent by running launchctl setenv UNSLOTH_DIFFUSION_ALLOW_OVERSIZED_LOAD 1

  3. peckinpah commented on Sep 24, 2026

    @peckinpah
    Author

    Hey, thank you for your feedback👌 I just tried the terminal command you suggested and that allowed me to load the model, but after one generation the app froze and I had to force quit :-/ The reported average memory usage in Activity Monitor during generation was approx. 60 gb and warmup + generation was slow.

    Meanwhile, I tried running an 8-bit MLX version (https://huggingface.co/ddalcu/Qwen-Image-2.1-MLX-Serve-8bit) in the app MLX Serve (https://mlxserve.com/) and that loaded fine and peaked at around 20gb mem usage, so it still seems odd to me that the Unsloth Q4 version is maxing out my system like that 🤔

    Anyway, thanks for the help 👍

  4. 159753a52 commented on Sep 29, 2026

    @159753a52

    For reference, here's roughly what this pipeline should need, which suggests 48 GB is not the real limit here. File sizes are from the published repos; the working memory on top is an estimate from other people's measurements:

    • DiT, Q4_K_M: 4.20 GB (3.9 GiB)
    • Text encoder (Qwen3-VL-8B): 17.5 GB in BF16, ~9.4 GB FP8, ~5.0 GB Q4_K_M
    • VAE: 0.68 GB BF16, 1.35 GB FP32
    • Working memory at ~1 MP: another ~2-5 GiB

    Worst sensible case (BF16 encoder kept resident, FP32 VAE) is ~21.5 GiB of weights and ~24-26 GiB peak. That's under the ~36 GB macOS lets the GPU wire on a 48 GB machine by default. Your MLX 8-bit run at ~20 GB is in line with that (~7.1 GB DiT + ~8.7 GB encoder + VAE + working memory).

    ~60 GB looks more like weights being upcast somewhere: a DiT dequantized to BF16 is 14.2 GB, the encoder in FP32 is 35.1 GB, and together with an FP32 VAE that's ~50.7 GB before any activations. So I'd suspect the Q4 DiT is being dequantized to full precision on MPS and/or the encoder is loaded as FP32, rather than the Q4 weights themselves being too big. The dtype the diffusion server picked for each component should be in the newest log under ~/.unsloth/studio/logs/diffusion-server/, which would confirm or rule this out. The oversized-load flag only skips the pre-check, so it lets the load start but the machine then swaps, which matches the freeze you saw.

  5. peckinpah commented on Sep 29, 2026

    @peckinpah
    Author

    @159753a52 - thank you for your reply 👍

    I just tried re-running the same Qwen Image 2.1 model in the latest Unsloth version and everything now works as expected - the model loads without giving a mem warning and I'm able to run generations without crashes. Thinking it's some of the latest mac optimizations that did the trick 🤔

    The memory footprint is now approx. 34 GB for initial loading of the model and 42 GB during generation.

  6. 159753a52 commented on Sep 29, 2026

    @159753a52

    Thanks for coming back with numbers, that's useful. To be upfront, they're well above what I estimated: I said ~24-26 GiB peak even with a BF16 encoder and FP32 VAE, and you're seeing ~34 GB loaded and ~42 GB while generating.

    The load figure matches the DiT being held at BF16 rather than Q4 almost exactly:

    • BF16 DiT 14.23 GB + BF16 encoder 17.53 GB + BF16 VAE 0.68 GB = 32.4 GB
    • with the Q4_K_M DiT kept quantized: 4.20 + 17.53 + 0.68 = 22.4 GB

    So my guess is the Mac path still dequantizes the GGUF DiT on load and the new build just stopped tripping the pre-check. The ~8 GB added during generation is also about twice the 2-5 GiB of working memory that CUDA runs show at ~1 MP. That could be MPS attention without a fused kernel, but I can't check it from here. The dtype line in the diffusion-server log would confirm or rule out the BF16 part.

    What resolution were those numbers at?

  7. peckinpah commented on Sep 29, 2026

    @peckinpah
    Author

    Resolution was 1024x1024 at 40 steps. Generation time 3 min 14 sek.

    I couldn't find the log file you mentioned, I don't seem to have a folder called /diffusion-server, but I have one that's just called /server with a bunch of log files. I did a search for "dtype" in them but found nothing :-/

    Here's some of the information I did find in the log-file:
    log.txt

  8. peckinpah commented on Sep 29, 2026

    @peckinpah
    Author

    I spoke too soon 🤥 - just tried starting the Qwen Image 2.1 model again (https://huggingface.co/unsloth/Qwen-Image-2.1-GGUF) on the same machine and now the same memory error is back again (this time it reports 17gb free out of 27gb available). This is after a reboot without anything else running.

  9. 159753a52 commented on Sep 29, 2026

    @159753a52

    Thanks, and I owe you a correction. After reading Studio's source, my guess that the Mac path dequantizes the DiT to BF16 is most likely wrong. GGUF weights stay packed and are dequantized one layer at a time during the forward pass (estimate_gguf_resident_mib in studio/backend/core/inference/diffusion_memory.py), so the Q4_K_M DiT takes ~4.2 GB, not 14.2. I also sent you looking for a log you don't have: diffusion-server seems to belong to Studio's sd.cpp engine, which is off on MPS by default. The log you attached is the HTTP log, so there's no dtype in it.

    What is big is the text encoder. Studio's FP8/INT8 encoder casts are CUDA-only, so on a Mac the Qwen3-VL-8B encoder stays at BF16: 17.5 GB. That puts the weights at 4.20 + 17.53 + 0.68 = 22.4 GB, and it's most of the gap to MLX Serve, whose 8-bit encoder is ~8.7 GB. The ~8 GB added while generating at 1024x1024 matches Studio's own budget of 8 GiB per megapixel (estimate_image_runtime_mib).

    The error coming back after a reboot looks like the pre-check, not the model. On unified memory Studio takes what macOS reports as available and subtracts 20% of total RAM for the system, ~9.6 GB on a 48 GB Mac. That's how 27 GB becomes 17. It then needs room for the weights plus 2 GB of overhead, roughly 23 GB by my count, so it refuses whenever less than ~33 GB is free at load time. Your successful load earlier today probably just happened while more was free.

    Since the weights do fit, UNSLOTH_DIFFUSION_ALLOW_OVERSIZED_LOAD=1 (the command BartoBowman posted above) is reasonable now. It only skips this check. The older build froze with it, so keep an eye on memory pressure the first time.

    The change that would help most is on Studio's side: the encoder is only used before step 0, and releasing it after encoding would take ~17.5 GB off the peak. I don't see a setting for that yet.

  10. peckinpah commented on Sep 30, 2026

    @peckinpah
    Author

    Ah ok, great, thank you for the explanation 🙏

    It seems crazy to me to use 17 gb on having a text-encoder taking up memory while the encoding happens, so I hope there's a fix for this soon 😬

  11. nefayran commented on Oct 7, 2026

    @nefayran

    On the text encoder question: it only has to be in memory while the prompt is encoded. I measured this with diffusers' QwenImage21Pipeline (bf16, 1024×1024, 20 steps) on an M5 Pro with 48 GB. With all three models loaded up front, the process footprint (the number Activity Monitor shows) was 31.4 GB through encoding and 32.5 GB while denoising, and the VAE decode then pushed it to 43.6 GB and into swap. Loading the text encoder (16.3 GB) only for encode_prompt, and freeing it before the transformer loads, kept the peak at 19.0 GB with no swap. A denoising step took the same time either way; the two extra loads cost about 13 s per run.

    So the 17.5 GB BF16 encoder that Studio keeps next to the Q4_K_M DiT doesn't need to stay there while the image is generated.

    Numbers, traces and the small library I wrote for this: https://github.com/nefayran/stageload (results in bench/results/2026-10-06-qwen-image).

  12. peckinpah commented on Oct 7, 2026

    @peckinpah
    Author

    @nefayran If I'm reading your comment right, you reduce the peak system memory load with approx 30% at the expense of an approx. 10 sek performance slowdown in your Qwen Image 2.1 test, correct?

    Seems like a functionality that would be nice to have a toggle for - I personally wouldn't mind a minor generation slowdown if that means gaining 30% more memory and being able to load bigger models 🤔

  13. nefayran commented on Oct 7, 2026

    @nefayran

    Roughly, though both numbers come out a bit differently. Memory: the peak went from 43.6 GB to 19.0 GB, 56% less, and the run with everything loaded was still climbing when it was stopped. While denoising, 32.5 GB became 16.2–18.6 GB.

    Time: a single image isn't slower, because the usual pipeline loads the same models up front (20 s here) and the staged run spreads that loading out (4.5 s at the start, then 13 s across the two stages). The cost comes with the next image: the usual pipeline keeps the models in memory, while the staged one loads them again, about 13 s per run here. In Studio only the text encoder would need reloading, since the Q4_K_M DiT is small, so it should cost less there, though I haven't measured Studio itself.

    So yes, a toggle fits: release the encoder after encoding when memory is tight, and keep it when there's room.

  14. peckinpah commented on Oct 7, 2026

    @peckinpah
    Author

    Ok, great, thanks for clarifying 👍

  15. danielhanchen commented on Oct 8, 2026

    @danielhanchen
    Member

    I'll check and I think we can optimize it

  16. danielhanchen commented on Oct 11, 2026

    @danielhanchen
    Member

    Fixed! On Apple Silicon, Studio now loads a 9.4 GB int8 copy of the Qwen-Image-2.1 text encoder instead of the 17.5 GB bf16 one, frees it while the image renders, and sizes the memory check by that smaller file even when the bf16 encoder is still in your cache from earlier runs. Fixed in #13026 and #13306; it will be in the next Unsloth Desktop release.

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

Metadata

Metadata

Assignees

Labels

bugfeature request

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions