Skip to content

Studio ROCm: explicit W8A8 only on gfx1151, fold the VAE upsample in strips - #18995

Merged
danielhanchen merged 3 commits into
mainfrom
studio-rocm-audit-followups
Nov 23, 2026
Merged

danielhanchen merged 3 commits into
mainfrom
studio-rocm-audit-followups

Conversation

@danielhanchen

Copy link
Copy Markdown
Member

Summary

Two follow-ups on merged ROCm work, found while re-checking the gfx1151 int8 and VAE changes:

  1. Studio video: read the hosted int8 ConvRot DiT as W8A8 on ROCm for an explicit int8 pick #18903 (and the FLUX.3 explicit W8A8 row before it) turned an explicit int8 pick into W8A8 on every RDNA3 / RDNA4 card, but only gfx1151 was ever measured. The W8A8 rows now apply only on gfx1151; other RDNA cards keep the weight-only explicit int8 build they used before.
  2. Studio diffusion: VAE upsample fold on by default on gfx1151 #18854's VAE upsample fold on gfx1151 ran one whole-map transposed conv at 1024 px, which doubled the full-map decode peak (1.55 -> 3.10 GiB in that PR's own table) while full_map_decode_mib, the estimate the admission check uses, has no term for it. ROCm now folds strip by strip, the shape the 2048 px decode already used with its peak unchanged. A decoder whose strip decode failed also no longer re-runs the fold in its retry.

Changes

  • diffusion_transformer_quant.py: rdna_explicit_w8a8_reason also needs the target card's own gfx arch, read by its ordinal through rocm_bf16._device_gfx_arch, to be in RDNA_EXPLICIT_W8A8_ARCHS = {"gfx1151"}. That covers:

    • FLUX.3 Klein explicit int8 (image);
    • LTX-2.5 explicit int8 through rdna_video_explicit_w8a8_reason, both the resident hosted read (_video_rocm_hosted_scheme) and the offloaded native build (_video_int8_act).

    The RDNA W8A8 kernels still accept every gfx11xx / gfx12xx card (_ROCM_FUSED_W8A8_ARCH), and the weight-only compiled explicit int8 tier (rdna_explicit_int8_reason) is unchanged on all of them. gfx1100 / gfx1101 / gfx1201 and an unreadable arch lose only the unmeasured W8A8 switch. AUTO (rdna_auto_w8a8_reason) is not touched here.

  • diffusion_vae_strips.py:

    • _fold_full_max(x): on ROCm the fold's whole-map limit is one strip (strip_elems), so MIOpen's transposed conv runs per strip with a bounded workspace. CUDA keeps FOLD_FULL_MAX_ELEMS.
    • full_map_decode: a decoder whose strip decode failed retries, and keeps decoding, on the torch ops without the fold, so a failing fold does not run twice before the tiles take over. The fold is not tied to the portable mode itself, because ROCm and no-Triton hosts run every strip decode in portable mode and must keep the fold.
  • Tests:

    • test_diffusion_flux3_rdna_shared_quant.py and test_video_rocm_hosted_int8.py check the arch gate: gfx1151 on, gfx1100 / gfx1101 / gfx1201 / "" off, the arch read by the target ordinal, and an unreadable arch treated as off. The video test covers the resident spec and the offloaded spec.
    • test_diffusion_vae_upsample_fold.py covers the ROCm strip limit and the fold call count per strip, and checks that a portable decode keeps the fold while the failed-decoder retry drops it.
    • The existing RDNA fixtures pin the arch to gfx1151.

Results (gfx1151, ROCm 7.13, torch 2.11)

Base = main 1446c1d, head = base + this branch, same runner and job, Linux ROCm 7.13.

FLUX.2 VAE (unsloth/flux-3-image-klein), whole-map strip decode (full_map_decode), bf16, fixed latents. Fresh process per arm, fold off / on in ABBA order, decode time is the median of 3 decodes after a warm one. Peak is max_memory_allocated above what was allocated before the decodes. Estimate is the tree's own full_map_decode_mib.

px arm base s head s base peak MiB head peak MiB estimate MiB
1024 fold off 2.506 2.509 1409 1409 2322
1024 fold on 2.372 2.289 2997 1427 2322
2048 fold off 11.380 11.442 3370-3497 3370 4682
2048 fold on 10.535 10.539 3388 3388 4682
  • Base's 1024 px fold peak (2997 MiB) is above its own estimate (2322 MiB), which is the under-pricing this fixes. Head's is 1427 MiB, within 18 MiB of the fold-off peak.
  • Fold speedup over fold off is unchanged or better: 1024 px 1.056x -> 1.096x, 2048 px 1.080x -> 1.086x. At 1024 px the strip fold is also faster than the whole-map fold measured inside the head tree (2.289 vs 2.384 s).
  • The fold still runs: 12 fold calls per run in both trees. The head runs 104 transposed convs (strips) where base ran 12.
  • Output: the fold-off images are byte-identical between base and head. Base's whole-map fold re-run inside the head tree is byte-identical to base. The head strip fold against the base whole-map fold differs only at rounding (max abs 0.031, PSNR 66.6 dB), closer than fold against no fold (64.8 dB, the tolerance Studio diffusion: VAE upsample fold on by default on gfx1151 #18854 shipped with).
  • LTX-2.5 explicit int8 (512x320, 17 frames, 8 steps): both arms log read 480 int8 ConvRot layers of transformer from the hosted checkpoint as native Linears, 15.83 / 15.93 s per clip, and the clips are byte-identical. The gate still allows gfx1151.

Not covered

  • gfx1100 / gfx1101 / gfx1201: no such runner was available, so the refusal on those archs is proven on CPU only (the gate's arch read is mocked per arch).
  • Windows ROCm: not run here. The arch gate is platform-neutral. The VAE strip fold matches the 2048 px shape that Studio diffusion: VAE upsample fold on by default on gfx1151 #18854 measured on Windows 7.14.
  • CUDA: unchanged by construction. The arch gate sits behind _rocm_cuda, and _fold_full_max returns the old limit on non-ROCm devices. Not rerun on hardware.

Test plan

  • tests/test_diffusion_flux3_rdna_shared_quant.py, tests/test_video_rocm_hosted_int8.py, tests/test_video_hosted_int8_fit.py, tests/test_diffusion_vae_upsample_fold.py, tests/test_diffusion_vae_strips.py, tests/test_diffusion_vae_full_map.py, tests/test_diffusion_vae_tiling.py pass
  • tests/test_diffusion_native_quant.py, tests/test_diffusion_vae_tiling_general.py: one pre-existing failure each, which fails the same way on main
  • gfx1151 hardware run, base (main) vs head: VAE criteria CONFIRMED (defect at base, cleared at head), LTX-2.5 NO_REGRESSION (byte-identical)

rdna_explicit_w8a8_reason (FLUX.3 Klein image, and LTX-2.5 through
rdna_video_explicit_w8a8_reason, resident and offloaded) now also needs the
target card's own gfx arch, read by its ordinal, to be in
RDNA_EXPLICIT_W8A8_ARCHS = {gfx1151}. The RDNA W8A8 kernels accept every
gfx11xx / gfx12xx card, but the explicit W8A8 rows were only measured on
gfx1151; gfx1100 / gfx1101 / gfx1201 and an unreadable arch keep the
weight-only explicit int8 build. The weight-only compiled tier is unchanged.
…oder's retry

On gfx1151 one whole-map transposed conv (MIOpen) doubled the FLUX.2 1024 px
full-map decode peak (1.55 -> 3.10 GiB), which full_map_decode_mib does not
price. ROCm now folds strip by strip (full_max = strip_elems), the shape the
2048 px decode already used with its peak unchanged. CUDA keeps the whole-map
limit.

A decoder whose strip decode failed now retries (and keeps decoding) on the
torch ops without the fold, so a failing fold is not run a second time before
the tiles take over. The fold is not tied to the portable mode itself: ROCm
and no-Triton hosts run every strip decode portable and keep the fold.
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 23, 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-23T03:39:28.639374Z 642a933 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. Another round soon, please!

Reviewed commit: 642a933907

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

[skip ci]
@danielhanchen
danielhanchen merged commit 6fb2c6c into main Nov 23, 2026
@danielhanchen
danielhanchen deleted the studio-rocm-audit-followups branch November 23, 2026 06:05
danielhanchen added a commit that referenced this pull request Nov 23, 2026
…p retrying a failed portable VAE fold (#19012)

## Summary

Two small follow-ups on main for the diffusion stack.

### 1. A fine-tune named like the official repo no longer loads the
official prequantised weights

`_same_base_model`
(`studio/backend/core/inference/diffusion_prequant.py`) accepted any two
ids whose last path segment matched. So `someone/Qwen-Image-2.1` counted
as `Qwen/Qwen-Image-2.1`, and every hosted prequant reader that runs
this check (the torchao prequant loader, the text encoder prequant
check, the converted single-file check and the fp8 training seed) could
load the official prequantised DiT in place of the fine-tune's own
weights.

Now:

- Both sides are still normalised through `canonical_base` (the
`unsloth/*` mirrors), and the retired full copies
(`unsloth/flux-3-image-klein[-base]`) map to their upstream too.
- The compare is case-insensitive on the full id.
- Two Hub repo ids must name the same repo. A different owner with the
same repo name is refused, so the loader falls back to quantising the
fine-tune's own dense weights.
- A local path (`/models/Qwen-Image-2.1`, `C:\models\Qwen-Image-2.1`, or
a relative directory that exists) still uses the name compare as before.
`family_prequant_repo` depends on that for a local copy of the base, and
so does its test.

Every `base_model_id` value I could find in the hosted files was checked
against its official id, every case spelling, its declared mirror and
its retired copy. These are the ids in the `unsloth_metadata` header of
each root `.safetensors` in every `unsloth/*` repo Studio names, read
from the live Hub headers. All of them still match. The new test lists
them, along with every pair in `_ALL_MIRROR_PAIRS` and
`_RETIRED_FULL_COPIES`.

### 2. A failed upsample fold on the portable VAE path is not retried on
every decode

On the portable whole-map decode (no fused kernels: ROCm, MPS, CPU, or
CUDA when the kernels are not usable), a non-OOM failure with the
upsample fold engaged was re-raised to the tiles without marking the
decoder. Every later decode tried the fold again before it fell back.

Now `full_map_decode` marks the decoder (`_unsloth_vae_fold_failed`)
when a portable run fails while the fold is engaged. It then retries
that decode once with the fold off, and later decodes skip the fold.
This is the same pattern the kernels path already uses with
`_unsloth_vae_strips_failed`. Since #18995, that strips mark also turns
the fold off. Now both marks feed the same `fold` switch and every retry
runs with the fold off, so the decoder has one fold-off path, not two.
Other behaviour does not change:

- OOM still goes to the tiles, with no mark.
- A portable failure with the fold not engaged still raises to the
tiles.
- The kernels path still marks `_unsloth_vae_strips_failed` and retries
on the torch ops without the fold, as in #18995.
- ROCm still folds strip by strip (`_fold_full_max`) until the fold
fails on that decoder.

## Tests

- `tests/test_diffusion_prequant_same_base.py` (new, 85 cases): on main,
7 fail (the same-name fine-tune cases and the text encoder / fp8
training readers). With the fix, all 85 pass. The 78 positive cases pass
on both.
- `tests/test_diffusion_vae_fold_failure.py` (new, 3 cases): on main,
the fold-failure case fails because the decode raises and the fold is
tried on every call. With the fix, all 3 pass. The OOM case and the
failure-outside-the-fold case pass on both.
-
`tests/test_video_h3_te_quant.py::test_the_index_compare_has_no_tail_name_tolerance`:
its precondition asserted that `te_base_equivalent` accepts
`someone/MiniMax-H3`, which was the hole being closed. It now asserts
that the Hub fine-tune is refused and that a local path is still
tolerated.
- Wider runs on CPU:
- The 146 test files that touch the prequant / TE prequant / converted
single-file / fp8 training / prequant cache / native cache paths: 6834
passed, 268 skipped, 25 failed, 4 errors. Only the H3 test above
differed from main. The other 24 failures and 4 errors also fail on
main, with the same test IDs, so they predate this change on this host.
The ones inspected are host environment issues: the installed
huggingface_hub lacks `get_cached_repo_tree`, and diffusers 0.40 is
older than some families need.
- The 14 test files that touch the VAE strips / tiling / whole-map
decode: 3245 passed, 49 skipped, 2 xfailed, 4 failed. All 4 fail the
same way on main, for the same `get_cached_repo_tree` import reason.

## Not covered here

- No GPU run. The fold change was checked on CPU with a tiny
AutoencoderKL and an injected failure. A real ROCm or MPS fold failure
was not reproduced.
- The prequant cache key (`base_identity`) still uses the repo name, so
it is coarser than the new compare. Two bases share a key only when
their dense source bytes are also identical, so the cached weights are
the same either way. The key is left unchanged so existing local caches
stay valid.
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