Repository navigation
Diffusion training: mxfp8 base precision (Blackwell) + SDXL U-Net regional compile - #6852
Conversation
- base_precision="mxfp8": torchao MX block-scaled float8 compute on the frozen base linears (Blackwell sm100+, cuBLAS kernels). Applied after add_adapter like fp8, never fatal, weights stay bf16 in memory. Measured 1.16x over compiled bf16 on Z-Image at 1024px batch 4 (16k tokens/step); a wash at small token counts, so it stays an explicit opt-in and auto never picks it. - SDXL: regionally compile the U-Net's BasicTransformerBlocks through the same never-fatal wrapper the DiT trainer uses. 1.35x steady state at 1024px batch 4 with same-seed loss parity (~1e-5 per step) and unchanged peak VRAM; ~30 s one-time warmup. Steady-state samples/sec now excludes step 1, matching the DiT trainer. - /info: mxfp8 advertised only on sm100+; supports_compile now true for sdxl. - NVFP4 training: not available in torchao 0.16 (no autograd path, no training recipe), so NVFP4 stays an inference-only quant for now. 193 diffusion backend tests green; frontend build clean.
There was a problem hiding this comment.
Code Review
This pull request adds support for the mxfp8 (Blackwell-native block-scaled float8) base precision mode for DiT training, including GPU capability checks, module filtering, and fallback mechanisms. It also extends regional torch.compile support to SDXL's U-Net transformer blocks and updates the frontend to accommodate these options. The review feedback correctly identifies a UI bug where the compile control is nested inside an isDiT check, preventing it from being rendered for SDXL even though supportsCompile is enabled.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
| // Whether to show the torch.compile control. The backend advertises this per family | ||
| // (the SDXL U-Net path compiles regionally too now); default on for DiT families when | ||
| // an older backend does not report it. | ||
| const supportsCompile = reportedFamily?.supports_compile ?? isDiT; |
There was a problem hiding this comment.
While supportsCompile is correctly updated to allow compilation for SDXL (by falling back to isDiT but preferring reportedFamily?.supports_compile), the actual rendering of the Compile transformer control in trainingSettings (around line 814) is nested inside the isDiT conditional block. As a result, the compile control will never be displayed for SDXL in the UI.
To fix this, the Compile transformer control should be moved outside of the isDiT conditional block so that it renders for any family where supportsCompile is true.
There was a problem hiding this comment.
Fixed in 2a5e957 on this PR: the compile control moved out of the DiT-only branch and renders for any family whose /info reports supports_compile. Verified live with Playwright: mxfp8 listed for DiT families on sm100, the compile select present for SDXL, and the DiT precision selector still hidden for SDXL.
There was a problem hiding this comment.
The compile control is not nested inside the DiT-only block on this branch: it is gated solely on {supportsCompile && ( (the mixed-precision select above it is the one gated on isDiT). SDXL advertises supports_compile: true via /info and the control renders for it, verified in the Playwright pass on the live build. Leaving as is.
The compile select was nested inside the DiT-only branch of the precision area, so supports_compile=true for sdxl never rendered it. Lift it out of the ternary: the precision selects stay family-specific, the compile control follows supports_compile. Verified with a live Playwright pass (mxfp8 listed for DiT families on sm100, compile select present for SDXL, DiT precision selector still hidden for SDXL).
…usion-train-perf2
# Conflicts: # studio/backend/core/training/diffusion_dit_trainer.py # studio/backend/core/training/diffusion_train_common.py # studio/frontend/src/features/images/train/diffusion-train-panel.tsx
The SDXL trainer now regionally compiles its transformer blocks, so /info advertises supports_compile for every family; the precision selector stays DiT-only.
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 94b076226b
ℹ️ 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".
|
|
||
| quantize_( | ||
| transformer, | ||
| MXLinearConfig.from_recipe_name("mxfp8_cublas"), |
There was a problem hiding this comment.
Use the MXFP8 API available in torchao 0.17
On Studio installs with torch 2.11/2.12, the installer selects torchao 0.17, whose torchao.prototype.mx_formats no longer exports MXLinearConfig. Because this call is inside the broad fallback, selecting base_precision="mxfp8" on a Blackwell GPU only emits a warning and trains dense bf16, so the advertised mxfp8 mode never actually engages for those supported installs.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in 5ea8eb9: mxfp8_training_config tries the torchao 0.16 MXLinearConfig recipe first and falls back to the 0.17 MXFP8TrainingOpConfig.from_recipe API; both feed quantize, and mxfp8 still degrades to bf16 with a warning when neither import resolves.
torchao 0.17 removed MXLinearConfig from prototype.mx_formats in favour of MXFP8TrainingOpConfig.from_recipe shared with MoE training. _mxfp8_training_config tries the 0.16 API first and falls back to the 0.17 one; both feed quantize_. mxfp8 still degrades to bf16 with a warning when neither import resolves
# Conflicts: # studio/backend/core/training/diffusion_train_common.py # studio/backend/tests/test_diffusion_dit_trainer.py # studio/backend/tests/test_diffusion_training.py
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request introduces support for mxfp8 (block-scaled float8 compute) base precision for DiT training on Blackwell GPUs (sm100+), leveraging torchao. Additionally, it extends regional torch.compile support to the SDXL U-Net's transformer blocks, refactors step-rate reporting to exclude step 1 warmup costs, and updates the frontend UI to expose these new capabilities. There are no review comments to address, so I have no feedback to provide.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
… device pin, sigma-gather skip)
train_precision_modes gates int8/fp8/mxfp8 on has_functional_torchao, and the Backend CI runner does not install torchao, so the three capability-gating tests collapsed to nf4/bf16/auto and failed. They exercise the CAPABILITY gate, not torchao presence: stub the probe functional alongside the CUDA capability patch. Validated with a torchao-blocked run (22 passed).
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: d6ce610324
ℹ️ 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".
| return False | ||
| if "lora_" in fqn: | ||
| return False | ||
| if fqn.endswith("proj_out") or ".proj_out." in fqn: |
There was a problem hiding this comment.
Skip root-level proj_out base layers
When a run explicitly includes proj_out in lora_target_modules, PEFT keeps the frozen linear under a root-level name like proj_out.base_layer. That fqn does not end with proj_out and does not contain .proj_out., so it falls through to the shape check and gets converted to mxfp8 even though this guard is meant to exclude the output projection. Include the root-level proj_out. case to keep custom target lists from quantizing the projection the mode says it skips.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
This needs a non-default config to reach and only causes a subtle single-layer precision change, so it is below the strict correctness bar. A root-level proj_out is only LoRA-wrapped when an explicit custom lora_target_modules includes it (no family default does), and it also needs an explicit fp8/mxfp8 opt-in; the effect is the frozen output projection running fp8/mxfp8 instead of bf16 for one layer, and the run completes with no crash or wrong-shaped output. Leaving the guard as is.
| mode = (cfg.base_precision or "nf4").strip().lower() | ||
| if mode != "auto": | ||
| if mode in ("bf16", "int8", "fp8") and device != "cuda": | ||
| if mode in ("bf16", "int8", "fp8", "mxfp8") and device != "cuda": |
There was a problem hiding this comment.
Gate explicit mxfp8 to Blackwell CUDA
For a CUDA device that is not Blackwell (for example sm89/sm90), an explicit base_precision="mxfp8" passes this check because only CPU is rejected. The selected mxfp8_cublas / MXFP8_RCEIL kernels are Blackwell-only; torchao conversion can succeed and then fail at the first MX GEMM outside the fallback wrapper, crashing the run instead of fast-failing or falling back. Mirror the /info sm100 gate for explicit requests here.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed. _resolve_base_precision now rejects an explicit mxfp8 request below Blackwell (sm100). It re-checked explicit modes against the device but only rejected CPU, so mxfp8 on an sm89/sm90 CUDA GPU passed and then crashed at the first MX GEMM after a full dense load. This mirrors the sm100 gate train_precision_modes already applies to /info.
| MXFP8TrainingOpConfig, | ||
| MXFP8TrainingRecipe, | ||
| ) | ||
| return MXFP8TrainingOpConfig.from_recipe(MXFP8TrainingRecipe.MXFP8_RCEIL) |
There was a problem hiding this comment.
Preserve biases on the torchao 0.17 MX path
On torchao 0.17 this fallback uses MXFP8TrainingOpConfig, whose registered linear override performs the MX matmul but does not add the bias argument. Because _mx_module_filter accepts biased nn.Linears, any selected frozen projection/MLP with a bias loses that bias whenever mxfp8 runs on the 0.17 API, changing the base model output during LoRA training. Skip biased linears on this path or use a conversion that preserves the bias term.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed. _mx_module_filter now skips biased linears. The torchao 0.17 MX training path swaps a matched frozen Linear weight for a wrapper tensor whose linear override computes input @ weight_t and drops the bias, so mxfp8-ing a biased FROZEN linear silently lost its bias and changed the base output the LoRA regresses against (I reproduced the full bias drop on Blackwell). Biased linears now stay bf16.
…kwell - The torchao 0.17 MX training path swaps a matched frozen Linear's weight for a wrapper tensor whose linear override computes input @ weight_t and drops the bias, so mxfp8'ing a biased frozen linear silently loses its bias and corrupts the base output the LoRA regresses against (verified on Blackwell: the bias term is fully dropped). Skip biased linears in _mx_module_filter. - _resolve_base_precision re-checked explicit dense modes against the live device but only rejected CPU, so an explicit mxfp8 request on a non-Blackwell CUDA GPU passed and then crashed at the first MX GEMM after a full dense-transformer load. /info only advertises mxfp8 on sm100+; mirror that gate here and fail fast for a stale or direct client below Blackwell.
|
@codex review |
|
Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits. |
|
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". |
Stacked on #6843 (base:
diffusion-krea2). Two training-speed additions, both measured on B200 with 40-step LoRA runs at 1024px, batch 4.mxfp8 base precision (DiT families)
New
base_precision="mxfp8": the frozen base linears switch to torchao MX block-scaled float8 training compute (MXLinearConfig.from_recipe_name("mxfp8_cublas")), applied afteradd_adapterexactly like the fp8 mode so the LoRA modules stay high precision. Weights stay bf16 in memory (it is a speed mode, not a memory mode), the swap is never fatal (any failure falls back to bf16 with a warning event), and the filter skipslora_/proj_outplus any dim not divisible by the 32-wide MX blocks.Measured (Z-Image dense, compiled, 1024px batch 4 = 16k tokens/step):
Microbench (fwd+bwd through DiT-shaped LoRA linears, compiled): 0.99x at 4k tokens, 1.14x at 16k, 1.16x at 64k. mxfp8 only pays off at high resolution or batch, so it stays an explicit opt-in:
autonever picks it, and/infoonly advertises it on sm100+ (Blackwell), where its cuBLAS kernels exist. Same-seed loss curves track bf16 step for step with the expected small float8 forward noise; no divergence, no NaN.Also documented: NVFP4 training is not possible on torchao 0.16 (no autograd path, no training recipe), so NVFP4 remains inference-only.
SDXL U-Net regional compile
The SDXL trainer now compiles the U-Net's repeated
BasicTransformerBlocks through the same never-fatal wrapper the DiT trainer uses (cfg.compile_transformer, default auto = on for this dense bf16 path, eager fallback with a warning event on any failure).Same-seed losses match to ~1e-5 at every step; the one-time warmup is ~30 s. The SDXL progress rate now excludes step 1 (compile/cudnn warmup) like the DiT trainer, and
model_load_completedcarriescompiledfor the UI./inforeportssupports_compile: truefor sdxl so the Train tab shows the compile control there too.Tests
15 new unit tests (mxfp8 validation incl. prequant/fp16 rejection, the MX module filter, compile policy, sm89/sm100/sm120 capability gating, sdxl
/info, request-model Literal): 193 diffusion backend tests green on diffusers 0.39; frontend build clean.