Repository navigation
Studio: auto runs compiled int8 W8A8 for Qwen-Image families on RDNA - #17013
Conversation
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. |
|
Base vs head on gfx1151 (Radeon 8060S, Linux, torch 2.11.0+rocm7.13.0 from Cells:
The harness verdict is NO_REGRESSION. In this run, the Qwen-Image-2.1 head default hit Inductor's 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. |
|
@codex review |
There was a problem hiding this comment.
💡 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".
| from .diffusion_speed import torch_compile_runtime_available | ||
|
|
||
| return bool(torch_compile_runtime_available()) |
There was a problem hiding this comment.
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 👍 / 👎.
There was a problem hiding this comment.
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.
… failed compile probe
|
@codex review |
There was a problem hiding this comment.
💡 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".
| if transformer_quant == TQ_AUTO | ||
| and kind == "pipeline" | ||
| and pipeline_seed_scheme is None | ||
| and not _memory_request_forces_offload(memory_mode, cpu_offload) |
There was a problem hiding this comment.
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 👍 / 👎.
There was a problem hiding this comment.
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.
|
@codex review |
|
Codex Review: Didn't find any major issues. Breezy! 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. 👍 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". |
…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.
…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.
What
On ROCm RDNA3 / RDNA3.5 / RDNA4 GPUs (gfx11xx / gfx12xx), Studio's
autotransformer precision now runs the native int8 W8A8 linear for Qwen-Image-2.1 and Qwen-Image, compiled from the first render. Before this,autoalways gave bf16 on AMD.Every other family keeps bf16, and so does every other AMD architecture. Explicit
int8keeps its current behaviour (weight-only unlessUNSLOTH_NATIVE_INT8_ACT=1), and the video path is not changed.FamilyProfile.rdna_auto_w8a8marks the families that opt in, together with their measured evidence. Onlyqwen-imageandqwen-image-2.1set it.rdna_auto_w8a8_reason()decides whether a load takes this path. All of these must hold:rocm_rdna_w8a8_ready(): RDNA arch, inductor runtime present, not disabled byUNSLOTH_NATIVE_INT8_FUSED=0).UNSLOTH_NATIVE_INT8_ACTis not0.auto, no hosted seed, and no requested offload.auto_bf16_when_residentstill applies first, so the small DiTs (FLUX.2-klein, Z-Image) never reach it.speed_modeis 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=0restores 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%.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.pycovers: