[BugFix]: Fix Bagel generate_image denoising schedule (#4509)

This commit is contained in:
汪志鹏 authored and GitHub committed 2026-06-18 02:02:38 +00:00
1 parent 2f64c712fd
commit f195e44bc1
5 files changed
+30 -15

No files matched your search

@@ -1129,6 +1129,13 @@ class Bagel(nn.Module):
config_class = BagelConfig
base_model_prefix = "bagel"
# Flow-matching denoise schedule convention. Official BAGEL samples
# ``num_timesteps`` points over [1, 0] and drops the terminal t=0, yielding
# ``num_timesteps - 1`` Euler steps. Lance samples one extra point
# (``num_timesteps + 1``) for ``num_timesteps`` steps; ``LanceBagel`` flips
# this on. See https://github.com/vllm-project/vllm-omni/issues/4470.
_denoise_schedule_extra_step: bool = False
def __init__(
self,
language_model,
@@ -1690,11 +1697,11 @@ class Bagel(nn.Module):
frame_condition_token_indexes = frame_condition_token_indexes.to(x_t.device).long()
pinned_x_t = x_t[frame_condition_token_indexes].clone()
# Use num_timesteps + 1 sample points so we get `num_timesteps` denoise
# steps after dropping the terminal t=0 (which has no dt). Upstream
# Lance / BAGEL both use this convention; without the +1 we silently
# run one fewer denoise iteration than the user asked for.
timesteps = torch.linspace(1, 0, num_timesteps + 1, device=x_t.device)
# Build the flow-matching schedule. BAGEL drops the terminal t=0 for
# ``num_timesteps - 1`` Euler steps; Lance keeps it for ``num_timesteps``.
# ``_denoise_schedule_extra_step`` (overridden by ``LanceBagel``) selects which.
num_sample_points = num_timesteps + 1 if self._denoise_schedule_extra_step else num_timesteps
timesteps = torch.linspace(1, 0, num_sample_points, device=x_t.device)
timesteps = timestep_shift * timesteps / (1 + (timestep_shift - 1) * timesteps)
dts = timesteps[:-1] - timesteps[1:]
timesteps = timesteps[:-1]
@@ -278,6 +278,11 @@ class LanceBagel(Bagel):
``forward_cache_update_vae`` — is reused unchanged.
"""
# Upstream Lance samples ``num_timesteps + 1`` schedule points (one extra
# over official BAGEL) so the denoise loop runs exactly ``num_timesteps``
# Euler steps. See Bagel.generate_image and issue #4470.
_denoise_schedule_extra_step: bool = True
@staticmethod
def _lance_compute_vit_buckets():
"""Replicate upstream Lance's ``BucketResize.init_buckets`` for the ViT path.