Repository navigation
Studio MiniMax-H3: keep the released bf16 denoiser resident beside a streamed conditioner on ~100 GB cards - #16877
Conversation
…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.
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 |
|
Codex Review: Didn't find any major issues. Delightful! 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". |
…itioner tier so output is unchanged
|
@codex review |
|
Codex Review: Didn't find any major issues. Hooray! 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". |
… 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
|
@codex review |
… streamed conditioner
|
@codex review |
…r a request only the rotation fits
|
@codex review |
|
@codex review |
|
Codex Review: Didn't find any major issues. Swish! 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". |
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_encoderpath 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 newte_streamedflag sizes the conditioner at its streamed footprint (H3_TE_STREAMED_GB) instead of its resident size. It defaults toFalse, 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) orNone(rotation; unchanged). The streamed tier is only offered when group offloading is importable andUNSLOTH_H3_TE_STREAMis not0."pin_stream_te", the denoiser is moved to the card and the conditioner is then streamed. If the stream is refused anyway,_h3_dense_unpinputs the denoiser back on the CPU and re-installs the rotation, because the sizing assumed the stream._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.Placement by card (released bf16 denoiser, 66.3 GB):
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).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 withspeed_mode=eager.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:_h3_dense_unpin);test_video_prequant.py,test_video_h3_te_quant.py,test_h3_low_vram_stream.py,test_h3_quantised_offload.pyplus the new file: 218 passed, 7 skipped on head.Not proven