Skip to content

Studio: auto runs compiled int8 W8A8 for Qwen-Image families on RDNA - #17013

Merged
danielhanchen merged 8 commits into
mainfrom
studio/rdna-auto-w8a8
Nov 7, 2026
Merged

danielhanchen merged 8 commits into
mainfrom
studio/rdna-auto-w8a8

Conversation

@danielhanchen

@danielhanchen danielhanchen commented Nov 7, 2026 •

Copy link
Copy Markdown
Member

What

On ROCm RDNA3 / RDNA3.5 / RDNA4 GPUs (gfx11xx / gfx12xx), Studio's auto transformer precision now runs the native int8 W8A8 linear for Qwen-Image-2.1 and Qwen-Image, compiled from the first render. Before this, auto always gave bf16 on AMD.

Every other family keeps bf16, and so does every other AMD architecture. Explicit int8 keeps its current behaviour (weight-only unless UNSLOTH_NATIVE_INT8_ACT=1), and the video path is not changed.

  • FamilyProfile.rdna_auto_w8a8 marks the families that opt in, together with their measured evidence. Only qwen-image and qwen-image-2.1 set it.
  • rdna_auto_w8a8_reason() decides whether a load takes this path. All of these must hold:
  • The image loader uses it only for a pipeline load with auto, no hosted seed, and no requested offload. auto_bf16_when_resident still applies first, so the small DiTs (FLUX.2-klein, Z-Image) never reach it.
  • When it engages and speed_mode is unset, the speed tier compiles from render 1. That is the configuration that was measured; with the W8A8 linear alone and the rest of the DiT eager, it trails compiled bf16.

Kill switch: UNSLOTH_NATIVE_INT8_ACT=0 restores bf16 auto (weight-only int8 measured no faster than bf16 on gfx1151).

Evidence (gfx1151, Radeon 8060S, Linux, torch 2.11.0+rocm7.13.0 from Studio's own install.sh --local)

Both arms are compiled from render 1 (speed_mode=default). W8A8 = transformer_quant=int8 + UNSLOTH_NATIVE_INT8_ACT=1. LPIPS-alex is measured against the compiled bf16 render with the same seeds. The bf16 A/A repeat is bit-identical, with an s/image spread of 0.1-0.2%.

family (steps, 1024^2) compiled bf16 s/image compiled W8A8 s/image s/step bf16 / W8A8 LPIPS mean / max peak GiB bf16 / W8A8 decision
Qwen-Image-2.1 (25, CFG 1) 95.06 83.25 (-12.4%) 3.708 / 3.238 0.020 / 0.031 41.4 / 36.4 auto W8A8
Qwen-Image (20, CFG 4) 141.18 133.13 (-5.7%) 7.011 / 6.632 0.014 / 0.021 61.2 / 55.3 auto W8A8
Wan2.1-T2V-1.3B (832x480x33, 20) 129.05 s/clip 141.34 (slower) - 0.139 21.2 / 19.0 stays bf16
Wan2.2-TI2V-5B (1280x704x21, 20) 144.90 s/clip 138.51 - 0.123 (over the 0.10 bar) 36.7 / 33.2 stays bf16

FLUX.1-schnell could not be measured: the runner's Hugging Face mirror returned 404 for its text encoder, so it stays bf16. Qwen-Image-Edit and Qwen-Image-Layered were not measured and stay bf16.

Base vs head with Studio defaults on the same box (auto engages int8 W8A8 at head, the kill switch is pixel-identical to base, untouched families pixel-identical): #17013 (comment)

Tests

tests/test_diffusion_native_quant.py covers:

  • the gate: per family, the kill switch, ROCm only, bf16 only, the arch / compiled-linear readiness check, and the family deny list;
  • explicit int8 keeping its weight-only default on RDNA;
  • the shipped family set.

@danielhanchen danielhanchen self-assigned this Nov 7, 2026
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 7, 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-07T17:27:54.749530Z 3ffd963 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

Base vs head on gfx1151 (Radeon 8060S, Linux, torch 2.11.0+rocm7.13.0 from install.sh --local). One exclusive job, one Studio venv, each state's own source tree. Base is the merge base 25b53fb91; head is that commit plus this PR's diff. 1024^2, same seeds.

Cells:

  • *_def: Studio defaults, nothing requested.
  • *_ref: compiled bf16 (transformer_quant=off, speed_mode=default), used as the LPIPS reference in both states.
  • q21_kill: defaults with UNSLOTH_NATIVE_INT8_ACT=0.
  • klein_def: a family this PR does not touch.
cell base s/image head s/image base s/step head s/step LPIPS vs ref base / head peak GiB base / head head resolved
Qwen-Image-2.1 defaults (25 steps) 94.37 90.81 3.678 3.546 0.0007 / 0.0182 39.3 / 32.9 transformer_quant=int8 (auto), speed_mode=default
Qwen-Image-2.1 compiled bf16 ref 94.53 94.47 3.697 3.701 - 39.3 / 39.3 unchanged, pixel-identical
Qwen-Image-2.1 defaults, UNSLOTH_NATIVE_INT8_ACT=0 94.50 94.97 3.685 3.700 0.0007 / 0.0007 39.3 / 39.3 bf16, pixel-identical to base
Qwen-Image defaults (20 steps, CFG 4) 153.18 133.53 (-12.8%) 6.994 6.606 0.019 / 0.026 57.9 / 50.7 transformer_quant=int8 (auto), speed_mode=default
Qwen-Image compiled bf16 ref 147.86 147.94 7.321 7.353 - 56.9 / 56.9 unchanged, pixel-identical
FLUX.2-klein-4B defaults (untouched) 14.75 11.32 1.435 1.434 - 16.1 / 16.1 unchanged, pixel-identical (s/image includes where the deferred compile lands; s/step is equal)

The harness verdict is NO_REGRESSION.

In this run, the Qwen-Image-2.1 head default hit Inductor's SubprocException at the first compiled forward and fell back to eager (compile_fallback_eager). Even so it was 3.8% faster than base. With compile engaged, the earlier measurement table in the description gives 83.25 vs 95.06 s/image (-12.4%).

The same compile-worker failure also hit the Qwen-Image compiled bf16 reference in BOTH states (base included), so it is a pre-existing intermittent Inductor worker issue on this runner, not something this change adds. Qwen-Image's auto W8A8 compiled cleanly here, and so did both families' explicit W8A8 in the measurement run.

@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 0844e8a793

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

Comment on lines +336 to +338
from .diffusion_speed import torch_compile_runtime_available

return bool(torch_compile_runtime_available())

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Honor the ROCm compile kill switch before enabling auto W8A8

On Linux RDNA with UNSLOTH_DIFFUSION_ROCM_COMPILE=0, this readiness check still returns true because torch_compile_runtime_available() checks runtime availability and TORCHDYNAMO_DISABLE, not the ROCm compile setting. Consequently, default Qwen pipeline loads now select W8A8 even though compile_eligible() rejects block compilation; the native linear's eager forward then calls _fused_w8a8(), which invokes torch.compile anyway. This bypasses the existing no-compile switch for users who disabled compilation to avoid compiler failures. Decline the automatic W8A8 path when ROCm compilation is disabled so those loads retain their previous bf16 behavior.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in bfd3e67: the auto pick now also requires compile_eligible(..., probe=False), which reads UNSLOTH_DIFFUSION_ROCM_COMPILE and a recorded probe failure, so those loads keep bf16 auto. Covered by test_auto_on_rdna_keeps_bf16_when_rocm_compile_is_off.

@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: bfd3e671fe

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

Comment on lines +8607 to +8610
if transformer_quant == TQ_AUTO
and kind == "pipeline"
and pipeline_seed_scheme is None
and not _memory_request_forces_offload(memory_mode, cpu_offload)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Keep automatic W8A8 disabled for the eager speed tier

On Linux RDNA, loading a measured Qwen family with automatic precision and speed_mode="eager" now selects W8A8 because this gate never checks the requested speed tier. The native path bypasses _pipeline_quant_uncompilable_reason(), which normally rejects eager quantization, and the native linear subsequently invokes torch.compile through _fused_w8a8(). This violates the UI's explicit “eager = fused kernels, no compile” choice and leaves the transformer blocks eager—the configuration the new speed-promotion comment identifies as slower than compiled bf16. Exclude the eager tier from this automatic selection so it retains the previous bf16 behavior.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in d3fcb61: the auto pick now runs only with speed_mode unset, default or max; eager (and off, as before) keep bf16 auto. Covered by test_auto_on_rdna_with_the_eager_tier_stays_bf16.

@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

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

Reviewed commit: d3fcb6125e

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

Reviewed commit: 3ffd963d2a

ℹ️ 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 6db37aa into main Nov 7, 2026
@danielhanchen
danielhanchen deleted the studio/rdna-auto-w8a8 branch November 7, 2026 20:45
github-actions Bot pushed a commit to Flipped-168/unsloth that referenced this pull request Nov 8, 2026
…floads (unslothai#17104)

## Problem

unslothai#17013 lets AUTO pick native int8 W8A8 on ROCm RDNA for the families it
was measured on (Qwen-Image), and the code says it is resident only:
"offload / low-VRAM keeps bf16". The gate only checked an explicit
offload request (`memory_mode` / `cpu_offload`). Under automatic memory
settings, a card too small for the transformer even at int8 still kept
the int8 W8A8 scheme: the int8 re-plan did not fit resident, the bf16
plan's offload stayed, and the native scheme was applied under it, with
the default compile tier switched on.

CPU fake runtime, Qwen-Image-2512 on a simulated 16 GiB RDNA card, no
explicit offload:

| | before unslothai#17013 | main | this PR |
|---|---|---|---|
| placement | offloaded | offloaded | offloaded |
| transformer | bf16 | native int8, `act_int8=True` | bf16 |
| speed tier | off | default | off |

## Change

After the int8 re-plan, if the RDNA AUTO pick is active and the plan
does not keep the transformer resident, AUTO declines: no native scheme,
the bf16 plan, and the reason in the resolved status (`auto int8 W8A8 on
RDNA is resident-only; the '<policy>' offload keeps the bf16
transformer`). Resident loads, explicit `int8` requests, NVIDIA and
every non-RDNA path are unchanged. `UNSLOTH_NATIVE_INT8_ACT=0` still
turns the AUTO pick off entirely.

## Tests

`test_auto_on_rdna_stays_bf16_when_the_int8_plan_still_offloads`
(`test_diffusion_backend.py`, the existing RDNA host stub with a 16 GiB
device): nothing quantised, `transformer_quant` None, an offload policy.

| arm | `test_diffusion_backend.py -k "quant or offload or rdna or amd"`
|
|---|---|
| main (`a174823`) | 156 passed, 1 failed (the new test: int8 W8A8 under
offload) |
| this PR | 157 passed |

The existing resident RDNA case
(`test_auto_on_rdna_runs_compiled_w8a8_for_a_measured_family`) still
picks int8 W8A8 with the default speed tier.

## Not covered

- No real RDNA card run: the routing is proven on the CPU fake runtime.
A resident load on gfx1151 takes the same path as before.
danielhanchen added a commit to danielhanchen/unsloth-staging-2 that referenced this pull request Nov 8, 2026
…ocess (unslothai#17078)

## Problem

unslothai#16825 enabled the compiled int8 W8A8 linear on ROCm RDNA3 / RDNA4 only
(gfx11xx / gfx12xx), and unslothai#17013 lets AUTO pick W8A8 on those cards. The
architecture check read the current device, and its answer was cached
for the whole process in one slot:

- an RDNA3 card used first, then an RDNA2 / CDNA card: the second card
got the same compiled function without its arch ever being read;
- an RDNA2 / CDNA card used first: the refusal (`ROCm gfx942`) stuck for
the process, so a later RDNA3 card stayed eager and AUTO never picked
W8A8 for it;
- a compile failure on one card also turned the compiled linear off for
every other card.

So on a host with two different ROCm cards, which card ran first decided
the path for both, even when each load was correctly placed on its own
card.

## Change

- The compiled-linear check is now per card. `_fused_w8a8(device)` takes
the input's device (the linear's forward passes `x.device`), reads that
card's arch once, and caches the answer under that card. The compiled
function itself is still built once.
- A compile failure is recorded against the card it happened on. That
card goes eager, and the other cards keep the compiled linear.
- `rocm_rdna_w8a8_ready(ordinal)` answers for the target's card. AUTO
W8A8 passes `target.ordinal` (current card when unset, as before).
- `fused_w8a8_state()` keeps `failed` (the process-wide reason, else the
first card's) and adds `devices` (each card's answer).
- Nothing changes on a single-card host: same arch rule, same compiled
function, same eager fallback, same `UNSLOTH_NATIVE_INT8_FUSED=0` kill
switch. NVIDIA keeps the compiled linear as before.
- The forward still runs only outside `torch.compile` (`not
torch.compiler.is_compiling()`), so the per-card lookup adds no guards.
Its cost: 0.68 µs per call on main, 0.84 µs here (CPU, `timeit`, 3 x 5 x
200k calls).

## Tests

`test_diffusion_native_quant_fused.py` (CPU, HIP arch and compile
runtime mocked):

- Two cards (gfx1100 + gfx1030), in both orders, by input device and by
switching the current card: each card gets its own answer, and each arch
is read once.
- CDNA card first, then RDNA: `rocm_rdna_w8a8_ready` is True for the
RDNA card and False for the CDNA one.
- A compile failure on card 1 keeps card 0 on the compiled function.

| arm | `test_diffusion_native_quant_fused.py` +
`test_diffusion_native_quant.py` |
|---|---|
| main (`a174823`) | 190 passed, 7 failed (the 6 new per-card cases,
plus 1 torchao test) |
| this PR | 196 passed, 1 failed (the same torchao test) |

The torchao failure (`AffineQuantizedTensor` has no `qdata`) comes from
the torchao version on this host and fails the same way on main. The
RDNA / AMD / W8A8 cases in `test_diffusion_backend.py` pass (13).

## On gfx1151 (Strix Halo, ROCm)

Two jobs, base `49453f39a` vs head `9e86484b7` on the same runner:
`test_diffusion_native_quant_fused.py` +
`test_diffusion_native_quant.py`. The GPU job presents the one real card
as two HIP devices (a second ordinal on the same gfx1151), so the
per-card bookkeeping runs against real HIP indices.

| job | base | head | verdict |
|---|---|---|---|
| suites (HIP masked) | 190 passed, 1 failed | 197 passed, 1 failed | no
regression; the failure is the torchao test above, on both |
| GPU (real gfx1151 + a second ordinal) | 195 passed, 5 failed | 203
passed, 5 failed, 0 skipped | no regression; the same 5 fail on base |

On the GPU job,
`test_each_real_card_runs_the_compiled_linear_bit_identical_to_eager`
ran on `cuda:1` and `cuda:0`: the compiled linear engaged on each and
matched eager bit for bit. The 5 failures on both arms
(`test_eager_w8a8_chunks_long_inputs_without_changing_the_result`, two
torchao offload tests, and the two ROCm
`test_cuda_engagement_tests_skip_where_production_stays_eager` cases)
pre-date this PR.

An earlier gfx1151 run of this branch caught a case the CPU tests
missed. On a ROCm torch with no visible card, a CPU input was judged by
the current card's arch (unreadable, so a refusal). Fixed in
`9e86484b7`: only the current card (no device given) and HIP inputs are
judged.

## Not covered

- Two physically different ROCm cards in one host: the second ordinal on
the gfx1151 runner is the same card, so mixed-arch routing is proven on
the mocked-arch CPU tests only.
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