Skip to content

Staged sampling - #1688

Open
dxqb wants to merge 5 commits into
Nerogar:masterfrom
dxqb:staged-sampling-squashed
Open

dxqb wants to merge 5 commits into
Nerogar:masterfrom
dxqb:staged-sampling-squashed

Conversation

@dxqb

@dxqb dxqb commented Aug 13, 2026

Copy link
Copy Markdown
Collaborator

Summary

Instead of cycling model parts for each sample, run all samples batched through the pipeline
Meaning: run text encoder for all samples, then denoising for all samples, then VAE for all samples
this does not mean the samples are send batched through the denoiser. only the sampling stages run batched

Intended for future large models and #1642 but some of the more recent and in-use samplers were ported to staged samplers anyway:

  • Flux2
  • Krea2
  • Anima
  • Qwen Image
  • Z-Image

Others are left sample-major

Test plan

  • pre-commit run --all-files passes
  • Launched the affected UI or script and exercised the change
  • Tested with at least one real preset / config when relevant (note which: LTX)

AI assistance

  • AI-assisted — I have read every line in this diff and can defend each change

dxqb and others added 5 commits July 18, 2026 16:24
Suppress a handful of specific, noisy-but-harmless messages emitted while
launching the UI and starting training:

- diffusers/transformers logger.warning() lines (Modular Diffusers experimental
  notice, unexpected-config-attributes, unrecognized loss_type) via filters on
  the exact emitting loggers
- huggingface_hub local_dir_use_symlinks deprecation and the torch.compile
  inductor performance notes via warnings/logger filters
- Qt gnome portal dbus errors via QT_LOGGING_RULES
- tensorboard subprocess banner/notices by discarding its stdout/stderr

Each filter targets one specific message, so other warnings from the same
libraries still come through.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
# Conflicts:
#	modules/util/ui/pyside6_util.py
A cold torch.compile cache announces every frame it compiles, which scrolls the
progress bar off the screen. There is no knowable total to build a real progress
bar from, so the announcement goes into the postfix of the innermost running bar
instead, and is cleared again by that bar's next redraw or by its close.

tqdm keeps its bars in an unordered WeakSet, so which of the nested bars is the
innermost one cannot be recovered from it. modules/util/tqdm_util.py subclasses
tqdm to track that itself and adds show_status() next to tqdm.write(); every
tqdm import in the repo now comes from there. Bars owned by mgds are outside
this and still draw as before.

Also gates the warning filters on OT_DEBUG_WARNINGS, so setting it brings every
suppressed message back, and silences the diffusers attention-backend
experimental notice.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Sampling used to run each sample end to end, so with several sample prompts
every model part was brought on-device once per sample: text encoder, then
transformer, then VAE, then back to the text encoder for the next prompt.

This adds modules/util/staged_pipeline.py. run_staged_pipeline() takes a list of
(label, stage) pairs and a column-oriented dict of per-sample inputs, and runs
every sample through stage 0, then every sample through stage 1, and so on. Each
sample carries a context dict that accumulates the stages' outputs, so a value
produced early reaches any later stage without being threaded through the ones
between; a stage only receives the arguments its signature names.

The Flux2, Qwen, Krea2, ZImage and Anima samplers are split into __encode,
__denoise and __decode stages and drive them through that pipeline in a new
sample_all(). Each part is now materialized once per stage instead of once per
sample. BaseModelSampler.sample_all() has an item-major default that just loops
sample(), so samplers that are not split keep working unchanged.

GenericTrainer hands the whole enabled sample list to sample_all() in one call.
Custom samples ("sample now") all share the samples/custom directory, so their
filenames now get the sample index appended - without it a batch finishing
within the same second wrote every image to the same path. Custom sample
requests that arrive while sampling is already running are drained before
training resumes instead of waiting for the next step.

The sample window keeps the images of a batch and gets prev/next buttons with a
counter to page through them.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
…uashed

# Conflicts:
#	modules/trainer/GenericTrainer.py
@dxqb

dxqb commented Aug 13, 2026

Copy link
Copy Markdown
Collaborator Author

contains #1628 and #1687

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