Skip to content

Studio: INT8 attention by default for FLUX.1, FLUX.2 and HunyuanVideo-1.5 where it wins per card - #18085

Merged
danielhanchen merged 1 commit into
mainfrom
studio-int8-attention-more-families
Nov 17, 2026
Merged

danielhanchen merged 1 commit into
mainfrom
studio-int8-attention-more-families

Conversation

@danielhanchen

Copy link
Copy Markdown
Member

Summary

These families call diffusers' dispatch_attention_fn but were never raced for INT8 attention while the switch is unset:

  • FLUX.1 (dev, schnell, Kontext);
  • FLUX.2 (klein, dev);
  • HunyuanVideo-1.5.

This PR adds them to AUTO_DITS, AUTO_CUDA_ONLY and the attention-sink set (SINK_DITS). The two FLUX classes also go into SPEED_UNSET_DITS, which T4 uses by default. The per-card accuracy check and race then decide, as for FLUX.3, Qwen-Image-2.1, Wan and Z-Image.

HunyuanVideo-1.5 also needed a fix. Studio's padded-text trim processor captured dispatch_attention_fn in a closure, so the route never saw its calls: 0 modules routed on main, even when forced. It now reads the function from diffusers' module at call time, with the same call and arguments.

Staying off:

  • Qwen-Image (v1 / Edit / 2512): stays request-only on accuracy. On G4, the per-step error max is 0.031 against 0.0125 for its INT8 weights, and 50-step images are LPIPS 0.145 from native.
  • HunyuanImage-2.1 and Krea-2: they attend with a text padding mask on every call, so there is nothing to route.

Results

Colab, main vs this branch, 3 interleaved repeats each. Error is teacher-forced per-step rel L2 against bf16 weights with native attention, the same gate #18004 uses.

family GPU main branch delta A/A spread per-step error (kernel vs INT8 weights) LPIPS mean / max engaged
FLUX.2 klein 4B T4 11.876 s 10.305 s +15.3% 3.07% 0.029 / 0.043 0.010 / 0.028 25 modules
FLUX.2 klein 4B L4 2.002 s 1.886 s +6.1% 1.35% 0.049 / 0.064 0.017 / 0.042 25 modules
FLUX.2 klein 4B G4 0.355 s 0.345 s +2.9% 1.27% 0.034 / 0.048 vs 0.046 / 0.062 0.025 / 0.051 25 modules
FLUX.1 schnell T4 High-RAM 24.834 s 21.364 s +16.2% 1.04% 0.025 / 0.134 0.050 / 0.104 57 modules
FLUX.1 schnell L4 4.885 s 4.58 s +6.7% 2.4% max 0.21 0.083 / 0.174 57 modules
FLUX.1 schnell G4 0.696 s 0.643 s +8.2% 0.36% 0.028 / 0.104 vs 0.057 / 0.169 0.077 / 0.172 57 modules
HunyuanVideo-1.5 480p, 61 frames G4 53.475 s/clip 40.964 s/clip +30.5% 0.17% 0.0087 / 0.0113 vs 0.019 / 0.024 see below 54 modules
  • Error columns: G4 rows show the gate (kernel alone vs INT8 weights alone, both against bf16). T4 and L4 rows are this branch against main at that card's defaults.
  • FLUX.2: races picked the attention-sink path on every card; without it the error was 1.2 to 1.3x higher.
  • HunyuanVideo-1.5 LPIPS cannot test the 0.05 video bar here. Main is not repeatable on G4: main against itself gives 0.16 to 0.29, while this branch against itself gives 0. The per-step error (0.0087, including a 0.0059 native-to-native floor) is the accuracy evidence. It is under half the INT8-weight error.

Testing

  • CPU: new test_diffusion_int8_attention_families.py, 25 tests plus 4 CUDA ones. It covers which families race when unset, the speed-unset rule, a lost race keeping the incumbent, the kill switches, Qwen and the masked families staying off, and the HunyuanVideo-1.5 trim route.
    • The exact-set assertions in test_diffusion_int8_attention_dispatch.py are updated.
    • Main: 8 fail.
    • This branch: the INT8 suites pass (169 passed).
  • GPU: pytest on T4 (sm75) and G4 (sm120) passes: 256 passed, 6 skipped (two-GPU tests).
  • Not covered:
    • A100 was not measured; the per-card race decides there.
    • FLUX.1 dev / Kontext, FLUX.2 dev / klein 9B and HunyuanVideo-1.5 at 720p or i2v follow the same per-class rule, but were not measured directly.

…-1.5 where it wins per card

FLUX.1 (dev, schnell, Kontext), FLUX.2 (klein, dev) and HunyuanVideo-1.5 call diffusers'
dispatch_attention_fn but were not raced with the switch unset. Add them to AUTO_DITS (and the
CUDA-only and attention-sink sets; the FLUX families also to SPEED_UNSET_DITS, the T4 default),
so the per-card accuracy check and race decide as for the other dispatch families.

HunyuanVideo-1.5's padded-text trim processor captured dispatch_attention_fn in a closure, so the
route could never see its calls; it now reads it from diffusers' module at call time (same call,
same arguments).

Qwen-Image (v1 / Edit / 2512) stays on request only: per-step error max 0.031 vs 0.013 for its
INT8 weights and 50-step images LPIPS 0.14 from native. HunyuanImage-2.1 and Krea-2 attend with a
text padding mask on every call, so there is nothing to route.
@danielhanchen danielhanchen self-assigned this Nov 17, 2026
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 17, 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-17T05:38:13.934633Z 3a510de 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. 🚀

Reviewed commit: 3a510dea55

ℹ️ 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 e6b0789 into main Nov 17, 2026
@danielhanchen
danielhanchen deleted the studio-int8-attention-more-families branch November 17, 2026 06:33
danielhanchen added a commit that referenced this pull request Nov 24, 2026
…request only) (#19235)

## Summary

Studio's automatic INT8 attention (on by default since #18085) routes
FLUX.1 and FLUX.2 denoisers. Re-gated with the accuracy rule Studio uses
for automatic kernels, INT8 moves FLUX.1 schnell and FLUX.2 klein 4B
significantly further from an fp32-attention reference than a bf16
kernel swap does, on both L4 and A100-40, for a 6-7% speed gain on L4
and under 2% on A100. This takes `FluxTransformer2DModel` and
`Flux2Transformer2DModel` out of Auto. Picking INT8 attention explicitly
still routes them.

## Change

- `diffusion_int8_attention_dispatch.py`: FLUX.1 and FLUX.2 removed from
`AUTO_DITS`, `SPEED_UNSET_DITS` and `AUTO_CUDA_ONLY`. FLUX.3, Krea 2,
MOSS-Image, HunyuanVideo-1.5, Qwen-Image-2.1, Wan and Z-Image keep Auto.

## Evidence

Colab, Studio main `a4135f0fa6`, 30 prompts with fixed seeds, 1024 px,
Studio defaults (4 steps, int8 weights, compiled), a fresh process per
arm, one VM per family and card.

- Reference: the same load with fp32-math attention, so only attention
differs.
- OFF: bf16 SDPA (flash), the path without INT8. Repeated on the same
VM, bit-identical.
- AUTO: Studio's default, INT8 attention routed.
- Kernel-swap floor: the larger LPIPS shift of two other bf16 attention
kernels (efficient, cuDNN) against OFF, i.e. how far an accepted bf16
kernel change moves the output.

Rule, fixed before running: keep Auto for a family only if the upper
bound of the paired bootstrap 95% CI of (AUTO minus OFF, LPIPS against
the reference) is at or below the floor.

| card / family | INT8 vs ref, mean / max | bf16 vs ref, mean / max |
INT8 minus bf16 [95% CI] | floor | s/img OFF -> INT8 |
|---|---|---|---|---|---|
| L4, FLUX.1 schnell | 0.103 / 0.217 | 0.085 / 0.204 | +0.0177 [0.0104,
0.0269] | 0.0057 | 4.65 -> 4.35 (-7.0%) |
| L4, FLUX.2 klein 4B | 0.031 / 0.083 | 0.019 / 0.063 | +0.0122 [0.0090,
0.0154] | 0.0010 | 1.98 -> 1.87 (-6.1%) |
| A100-40, FLUX.1 schnell | 0.099 / 0.196 | 0.091 / 0.230 | +0.0074
[0.0016, 0.0122] | 0.0018 | 1.151 -> 1.134 (-1.5%) |
| A100-40, FLUX.2 klein 4B | 0.027 / 0.071 | 0.019 / 0.065 | +0.0089
[0.0061, 0.0119] | 0.0009 | 0.590 -> 0.580 (-1.7%) |

Every lower bound is above its floor, so all four cells fail the rule.
On klein 4B INT8 is about 1.5-1.65x further from the reference than
bf16. On schnell (4 distilled steps) any attention change can move the
layout; INT8 moves it more than the bf16 kernels do (for example added
furniture and a different ceiling on one interior prompt).

Tests: the INT8 attention dispatch, families, auto, toggle and
speed-route suites, 259 passed, 90 skipped (GPU-only). The family tests
now assert FLUX.1 / FLUX.2 stay off under Auto and still route when INT8
is requested.

## Not covered

- T4, Blackwell (G4) and AMD were not re-gated.
- FLUX.1 dev / Kontext and FLUX.2 klein 9B / dev share the two classes
and leave Auto with them; they were not measured separately.
- One seed per prompt, no human rating.
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