Skip to content

Studio image: read the hosted int8 ConvRot DiT as W8A8 on ROCm for an explicit int8 pick (FLUX.3 Klein, Qwen-Image-2.1) - #18951

Merged
danielhanchen merged 10 commits into
mainfrom
studio-rocm-hosted-int8-image
Nov 23, 2026
Merged

danielhanchen merged 10 commits into
mainfrom
studio-rocm-hosted-int8-image

Conversation

@danielhanchen

@danielhanchen danielhanchen commented Nov 22, 2026 •

Copy link
Copy Markdown
Member

Summary

On ROCm (gfx1151), an explicit int8 pick for FLUX.3 Klein or Qwen-Image-2.1 downloaded the dense bf16 transformer shards and quantised them at load into the native W8A8 ConvRot build. The family's hosted *-INT8-ConvRot.safetensors already holds that build: the same 228 / 224 layers, the same g256 rotation, per-row int8 codes and float32 scales. This PR reads the hosted file as native W8A8 Linears for that pick, the same way #18903 does for LTX-2.5 video. Generation speed and VRAM do not change. Warm loads take about half as long, the DiT download is about half the size, and host RSS is lower.

Root cause:

  1. The image planner returned early on any host without the torchao dense path (dense_transformer_supported), so ROCm never seeded a hosted denoiser and always kept the dense shards.
  2. The seed loader (denoiser_prequant_pipe_kwargs) only knew the torchao reader, which ROCm cannot use.
  3. The shared hosted reader (load_native_from_hosted) refused FLUX.3's file, which stores norm_q / norm_k as float32. A bf16 from_pretrained also keeps those in float32 (_keep_in_fp32_modules).

Changes

  • diffusion_rocm_hosted_int8.py (new): rocm_image_hosted_int8_reason() qualifies a load only when all of these hold:

    • the request is an explicit int8 pick;
    • the card is a ROCm RDNA card on the compiled int8 tier (rdna_explicit_int8_reason);
    • the family has a hosted int8 ConvRot file;
    • the family's runtime build would already be W8A8 (rdna_explicit_w8a8 or rdna_auto_w8a8, or UNSLOTH_NATIVE_INT8_ACT=1). The hosted file is W8A8 only;
    • the target card's own gfx arch, read by its ordinal through rocm_bf16._device_gfx_arch, is a measured arch (ROCM_IMAGE_HOSTED_INT8_ARCHS = {"gfx1151"}). The RDNA W8A8 kernels accept every gfx11xx / gfx12xx card, but only gfx1151 has speed and quality numbers, so gfx1100 / gfx1101 / gfx1201 and an unreadable arch keep quantising the dense shards at load. CUDA never asks for an arch.

    load_rocm_hosted_transformer() accepts only the ConvRot safetensors file and reads it through load_native_from_hosted. The planner's source probe, the download plan and the resolver share one ConvRot-only candidate list (rocm_convrot_source), so a mirror holding only the plain int8 file cannot make the plan pick one file and the load another.

  • diffusion.py:

    • On a host without the torchao path, _pipeline_planned_denoiser_scheme now asks _rocm_hosted_int8_seed instead of returning None. That helper applies the same gates as the load's compiled RDNA int8 tier (pipeline, no forced offload, a compiling speed tier, compile_eligible), takes hosted repo sources only, and requires a resident plan.
    • The loader asks those gates again before it keeps the seed. A compile probe recorded after planning drops the seed and restores the dense shards.
  • diffusion_denoiser_prequant.py: on such a host the seed goes through the native reader. A refusal returns {}, which already restores the dense shards and re-plans at bf16.

  • diffusion_native_hosted.py:

    • New keep_fp32 opt-in (image caller only) that allows float32 where the class keeps it, as the pickle reader already does. The video callers keep the strict bf16 rule.
    • New tag argument so the image log lines read diffusion.rocm_hosted_int8:. The default output is unchanged.
    • When the caller passes base, the reader now refuses a checkpoint whose header base_model_id is missing or names another base, even with UNSLOTH_PREQUANT_HEADER_PROBE=0. This also applies to the video reads (Studio video: read the hosted int8 ConvRot DiT as W8A8 on ROCm for an explicit int8 pick #18903 and Studio video: load explicit int8 LTX-2.5 on Windows ROCm from the hosted int8 DiT #18958 pass base = fam.base_repo for LTX-2.5). It does not change them for the official file, whose header carries Lightricks/LTX-2.5-Diffusers (a test checks LTX-2.5's own base against that value); a checkpoint baked for another base is now refused there too, which is the intended behaviour.
  • Kill switch UNSLOTH_ROCM_IMAGE_HOSTED_INT8=0 (checked before any host query); UNSLOTH_NATIVE_INT8_ACT=0 also keeps the old path.

  • Z-Image is not turned on. Its explicit int8 on RDNA is weight-only, and the hosted file is W8A8. Measured W8A8 is 11% faster but further from bf16 (LPIPS 0.018 to 0.023, against 0.012 for weight-only), so it stays weight-only. With UNSLOTH_NATIVE_INT8_ACT=1 it reads the hosted file (measured below).

  • MiniMax-H3-Image is untouched. Its family has no runtime ConvRot spec and supports_torch_compile=False, so it never reaches the compiled RDNA int8 tier.

  • Tests: tests/test_diffusion_rocm_hosted_int8.py (new, 56 cases) covers the gates, the measured-arch gate (gfx1151 / gfx1100 / gfx1101 / gfx1201 / unknown, read by the target ordinal), kill switches, Auto, CUDA, weight-only and unsupported families, local overrides, non-ConvRot files, the planner and the seed. tests/test_video_native_hosted.py gets cases for the float32 opt-in, the base check and LTX-2.5's official header.

CUDA is unchanged by construction. Every new branch sits behind not dense_transformer_supported(target) plus rdna_explicit_int8_reason, which requires a ROCm device. The video callers of the shared reader keep their float32 rule; the only change for them is the base check above.

Results (gfx1151, ROCm 7.13, torch 2.11, 1024x1024)

Base = merge base d480a0a, head = base + this patch, same runner and job, fresh process per cell, 4 cells per arm in ABBA order. FLUX.3 Klein ran 16 steps, Qwen-Image-2.1 12 steps, Z-Image Turbo 8 steps. LPIPS (alex) and PSNR are against the bf16 DiT image of the same run, scored on CPU.

family / arm s/image base / head VRAM over idle (GiB) b / h host RSS (GiB) b / h warm load s b / h LPIPS vs bf16 b / h PSNR vs bf16 (dB) b / h
FLUX.3 Klein bf16 DiT (reference) 23.79 / - 24.70 / - 16.6 / - 21.7 / - 0 inf
FLUX.3 Klein Auto 23.79 / 23.80 24.70 / 24.70 16.7 / 16.7 21.4 / 21.6 0 / 0 inf / inf
FLUX.3 Klein explicit int8 23.79 / 23.75 20.50 / 20.50 17.8 / 17.0 50.4 / 28.8 0.0013 / 0.0024 44.1 / 38.8
FLUX.3 Klein int8, kill switch 23.78 / 23.81 20.50 / 20.50 17.8 / 17.8 50.6 / 51.4 0.0012 / 0.0013 44.7 / 44.1
Qwen-Image-2.1 bf16 DiT (reference) 32.97 / - 34.88 / - 18.4 / - 29.5 / - 0 inf
Qwen-Image-2.1 Auto 31.79 / 31.78 28.43 / 28.45 19.8 / 19.8 59.0 / 58.8 0.0716 / 0.0716 27.5 / 27.5
Qwen-Image-2.1 explicit int8 31.77 / 31.75 28.43 / 28.44 19.8 / 18.5 59.5 / 33.5 0.0716 / 0.0033 27.5 / 42.6
Qwen-Image-2.1 int8, kill switch 31.77 / 31.78 28.43 / 28.44 19.8 / 19.8 59.8 / 58.2 0.0716 / 0.0716 27.5 / 27.5
Z-Image Turbo bf16 (reference) 19.38 / - 29.07 / - 20.4 / - 24.2 / - 0.004 (repeat spread) 41.5
Z-Image Turbo int8 (weight-only, unchanged) 19.96 / 19.85 23.53 / 23.54 19.4 / 19.2 37.5 / 38.0 0.012 / 0.012 36.0 / 36.2
Z-Image Turbo int8, UNSLOTH_NATIVE_INT8_ACT=1 17.80 / 17.64 23.56 / 23.56 18.9 / 16.6 57.1 / 29.5 0.018 / 0.023 33.9 / 33.0
  • Every head int8 cell logs the hosted read, for example diffusion.rocm_hosted_int8: read 228 int8 ConvRot layers of transformer from the hosted checkpoint as native Linears in 7.2 s. FLUX.3 also logs 228 native int8 Linears on the ROCm RDNA W8A8 kernels share one rotation + act quant per block, so the fused shared quant still engages. No head cell fell back.
  • Download for the int8 DiT: 6.44 GB for FLUX.3 instead of 11.10 GB of dense shards, and 7.26 GB for Qwen-Image-2.1 instead of 14.23 GB. The first head load per family fetched the file cold (86.8 s and 259.6 s); the warm loads are in the table.
  • Kill switch and Auto images are byte-identical to base on every cell:
    • Qwen-Image-2.1: kill switch and Auto all share the base explicit-int8 MD5.
    • FLUX.3 Auto keeps the bf16 MD5.
    • FLUX.3 explicit int8 alternates between the same two MD5s on base and kill-switch head (process-to-process nondeterminism present on base too).
    • Z-Image weight-only int8 shows the same two MD5s on both arms.
  • The hosted codes are not bit-identical to the codes quantised at load. FLUX.3 moves from 0.0013 to 0.0024 LPIPS against bf16, both negligible. Qwen-Image-2.1 moves much closer to bf16 (0.0716 to 0.0033).
  • Qwen-Image-2.1 Auto also builds the runtime W8A8 here (rdna_auto_w8a8) and would see the same quality gain from the hosted file. AUTO is left unchanged in this PR. One prompt per family was measured.

Not covered

  • Windows ROCm: the hosted source needs torchao's safetensors helpers, which the Windows ROCm torchao stub does not provide, so this route stays off there (the dense path runs as before). That exclusion comes from the source check, not an explicit platform gate.
  • Other RDNA cards (gfx1100 / gfx1101 / gfx1201): not measured, so the route is gated off there; widen ROCM_IMAGE_HOSTED_INT8_ARCHS per arch once a card is measured.
  • The large table above was measured on the first two commits. The final head was confirmed on gfx1151 in a second run, one cell per arm, base d480a0a vs head (the head is the code at c26b54d; the last commit only adds a test):
    • FLUX.3 Klein explicit int8 logs read 228 int8 ConvRot layers of transformer from the hosted checkpoint as native Linears in 8.4 s; Qwen-Image-2.1 logs read 224 ... in 6.8 s. No base cell reads the hosted file.
    • s/image base / head: FLUX.3 int8 23.31 / 23.25, Qwen-Image-2.1 int8 31.37 / 31.65.
    • Qwen-Image-2.1 kill switch and Auto: byte-identical to base (same MD5 as base explicit int8).
    • FLUX.3 kill switch: the head image has the MD5 of the base explicit int8 cell. Base itself alternates between two MD5s from process to process (its int8 and kill-switch cells differ while running the same code).
    • FLUX.3 Auto: same resolved route on both arms (transformer_quant off, same speed steps), 23.32 / 23.25 s/image. The images are not byte-identical in this single pair (PSNR 56 dB). Each process compiled the DiT locally (the cache bundles differ by a few KB), and the bf16 cells of the earlier run also showed an occasional outlier MD5.
  • CUDA was not rerun on hardware. It is covered by construction and the CPU tests.
  • Quality is one prompt and seed per family.

Test plan

  • python -m pytest tests/test_diffusion_rocm_hosted_int8.py tests/test_video_native_hosted.py (56 + 15 passed)
  • Related suites (test_diffusion_pipeline_prequant.py, test_video_hosted_int8_offload.py, test_diffusion_backend.py, test_video_backend.py and others): head and base fail the same test IDs (pre-existing), no new failures
  • The real hosted files for FLUX.3 Klein, Qwen-Image-2.1 and Z-Image read on CPU through the image reader: all accepted, every quantised layer W8A8 and rotated
  • gfx1151 hardware run, base vs head, 77 cells
  • gfx1151 final-head run: NO_REGRESSION, hosted read logged on both families, kill switch and Auto on the base route

… explicit int8 pick

On ROCm RDNA an explicit int8 pick for FLUX.3 Klein or Qwen-Image-2.1 fetched the dense
bf16 transformer shards and quantised them at load into the native W8A8 ConvRot build,
while the family's hosted int8 ConvRot file already holds exactly that build. The planner
now seeds that file on ROCm for an explicit int8 pick on the compiled RDNA tier and the
seed reads it as native W8A8 Linears. AUTO, CUDA and weight-only families keep their
routes. Kill switch UNSLOTH_ROCM_IMAGE_HOSTED_INT8=0.
… does

FLUX.3 Klein's hosted int8 ConvRot file stores norm_q / norm_k as float32, the
modules Flux3Transformer2DModel keeps in float32 under a bf16 from_pretrained, so the
reader refused it as a non-bf16 dense tensor. Allow float32 for the class's
_keep_in_fp32_modules, as the pickle reader already does. LTX-2.5 has no keep list.
Hosted repo sources only, the ConvRot safetensors build only, the load re-asks the
compiled RDNA int8 gates before it keeps the seed, and the float32 keep-list rule is
an opt-in the image caller takes (the video callers keep the strict bf16 rule).
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 22, 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-23T05:13:20.026744Z 31c2ffb 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

@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Nov 22, 2026
… base

A fine-tune with the family's shapes loaded the official ConvRot codes strict=True when
UNSLOTH_PREQUANT_HEADER_PROBE=0 skipped the planning header check. The native safetensors
reader now requires a matching base_model_id whenever the caller names a base, as the
pickle and torchao readers already do.
…n and load

A mirror holding only the plain INT8 file let planning skip the dense shards for the
ConvRot file while the loader's mirror-first resolver returned the plain file, refused
it, and restored the dense shards. rocm_convrot_source narrows the source to its
-ConvRot.safetensors names; the planner's header probe and the loader's resolver both
use it.

[skip ci]
@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

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

Reviewed commit: 94d1822fc3

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

…asured gfx1151

rocm_image_hosted_int8_reason now also needs the target card's own gfx arch,
read by its ordinal through rocm_bf16._device_gfx_arch, to be in
ROCM_IMAGE_HOSTED_INT8_ARCHS = {gfx1151}. The RDNA W8A8 kernels accept every
gfx11xx / gfx12xx card, but only gfx1151 was measured; gfx1100 / gfx1201 and
an unreadable arch keep quantising the dense shards at load. CUDA never asks
for an arch.
LTX-2.5's own base matches the base_model_id its official hosted int8 ConvRot
file carries, so the base check the shared reader now applies to every read
with a base leaves the video route unchanged; another base is refused.

[skip ci]
@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

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

Reviewed commit: 0df172a2ec

ℹ️ 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. Another round soon, please!

Reviewed commit: 31c2ffbcd3

ℹ️ 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 cac023e into main Nov 23, 2026
@danielhanchen
danielhanchen deleted the studio-rocm-hosted-int8-image branch November 23, 2026 07:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant