Repository navigation
Studio MiniMax-H3: opt-in 4-bit GGUF text encoder for hosts that cannot keep int8 resident - #17479
Conversation
…int8 resident New family-neutral module diffusion_weight_only_quant.py: GGUF block-format projections load as diffusers' GGUFLinear over the file's blocks (the layer the GGUF denoisers already use), dequantized per call for a float GEMM, so any GPU or the CPU runs them. The H3 text encoder loader reads the hosted int8 safetensors file (unchanged) or a GGUF file; GGUF tensors stored with merged dimensions are reshaped when the element count matches. New scheme q4_k_m: the GGUF mirror's Q4_K_M file the sd.cpp path already uses. Each scheme names its own unsloth source repo. Opt-in only: an unset request keeps int8; UNSLOTH_H3_TE_QUANT_AUTO=q4_k_m selects the GGUF encoder. The host-RAM switch (int8 when the host holds it beside the denoiser, else q4_k_m, int8 without a GGUF reader) sits behind H3_TE_LOW_RAM_AUTO = False.
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. |
|
Codex Review: Didn't find any major issues. You're on a roll. 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". |
|
Codex Review: Didn't find any major issues. Bravo. 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". |
|
@codex review |
|
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". |
…act text (#17497) ## Summary `Repo tests (CPU, rest)` fails on main since #17329, and on every PR based on it (seen on #17479): ``` FAILED tests/test_gemma3_generate_off_flex.py::test_generate_enters_the_scope E assert '_NonFlexGenerate(self)' in 'def unsloth_base_fast_generate(self, *args, **kwargs): ... ``` The test checks that `unsloth_base_fast_generate` enters the `_NonFlexGenerate` scope for the model it generates with. It did that by looking for the literal text `_NonFlexGenerate(self)`. #17329 (flex attention decode steps) still enters the scope, now with a keyword argument: ```python _NonFlexGenerate(self, flex_decode = not _wants_attentions(self, kwargs)), ``` So the code is right and the test is too strict: any added argument or reflow breaks it without the behaviour changing. ## Change `test_generate_enters_the_scope` now parses the function and requires a `_NonFlexGenerate(...)` call whose first argument is `self`. Keyword arguments and formatting no longer matter, but the scope still has to be entered for the model itself: a comment or string that mentions it, or the scope built for another object, does not count. A new `test_the_scope_check_reads_calls_not_text` covers those cases. ## Testing - `tests/test_gemma3_generate_off_flex.py`: fails on main (1 failed, 18 passed), 20 passed here. - With the `_NonFlexGenerate(...)` entry in `unsloth_base_fast_generate` replaced by `contextlib.nullcontext()`, `test_generate_enters_the_scope` fails.
Studio MiniMax-H3: opt-in 4-bit GGUF text encoder for hosts that cannot keep the int8 one resident
Problem
The MiniMax-H3 text encoder (Qwen3-VL 32B, 50 of 64 layers) is hosted as an int8 ConvRot file of 27.1 GB. Beside the
int8 denoiser (20.3 GB) and the VAEs (11.1 GB) it does not fit in the page cache of a 53 GB host, so on an L4 at a
12 GiB budget the encoder is re-read from disk on every new prompt (about 33k major page faults per encode). H3-Image
(#17453) reuses the same encoder and loader.
What this changes
diffusion_weight_only_quant.py(new, family-neutral): GGUF block-format projections (Q4_K / Q6_K / ...) load asdiffusers'
GGUFLinearover the file's blocks, the layer Studio's GGUF denoisers already use. The blocks stayresident and each call rebuilds a transient dense weight for a float GEMM, so any GPU or the CPU runs it.
GGUF file. GGUF tensors stored with merged dimensions (the vision patch conv, which GGUF holds in 4-D) are
reshaped when the element count matches and refused otherwise.
q4_k_m:unsloth/MiniMax-H3-GGUF/qwen3vl_32b_minimax_h3-Q4_K_M.gguf, the file the sd.cpp path alreadydownloads (18.2 GB, no new upload). Each scheme names its own unsloth source repo (fetch, Hub size check, delete
guard).
UNSLOTH_H3_TE_QUANT_AUTO=q4_k_mselects the GGUFencoder (
int8forces int8). The host-RAM switch is in place behindH3_TE_LOW_RAM_AUTO = False: when on, an unsetrequest takes int8 when the host (total RAM, capped by the cgroup limit) holds encoder + denoiser + VAEs + headroom
(64.5 GB), else
q4_k_m, and stays on int8 without a GGUF reader. Turning it on is one line once the accuracy tradebelow is accepted.
q4_k_mis not atext_encoder_quantrequest value.The trade
Accuracy, CPU, real weights, 8 prompts:
hidden_states[50]against the released bf16 encoder, relative L2 over thevalid tokens with token 0 excluded (the attention-sink row carries most of the norm):
Clips against the int8 clips (same seeds; int8 itself is deterministic, A/A LPIPS 0):
Speed and memory. Studio main 57a486b against main plus this branch, every arm a fresh process, files prefetched
and read into the page cache before each arm; major faults counted over each prompt's encode.
L4 (55.5 GB host), 12 GiB budget, 8 new prompts per arm:
A100-40 (83 GB host), whole card:
So on a low-RAM host q4_k_m removes the per-prompt re-read (-28 to -33 s per new prompt on the L4) for a 3.6x larger
hidden-state error; on a host that holds int8 it only saves host RAM. Repeat runs gave bit-identical frames, and the
int8 path through the new loader is bit-identical to main.
Tests
tests/test_h3_te_4bit.py(new, CPU): a tiny Qwen3-VL written in the hosted int8 layout and as a GGUF (Q8_0projections, bf16 table, patch conv stored 4-D as the hosted file does) loaded through the real loader and compared
with its own dense decode; wrong-scheme refusal both ways; unset request stays int8 on every host; env opt-in; the
switch's host-RAM rule and its no-GGUF-reader guard; the resolver wiring.
tests/test_video_h3_te_quant.py: the request-value check skips the opt-in-only scheme.tests/test_video_backend.py -k "h3 or minimax": 179passed. Red on main as well, untouched here:
tests/test_integrated_gpu_no_host_pin.py(2 pinning-site assertions infiles this branch does not change) and
tests/test_diffusion_gguf_compile.py::test_installed_dequant_survives_a_failing_compileunder xdist (passes serially).
Not covered here
(68.5 GB VRAM floor), so the clip numbers are against int8; the bf16 comparison is the hidden-state check above.
rest is the leaf-by-leaf stream itself (not investigated here).