Repository navigation
Studio diffusion: compiled int8 W8A8 linear on RDNA3 / RDNA4 ROCm (Qwen-Image-2.1 int8 21% faster per step on gfx1151, now ahead of bf16) - #16825
Conversation
|
@codex review |
Codex Review SummaryThis 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. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 00247844f6
ℹ️ 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".
| # No readable gfx arch (this host has no ROCm device): unmeasured, so eager. | ||
| assert nq._fused_w8a8() is None | ||
| assert nq.fused_w8a8_state()["failed"] == "ROCm" | ||
| assert nq.fused_w8a8_state()["failed"] == "ROCm unknown arch" |
There was a problem hiding this comment.
Mock the unreadable architecture in the eager-fallback test
On a real ROCm host, this test still reads the physical GPU's architecture: changing torch.version.hip does not make _device_gfx_arch return an empty string. Consequently, RDNA3/RDNA4 hosts now return a compiled function and fail the first assertion, while other readable AMD architectures fail the ROCm unknown arch assertion. Mock _device_gfx_arch to return "" here, as the new architecture-specific tests already mock it, so this fallback test remains runnable on the hardware this change supports.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed: the test now pins _device_gfx_arch to an unreadable arch, so it holds on any host, including a real RDNA3 / RDNA4 one.
|
@codex review |
|
Codex Review: Didn't find any major issues. Chef's kiss. 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". |
… fixed 1 KiB/s (#16871) ## Summary The Windows `GGUF inference smoke (API, tools, vision)` job runs `tests/studio/test_mirror_fallback.ps1` first, and one of its checks fails now and then on unrelated PRs. In the last day it hit the staging runs for #16825 (int8 diffusion on RDNA3) and #16804 (LTX-2.5 encode), and a rerun of the #16825 job passed: ``` PASS probe: gives up at its deadline, cancelling what has not answered FAIL probe: a ranged 1 KiB answer is 206 with its speed ##[error]Process completed with exit code 1. ``` The check wanted the `/ok` probe's speed above 1024 bytes/s. `Wait-MirrorProbe` measures speed as bytes read over the probe's own clock, so for a 1 KiB answer that floor really means "answered in under a second". The probe gives that batch of 6 URLs 1.5 s, and on a busy Windows runner the local server can take longer than a second to answer. The probe is then working correctly and the check still fails. Reproduced locally with `pwsh`: delaying the test server's `/ok` answer by 1.1 s, still inside the 1.5 s deadline, fails this check on main. ## Change `tests/studio/test_mirror_fallback.ps1`, this one check. It now asks for: - status 206, as before; - the whole 1 KiB in the probe's buffer (`Position -eq 1024`), which the old check did not look at; - a speed of at least 1024 bytes over the batch's total time from the test's own stopwatch. The probe's clock starts after that stopwatch, so a correct speed can never be below this bound. A zero, missing or miscomputed speed still fails. No installer code changes. ## Testing `pwsh -File tests/studio/test_mirror_fallback.ps1`, Linux pwsh 7: | case | main | this branch | |---|---|---| | as is | pass | pass, 0 FAIL lines in the whole file | | `/ok` answers after 1.1 s (slow runner) | FAIL | pass | | `/ok` answers 200 instead of 206 | FAIL | FAIL | | `/ok` sends 512 of the 1024 bytes | pass (not caught) | FAIL |
…nslothai#17013) ## 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: - ROCm CUDA device, bf16, on a native quant host, on Linux (Windows ROCm was not measured and runs the speed tier off). - The compiled W8A8 linear from unslothai#16825 can run (`rocm_rdna_w8a8_ready()`: RDNA arch, inductor runtime present, not disabled by `UNSLOTH_NATIVE_INT8_FUSED=0`). - The family is not denied int8. - `UNSLOTH_NATIVE_INT8_ACT` is not `0`. - 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): unslothai#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.
…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
Studio's native int8 W8A8 linear (
transformer_quant=int8with int8 activations, the path AMD GPUs use since torchao's dense schemes are NVIDIA-only) now runs as one compiled function on ROCm RDNA3 / RDNA3.5 / RDNA4 (gfx11xx / gfx12xx), as it already does on CUDA. Other ROCm archs keep the eager kernels.Why
#15183 added the compiled
_w8a8_rowsand kept it off on ROCm as a precaution ("stays off on ROCm and on hosts without Triton"); no ROCm failure was recorded. On AMD the eager path is slower than bf16: at 4096 rows, 3072 -> 3072 on a Strix Halo (Radeon 8060S, gfx1151) it takes 4.97 ms against 2.85 ms for bf16 with bias, split into per-token quantisation 1.82 ms,_int_mm2.19 ms, scale / bias epilogue 1.37 ms and the ConvRot rotation 0.42 ms. The int8 GEMM itself is fine (hipBLASLt int8 is about 1.27x bf16); the separate quantise and epilogue passes eat the gain.Measured on the gfx1151 runner with torch 2.11.0+rocm7.13.0 (what Studio installs there) and torch 2.14.1+rocm7.2:
torch.compile(_w8a8_rows, dynamic=True, fullgraph=True)compiles in 0.1-2 s and its output is bit-identical to the eager kernels, with and without ConvRot256._alloc_from_poolfailure on gfx1151 did not reproduce on either torch.Runs: https://github.com/oobabooga/unsloth/actions/runs/41989449486 and https://github.com/oobabooga/unsloth/actions/runs/42001287645.
End-to-end A/B on the same gfx1151 runner, base = main
f7e499a349, head = this branch, same seeds,transformer_quant=int8(+UNSLOTH_NATIVE_INT8_ACT=1for W8A8). Run: https://github.com/oobabooga/unsloth/actions/runs/42051745713 (job "Native int8 W8A8 on ROCm").On Qwen-Image-2.1, int8 W8A8 on this branch is now faster than bf16 (3.60 vs 4.25 s/step, 92 vs 106 s per 1024x1024 image), where on main it was slower. Head logs
diffusion.native_quant: int8 W8A8 linear runs as one compiled functionin every W8A8 cell; weight-only int8 and bf16 cells are unchanged (pixel-identical renders base vs head). The smaller FLUX.2-klein and Z-Image DiTs gain the same ~21% on their int8 W8A8 path but stay behind their compiled bf16 runs.How
_fused_w8a8(): the ROCm refusal now applies only when the device arch is not gfx11xx / gfx12xx (read with the existingrocm_bf16._device_gfx_arch). The reason is recorded as before (ROCm gfx942,ROCm unknown arch), theUNSLOTH_NATIVE_INT8_FUSED=0kill switch still wins, and a compile or runtime failure still falls back to eager once and stays there.int8 W8A8 linear runs as one compiled functionorint8 W8A8 linear stays eager (<reason>).Tests
studio/backend/tests/test_diffusion_native_quant_fused.py:test_diffusion_native_quant_fused.py+test_diffusion_native_quant.py: 185 passed, 9 skipped (CUDA-only cases) on CPU.Risk