Repository navigation
Studio sd.cpp: pick the Q8_0 BF16 cuBLAS route from the diffusion GGUF, not its companions (1.57x on A100) - #17098
Merged
Conversation
…F, not its companions A Q8_0 diffusion GGUF next to a k-quant text encoder (for example Qwen3-4B Q4_K_M) kept the whole load on int8 MMQ. On an A100 that is 1.6x slower sampling for Z-Image Turbo at 1024 px. The route is now decided from the diffusion GGUF's tensor types alone; the per-GPU table, the multi-card agreement rule and a user-set value are unchanged.
Codex Review Summary: ✅ CompletedThis 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 |
shimmyshimmer
pushed a commit
to shimmyshimmer/unsloth-staging-4
that referenced
this pull request
Nov 8, 2026
|
Codex Review: Didn't find any major issues. Keep it up! 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". |
danielhanchen
added a commit
that referenced
this pull request
Nov 8, 2026
…OS legs (#17107) ## Summary Two test files on main assume a Linux host. Any PR whose cross-platform run selects them goes red on the leg that is not Linux, whatever the PR changed. Two current examples: ``` windows-latest (#17067) FAILED test_diffusion_comfy_block.py::test_a_many_layer_nvfp4_fallback_load_that_fits_is_not_refused FAILED test_diffusion_comfy_block.py::test_block_dequant_is_checked_for_its_peak_intermediates[nvfp4] ... and four more, all: FileNotFoundError: [Errno 2] No such file or directory: '/proc/self/status' macos-15 (#17098) FAILED test_sd_cpp_args.py::test_native_speed_flags assert ['--diffusion-fa'] == ['--diffusion-fa', '--diffusion-conv-direct'] FAILED test_sd_cpp_args.py::test_minimax_h3_video_command_has_all_joint_av_components assert ['--offload-to-cpu', '--clip-on-cpu'] == ['--diffusion-fa', '--offload-to-cpu'] ``` In both files the product code is right and the tests are wrong. - **`test_diffusion_comfy_block.py`.** The six memory-peak tests already skip with `needs /proc/self/status RssAnon` when `_rss_anon_bytes()` returns `None`. But the helper opens `/proc/self/status` unguarded. Off Linux it raises `FileNotFoundError` instead of returning `None`, so the tests error out instead of skipping. - **`test_sd_cpp_args.py`.** On Apple Metal, sd.cpp deliberately drops `--diffusion-conv-direct` and adds `--clip-on-cpu` (#13369). Most tests in the file pin `sys.platform` before they build a command. These two do not, so on a Mac runner they get the Metal command and compare it against the Linux one. ## Change Tests only: - `_rss_anon_bytes()` returns `None` when `/proc/self/status` cannot be opened, so the existing skips fire on Windows and macOS. On Linux nothing changes. - The file's existing autouse fixture in `test_sd_cpp_args.py`, which already pins the host probes, also pins `sys.platform` to `linux`. Every test there now builds the same command on any host unless it sets the platform itself, as the Metal tests already do. That covers the two tests above and any later one that forgets the pin. ## Testing | | result | |---|---| | `test_sd_cpp_args.py`, `test_sd_cpp_backend.py`, `test_diffusion_comfy_block.py` on Linux, this branch | 345 passed, 5 skipped | | main, Windows and macOS legs of #17067 and #17098 | the failures above | | this branch, `test_diffusion_comfy_block.py` + `test_sd_cpp_args.py` on ubuntu-latest | 156 passed, 5 skipped | | this branch, same files on macos-15 | 150 passed, 11 skipped (the six RssAnon tests skip) | | this branch, same files on windows-latest | 150 passed, 11 skipped (the six RssAnon tests skip) |
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.
Problem
On CUDA, Studio sets
GGML_CUDA_QUANT_CUBLAS_MIN_BATCHfor the sd.cpp child when the model is Q8_0, so its large matmuls run as BF16 dequant + cuBLAS instead of int8 MMQ (#14983: faster on A100 / Hopper / datacenter Blackwell, and closer to the unquantized render). Since #15054 the check takes the union of the quantized types of the diffusion GGUF and every companion GGUF, so a Q8_0 DiT next to a k-quant encoder gets no env and the whole denoiser stays on MMQ. That pairing is common: the Qwen-Image families (text-to-image, edit, layered) load Qwen2.5-VL Q4_K_M as their encoder,UNSLOTH_SD_CPP_TEXT_ENCODER_QUANT=q4_k_mpicks Qwen3-4B Q4_K_M, and a cache-only load falls back to an older cached Q4_K_M encoder.A100 40 GB, Studio's pinned prebuilt (
master-982-0518b34-uaba3a1c, Linux CUDA 13 bundle), Z-Image Turbo Q8_0 DiT + Qwen3-4B Q4_K_M encoder, 1024 px, 8 steps, cfg 1, seed 42, Studio's native argv (--diffusion-fa --diffusion-conv-direct), one warm-up per arm then 3 interleaved reps. Each arm gets the env its own tree computes from the same GGUF files (main: none; this branch:1024):main(MMQ)1.57x faster sampling. Each arm renders the same pixels in every rep; the two arms differ, as expected when the denoiser changes matmul path.
Why the companion rule can go
#15054 added the union because the env is process-wide: with it set, an encoder's quantized matmuls with at least that many rows also take BF16 cuBLAS. In practice:
Change
gguf_quantized_weight_types(files.diffusion_model)instead of the union, andmodel_files_quantized_weight_types(its only caller) is removed.0included.QUANT_CUBLAS_ENVsays so.Cells
Each tree's own
sd_cpp_argsand load glue on real GGUFs (Z-Image Turbo Q8_0 / Q4_K_M DiT x Qwen3-4B Q4_K_M / Q8_0 / BF16 / safetensors encoder x sm75 / 80 / 86 / 89 / 90 / 100 / 120): 56 cells, 52 identical, 4 moved. The 4 moved cells are all Q8_0 DiT + Q4_K_M encoder on sm80 / sm90 / sm100 (none -> 1024) and sm120 (none -> 4096). L4 (sm89), consumer Ampere and T4 do not move.Tests
tests/test_sd_cpp_backend.py:test_a_q8_0_diffusion_gguf_with_a_k_quant_companion_keeps_mmqbecomestest_a_q8_0_diffusion_gguf_takes_the_route_whatever_its_companions_hold: a k-quant encoder, a Q8_0 encoder with a Q5_K VAE, an unreadable encoder, and a Qwen2.5-VL k-quant encoder with its projector all get1024, and only the diffusion GGUF is read. Onmainall 4 cases fail; the existing k-quant / mixed / unknown diffusion GGUF cases still keep MMQ.tests/test_sd_cpp_args.pychecks the tensor-table reader and the route on real tiny GGUFs.test_sd_cpp_args.py+test_sd_cpp_backend.py: 291 passed.Not covered
h3_quant_cublas_env, 1024 on every sm80+ card, every type). It was measured faster with the route on L4 too (Studio: MiniMax-H3 GGUF uses the BF16 cuBLAS matmul path by default on sm80+ (1.2 to 2.3x per step, closer to an F32 reference) #12527: 54.6 -> 44.3 s/step), so the image table is not applied to it.