Skip to content

Diffusion training: mxfp8 base precision (Blackwell) + SDXL U-Net regional compile - #6852

Merged
danielhanchen merged 41 commits into
image-generationfrom
diffusion-train-perf2
Jul 7, 2026
Merged

danielhanchen merged 41 commits into
image-generationfrom
diffusion-train-perf2

Conversation

@danielhanchen

Copy link
Copy Markdown
Member

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 after add_adapter exactly 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 skips lora_/proj_out plus any dim not divisible by the 32-wide MX blocks.

Measured (Z-Image dense, compiled, 1024px batch 4 = 16k tokens/step):

mode steady samples/s peak VRAM
bf16 + compile 3.94 19.36 GB
mxfp8 + compile 4.57 (1.16x) 19.38 GB

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: auto never picks it, and /info only 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).

SDXL 1024px batch 4 steady samples/s peak VRAM
compile off 6.68 8.92 GB
compile on 9.01 (1.35x) 8.92 GB

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_completed carries compiled for the UI. /info reports supports_compile: true for 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.

danielhanchen and others added 2 commits July 3, 2026 19:13
- 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.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

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.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

danielhanchen and others added 8 commits July 3, 2026 19:18
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).
# 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.
@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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"),

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge 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 👍 / 👎.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

danielhanchen and others added 3 commits July 4, 2026 03:23
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
@danielhanchen

Copy link
Copy Markdown
Member Author

/gemini review

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

danielhanchen and others added 6 commits July 4, 2026 07:27
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).
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Jul 6, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Jul 6, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Jul 6, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Jul 6, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Jul 6, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Jul 6, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Jul 6, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Jul 6, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Jul 6, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Jul 6, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Jul 6, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Jul 6, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Jul 6, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Jul 6, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Jul 6, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Jul 6, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Jul 6, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Jul 6, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Jul 6, 2026
@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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:

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge 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 👍 / 👎.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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":

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge 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 👍 / 👎.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge 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 👍 / 👎.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Jul 6, 2026
@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits.
Repo admins can enable using credits for code reviews in their settings.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. 🎉

Reviewed commit: 6384fea272

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

Base automatically changed from diffusion-krea2 to image-generation July 7, 2026 01:33
@danielhanchen
danielhanchen merged commit e1dd2dd into image-generation Jul 7, 2026
41 of 44 checks passed
@danielhanchen
danielhanchen deleted the diffusion-train-perf2 branch July 7, 2026 01:33
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