Repository navigation
Studio: per-load INT8 attention Auto / On / Off, MiniMax-H3 video raced INT8 attention by default - #18248
Merged
Conversation
…ttention by default - int8_attention: auto / on / off on the image and video load requests. A per-load on / off beats UNSLOTH_DIFFUSION_INT8_ATTENTION_KERNEL, which beats the family default. Resolved once per load into an Int8Policy that every install, dispatch, deferred-speed and H3-Image path takes; os.environ is never touched. attention_backend=unsloth_int8 stays the alias for on. - An explicit attention pick (native, sage, cudnn, flash) is no longer raced over by the dispatch route in auto; on layers the kernel on top of it. - MiniMax-H3 video: in auto, on Studio's hosted INT8 ConvRot denoiser with speed on and attention left to Studio, the strided processors race the kernel at H3's own lengths (FAMILY_RACE_TOKENS, 16k / 8k tokens) after the fp32 accuracy check, with a token floor that keeps the token refiner on its incumbent. Strided processors go in first, then INT8, then status reports what engaged (attention_backend and resolved.int8_attention name unsloth_int8). The probe keys on the load's real card. - H3 strided processor forwards the kernel's sink mode; FlashInfer stands aside when the INT8 kernel is engaged. - resolved.int8_attention on image, H3-Image and video loads (engaged, impl, modules). - Routes forward int8_attention only when set; sd.cpp and MLX accept and ignore it.
…s and Video pages
Member
Author
|
@codex review |
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 |
|
Codex Review: Didn't find any major issues. Keep them coming! 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". |
[skip ci]
danielhanchen
added a commit
that referenced
this pull request
Nov 18, 2026
## Drive the clock by hand in the Hub backoff-window tests `Frontend unit tests (Windows)` failed on #18248, a backend-only change: ``` not ok 6571 - a lapsed backoff window means probing, never proven-available location: 'studio\frontend\tests\hub-network-availability.test.ts:58:1' expected: 'unavailable' actual: 'probing' ``` ### Cause The test calls `markRemoteNetworkOffline(HF, 10, ...)` and immediately asserts the Hub is `unavailable`. It then sleeps 30 ms and asserts `probing`. `network.ts` measures the window with `Date.now()`, so the first assert only holds if it runs within 10 ms of the mark. On a loaded runner, especially Windows, where timers tick about every 15 ms and the frontend suite runs on 8 workers, that window had already lapsed. The code under test behaved correctly; only the test raced the wall clock. `only a success clears the recorded failure` sleeps the same way. It does not fail today, but it depends on real time for no reason. ### Fix Both tests now drive `Date.now()` through a small `manualClock()` helper instead of sleeping. The helper restores the real clock in `finally`. - **First test:** the clock moves 9 ms, still inside the 10 ms window, and must read `unavailable`. It then moves past the window and must read `probing`. - **Second test:** the clock moves past the window before checking the recorded failure. The assertions are unchanged, and the file no longer sleeps. ### Verification - `node --test tests/hub-network-availability.test.ts`: 16 passed. - Sabotage checks in `network.ts`: - Treating an expired window as `available` instead of `probing` fails `a lapsed backoff window means probing`. - Ignoring the TTL, so the window ends immediately, fails it as well, along with three other tests. - eslint on the file reports two unused imports, `getBrowserOfflineRetryDelayMs` and `isHuggingFaceOffline`, on lines this change does not touch.
danielhanchen
added a commit
that referenced
this pull request
Nov 19, 2026
…8418) ## Summary When a load asks for a specific attention backend (SageAttention, flash, cuDNN, native, or INT8 attention On), Studio now either runs that backend or the status says what ran instead and why. The status is read off the DiT's attention modules, so it never names a backend that no module routes to. Before this change, an explicit `attention_backend="sage"` that could not run (SageAttention not installed, its probe failed, unsupported dtype or head_dim, a ROCm / Apple Silicon / CPU load) fell back to SDPA, and the status said `value: "native", status: "applied", reason: "diffusers default"`. The badge stayed hidden, so the page looked as if the pick had been honoured. ## Changes **Status (`resolved.attention_backend`)** - An explicit pick that did not engage now reads `fell_back`, or `unsupported` where the platform or card cannot run it. The reason names the cause, for example: - `sageattention is not installed and the Hugging Face kernels-hub build could not be loaded (...)` - `SageAttention failed its check on this GPU (self-check: cosine ...)` - `SageAttention serves head_dim <= 128 and this model uses 256` - `SageAttention needs an NVIDIA CUDA GPU and this load runs on Apple Silicon (MPS)` - `cuDNN attention has no kernel for this model's head_dim with this torch/cuDNN build` - `FlashAttention 3 needs a sm90 to below sm100 GPU and this one is sm89` - INT8 attention On over an explicit pick says the INT8 kernel runs, and on how many modules. - The entry carries the module census: `engaged` (the backend the modules run), `modules` (how many run it) and `routed` (every backend's count). A split is named in the reason, for example `40 of 60 attention modules run SageAttention, 20 run native SDPA`. - The value is never a backend with 0 modules. The image status re-reads the census when a later race moves modules. **Explicit picks are never raced over** - The image and video loads already kept an explicit pick away from the INT8 races (#18248). Tests now pin this for the strided route, the dispatch route and the INT8 On layering. - MiniMax-H3-Image ignored the load's attention pick entirely. It now honours it: - an explicit `sage` pins SageAttention on the DiT blocks, with no race against native and no INT8 race (INT8 only when its control is On); - any other explicit pick keeps the checkpoint's SageAttention off; - its status gains an `attention_backend` entry. **Frontend** - The existing attention badge shows a declined pick as `SAGE -> NATIVE`, with the backend's reason in the tooltip. `unsloth_int8` reads `INT8`. No new UI elements. - The loaded build summary names the backend the modules run. - The Attention select keeps the user's own pick when it fell back, so the next load asks for it again (for example after installing SageAttention). ## Tests - New `tests/test_diffusion_attention_honest_status.py` (24 tests, fake backends, real module census). It covers: - an explicit sage pick winning against the INT8 race, with both the pip and the kernels-hub build; - sage missing, probe failure, import failure, head_dim, fp32, and MPS / CPU / ROCm; - INT8 On over sage, and an INT8 claim with 0 routed modules; - split censuses and the live re-read; - native, cuDNN, flash and FlashAttention 3 picks; - torch.compile: a compiled DiT that reads each processor's backend, with every status read run between renders. It shows 0 graph breaks, 1 compiled frame before and after (no recompile) and 0 tensor ops on the status path, so no host sync. A deliberate `graph_break()` is counted first to prove the counters work. - Two new MiniMax-H3-Image tests: the explicit pick beats the checkpoint and its races, and the load passes the pick and reports it. - New frontend `tests/attention-resolved-badge.test.ts` (9 tests). - All of them fail on main and pass here. The 40 attention, INT8 and H3 backend test files pass: 1518 on main, 1543 here (the 25 new tests). The 36 frontend tests pass, and `tsc` is clean. ## GPU check (Colab L4) One Colab L4 VM (torch 2.13.0+cu130, diffusers 0.42.1). Studio was installed with `./install.sh --local` at the merge base. The head tree is that tree plus this change. Every arm is a fresh process with `attention_backend="sage"` and speed left at its default (the DiT compiles). FLUX.2-klein-4B renders 768 px in 4 steps. Qwen-Image-2.1 (`model_kind=pipeline`) renders 768 px in 8 steps. - "installed" means the kernels-hub SageAttention 2 build, which is what Studio installs and loads for `sage` (`kernels` 0.12.3, no pip `sageattention`). - "not installed" means `kernels` and `sageattention` removed, with `UNSLOTH_DIFFUSION_ATTENTION_INSTALL=0`. - Sage calls are counted inside Studio's opaque Sage op, so they are real runtime counts under compile too. | model | Sage | tree | status value / status | status reason | modules in status | modules routed (census) | Sage calls per render | INT8 calls | |---|---|---|---|---|---|---|---|---| | FLUX.2-klein-4B | installed | base | `sage_hub` / applied | requested | not reported | 25 sage_hub | 100 (25 x 4 steps) | 0 | | FLUX.2-klein-4B | installed | head | `sage_hub` / applied | requested | 25 | 25 sage_hub | 100 | 0 | | Qwen-Image-2.1 | installed | base | `sage_hub` / applied | requested | not reported | 32 sage_hub | 224 of 256 | 0 | | Qwen-Image-2.1 | installed | head | `sage_hub` / applied | requested | 32 | 32 sage_hub | 224 of 256 | 0 | | FLUX.2-klein-4B | not installed | base | `native` / **applied** | **diffusers default** | not reported | 25 native | 0 | 0 | | FLUX.2-klein-4B | not installed | head | `native` / **fell_back** | sageattention is not installed and the Hugging Face kernels-hub build could not be loaded (the kernels package is not importable) | 25 | 25 native | 0 | 0 | | Qwen-Image-2.1 | not installed | base | `native` / **applied** | **diffusers default** | not reported | 32 native | 0 | 0 | | Qwen-Image-2.1 | not installed | head | `native` / **fell_back** | same as above | 32 | 32 native | 0 | 0 | - The explicit pick is not raced in either tree: 0 INT8 calls in every arm, although both DiTs are on the INT8 Auto list. - The status now matches what ran in every arm. On main, the not-installed arms report the fallback as an honoured pick. - On Qwen-Image-2.1, 32 of the 256 attention calls per render do not run Sage. That is the same in both trees: Sage's per-call guard sends calls it cannot take to SDPA. This change does not report that per-call split (see below). ## Not covered - Nothing on the per-call attention path changed: the Sage / FA4 guards, the strided processors, the INT8 op and the dispatch route are untouched. The new code runs at load time and when the status is read. Graph breaks and recompiles were counted on CPU (torch 2.14.1) with Dynamo counters. They were not counted on the GPU arms, which ran torch 2.13. Other torch versions were not run. - Per-call fallbacks inside an engaged Sage backend (a masked call, a head_dim above 128 on some modules) are not in the status. Under compile those calls are traced, not counted. The census is per module. - pip SageAttention 2 was not run end to end on the GPU. Only the kernels-hub build was; the pip path is covered by the CPU tests. - ROCm, Apple Silicon and Windows fallbacks, the MiniMax-H3 video and MiniMax-H3-Image picks, and flash / cuDNN / FlashAttention 3 picks were tested on CPU with fake backends only. None ran on a GPU here. - The INT8 On over Sage arm was not run on the GPU. ### UI before / after Images page, loaded diffusers build on a CUDA host, Advanced > Attention set to SageAttention. Left = main (merge base `ec3ba179c`), right = this PR (`f9a0c756f`). The status served to each side was produced by that side's own backend code for the same load. **SageAttention requested but not installed (no hub build):** main shows no badge, so the UI implies Sage ran. This PR shows `SAGE → NATIVE` next to Attention, and the tooltip says why.  **SageAttention requested with INT8 attention On:** main shows no badge. This PR shows `SAGE → INT8`, and the tooltip names Studio's INT8 kernel and how many attention modules it runs.  **Loaded build summary, same INT8 On load:** the Attention row reads `UNSLOTH_INT8` on main and `INT8` with this PR, naming what the attention modules run. 
danielhanchen
added a commit
that referenced
this pull request
Nov 24, 2026
…drift past the L4 floor) (#19098) ## Summary MiniMax-H3 video's default (Auto) INT8 attention, made the default in #18248, moves the generated **audio** past the bf16 noise floor on NVIDIA L4 (sm89). This PR keeps Auto INT8 attention off for H3 video on **sm89** only. Every other card, including the unmeasured sm86, behaves exactly as on `main`. Explicit `int8_attention="on"` and `UNSLOTH_DIFFUSION_INT8_ATTENTION_KERNEL=1` still engage the kernel on every card. Cost: sm89 gives up INT8 attention's denoise speedup under Auto. On L4 INT8 cut denoise time by 23.4% in this run (241 s vs 315 s per clip) and by 22.8% in the #18248 recheck. ## Why sm89, and only there The bar is our standing rule: each lever is scored against the same card's own bf16 spread. That spread is the `int8_attention="off"` render against an off render that only swaps the bf16 attention kernel (flash vs cuDNN). Measured over 12 rows (6 prompts x 2 seeds, Studio defaults: 20 steps, 960x544x124), with everything scored against the off render: | card | INT8 Auto audio log-mel L1 | bf16 floor | Auto vs floor (paired) | |---|---:|---:|---| | L4 (sm89) | 0.481 | 0.329 | +0.152 [+0.050, +0.276], worse on 11/12 rows, p 0.01 | | A100-40GB (sm80) | 0.426 | 0.404 | +0.022 [-0.056, +0.101], 6/12, p 0.68 | | RTX PRO 6000 (sm120) | 0.441 | 0.454 | -0.014 [-0.102, +0.071], 6/12, p 0.91 | The INT8 audio drift against off is about the same on every card: log-mel L1 0.40-0.44 on L4, A100 and RTX PRO 6000. The INT8 kernel's bits do not depend on the card. Only L4's own bf16 floor (0.24-0.33) is tight enough to flag it. On L4, MCD was 18.1 vs 12.3 dB and waveform SNR 7.6 vs 11.2 dB. Frames lean worse there too (LPIPS 0.215 vs 0.169, 10/12 rows, p 0.06). A100 and RTX PRO 6000 are inside their floors on frames and audio. ## What was tried first **Keeping INT8 on the video query rows only** (text and audio query rows recomputed on bf16 attention against the full K / V) does not fix it end to end, so it is not in this PR. - **Diagnosis on L4 (teacher-forced, one prompt).** It pointed at the audio query rows' own attention. With only the video rows on bf16, the per-step audio velocity error stayed at the INT8 level (0.0300 vs 0.0297). With the audio rows on bf16, it came close to the kernel-swap floor (0.0270 vs 0.0259). - **End to end (free-running, 20 steps).** The renders still diverged as much as with INT8 on every row: | card | head with split vs main Auto, audio log-mel L1 (paired) | denoise time vs main Auto | |---|---|---| | L4 (12 rows) | 0.480 vs 0.481, -0.001 [-0.054, +0.051], p 0.97 | +2.0% | | RTX PRO 6000 (12 rows) | 0.419 vs 0.441, -0.022 [-0.100, +0.055], p 0.57 | +2.9% (A/A spread 0.01%) | ## Changes - `video_minimax_h3_attn.py`: - `H3_INT8_AUTO_OFF_ARCHS = {(8, 9)}`. - `h3_int8_auto_off_reason(capability)` and `cuda_capability(device)`. - `h3_int8_load_gate(*, mode, attention_backend, auto_attention, speed_on, hosted_int8, comfy_checkpoint, adapters, capability) -> H3Int8Gate(forced, auto, reason)`: the H3 video load's INT8 attention decision, moved out of `video.py` so it can be tested directly. Same conditions and status reasons as before, plus the arch check under Auto. - `video.py`, H3 video load: - Calls `h3_int8_load_gate` with the load's own card and uses its `forced` / `auto` / `reason`. The forced path (explicit On / env `1` / an explicit INT8 backend pick) never looks at the arch. - When every other Auto condition held, the `int8_attention` status reason says why it is off: `Auto keeps it off for MiniMax-H3 video on sm89 (it moved the audio past the bf16 noise floor on L4); int8_attention='on' engages it`. ## Verified on L4 This branch under Auto against `int8_attention="off"`, one prompt plus warm-up, fresh process per arm: - **Status:** `int8_attention` reads `{"value": "off", "source": "auto", "engaged": false, "reason": "Auto keeps it off for MiniMax-H3 video on sm89 (it moved the audio past the bf16 noise floor on L4); int8_attention='on' engages it"}`. - **Frames:** bit-identical to off (same frames MD5, LPIPS 0). - **Audio:** log-mel L1 0.002 / 0.004 against off. That is inside L4's off-vs-off repeat spread (0.001-0.004); L4 audio is not bit-reproducible run to run. - **Denoise time:** 309.4 s vs 309.6 s. ## Tests `studio/backend/tests/test_h3_int8_auto_arch.py` (CPU, 33 cases) drives `h3_int8_load_gate` directly: - sm89 under Auto: not forced, not raced, the reason names sm89, the audio and the explicit On override - sm80, sm86, sm90, sm100, sm120, sm75 and an unknown / ROCm card under Auto: raced as on `main`, no reason - the off set is exactly sm89 - explicit On, env `1` (also env `0` with a per-load On) and an explicit INT8 backend pick force the kernel on sm89 - env `0`, a per-load Off, and a per-load Off over env `1` stay off with no reason - speed off, an explicit attention pick and an off-config load (no hosted INT8, Comfy checkpoint, adapters) keep their existing reasons on every arch - one AST check that the H3 video load calls the gate once, with the load card's capability, and uses `forced`, `auto` and `reason` All 33 fail on `main` (the gate does not exist there) and pass on this branch. An exhaustive check of the gate against the inline gate it replaces (this PR's first commit) over 720 input combinations differs only in the sm86 Auto cell, now raced as on `main`. The existing `test_diffusion_int8_attention_toggle.py` source check now reads the gate's inputs at the call site. The INT8 attention toggle, auto, families, H3 attention and H3 forward suites pass (236 passed, 34 skipped). ## Not tested - **sm86 (RTX 3090 / A10 / A40):** never measured, so Auto is left as on `main` there. It may need the same gate once measured against its own bf16 floor. - **Other Ada parts (RTX 4090, RTX 6000 Ada):** only the L4 was measured. They share sm89, so the gate applies to them. - **T4 (sm75), H100 (sm90), B200 (sm100):** not measured. Auto behaves as on `main` there. - **i2v / reference workflows and the 10-step setting:** not re-measured. There was no listening test.
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.
Summary
int8_attention:"auto" | "on" | "off"on the image and video load requests, with an "INT8 attention" select on the Images and Video pages.Changes
Per-load setting
int8_attentionis resolved once per load and stored on the load state. The deferred 3rd-image compile reuses it, and the environment is never modified.UNSLOTH_DIFFUSION_INT8_ATTENTION_KERNEL. Auto or null leaves the env switch in charge.attention_backend="unsloth_int8"still means On.resolved.int8_attention(requested, source, engaged), with a badge on both pages.MiniMax-H3 video Auto
Fixes
unsloth_int8. Main reported_native_flash.Results
Colab, 960x544, 124 frames, 10 steps. 3 interleaved fresh processes per arm.
Off vs main:
Auto:
INT8 attention engaged (policy auto from default, raced): 52 attention modules.Quality vs main. Floor = swapping one bf16 attention kernel for another.
The A100 audio is slightly above that prompt's floor, and the same as On.
Refiner: it stays on SDPA. Auto makes 600 INT8 calls per process vs 604 under On; the 4 extra are the refiner calls On forces.
Controls: FLUX.2 klein 4B INT8 on L4 and MiniMax-H3-Image on A100 are bit-identical to main (9 of 9 renders each).
Why INT8 and not SageAttention for H3 video (main, same settings):
Quality vs flash: SageAttention lands at 1.6 to 2.7x the bf16 noise floor on frames and 2 to 8x on audio. INT8 stays at or near the floor.
Kernel accuracy vs fp32 at 19.3k tokens:
Testing
test_diffusion_int8_attention_toggle.py, 46 tests. All 46 fail on main and pass here.Not covered