Skip to content

add a helper function insert_step_callback and callback test on modular - #15427

Merged
yiyixuxu merged 3 commits into
mainfrom
modular-step-callback
Nov 27, 2026
Merged

yiyixuxu merged 3 commits into
mainfrom
modular-step-callback

Conversation

@yiyixuxu

@yiyixuxu yiyixuxu commented Nov 27, 2026 •

Copy link
Copy Markdown
Collaborator

This PR adds insert_step_callback, which makes a modular pipeline accept callback_on_step_end:

      from diffusers.modular_pipelines import insert_step_callback
  
      pipe = ModularPipeline.from_pretrained(repo)
      insert_step_callback(pipe)
      pipe(prompt="a cat", callback_on_step_end=my_fn, output="images")

It adds a block to the end of each denoising loop that calls the callback with
(pipeline, step, timestep, callback_kwargs). callback_kwargs holds the loop
values (e.g. latents) plus num_timesteps, and returned values are written back.

Motivation: #15017 (diffusers serve) writes this block by hand to report progress.
It stays useful after pipe.stream() (#14159) for anyone who already has a callback.

Notes:

  • No callback_on_step_end_tensor_inputs: the callback gets the whole loop state.
  • To stop early, raise from the callback. pipe._interrupt is not supported.
  • Pipelines with a nested denoising loop (Helios, Kandinsky S2V, MiniMax Music 3,
    Wan Animate 2) and Echo are not supported and raise a ValueError.

Tests: test_step_callback and test_step_callback_early_stop in
ModularPipelineTesterMixin run on every modular pipeline. The unsupported ones
skip them explicitly.

Docs: the "Modular pipelines" section of the callbacks guide now uses the function.

yiyixuxu and others added 2 commits November 27, 2026 23:08
Adds a step callback block to every denoising loop of a modular pipeline,
so it accepts `callback_on_step_end` like a standard pipeline.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
@github-actions github-actions Bot added documentation Improvements or additions to documentation tests modular-pipelines size/L PR with diff > 200 LOC labels Nov 27, 2026
@HuggingFaceDocBuilderDev

Copy link
Copy Markdown

The docs for this PR live here. All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update.

Pages changed in this PR:

@yiyixuxu
yiyixuxu merged commit 509b765 into main Nov 27, 2026
17 checks passed
@yiyixuxu
yiyixuxu deleted the modular-step-callback branch November 27, 2026 23:51
@yiyixuxu yiyixuxu mentioned this pull request Nov 27, 2026
10 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation modular-pipelines size/L PR with diff > 200 LOC tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants