Skip to content

Studio MiniMax-H3: keep the released bf16 denoiser resident beside a streamed conditioner on ~100 GB cards - #16877

Merged
danielhanchen merged 9 commits into
mainfrom
studio-h3-bf16-resident-placement
Nov 9, 2026
Merged

danielhanchen merged 9 commits into
mainfrom
studio-h3-bf16-resident-placement

Conversation

@danielhanchen

@danielhanchen danielhanchen commented Nov 6, 2026 •

Copy link
Copy Markdown
Member

Summary

With the released bf16 MiniMax-H3 components (transformer_quant=none, text_encoder_quant=none) on a 96 GB card (RTX PRO 6000 Blackwell, 101.4 GB free), Studio keeps the 66 GB denoiser in the CPU-offload rotation. The load sizes the pinned denoiser beside the rotating 66.8 GB bf16 conditioner, plus headroom, at 142.0 GB, which does not fit. So every clip pages the conditioner and the denoiser on and off the card: encode takes 28-29 s and decode 18-19 s, around 20 denoise steps of 3.70 s each.

This PR adds a middle placement tier for the released bf16 denoiser. When the denoiser fits beside a conditioner that streams leaf by leaf, the conditioner is streamed first and then the denoiser is pinned. The streamed conditioner uses the existing stream_h3_text_encoder path that the quantized conditioner already takes, and needs about 3 GB on the device. The sizing for this case is 86.3 GB. On a G4 this cuts the steady clip from 114.8 s to 75.7 s, with bit-identical frames.

What / why

  • _h3_others_bytes / _h3_dense_denoiser_resident_bytes: a new te_streamed flag sizes the conditioner at its streamed footprint (H3_TE_STREAMED_GB) instead of its resident size. It defaults to False, so every existing caller gets the same numbers as before.
  • _h3_dense_pin_plan: returns "pin" (fits beside a rotating conditioner; unchanged), "pin_stream_te" (fits only beside a streamed one; new) or None (rotation; unchanged). The streamed tier is only offered when group offloading is importable and UNSLOTH_H3_TE_STREAM is not 0.
  • Load path, released bf16 denoiser branch only: for "pin_stream_te", the denoiser is moved to the card and the conditioner is then streamed. If the stream is refused anyway, _h3_dense_unpin puts the denoiser back on the CPU and re-installs the rotation, because the sizing assumed the stream.
  • Request guard: the tier is sized for the default clip (124 frames at the first preset). A longer or larger request whose VRAM floor only the rotation meets (for example 1344x768 at 345 frames: 108.5 GB pinned against 96.6 GB in the rotation, with 101.4 GB available) now hands the denoiser back to the rotation (_h3_dense_demote) instead of being refused. Over every preset and frame count and 85 to 145 GB available, no request that main accepts is refused here (102,000 cells, 0). With no host RAM for the denoiser's copy, the guard refuses as before.
  • The new tier keeps the eager speed tier of the rotation it replaces. Placement alone is bit-identical, but the regional compile is not (LPIPS 0.115 over 20 steps on the G4), so enabling compile here should be a separate change with its own accuracy check.
  • The pre-quantized (INT8 / FP8 / NVFP4) branches are untouched, so the default INT8 path is unchanged.

Placement by card (released bf16 denoiser, 66.3 GB):

free VRAM before after
about 178 GB (B200 class) pinned, conditioner rotates same
about 101 GB (RTX PRO 6000 96 GB) rotation pinned, conditioner streams
80 GB and below rotation rotation

Evidence: final code (Colab G4, RTX PRO 6000 Blackwell 96 GB, 177 GiB host, one VM)

Base = main ccc8a82, head = main plus this branch's video.py (the measured head is 7dc8a4d; e5a2a96 only adds the request-guard fallback, which a 960x544, 124-frame request never reaches). Default settings, fresh Studio home per arm, 960x544, 124 frames, 20 steps, t2v + audio, one clip per arm (h00), same seed. Arms interleaved S P S P with each arm's weights read into the page cache first (warm), then P S P S with the page cache dropped before each arm (cold).

arm page cache load s warm-up clip s load + warm-up s steady clip s load + warm-up + first full clip s peak VRAM GiB host peak GiB
S1 main warm 5.7 265.6 271.4 114.9 386.3 68.2 134.9
P1 this PR warm 395.2 9.2 404.4 74.3 478.7 70.4 78.9
S2 main warm 26.1 318.8 344.9 114.3 459.2 68.2 134.9
P2 this PR warm 386.5 9.5 396.0 74.5 470.5 71.8 78.8
P3 this PR cold 361.8 9.2 371.0 76.3 447.3 70.4 79.0
S3 main cold 23.6 318.7 342.4 115.7 458.1 68.2 135.1
P4 this PR cold 428.1 8.8 436.9 74.4 511.3 71.8 78.9
S4 main cold 28.0 282.3 310.4 115.1 425.5 68.2 134.9
  • Frames: S vs P identical in all four pairs and P1 vs P4 identical (16 of 16 sampled frames, max abs diff 0).
  • Steady clip: 115 s to 74.5 s (-35%). Peak VRAM 68 to 70-72 GiB, host RAM peak 135 to 79 GiB.
  • Time to the first clip is slower. Both sides read the same 134 GiB of weights from disk once: main inside its first clip, this branch at load. The disk on this VM read 280 to 570 MiB/s and drifted between arms, so main's own load + warm-up clip ranged from 271 to 345 s here (287 to 527 s across four sessions). Medians on this run: load + warm-up clip 327 s on main against 400 s here (+73 s); load + warm-up + the first full clip 442 s against 475 s (+33 s). This branch is ahead from the second clip (38 to 40 s saved per clip).
  • What did not close the gap (same VM, same protocol): a threaded ring upload of the denoiser (slower: 207 to 230 MiB/s), reading ahead in file order (touch or MADV_WILLNEED, slower), and moving the denoiser on a second thread while the conditioner is pinned (the disk stayed the limit: 412 / 499 s against main's 388 / 446 s in that session).

Evidence: earlier run (same VM type, merge base b75a4cd)

Setup: 960x544, 124 frames, 20 steps, t2v + audio, two prompts per arm (h00, h01), and the same seeds in every arm. The arms ran one after another on the same VM, in the order S1, F1, E1, Z1, F2, S2. S = main at the merge base, F = this branch, E = this branch with speed_mode=eager, Z = main with speed_mode=eager.

arm s/clip (median of 2) encode s decode s s/step peak VRAM GiB host peak GiB load + first clip s
S1 main 113.63 28.13 18.18 3.705 68.2 134.9 252.7
S2 main 114.79 28.97 18.53 3.705 68.2 134.9 311.0
Z1 main, eager 115.64 29.39 18.98 3.705 68.5 135.9 427.4
E1 this PR, eager 75.75 4.95 3.41 3.705 73.8 79.7 318.7
  • Frames: E1 vs Z1 are identical on all 16 sampled frames of both prompts (max abs diff 0, LPIPS 0.0). The A/A pairs are also identical: S1 vs S2, and the two compile-on F arms against each other.
  • Steady clip: 114.8 s to 75.7 s (-34%). Encode 28-29 s to 4.9 s, decode 18-19 s to 3.4 s, step time unchanged.
  • Peak VRAM rises from 68 to 74 GiB, because the denoiser now stays resident through encode and decode. Host RAM peak drops from 135 to 80 GiB, because the denoiser's host copy is released.
  • Load plus first clip: 253 / 311 / 427 s on main, 314 / 319 / 347 s here. Both read the 134 GiB of weights from disk once. Main reads them lazily during its first clip; this branch reads them at load, mostly the 66 GB denoiser move at disk speed. The final-code run above has the per-arm numbers.

Default INT8 path at a 12 GiB budget (ballast), arms S, F, F, S on the same VM: 54.13 / 54.13 s/clip on main and 54.07 / 54.14 s/clip here (S1 was the first arm at 58.0 s), with the same peak VRAM. Frames are identical across all four arms.

Tests

  • studio/backend/tests/test_h3_bf16_streamed_te_pin.py (new, 15 tests). They cover:
    • the streamed sizing;
    • the placement tier for each card size: 96 GB pins with a streamed conditioner, 178 GB pins as before, and 80 / 47 / 12 GB keep the rotation;
    • unreadable sizes, and a missing stream, which keep the rotation;
    • the load order and the fallback when the stream is refused (_h3_dense_unpin);
    • the request guard handing the denoiser back to the rotation before refusing, idempotently, and refusing as before with no host RAM for it;
    • the new tier holding the compile off.
  • test_video_prequant.py, test_video_h3_te_quant.py, test_h3_low_vram_stream.py, test_h3_quantised_offload.py plus the new file: 218 passed, 7 skipped on head.

Not proven

  • Time to the first clip is slower on this VM (above). A faster disk shrinks the gap; it was not measured.
  • Cards between 86 and 142 GB other than the RTX PRO 6000 (H100 NVL 94 GB, H200 141 GB) were not run; they take the same tier by sizing.
  • The request-guard fallback (a longer clip handing the denoiser back to the rotation) is covered by unit tests and the floor sweep, not by a GPU run.
  • Windows and ROCm were not run. The stream path refuses where group offloading or pinning is unavailable, and that case keeps the rotation (covered by unit tests).

…streamed conditioner when it fits

On a 96 GB card the bf16 denoiser (66 GB) does not fit beside a rotating bf16
conditioner (142 GB sized), so both stayed in the CPU-offload rotation and every
clip paged them across the bus (encode 30.9 s, decode 19.2 s) with the regional
compile held off. When the denoiser fits beside a conditioner streamed leaf by
leaf (86 GB sized), stream the conditioner first and pin the denoiser. Cards that
cannot hold it keep the rotation; a refused stream keeps the rotation.
@danielhanchen danielhanchen self-assigned this Nov 6, 2026
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 6, 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-09T05:02:54.701788Z cf53d3b 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.

@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Delightful!

Reviewed commit: 4c6fa54d79

ℹ️ 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. Hooray!

Reviewed commit: af326bf940

ℹ️ 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 added a commit that referenced this pull request Nov 6, 2026
… memo tests (#16908)

## Summary

`Repo tests (CPU, studio)` has been failing on unrelated PRs since
#16793 landed, always in the same test with a different parameter each
time:

```
tests/python/test_preference_chunked_logprobs.py:278: in test_matches_trl
    torch.testing.assert_close(g, w, rtol = 1e-4, atol = 1e-6)
E   AssertionError: Tensor-likes are not close!
E   Mismatched elements: 1 / 32 (3.1%)
E   Greatest absolute difference: 3.814697265625e-06 at index (0, 6) (up to 1e-06 allowed)
```

Seen on the staging runs for #16109, #16886, #16882 and #16877 today
(`cpo-kwargs1`, `kwargs2`, `kwargs3`, `kwargs5`, `kwargs6`, always
`qwen3_lora`).

The cause is test pollution. #16793 added
`test_load_probe_memo.py::test_fastmodel_adapter_load_probes_base_config_once`,
which runs `FastModel.from_pretrained` up to the weights. That load does
what it does in real use: it swaps PEFT's LoRA forwards
(`peft.tuners.lora.layer.Linear` and 8 other LoRA layer classes) for
Unsloth's, process-wide, and sets `UNSLOTH_FORCE_FLOAT32`,
`UNSLOTH_FULLGRAPH`, `UNSLOTH_RETURN_LOGITS` and `UNSLOTH_MODEL_NAME`.
The test never puts them back, so when xdist schedules the CPO parity
test on the same worker later, it compares the chunked path against TRL
on Unsloth's LoRA forward instead of stock PEFT, and its tight gradient
tolerance trips. The swapped forward is the part that matters: restoring
only the environment variables still fails with the same numbers,
restoring only the forwards passes.

Neither side's product code is wrong. #16793's loader change and its
probe-count assertions are correct; only the test leaks process state.

## Change

Tests only.

- `tests/python/test_load_probe_memo.py`: an autouse fixture records
every PEFT LoRA layer class's own `forward` and the `UNSLOTH_*`
variables before each test and puts them back after. A PEFT module first
imported during the load falls back to the `_unsloth_original_forward`
the wrapper carries.
- `tests/python/test_preference_chunked_logprobs.py`:
`test_matches_trl[...-qwen3_lora]` pins stock PEFT forwards for its
duration (through `monkeypatch`), since its reference is TRL on stock
PEFT. This keeps it deterministic whatever else ran earlier in the
worker.

## Testing

The failing worker's exact history from a local rerun of the CI shard
(`-n 4 --dist loadgroup`) replayed serially reproduces the CI failure
with the same numbers, and bisects to the #16793 test. With that test
followed by `test_matches_trl[cpo-kwargs1-qwen3_lora]`:

| | result |
|---|---|
| main | 1 failed (`3.814697265625e-06 at index (0, 6)`, as in CI) |
| this branch | 2 passed |
| this branch, parity test pin removed | 2 passed |
| this branch, probe memo fixture disabled | 2 passed |
| this branch, both removed | 1 failed (same numbers) |

The same failing worker's history replayed serially (1595 tests) on this
branch: `test_matches_trl[cpo-kwargs1-qwen3_lora]` passes. On main the
same replay fails it. One other failure in both arms,
`test_cached_paths_hold_no_credentials.py::test_model_cache_variables_are_not_treated_as_credential_homes`,
comes from this machine's environment; it passes in CI and is unchanged
here.

Both touched files pass in full: `tests/python/test_load_probe_memo.py`
plus `tests/python/test_preference_chunked_logprobs.py`, 33 passed
(torch 2.10.0+cpu, transformers 5.17.0, TRL 1.15.0, PEFT 0.21.2, the CI
shard's versions).
…ring so the load is not slower than main's first clip
@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Nov 6, 2026
@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Nov 6, 2026
@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Swish!

Reviewed commit: e5a2a965af

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

ℹ️ 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 ed3eec6 into main Nov 9, 2026
@danielhanchen
danielhanchen deleted the studio-h3-bf16-resident-placement branch November 9, 2026 14:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant