Repository navigation
Studio: price the int8 ConvRot text encoder on Apple Silicon when the dense one is still cached - #13306
Merged
Conversation
… dense one is still cached
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
Member
Author
|
@codex review |
1 similar comment
Member
Author
|
@codex review |
|
Codex Review: Didn't find any major issues. Already looking forward to the next diff. Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
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". |
1 of 5 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #11792
Follow-up to #13026. That PR loads the int8 ConvRot Qwen-Image-2.1 text encoder (9.35 GB) on Apple Silicon by default instead of the bf16 one (17.5 GB), but the memory check before the load still refused the reporter, because they had already downloaded the bf16 encoder.
Problem
On a 48 GB Mac with 27 GB free,
unsloth/Qwen-Image-2.1-GGUFQ4_K_M with default settings is still refused on main with exactly the message from the issue:Two things in the planner kept the bf16 encoder's size in the budget:
_plan_memoryfloors the pre-cast encoder at the size of any cached dense text encoder shards ("a bad checkpoint falls back to opening them"). Everyone who ran Qwen-Image-2.1 on a Mac before Studio: int8 ConvRot Qwen-Image-2.1 text encoder on Apple Silicon, and release text encoders during denoise on unified memory #13026 has those 17.5 GB of shards cached, so the encoder was priced at 16,722 MiB while the load opens the 8,916 MiB int8 file._precast_text_encoder_mibthen prices it from the family table at the fp8 scale (0.65) instead of the int8 ConvRot scale (0.56) thatte_prequant_budget_scalealready uses on MPS.Change
diffusion.py: on MPS, the dense-shard floor is skipped, and an uncached pre-cast encoder is priced atTE_INT8_CONVROT_BUDGET_SCALE. Every other device keeps the floor and the 0.65 scale (both branches are gated onint8_convrot_te_runs_on(target), i.e.device == "mps").diffusion_te_prequant.py: since the MPS plan no longer budgets the dense encoder, a pre-cast encoder that fails to load on MPS now raises a clear error instead of silently loading the dense 17.5 GB encoder in its place (which is what swapped and froze the machine in the issue). The message points at Text encoder precision > Dense (bf16), which goes through the normal memory check sized for the dense encoder. CUDA, ROCm and CPU keep the existing fallback.Results
The real
DiffusionBackend._plan_memoryandunified_memory_shortfall_messagefor a GGUF Q4_K_M load, on CPU with an MPS target and spoofed unified memory (48 GiB total). The HF cache is a sparse fake sized from the real Hub files:Testing
test_mps_prices_the_int8_encoder_over_cached_dense_shards[True/False]: the report's numbers with the dense shards cached, the int8 file cached or not.test_precast_text_encoder_mib_prices_an_uncached_int8_encoder_on_mps.test_a_failed_int8_encoder_on_mps_never_falls_back_to_dense[mps], with[cuda]as the control that keeps the fallback.test_plan_memory_prices_cached_dense_shards_over_a_cached_precast,test_cached_dense_shards_keep_the_24g_denoiser_resident) are unchanged and pass.test_health_reports_unified_memory.pyx5,test_mirrored_base_still_trips_the_flux2_shape_guard).test_diffusion_te_release.pyfrom Studio: int8 ConvRot Qwen-Image-2.1 text encoder on Apple Silicon, and release text encoders during denoise on unified memory #13026 passes on the macos-15 and macos-26 runners (20 passed) with torch 2.14.1 and diffusers 0.41.0.test_download_plan_*/ nvfp4) fail when torchao is missing, and the staging legs do not install it.test_gguf_offload_swap_on_mps_keeps_the_ggufreads the host's real free memory, which was 3 GB on the macOS runner.Not covered