Repository navigation
Studio: pick DiT block swap from the training API and the Train tab - #18640
Conversation
Adds an optional block_swap field (off, auto or a block count) to the diffusion training start request. The start route refuses it before freeing GPU residents for families without the DiT trainer, non-bf16 bases, runs without gradient checkpointing, the fp16 fallback and hosts without a discrete CUDA or ROCm GPU. Unset keeps today's behaviour. Families report supports_block_swap, the Train tab shows a Block swap control for them on bf16, and the trainer reports what the swap resolved to (blocks swapped, pinned GiB) in the training status.
|
@codex review |
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. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: ddc28aeba7
ℹ️ 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".
| "'auto' swaps as few as fit, a number swaps that many, 'off' or 0 none. Needs gradient " | ||
| "checkpointing and a discrete CUDA / ROCm GPU. null keeps the server default (UNSLOTH_DIT_BLOCK_SWAP)." |
There was a problem hiding this comment.
Honor explicit off values instead of inheriting the environment
When the server has UNSLOTH_DIT_BLOCK_SWAP=auto or a positive count, requesting block_swap="off" or 0 does not disable swapping as this API contract promises. The route forwards these as strings, but block_swap_request() treats both as reasons to fall back to the environment, while block_swap_start_error() skips validation for them. Consequently, an explicitly disabled request can still incur block-swapping overhead or fail in the trainer when using nf4 or disabled gradient checkpointing. Preserve the distinction between an omitted value (inherit the server default) and an explicit off value through the trainer's request resolution.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in 8998c0b and 529a3cf7b. The config default is now "" (unset), which still takes UNSLOTH_DIT_BLOCK_SWAP, while an explicit "off" or 0 is off even when the env asks for a swap. An explicit off also skips auto's int8-band bf16 + swap, so a request that says off never swaps. The API keeps omitting the field when it is null, so an omitted block_swap still inherits the server default. Tests cover "off", "0" and 0 against UNSLOTH_DIT_BLOCK_SWAP=auto through _config_from_dict (the start route's path), and the unset cases.
|
@codex review |
|
Codex Review: Didn't find any major issues. Another round soon, please! 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". |
#18604 added a block swap for DiT LoRA training (
cfg.block_swap/UNSLOTH_DIT_BLOCK_SWAP= off, auto or a block count). It could only be turned on through the trainer config dict or the env var. The training API dropped the field, becauseDiffusionTrainingStartRequestdid not declare it, and the Train tab had no control for it. This PR lets you pick it from both.Change
Backend:
DiffusionTrainingStartRequest.block_swap: optional,"off","auto"or an integer 0..1024. The default is unset, which sends nothing to the trainer, so behaviour is the same as today, andUNSLOTH_DIT_BLOCK_SWAPstill applies. A count is passed on in the trainer's string form./api/train/diffusion/startnow callsblock_swap_start_error, which runs before any GPU residents are freed. It refuses a block swap the trainer would only refuse after loading the base, plus families whose trainer has no swap path:base_precisionother thanbf16gradient_checkpointingoffoffand0are accepted for every family. Only the request field is checked here, not the env var.family_train_infosreportssupports_block_swap, which is true for DiT families that listbf16and are not on the fp16 fallback.block_swapevent right after the swap is installed. The fields areswapped_blocks,total_blocks,host_gibandpinned_gib. The training service folds it into a newblock_swapfield on/api/train/diffusion/status. Before this, the only trace was a warning message that the first progress event overwrote.Frontend (Images > Train):
supports_block_swapoffloadHardwareSupported, reused fromfeatures/training/api/mappers.ts)Tests
studio/backend/tests/test_diffusion_block_swap_api.py(18, CPU) covers:autoand a count through the real route to the service, and that the forwarded value parses back in the traineroffis accepted for SDXLtest_differential.pyagainst b57c06f: DISCRIMINATING, 3 FIXED + 15 NEW_API, head_fail 0.test_diffusion_training.py,test_diffusion_block_swap.py,test_diffusion_base_precision.py,test_diffusion_dit_trainer.py, checkpoint resume, samples, LTX-2): all pass.studio/frontend/tests/diffusion-train-block-swap.test.tscovers when the control shows, the payload, the status line and the panel wiring. The fullnpm testpasses (16915 tests, 0 failures), and so doesnpm run build.GPU check (Colab L4, 22.5 GiB, standing in for a 24 GB card)
Wan2.2-TI2V-5B, bf16 base, 512 px, rank 16, 50 steps, seed 0. Each arm ran in a fresh process, interleaved off / N / auto / N / off, plus one more repeat of each. The request went through
DiffusionTrainingStartRequestand the route preflight, using the host's real GPU facts. The status came from the service's event fold.block_swap)block_swapoffauto10Notes on the results:
autoswaps nothing and runs at the same speed as off, and the status says so.Resume with the same
block_swap=10: one process stopped and saved at step 25 (checkpoint-25). A new process resumed from that output dir to 50. The resumed run reportedresumedat step 25, picked up the same swap (10 of 30 blocks), and trained steps 26 to 50. Its loss over steps 26 to 50 differs from the three uninterrupted10runs by a mean absolute 0.00028-0.00046 per step. The uninterrupted runs differ from each other by 0.00041-0.00055 on the same steps, so the resumed curve is inside run-to-run noise. Mean loss over steps 26 to 50: 0.2375 for the resumed run, 0.2375 for the uninterrupted one.Wan renders no previews (video families refuse
sample_every), so the preview leg used FLUX.2-klein-base-4B with bf16 andblock_swap=8. Status showed 8 of 25 blocks with 2.29 GiB pinned, at 0.83 s/step with a 6.6 GiB peak. The samples rendered at steps 0, 10 and 20 while the swap was on.Not proven here
/api/systemand the family listing rewritten in the browser to a 24 GB CUDA card. The rewrite was the same on both sides.UI
Train tab, FLUX.1 with a bf16 base. Before (main) and after (this branch): the Block swap select and, for a fixed count, Blocks to swap.
The running job's status line after the base loads (the job is faked with the FLUX.1-dev numbers from #18604: 21 of 57 blocks, 8.1 GiB pinned).