-
Notifications
You must be signed in to change notification settings - Fork 7.1k
[diffusion] Support RL rollout for the Wan pipeline via a per-request scheduler switch #30036
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
zhihengy
wants to merge
10
commits into
sgl-project:main
Choose a base branch
from
Rockdu:feat/wan-rl-rollout
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 8 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
e33ecb2
[diffusion] Support RL rollout for the Wan pipeline via a per-request…
zhihengy 938c2cb
Address review: per-request scheduler resolution, class-level log flag
zhihengy 9f7661b
Address review: bind rollout scheduler per request in the standard ti…
zhihengy c026edc
Drop stage-binding unit test per author preference
zhihengy 101944a
Fix stale comment on rollout log flag
zhihengy eb4e63c
Tighten rollout_scheduler comment
zhihengy 8c43458
Move rollout binding logic into RolloutTimestepPreparationMixin under…
zhihengy 36d8134
Fix RolloutDenoisingMixin to use the request-bound scheduler
zhihengy 7c5770e
Create the rollout scheduler lazily on first rollout request
zhihengy b329fb7
Tighten rollout binding comment
zhihengy File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
60 changes: 60 additions & 0 deletions
60
python/sglang/multimodal_gen/runtime/post_training/rollout_timestep_mixin.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,60 @@ | ||
| # SPDX-License-Identifier: Apache-2.0 | ||
| """Mixin for per-request rollout scheduler binding in TimestepPreparationStage. | ||
|
|
||
| Kept under post_training to keep the core stage lean; mirrors | ||
| RolloutDenoisingMixin on DenoisingStage. | ||
| """ | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| from sglang.multimodal_gen.runtime.pipelines_core.schedule_batch import Req | ||
| from sglang.multimodal_gen.runtime.utils.logging_utils import init_logger | ||
|
|
||
| logger = init_logger(__name__) | ||
|
|
||
|
|
||
| class RolloutTimestepPreparationMixin: | ||
| """Bind an alternate scheduler to rollout=True requests. | ||
|
|
||
| The rollout SDE/log-prob path needs a first-order flow-match Euler | ||
| scheduler, which not every pipeline serves (e.g. Wan serves UniPC). The | ||
| host stage sets ``self.rollout_scheduler``; None keeps the serving | ||
| scheduler for rollout requests. Downstream stages read the scheduler | ||
| from ``batch.scheduler``, so the host stage is the single switch point. | ||
| """ | ||
|
|
||
| # Class-level so the rollout info log prints once per process, not once | ||
| # per stage instance. | ||
| _logged_rollout_scheduler_check = False | ||
|
|
||
| def _resolve_rollout_scheduler(self, batch: Req): | ||
| """Return the rollout scheduler template for this request, or None.""" | ||
| if batch.rollout and self.rollout_scheduler is not None: | ||
| return self.rollout_scheduler | ||
| return None | ||
|
|
||
| def _check_rollout_timesteps(self, scheduler) -> None: | ||
| # The rollout SDE/log-prob math assumes the flow-match Euler | ||
| # convention timesteps == sigmas[:-1] * num_train_timesteps. | ||
| sigmas = scheduler.sigmas | ||
| timesteps = scheduler.timesteps | ||
| if sigmas is None or timesteps is None or sigmas.numel() < 2: | ||
| return | ||
| reconstructed = sigmas[:-1].to(device=timesteps.device) * float( | ||
| scheduler.config.num_train_timesteps | ||
| ) | ||
| max_abs_diff = (timesteps.float() - reconstructed.float()).abs().max().item() | ||
| if max_abs_diff > 1e-3: | ||
| raise ValueError( | ||
| f"rollout timestep/sigma mismatch: max_abs_diff={max_abs_diff:.6g}" | ||
| ) | ||
| if not RolloutTimestepPreparationMixin._logged_rollout_scheduler_check: | ||
| logger.info( | ||
| "RL rollout using %s (timesteps dtype=%s, sigmas dtype=%s, " | ||
| "max_abs_diff=%.6g)", | ||
| type(scheduler).__name__, | ||
| timesteps.dtype, | ||
| sigmas.dtype, | ||
| max_abs_diff, | ||
| ) | ||
| RolloutTimestepPreparationMixin._logged_rollout_scheduler_check = True |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
could we make sure only one scheduler is initialized and passed at runtime?