Skip to content

Studio MiniMax-H3: opt-in 4-bit GGUF text encoder for hosts that cannot keep int8 resident - #17479

Merged
danielhanchen merged 5 commits into
mainfrom
studio-h3-te-4bit
Nov 11, 2026
Merged

danielhanchen merged 5 commits into
mainfrom
studio-h3-te-4bit

Conversation

@danielhanchen

Copy link
Copy Markdown
Member

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

  1. diffusion_weight_only_quant.py (new, family-neutral): GGUF block-format projections (Q4_K / Q6_K / ...) load as
    diffusers' GGUFLinear over the file's blocks, the layer Studio's GGUF denoisers already use. The blocks stay
    resident and each call rebuilds a transient dense weight for a float GEMM, so any GPU or the CPU runs it.
  2. The H3 text encoder loader reads either the hosted int8 safetensors file (unchanged, bit-identical to main) or a
    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.
  3. New scheme q4_k_m: unsloth/MiniMax-H3-GGUF/qwen3vl_32b_minimax_h3-Q4_K_M.gguf, the file the sd.cpp path already
    downloads (18.2 GB, no new upload). Each scheme names its own unsloth source repo (fetch, Hub size check, delete
    guard).
  4. Opt-in only. An unset request keeps int8 on every host. UNSLOTH_H3_TE_QUANT_AUTO=q4_k_m selects the GGUF
    encoder (int8 forces int8). The host-RAM switch is in place behind H3_TE_LOW_RAM_AUTO = False: when on, an unset
    request 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 trade
    below is accepted. q4_k_m is not a text_encoder_quant request value.

The trade

Accuracy, CPU, real weights, 8 prompts: hidden_states[50] against the released bf16 encoder, relative L2 over the
valid tokens with token 0 excluded (the attention-sink row carries most of the norm):

encoder size rel. L2 mean rel. L2 worst prompt worst token cosine
int8 (today) 27.1 GB 1.63% 1.92% 0.998
q4_k_m 18.2 GB 5.82% 7.94% 0.971

Clips against the int8 clips (same seeds; int8 itself is deterministic, A/A LPIPS 0):

  • L4, 8 prompts, 960x544, 25 frames, 2 steps: mean LPIPS 0.080 (0.027 to 0.184), mean PSNR 34.5 dB.
  • A100-40, 2 prompts, 960x544, 49 frames, 20 steps: LPIPS 0.304 / 0.167, PSNR 18.1 / 23.5 dB.

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:

encoder encode s per prompt (median) major faults per encode process RSS during encode load s
int8, run 1 47.4 32.7k-33.2k 46.7-47.1 GiB 159
int8, run 2 53.1 32.3k-37.5k 46.6-47.5 GiB 187
q4_k_m, run 1 19.7 0 43.1-43.2 GiB 144
q4_k_m, run 2 19.8 0 44.0-44.1 GiB 156

A100-40 (83 GB host), whole card:

encoder encode s process RSS during encode load s
int8 (main), two runs 6.1-6.4 45.3-46.8 GiB 114-139
int8 through this branch's loader 6.2 46.5 GiB 140
q4_k_m 6.2 25.9 GiB 168

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_0
    projections, 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.
  • Related H3 / encoder / companion / GGUF suites: 630 passed; tests/test_video_backend.py -k "h3 or minimax": 179
    passed. Red on main as well, untouched here: tests/test_integrated_gpu_no_host_pin.py (2 pinning-site assertions in
    files this branch does not change) and tests/test_diffusion_gguf_compile.py::test_installed_dequant_survives_a_failing_compile
    under xdist (passes serially).

Not covered here

  • A clip against the bf16 encoder: the released dense encoder (66.7 GB) is refused on an A100-40 at generate time
    (68.5 GB VRAM floor), so the clip numbers are against int8; the bf16 comparison is the hidden-state check above.
  • H3-Image (Studio: MiniMax-H3-Image text to image and reference edits #17453): it reuses this loader, but no H3-Image render pair ran.
  • The q4_k_m encode at L4 12 GiB is 19.7 s, not the ~4 s of a fully host-resident encoder: the faults are gone, the
    rest is the leaf-by-leaf stream itself (not investigated here).
  • q4_k_m loads 10-30 s slower than int8 on the A100 (the GGUF payload is copied into anonymous memory at load).
  • T4, ROCm, Windows, Apple: not run.

…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.
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 11, 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-11T08:14:35.941351Z 19d1769 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.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. You're on a roll.

Reviewed commit: 287b6356bb

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

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Bravo.

Reviewed commit: 51bfcaf6e9

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

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: 19d17693e0

ℹ️ 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 568e79e into main Nov 11, 2026
@danielhanchen
danielhanchen deleted the studio-h3-te-4bit branch November 11, 2026 10:03
danielhanchen added a commit that referenced this pull request Nov 11, 2026
…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.
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