Skip to content

Studio: random flip opt-in, plus checkpoint retention, caption dropout, LoRA dropout and timestep shift on the image Train tab - #13210

Merged
danielhanchen merged 6 commits into
mainfrom
studio-diffusion-flip-opt-in
Oct 13, 2026
Merged

danielhanchen merged 6 commits into
mainfrom
studio-diffusion-flip-opt-in

Conversation

@danielhanchen

@danielhanchen danielhanchen commented Oct 10, 2026 •

Copy link
Copy Markdown
Member

Refs #10590 (every setting from that request: random flip, checkpoint retention, caption dropout, LoRA dropout and timestep shift)

Image LoRA training in Studio mirrored about half of every training image left-right by default, and the Train tab had no way to turn it off. That teaches the model both orientations of anything one-sided: text and logos come out mirrored, and a character's side parting, scar or tattoo lands on either side.

The default came from the diffusers SDXL example commands, which pass --random_flip. In the script itself the flag is opt-in, and it is off by default in every other trainer:

Trainer Random flip default
diffusers example scripts off (--random_flip, opt-in)
kohya sd-scripts / kohya_ss GUI off (flip_aug)
ostris/ai-toolkit off (flip_x)
OneTrainer off (enable_random_flip)
SD-Trainer (lora-scripts) off
ComfyUI-FluxTrainer off
SimpleTuner, musubi-tuner, diffusion-pipe, DiffSynth-Studio not offered

What changed

  • random_flip defaults to off in the API request model and the trainer config.
  • The Train tab gets a Random flip Off / On select, next to Gradient checkpointing, with a hint on when to turn it on (styles, symmetric subjects). It is hidden for MiniMax-H3, which never flips.
  • Keep checkpoints appears next to "Checkpoint every" once periodic checkpoints are on. It sends save_total_limit, which was fixed at 2, so earlier steps can be kept for comparison (0 keeps every one).
  • Caption dropout (cfg_dropout, the chance a sample trains on the empty prompt) is exposed for the DiT families. It stays hidden for SDXL, whose loop does not read it, and for MiniMax-H3, which refuses it.
  • LoRA dropout (lora_dropout, PEFT dropout on the LoRA input) is exposed for every family; all three trainers read it. 0 by default, as before.
  • Timestep shift (flow_shift) is a Default / Custom select (plus a value when Custom) for the flow-matching image families; SDXL has no flow shift, and MiniMax-H3 keeps its released video / audio shifts (a number would move only its video schedule). Default sends nothing, so each family keeps its current default (Auto for Qwen-Image and LTX-2, the model's own schedule otherwise). With Studio: diffusion flow_shift is the effective shift, and min-SNR is recorded as unused for flow-matching runs #13215 a custom value is the effective shift; merge that first so a Z-Image custom value is not applied on top of its built-in shift.
  • The API already accepted all five fields; this PR only adds the controls (and the flip default). These fields are not seeded per family, so editing them does not stop a family switch from reseeding rank, LR and resolution.

What did not change

  • Resume replays a run's stored config, which holds random_flip explicitly, so existing runs resume with the value they started with. A changed value is still refused by the checkpoint identity check.
  • The persistent conditioning cache keys every latent on its flip bit, so a run with flip off never reads a flipped latent cached by an earlier run.
  • MiniMax-H3 still normalises random_flip to off.

Tests

  • New test_random_flip_is_opt_in: the request and config default to off, an untouched request plans no flipped cache variant, and random_flip=True is still accepted.
  • test_the_identity_covers_the_input_stream now toggles flip on (the non-default value) and checks both on and off are recorded.
  • tests/test_diffusion_*.py + tests/test_video_*.py, merge base vs this branch: 41 failures on both sides (compat preflight, nvfp4, one backend test; environment), none only on this branch.
  • Frontend: tsc --noEmit clean, npm test 11155/11155, tests/studio/test_diffusion_train_settings_layout_contract.py passes; eslint on the panel reports the same 7 pre-existing problems as main.

Screenshots

Before (merge base) vs after (this PR), from two separate Studio installs.

Image Train tab, Z-Image selected, "Checkpoint every" set to 50. After: Keep checkpoints (2), Random flip (Off), Caption dropout (0), LoRA dropout (0) and Timestep shift (Default) appear; before has none of them.

before and after

@danielhanchen danielhanchen self-assigned this Oct 10, 2026
@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 10, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ⚠️ Failed 2026-10-12T09:11:15.360906Z 17801c2 New commits
ℹ️ 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.

@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Oct 10, 2026
@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Swish!

Reviewed commit: f0e2556b6d

ℹ️ 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 changed the title Studio: make random flip opt-in for image LoRA training Studio: random flip opt-in, plus checkpoint retention and caption dropout on the image Train tab Oct 10, 2026
@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

1 similar comment
@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Delightful!

Reviewed commit: e27d727632

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

Copy link
Copy Markdown
Member Author

pre-commit.ci run

danielhanchen pushed a commit to danielhanchen/unsloth-staging-2 that referenced this pull request Oct 10, 2026
@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

1 similar comment
@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

danielhanchen pushed a commit to danielhanchen/unsloth-staging-2 that referenced this pull request Oct 11, 2026
@danielhanchen danielhanchen changed the title Studio: random flip opt-in, plus checkpoint retention and caption dropout on the image Train tab Studio: random flip opt-in, plus checkpoint retention, caption dropout, LoRA dropout and timestep shift on the image Train tab Oct 11, 2026

@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: 816a99ed50

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

Comment on lines +1205 to +1209
flow_shift:
isDiT && flowShiftMode !== "default"
? flowShiftMode === "auto"
? "auto"
: flowShift

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 Avoid compounding custom shifts on static schedulers

When a user selects Custom for FLUX, Z-Image, or Krea 2, this sends the entered value even though those pretrained schedulers already bake a static shift into scheduler.sigmas. _training_sigma_table then applies the numeric transform to that already-shifted table, so selecting 3 for a FLUX shift-3 scheduler produces an effective shift of 9 rather than the direct shift of 3 advertised by the UI, materially changing the training timestep distribution. Gate this option to unshifted/dynamic schedulers or convert the requested absolute shift before applying it.

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.

Not changing this: FLUX.1, FLUX.2 and Krea 2 ship schedulers with use_dynamic_shifting (Krea's shift is 1.0), so diffusers never bakes a static shift into their sigmas and a custom value is applied once. Only Z-Image bakes one in (3 / 6), and #13215 makes a number the effective shift on the unshifted schedule there; this PR's description asks for #13215 to merge first.

// Everything else is a DiT family.
const isDiT = familyName !== "sdxl";
const isH3 = familyName === "minimax-h3";
const supportsCfgDropout = isDiT && !isH3;

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 Hide caption dropout for guidance-distilled FLUX families

For flux.1, flux.2-klein, and flux.2-dev, this predicate enables Caption dropout even though the family registry marks their pipelines as ignoring negative prompts and their training forwards use only a fixed distilled-guidance vector rather than an unconditional CFG branch. A nonzero value therefore spends that fraction of an expensive run training empty captions that Studio inference never evaluates, contrary to the control's claim that it improves CFG response and potentially weakening prompt conditioning. Derive this capability per family and exclude guidance-distilled/no-negative-prompt families as well as MiniMax-H3.

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.

Not changing this: caption dropout is standard for guidance-distilled FLUX LoRAs too (ostris/ai-toolkit's FLUX example config sets caption_dropout_rate: 0.05). It keeps the LoRA from depending on the exact caption; it defaults to 0, so nothing changes unless a user sets it.

@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

1 similar comment
@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: 816a99ed50

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

</div>
)}
{supportsCfgDropout &&
numberField("Caption dropout", cfgDropout, setCfgDropout, 0, {

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 Keep auxiliary edits from freezing family defaults

When a user edits Caption dropout—and likewise the new LoRA dropout or custom Shift value—this call goes through numberField, whose default handler sets the shared settingsDirty flag. A later model-family change therefore skips reseeding the family-specific learning rate, rank, and resolution even though none of those fields was edited; for example, changing dropout under Qwen-Image and then selecting Krea 2 retains Qwen's 5e-5 LR/rank 16 instead of Krea's 3e-4/rank 32 defaults, which can materially alter the experiment. Give these unrelated controls their own dirty handling rather than marking the family-default fields dirty.

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 039689d: Keep checkpoints, Caption dropout, LoRA dropout and the shift value pass their own no-op dirty handler, so editing them no longer stops a family switch from reseeding rank, LR and resolution.

</SelectTrigger>
<SelectContent>
<SelectItem value="default">Default</SelectItem>
<SelectItem value="auto">Auto (match generation)</SelectItem>

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 Compute Auto shift from the selected resolution

When Auto is selected for FLUX.1 at a resolution below its maximum sequence length (including the panel's 512px family default), this option does not actually match generation: _training_sigma_table always calls time_shift with scheduler.config.max_shift, while the FLUX inference schedule derives mu from the image token count between base_shift and max_shift. At 512px this trains against the max-resolution distribution rather than the 512px generation distribution advertised by this label; either calculate Auto from the configured training resolution or restrict it to families whose shift is resolution-independent.

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 039689d: the Auto option is gone. It is resolution-independent only for Qwen-Image and LTX-2, which already default to it, so the control is now Default / Custom.

Comment on lines +976 to +977
random_flip: bool = Field(
False, description = "Randomly mirror training images left-right (augmentation)"

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 the legacy flip default when resuming old checkpoints

When an API client resumes a checkpoint whose manifest predates the random_flip identity field and omits random_flip again, this new request default resolves to off even though that checkpoint was created under the former on-by-default behavior. Because random_flip is optional in CheckpointIdentity.mismatch_reason, the missing legacy value skips the compatibility check, so the trainer restores optimizer/RNG state and silently changes the input stream halfway through the run. Interpret a missing legacy identity as the historical on value, or reject such resumes unless the caller supplies the original setting.

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.

Not changing this: Studio's resume replays the run's stored config, which records random_flip explicitly (old runs stored True), so a resumed run keeps its flip setting. It takes a hand-built API resume that also omits the field to hit this.

Comment on lines +1592 to +1595
numberField("Shift value", flowShift, setFlowShift, 3, {
min: 0.1,
step: 0.5,
hint: "1 is no shift; around 3 suits most image models.",

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 Special-case MiniMax-H3's video-only custom shift

When MiniMax-H3 is selected, choosing Custom exposes the same value and hint as image families, but the H3 loop applies cfg.flow_shift only to sigma_video while keeping sigma_audio fixed at 3.0. The initial custom value of 3 also replaces H3's released video shift of 12, and the claim that 1 means “no shift” is false for the still-shifted audio schedule. This can unintentionally move H3 onto a substantially different coupled noise distribution; hide Custom for H3 or label it as video-only and initialize it to the H3 video default.

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 039689d: the shift control is hidden for MiniMax-H3, which keeps its released video / audio shifts.

… only Default / Custom shift, not for MiniMax-H3
@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

1 similar comment
@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Chef's kiss.

Reviewed commit: 039689dace

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant