Repository navigation
Studio diffusion training: recheck fixes for fp8 probe order, fp16 W8A8 preflight, atomic W8A8 conversion, int8 kernel in resume identity, torch 2.4 op - #18980
Merged
Conversation
The Auto resolver ran the fp8 probe (allocate, scaled GEMM, sync, and a failure warning) before the capability and compile checks, so an A100 or an eager run paid for it although the policy never picks fp8 there. Check sm89+ and the compile gate first; the picks are unchanged.
…sing torchao On an fp16-fallback card (T4) with UNSLOTH_DIFFUSION_INT8_TRAIN=w8a8 the trainer builds the W8A8 base with torch._int_mm and raises rather than falling back to torchao, but the start preflight still required a functional torchao for base_precision='int8' and refused the run. Skip that check on the fp16 W8A8 route; the bf16 route keeps it, since its fallback is torchao weight-only int8.
…ng in torchao int8 convert_frozen_int8 moves each host Linear to the device outside its per-layer handler, so an OOM on a later move escaped after earlier layers were already W8A8. The bf16 trainer then took the torchao weight-only fallback on the remaining nn.Linear layers and trained a mixed base that compile, the backward-weight cache and the checkpoint all treated as weight-only int8. Raise in that case; a failure before any layer converted still falls back as before.
…ght-only Both int8 bases record base_precision_effective='int8', so flipping UNSLOTH_DIFFUSION_INT8_TRAIN across a resume switched the frozen base between torchao weight-only and W8A8 math under the restored adapter and optimizer without a refusal. Record the int8 kernel in the checkpoint identity as an optional field: a switch is refused with a named reason, and bundles written before the field stay resumable.
diffusion_frozen_int8 used postponed annotations, so the custom op's signature reached torch.library.custom_op as 'torch.Tensor' strings. torch 2.4's schema inference rejects those; the registration error was swallowed and every backward took the inline column-major copy, with the cache never engaging. Drop the future import (the fp8 module already has none). On torch 2.4 the cache now records hits; gradients were and stay bit-identical.
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 |
|
Codex Review: Didn't find any major issues. Keep them coming! 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". |
danielhanchen
added a commit
that referenced
this pull request
Nov 23, 2026
… graph release and quantize OOM (#19011) ## Summary Follow-up fixes from a recheck of the merged Studio training and memory PRs #18967, #18978 and #18980. Each commit fixes one root cause and adds a test that fails on the merge base (`02bed8883e`) and passes here. #18964 and #18983 were rechecked as well and need no change. ## Changes 1. **DDP compares the converted layer set, not only the precision label** (#18967). `check_effective_precision` gathered one precision code per rank. The fp8 and W8A8 converters keep a layer that fails to convert in bf16 and still report success, so two ranks could both report `fp8` while training different frozen bases. In a real two-process Gloo run with one rank-local constructor failure, rank 0 converted 2 of 2 layers, rank 1 converted 1 of 2, and both passed. Each rank now also sends a digest and count of its sorted `(name, format)` set from `lowp_layers_digest`, and every rank refuses when they differ. A count alone would miss equal counts at different layers. Callers that pass no `layers` keep the old one-int64 exchange. 2. **An unreadable Windows ROCm card keeps the default memory budgets** (#18967). `rocm_windows_discrete()` negated `device_is_integrated()`, which answers False when the device property cannot be read. An APU whose classification failed therefore lost budgeted checkpointing and the dequant cache, like a known discrete Radeon. The new `device_integrated_status()` returns True, False or None (unknown), and only a positive discrete reading turns the budgets off. `device_is_integrated()` behaves as before. 3. **The env oversized override releases idle CUDA graphs like the request flag** (#18978). `graph_release_fits` cleared `allow_oversized` for its un-overridden check, but `image_activation_verdict` still read `UNSLOTH_DIFFUSION_ALLOW_OVERSIZED_GENERATE`. With the env override set, the release returned 0 without reading the pool, and the request took the oversized path even when dropping the graphs would have let it run normally. On the recorded L4 6-image case, `allow_oversized=True` released 3.3 GiB while the env override released 0. The check now ignores both overrides (`env_override=False`). 4. **Graph release credits only the pools this pipeline frees, on the card being checked** (#18978). The guard credited every live graph pool on the card and then reset only the image pipeline's handles. The whole-step pool is shared across the process. While a co-resident video pipeline still recorded into it, the reset freed nothing, and the image graphs were dropped for no gain. `releasable_pool_bytes(handles, device)` counts only whole-step pools that no other live wrapper records into, plus the block-graph pools these handles own, on the named card. A layer split's block card could also be refused because of its own idle block-graph pool, with no release, because only the primary card ran one. That card now drops the graphs and re-reads when their pool there closes the gap. `UNSLOTH_DIFFUSION_GUARD_RELEASE_GRAPHS=0` still turns both off. 5. **An OOM while quantizing a frozen layer is no longer counted as a kept layer** (#18980). `convert_frozen_int8` and `convert_frozen_fp8` caught `torch.cuda.OutOfMemoryError` (a `RuntimeError`) in their per-layer `except (RuntimeError, ValueError)`. An allocation failure inside the second layer's quantization therefore produced `[FrozenInt8Linear, Linear]` and `True`. That run recorded the same `base_int8_kernel='w8a8'` resume identity as a full conversion. The OOM now propagates. W8A8 refuses a partly converted base through the check #18980 added. fp8 had the same hole, and an exception escaping after some layers converted left them inside a base the caller recorded as bf16. The fp8 path now refuses a partial base the same way. The host-first nf4 reload (`Fp8FallbackDoesNotFit`) still runs first. Deliberate per-layer skips (alignment, a non-OOM error) are unchanged. ## Not changed - #18980: a T4 without torchao passes the W8A8 preflight, but `_resolve_base_precision` would refuse it. That function only runs on the bf16 route. The fp16 route (`fp16_amp`) sets `base_precision` directly and never calls it, so the preflight and the trainer agree. - #18980: torch 2.1 `is_autocast_enabled(device)` and torch 2.4 compiled-backward cache misses are both below the supported torch floor. The 2.4 case only affects performance, and its gradients are bit-identical. Torch 2.10 through 2.15 engage the cache. ## Testing - Flip tests: every new test fails on the merge base and passes here, and each arm imports its own tree. Behavioural probes that use no new symbols, base then head: - Two-rank Gloo, rank-local fp8 layer failure: both ranks accepted, then both ranks refused. - Unreadable Windows ROCm card: `rocm_windows_discrete()` was True (budgets off), now False. - Image reset with a video wrapper sharing the pool: 3 GiB credited, now 0. - Env oversized override, L4 6-image case: release was 0, now 3.3 GiB. - OOM inside the second W8A8 layer: returned True with a mixed base, now refused. - Changed test files on head (`test_diffusion_ddp_effective_precision`, `test_diffusion_gc_budget_rocm_windows`, `test_diffusion_guard_graph_release`, `test_diffusion_frozen_int8`, `test_diffusion_layer_split_lifecycle`): 85 passed. - 19 related training, graph and memory suites: base and head both 853 passed, 95 skipped, with the same 4 pre-existing failures (three `test_integrated_gpu_no_host_pin` source scans and `test_capture_then_replay_uses_one_graph_and_copies_statics`, which cannot import `torch_config_guard` in its subprocess). - `test_diffusion_dit_trainer`, `test_diffusion_training`, `test_rocm_windows_vram_7072` on head: 340 passed. ## Not covered - No GPU run. A real multi-GPU check (two cards, W8A8 or fp8 with one injected rank-local failure) should confirm that both ranks refuse before the first optimizer step and that a clean run trains. - A real CUDA OOM during conversion, co-resident image and video graphs on one card, and a layer split with block graphs on the second card were tested with mocks only. - The unreadable Windows ROCm property case was tested by mocking the property read. No Windows ROCm hardware was used.
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
Follow-up fixes from a recheck of the Studio diffusion LoRA training PRs #18770, #18782, #18825, #18860 and #18869 (frozen fp8 / int8 W8A8 bases, ROCm memory budgets, cached int8 backward weight, low-precision block swap). Each commit fixes one root cause and adds a test that fails on
mainand passes here. Findings already handled by #18967 (fp8 Auto host-RAM gate, measured-family fp8 band, row-major_scaled_mm, discrete Windows ROCm budgets off, DDP effective-precision check, block-swap re-plan after a failed conversion) are not repeated. This branch merges cleanly with #18967 and with currentmain.Changes
_resolve_base_precisionran_auto_fp8_probe_ok(allocate, scaled GEMM, sync, plus a failure warning on sm80) before the sm89 and compile checks. An A100 or an eager run paid for the probe even though the policy never picks fp8 there. The cheap gates now run first. Picks are unchanged.UNSLOTH_DIFFUSION_INT8_TRAIN=w8a8, the trainer builds the W8A8 base withtorch._int_mmand raises rather than falling back to torchao. The start preflight still required a functional torchao forbase_precision='int8'. The bf16 route keeps the check, because its fallback is torchao weight-only int8.convert_frozen_int8moves each host Linear to the device outside its per-layer handler. If a later move hit an OOM, the error escaped after earlier layers were already W8A8. The bf16 trainer then quantized the remainingnn.Linearlayers with torchao weight-only, giving a mixed base that compile, the backward-weight cache and the checkpoint all treated as weight-only int8. This case now raises a clear error. A failure before any layer converts still falls back as before.base_precision_effective='int8', so flippingUNSLOTH_DIFFUSION_INT8_TRAINacross a resume switched the base math under the restored adapter and optimizer with no refusal. The kernel is now stored as an optional identity field (base_int8_kernel), so a switch is refused with a named reason. Bundles written before the field still resume.from __future__ import annotations, so torch 2.4'scustom_opschema inference saw'torch.Tensor'strings and raised. The error was swallowed, and the cache never engaged. On torch 2.4 the base gives 0 cache hits and the head gives 1 hit and 1 miss over two backwards. Gradients are bit-identical either way.Testing
main(b0bc664) and passes on this branch. Each arm imported its own tree.test_diffusion_fp8_auto_stream,test_diffusion_frozen_int8,test_diffusion_frozen_int8_bwd_cache,test_diffusion_base_precision,test_diffusion_block_swap_lowp,test_diffusion_checkpoint_resume,test_diffusion_ddp,test_diffusion_dit_fp16_t4,test_diffusion_dit_trainer,test_diffusion_training: 583 passed, 10 skipped.huggingface_hub.get_cached_repo_tree/ diffusers pipeline imports).int8 op: False,hits 0; headint8 op: True,hits 1 misses 1.Not covered