Repository navigation
Studio video: load explicit int8 LTX-2.5 on Windows ROCm from the hosted int8 DiT - #18958
Merged
Merged
Conversation
…ted int8 DiT The hosted int8 ConvRot read added for ROCm RDNA was committed through a torchao source check the Windows ROCm torchao stub always fails, and the unified-memory guard priced the load at the dense bf16 DiT even when the hosted int8 file replaces it. Accept the hosted safetensors file for the native read without torchao, price that read at the file size, and re-plan at the dense size (guard included) if the read does not happen. Kill switch UNSLOTH_VIDEO_HOSTED_INT8_FIT=0.
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. |
Member
Author
|
@codex review |
Member
Author
|
@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". |
This was referenced Nov 23, 2026
danielhanchen
added a commit
that referenced
this pull request
Nov 23, 2026
…ache reads, OOM tile probe, ConvRot-only hosted int8 video (#18982) ## Summary Four fixes found while re-checking recent Studio image and video load changes, one commit each, plus one test-compat fix. 1. **klein 9B KV identity (follow-up to #18831).** `_resolve_base_repo` swaps the KV base (`black-forest-labs/FLUX.2-klein-9b-kv`) for the stock 9B it borrows its text encoder, VAE and scheduler from. The queued load then wrote that 9B back into `base_repo` before `load_pipeline` picked the pipeline class, and a base taken from the model card never reached it at all. A KV GGUF or single file with a generic name (no "KV" in the repo or file name) ran through the stock `Flux2KleinPipeline`, advertised inpaint / outpaint, and passed the guard that keeps the base's dense transformer from replacing the KV DiT. `_resolve_base_repo` now records the base the caller or the card named (`_checkpoint_base_of`), the queued load passes it to `load_pipeline` as `_checkpoint_base`, and the pipeline class, that guard, the dense prefetch widening and the load state read it. Companion fetches still use the stock 9B. 2. **FLUX.3 cache-only reads pin the validated commit (follow-up to #18837).** `current_snapshot` returns the commit it validated, but the loader only kept a bool. Every cache-only read then resolved `refs/main` again. If another download moved that ref in between, the load read files from a snapshot nobody had validated. The commit is now passed as `revision` to every cache-only read (index, processor, text encoder, transformer, VAE, stored-dtype probes). A read that falls back to the Hub is unpinned, as before. 3. **CUTLASS tile probe and the async allocator (follow-up to #18837).** A failure persists only when it repeats and `num_ooms` did not move. Under `PYTORCH_CUDA_ALLOC_CONF=backend:cudaMallocAsync` that count stays 0, because the async allocator fills none of the native allocator's stats (`CUDAMallocAsyncAllocator.cpp`, `getDeviceStats`). A probe on a full card therefore persisted an empty tile list, and every later process on that card skipped the CUTLASS int8 tiles. `_probe_tile` now counts its own out-of-memory failures, and a probe that hit one does not persist. Editing the module also invalidates the verdicts already stored. 4. **Torchao-free hosted int8 commit takes only the ConvRot file (follow-up to #18958).** With no usable torchao (the Windows ROCm stub), the check that drops the dense LTX-2.5 DiT shards accepted any hosted `.safetensors` name. The native read only accepts the ConvRot file. So with `UNSLOTH_DIFFUSION_INT8_CONVROT=0` (which resolves the unrotated `LTX-2.5-INT8.safetensors`), or with a listing that has no ConvRot file, the load staged 25 GB and the reader then refused it. Now only the `-ConvRot.safetensors` file counts. With ConvRot off, the ROCm hosted int8 route (plan, price, commit) does not apply, so the load uses the dense shards and runtime build as before. This matches the ConvRot gate the image route already has. 5. **Tests.** The FLUX.3 warm-load fixture patched `diffusers.Flux3Transformer2DModel.from_pretrained`, so its four loader tests failed with `AttributeError` on a diffusers that meets the declared floor (>= 0.39) but predates the FLUX.3 classes. A missing class now gets a stand-in. ## Tests New tests fail on the merge base and pass on this branch (base arm = the merge base with the new test files copied in): | file | new tests | base | head | |---|---|---|---| | `test_diffusion_flux2_klein_kv.py` | card-only and explicit KV identity, queued load hands `load_pipeline` the KV identity, `load_pipeline` wiring | 4 failed | pass | | `test_diffusion_hub_snapshot.py` | cache-only reads pin the validated commit, Hub fallback stays unpinned, real `hf_hub_download` cache read after `refs/main` moves | 2 failed (4 more fail on the old fixture with diffusers 0.40) | pass | | `test_diffusion_int8_cutlass_probe_persist.py` | an OOM the allocator stats never count is not persisted | 1 failed (persisted `ok: []`) | pass | | `test_video_hosted_int8_fit.py` | unrotated file never committed without torchao, ConvRot file beside it still committed, ConvRot off takes the hosted route off | 3 failed | pass | Related suites (klein KV, FLUX.3 loader / storage / manual cast, hub snapshot, CUTLASS, gated base, compat preflight, video hosted int8 / native hosted / families, refactor guard): 1676 passed. The 8 failures are the same 8 test IDs on the merge base: 5 MiniMax H3 download-plan tests and 2 FLUX.3 retired-copy tests from a `huggingface_hub` without `get_cached_repo_tree` / diffusers 0.40, and 1 causal-mask patch test. ## Not covered - No GPU run. The async-allocator OOM path is shown by injecting `OutOfMemoryError` with `num_ooms` fixed at 0, which is what the upstream allocator source reports. It was not run on a real card with `backend:cudaMallocAsync`. - No Windows ROCm run of the ConvRot gate. The check is CPU-only, using the existing torchao-stub fixture. - The native sd.cpp engine takes its base from the request alone, so a card-only KV identity does not reach its reference-edit refusal. That is not changed here.
danielhanchen
added a commit
that referenced
this pull request
Nov 23, 2026
… explicit int8 pick (FLUX.3 Klein, Qwen-Image-2.1) (#18951) ## 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 (#18903 and #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 - [x] `python -m pytest tests/test_diffusion_rocm_hosted_int8.py tests/test_video_native_hosted.py` (56 + 15 passed) - [x] 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 - [x] 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 - [x] gfx1151 hardware run, base vs head, 77 cells - [x] gfx1151 final-head run: NO_REGRESSION, hosted read logged on both families, kill switch and Auto on the base route
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
On Windows ROCm (gfx1151, Strix Halo), an explicit int8 pick for LTX-2.5 cannot load at all. Studio refuses it at the unified-memory guard:
#18903 added a route that reads the hosted
LTX-2.5-INT8-ConvRot.safetensorsDiT (25.11 GB) as native W8A8 Linears on ROCm RDNA, instead of loading the dense bf16 shards and quantising them at load. On Windows that route never engages, and the guard would refuse it even if it did.Root cause (two independent gaps, both on the explicit int8 hosted read path):
VideoBackend._denoiser_prequant_verified) asksrestricted_prequant_load_supported(), which needs the torchao pickle allowlist. On Windows ROCm torchao is a stub, so_register_prequant_safe_globals()always answers False and the check refuses. The native read itself (load_native_from_hosted) reads the safetensors file withsafetensorsand builds native Linears; it never touches torchao.components[0] * dtype_scale) unless a torchao seed is planned. The hosted native read is not a torchao seed, so it was priced at 42 GB of bf16 DiT instead of the 25.11 GB file it actually reads. On a unified-memory APU that sends every explicit int8 LTX-2.5 load to the refusal.Changes
All in
studio/backend/core/inference/video.py:_denoiser_prequant_verified(..., native_hosted=True)(only the commit of the native hosted read passes it): when torchao cannot deserialize a checkpoint but the family's hosted int8 file is ConvRot safetensors (not a torchao pickle), the check accepts it and only counts.safetensorsnames._denoiser_prequant_hub_filesand_denoiser_prequant_cached_repotake an optionalreadablefilter for that; without it they behave exactly as before. A torchao seed still needs torchao._video_hosted_read_dit_gb(): when an explicit int8 ROCm RDNA load has the hosted int8 file staged in place of the dense shards (the same_video_rocm_hosted_schemegate the read uses), the plan prices the DiT at the family's hosted file size (prequant_resident_gb_by_scheme, 25.11 GB for LTX-2.5). The existing companion, worker and overhead margins are unchanged.UNSLOTH_VIDEO_HOSTED_INT8_FIT=0restores the previous behaviour (torchao-gated source check, dense price). The existingUNSLOTH_ROCM_VIDEO_HOSTED_INT8=0andUNSLOTH_NATIVE_INT8_ACT=0switches still turn the whole hosted read off.Not changed: the guard itself (
diffusion_memory.py), Auto (never takes the hosted read on ROCm), dense loads, CUDA (the pricing requires the ROCm RDNA explicit int8 gate), pickle families such as Wan2.2 A14B, and the image loaders.Tests
tests/test_video_hosted_int8_fit.py(new, CPU): the torchao-free source check (stubbed torchao commits the ConvRot safetensors file; a pickle-only repo, a torchao seed and the kill switch still refuse; a real torchao keeps the old filter), the pricing gate (ROCm explicit int8 with the hosted file planned prices 25.11 GB; Auto, off, fp8, GGUF, Wan A14B, CUDA, stored-precision checkpoints and every kill switch keep the dense price), the dense re-guard wiring, and the guard arithmetic on the failing host (80 GB total / 77 GB free reproduces "needs about 73 GB ... only about 61 GB usable"; the hosted DiT plan fits).Related CPU suites, head:
test_video_hosted_int8_fit.py,test_video_rocm_hosted_int8.py,test_diffusion_flux3_rdna_shared_quant.py,test_diffusion_rocm_tag_detect.py,test_video_hosted_int8_offload.py,test_video_native_hosted.py,test_video_offline_load.py,test_video_ltx25_prequant.py,test_video_prequant.py,test_video_prequant_safetensors_twins.py,test_video_backend.py,test_diffusion_unified_load_override.py,test_diffusion_memory_rocm_apu_reserve.py: 908 passed, 19 skipped.gfx1151 Windows results
Windows 11 gfx1151 (Radeon 8060S, torch 2.11.0+rocm7.14.0, HIP 7.14), Studio installed with the head tree's Windows installer, base = merge base 22f1d70, head = base + this patch, same job and runner, LTX-2.5 512x320x17, 8 steps, one clip per arm. Studio downloads what it loads, no HF token on the runner.
UNSLOTH_VIDEO_HOSTED_INT8_FIT=0off)Head explicit int8 log:
Not covered