Skip to content

Studio: pick the sampler on the Images page and load v-prediction SDXL checkpoints correctly - #13569

Merged
danielhanchen merged 7 commits into
mainfrom
studio-images-sampler
Oct 13, 2026
Merged

danielhanchen merged 7 commits into
mainfrom
studio-images-sampler

Conversation

@danielhanchen

@danielhanchen danielhanchen commented Oct 13, 2026 •

Copy link
Copy Markdown
Member

Fixes #11714

What this does

The Images page had no way to choose a sampler: every SDXL generation ran on whatever scheduler the base repo ships (Euler, leading spacing). This adds a Sampler control with the samplers people actually name on model cards, plus a Schedule type beside it, and fixes v-prediction SDXL checkpoints, which currently render as noise.

1. Sampler and Schedule type (diffusers engine, SDXL)

Sampler diffusers
Model default the shipped scheduler, untouched (the default)
Euler EulerDiscreteScheduler
Euler a EulerAncestralDiscreteScheduler
DPM++ 2M DPMSolverMultistepScheduler(algorithm_type="dpmsolver++")
DPM++ 2M SDE DPMSolverMultistepScheduler(algorithm_type="sde-dpmsolver++")

Schedule type: Automatic (AUTOMATIC1111's per-sampler default: Karras for DPM++ 2M, Exponential for DPM++ 2M SDE, else the model's), Uniform, Karras, Exponential. A sampler only lists the schedule types it supports (Euler a has none of the sigma flags).

  • The control is only shown when the loaded scheduler lists compatible alternatives (_compatibles), so FLUX, Qwen-Image, Z-Image and every other flow-matching model, and the native and MLX engines, see no change.
  • "Model default" + "Automatic" sends exactly the request the page sent before, so nothing moves for anyone who does not touch it.
  • The swap is per generation on the pipeline that runs (txt2img, img2img, inpaint, upscale, ControlNet) and is restored afterwards, so it is idempotent and never leaks into the next request.
  • The new scheduler is built from the loaded config, so prediction type and zero-SNR settings carry over. It always starts at the first timestep: a zero-SNR Karras grid repeats its first timestep ([999, 999, 998, ...]) and the SDXL ControlNet pipeline never sets a begin index, so DPM++ otherwise overran its sigmas with an IndexError.
  • Remembered per checkpoint (repo + file, since community SDXL files all share the SDXL base repo), recorded in the recipe (sampler, schedule_type), shown in the recipe popover ("DPM++ 2M Karras"), restored by "Restore these settings", and written to the PNG parameters text as Sampler: DPM++ 2M, Schedule type: Karras like AUTOMATIC1111.
  • A sampler sent to an engine that cannot run it is a 400, not silently ignored, so a recipe never records a sampler that did not run.

2. v-prediction SDXL checkpoints

Single-file SDXL checkpoints trained with v-prediction (NoobAI-XL V-Pred and its merges) mark themselves with empty v_pred / ztsnr tensors in the safetensors header, which is how ComfyUI detects them (comfy/supported_models.py, SDXL.model_type). Studio loads the single file against the SDXL base repo's epsilon scheduler and never looked at those markers, so these checkpoints produced pure noise. The loader now reads the header and sets prediction_type="v_prediction", plus rescale_betas_zero_snr=True and timestep_spacing="trailing" for ztsnr. Unmarked checkpoints are untouched.

Reproduced with Laxhar/noobai-XL-Vpred-1.0 (NoobAI-XL-Vpred-v1.0.safetensors), same seed, 28 steps, CFG 5, through Studio's diffusion backend:

scheduler after load output
main prediction_type=epsilon, leading noise
this PR prediction_type=v_prediction, zero SNR, trailing clean image

Not included

Samplers for flow-matching models (diffusers only partially supports them), the native sd.cpp engine's sampler flags, and Clip skip. Clip skip is not needed for SDXL: diffusers and ComfyUI already use the penultimate CLIP layer for SDXL, which is what "clip skip 2" means on Pony and Illustrious model cards.

Tests

  • studio/backend/tests/test_diffusion_sampler.py: sampler list per scheduler (SDXL offers them, flow matching offers none), schedule resolution, prediction settings carry over, refusals, v-pred / ztsnr markers (and idempotence), parameters text, route refusal on other engines.
  • studio/frontend/tests/images-sampler-choice.test.ts: request fields, fallback for a choice the model lacks, per-model memory, recipe label.
  • Real runs on SDXL base and NoobAI-XL V-Pred through the backend: every sampler renders; switching samplers after the deferred compile costs one ~15 s re-capture the first time a different timestep dtype is seen, then runs at full speed.

Before / after in Studio

Same clicks on both sides (merge base vs this branch, two separate installs): load NoobAI-XL-Vpred-v1.0.safetensors as a single file, type the prompt, seed 42, page defaults (25 steps, CFG 7), Generate.

Settings column: the Sampler row appears (Model default / Automatic) only on the branch.

Images settings column, before and after

Result: main renders noise from the v-prediction checkpoint, the branch renders the image. Mean neighbouring-pixel difference 7.91 (noise) vs 1.81.

Images page after one Generate, before and after

@danielhanchen danielhanchen self-assigned this Oct 13, 2026
@chatgpt-codex-connector

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 🔄 Running since 2026-10-13T08:32:15.002393Z 4929f35 PR opened
ℹ️ 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.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 13, 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-13T12:21:51.104246Z ed6bee1 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 13, 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 13, 2026
danielhanchen pushed a commit to danielhanchen/unsloth-staging-2 that referenced this pull request Oct 13, 2026
@chatgpt-codex-connector

Copy link
Copy Markdown

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

Reviewed commit: 4faf849d3b

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

@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: dd0febb9c8

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

"karras": ("Karras", "use_karras_sigmas"),
"exponential": ("Exponential", "use_exponential_sigmas"),
}
_SIGMA_FLAGS = ("use_karras_sigmas", "use_exponential_sigmas", "use_beta_sigmas")

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 Clear every inherited schedule-selection flag

When the resident DPMSolverMultistepScheduler config has use_lu_lambdas=True or use_flow_sigmas=True, choosing Uniform only clears the three flags in this tuple, so from_config preserves the omitted flag and the generated image continues using the inherited LU/flow schedule while the recipe records Uniform. An inherited LU schedule can also take precedence over a requested Exponential schedule in set_timesteps. Clear all mutually exclusive schedule-selection fields supported by the target scheduler before enabling the selected one.

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 44c6273: use_lu_lambdas is cleared with the sigma flags, and a scheduler configured for flow sigmas or flow prediction offers no samplers.

Comment on lines +2499 to +2502
changeSamplerChoice({
sampler: image.sampler ?? DEFAULT_SAMPLER,
scheduleType: image.schedule_type ?? AUTOMATIC_SCHEDULE,
});

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 restored samplers while no model is loaded

When the user restores a gallery recipe while the model is unloaded, samplerOptions is empty and samplerModelKey is "", so this call normalizes every recorded sampler to the default and withSamplerChoice declines to store it. The subsequent Generate auto-recalls the remembered model but runs with its previous/default sampler even though the UI reported that the recipe settings were restored; retain the recipe choice until the recalled model's options are available.

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 44c6273: Restore keeps the recipe's choice until the recalled model's options exist, so the auto-loaded Generate runs with 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: 44c62738fe

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

const samplerModelKey = status?.loaded ? `${status.repo_id ?? ""}|${status.gguf_filename ?? ""}` : "";
const samplerChoice = normalizeSamplerChoice(
samplerOptions,
restoredSampler ?? samplerChoices[samplerModelKey],

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 Clear the restored sampler after applying it

When a recipe has been restored, restoredSampler permanently takes precedence over every entry in the per-model map; the only clearing path is manually changing the sampler. After the restored model becomes available—and even after generating—switching to another SDXL checkpoint therefore reuses the restored sampler instead of that checkpoint's remembered choice, contradicting the per-model behavior and potentially running an unintended scheduler. Consume or scope the restored override once its target model's options become available.

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 fa4cbf5: a restore with the model loaded stores the choice for that model directly; one made while unloaded is used by the next Generate, stored for the recalled model and then dropped.

@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. Hooray!

Reviewed commit: fa4cbf53ca

ℹ️ 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 added a commit that referenced this pull request Oct 13, 2026
#13612)

- diffusion.py: read pipe.scheduler with getattr on the generate path,
  like the status poll. #13569 made every generate touch it, which broke
  173 test_diffusion_backend tests whose fake pipelines have none.
- test_diffusion_autoopt_parity: skip the two fixture comparisons when
  diffusers is not installed (Backend CI); without it nothing compiles
  and every case differs.
- Format three files from #13610 and #13531.
- Raise the startup budget by the 0.8 KB transfer five merges added.
danielhanchen added a commit that referenced this pull request Oct 13, 2026
)

#13569 made restoreSettings re-apply the restored sampler through
changeSamplerChoice / samplerOptions. The test evaluates the callback
in a sandbox that only knew a fixed list of closure names, so it threw
ReferenceError before reaching the negative prompt and fails on main on
every OS. Resolve any non-global name to a recording no-op instead.
danielhanchen added a commit that referenced this pull request Oct 13, 2026
…rity fixture with diffusers (#13608)

* Studio images: read the scheduler like the status poll does, and fix the tests #13569 left red

generate passed pipe.scheduler straight to build_scheduler, so a pipeline
without a scheduler attribute failed every request, even with the default
sampler. Read it with getattr like the status endpoint; build_scheduler
already treats None as offering no samplers.

The negative-prompt restore test evaluates restoreSettings in a stub scope,
which now also needs the sampler names #13569 added.

The auto-optimizer parity fixture records real diffusers classes, so it can
only pass where diffusers is installed. Skip it without diffusers and run
it in the Studio VAE seam guard job, which installs the pinned diffusers.

* Tests: pin the Triton probes in the autoopt parity snapshot, and expect no titlebar blur

The flux2 fp16 RoPE and Wan fused gates ask whether Triton imports. CPU
torch from pip has no Triton, so the seam guard job lost both patches
that the fixture records; pin them like the other host probes.

#13577 made popup backdrops dim without blurring, the titlebar's included,
so the titlebar smoke now expects no backdrop filter.
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.

[Feature] Unsloth Studio: let the Images page pick the sampler (scheduler), not just the step count

1 participant