Skip to content

Studio SDXL LoRA training: route the VAE's attention on ROCm before encoding latents - #18560

Merged
danielhanchen merged 1 commit into
mainfrom
fix-sdxl-train-rocm-vae-attention
Nov 20, 2026
Merged

danielhanchen merged 1 commit into
mainfrom
fix-sdxl-train-rocm-vae-attention

Conversation

@danielhanchen

@danielhanchen danielhanchen commented Nov 20, 2026 •

Copy link
Copy Markdown
Member

#17953 fixed wrong training latents on Windows ROCm: the VAE's single-head attention (head dim 512) went through fused SDPA kernels that return garbage at that width. The fix routed the VAE's attention through the exact path inference uses (diffusion_vae_attn_chunked.install), but only in the DiT trainer. The SDXL LoRA trainer runs in its own training process, never installs the wide-head guard, and encodes every training latent through pipe.vae, so SDXL LoRA training on Windows ROCm still encoded its latents through the broken kernels.

Change

The SDXL trainer calls the same install(vae) right after the VAE moves to its card, before any latent is encoded. install acts only on ROCm torch (CUDA, MPS and CPU builds return without patching), so nothing changes off ROCm. On ROCm Linux, the VAE takes the same routed path the DiT trainers and inference already use.

Tests

test_the_sdxl_trainer_routes_its_vae_attention_before_encoding_latents runs a real 1-step SDXL LoRA training on the tiny SDXL pipeline with a ROCm torch reported. It checks that the pipeline's AutoencoderKL is patched and that every encoder forward runs after the patch. It fails on main (nothing patched) and passes here. tests/test_diffusion_lora_trainer.py and the SDXL cases in tests/test_diffusion_gc_budget_trainers.py: 62 passed.

On Windows gfx1151 (Strix Halo, torch 2.11.0+rocm7.14.0)

The SDXL trainer itself (1 step, tiny SDXL pipeline with the real SDXL VAE swapped in, 256 px): the first training latents it encodes, against a CPU fp32 encode of the same pixels.

tree VAE attention routed relative L2 max abs
main no 0.120 10.8
this PR yes (2 modules) 7.8e-6 0.0011

On Linux gfx1151 (torch 2.11.0+rocm7.13.0), where the fused kernels are correct at this width, main and this PR give the same latents (relative L2 6.7e-6 against the CPU encode on both, the routed path on this PR).

@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 20, 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-20T04:14:14.141749Z 017055c 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

@chatgpt-codex-connector

Copy link
Copy Markdown

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

Reviewed commit: 017055c275

ℹ️ 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 5f386ab into main Nov 20, 2026
@danielhanchen
danielhanchen deleted the fix-sdxl-train-rocm-vae-attention branch November 20, 2026 05:29
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