[diffusion] fix: keep generic warmup valid for step-floored models and stop reporting a failed warmup as warm (#41641)

Co-authored-by: Mick Qian <mickqian@users.noreply.github.com>
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Mick
2026-10-05 17:23:06 +08:00
committed by GitHub
co-authored by Mick Qian Claude Opus 5.5
parent 55dcf3254f
commit 0263fdacb2
9 changed files with 149 additions and 9 deletions
@@ -3,7 +3,7 @@ import math
import os
from collections.abc import Mapping
from dataclasses import dataclass, field
from typing import Any
from typing import Any, ClassVar
import msgspec
@@ -36,6 +36,9 @@ def _optional_positive_finite_float(value: Any, field_name: str) -> float | None
@dataclass
class MiniMaxH3SamplingParams(SamplingParams):
# The video/audio sigma schedules include both interval endpoints.
min_num_inference_steps: ClassVar[int] = 2
height: int = 512
width: int = 896
num_inference_steps: int = 50
@@ -294,6 +294,9 @@ class SamplingParams:
# The base __post_init__ will apply them when height/width are not provided.
_default_height: ClassVar[int | None] = None
_default_width: ClassVar[int | None] = None
# Fewest denoising steps the model's schedule accepts. Warmup requests are
# clamped to it, so a generic 1-step warmup stays a valid request.
min_num_inference_steps: ClassVar[int] = 1
height: int | None = None
width: int | None = None
@@ -531,10 +531,17 @@ class DiffGenerator:
return
if self.server_args.warmup_mode != "off":
total_duration_ms = results[0].metrics.get("total_duration_ms", 0)
logger.info(
f"Warmed-up request processed in {GREEN}%.2f{RESET} seconds (with warmup excluded)",
total_duration_ms / 1000.0,
)
if results[0].metrics.get("warmup_failed"):
logger.warning(
"Warmup failed, so this request ran cold: %.2f seconds "
"includes first-use cost and is not a warmed-up timing",
total_duration_ms / 1000.0,
)
else:
logger.info(
f"Warmed-up request processed in {GREEN}%.2f{RESET} seconds (with warmup excluded)",
total_duration_ms / 1000.0,
)
peak_memories = [r.peak_memory_mb for r in results if r.peak_memory_mb]
if peak_memories:
@@ -815,6 +815,10 @@ class Scheduler(SchedulerWarmupMixin, SchedulerPostTrainingMixin, SchedulerDisag
self.metrics.finish(id(processed_req), error=output_batch.error is not None)
is_warmup = is_warmup_req(processed_req)
self._log_warmup_result(output_batch, processed_req, is_warmup)
if not is_warmup and self._req_based_warmup_failed:
self._req_based_warmup_failed = False
if output_batch.metrics is not None:
output_batch.metrics.warmup_failed = True
if self._should_return_lightweight_warmup_result(processed_req):
output_batch.drop_payload_for_warmup()
@@ -346,7 +346,8 @@ class Req:
self.metrics.suppress_stage_breakdown = True
self.extra["cache_dit_num_inference_steps"] = self.num_inference_steps
self.extra["warmup_target_num_inference_steps"] = self.num_inference_steps
self.num_inference_steps = warmup_steps
floor = getattr(type(self.sampling_params), "min_num_inference_steps", 1)
self.num_inference_steps = max(warmup_steps, floor)
def copy_as_warmup(self, warmup_steps: int = 1) -> Req:
req = deepcopy(self)
@@ -8,6 +8,7 @@ from dataclasses import dataclass
from typing import Any, Mapping
from sglang.multimodal_gen import envs
from sglang.multimodal_gen.configs.sample.minimax_h3 import MiniMaxH3SamplingParams
from sglang.multimodal_gen.configs.sample.sampling_params import QUALITY_LEVELS
from sglang.multimodal_gen.runtime.pipelines_core.schedule_batch import Req
from sglang.multimodal_gen.runtime.pipelines_core.stages.base import PipelineStage
@@ -151,10 +152,11 @@ class MiniMaxH3PartitionAdmissionStage(PipelineStage):
if not isinstance(task, str) or not task.strip():
raise ValueError("MiniMax H3 request task must be a non-empty string")
self.metadata.canonical_task(task)
if batch.num_inference_steps < 2:
min_steps = MiniMaxH3SamplingParams.min_num_inference_steps
if batch.num_inference_steps < min_steps:
raise ValueError(
"MiniMax H3 requires num_inference_steps >= 2 because its "
"video/audio sigma schedules include both interval endpoints"
f"MiniMax H3 requires num_inference_steps >= {min_steps} because "
"its video/audio sigma schedules include both interval endpoints"
)
gpu_plans = envs.SGLANG_DIFFUSION_MINIMAX_H3_ADALN_GPU_PLANS
if (
@@ -288,6 +288,9 @@ def prepare_warmup_image_path(server_args: ServerArgs) -> str:
class SchedulerWarmupMixin:
# A failed request-based warmup leaves the next request cold.
_req_based_warmup_failed: bool = False
@staticmethod
def _format_warmup_req(req_or_group: Any) -> str:
return format_warmup_req(req_or_group)
@@ -391,6 +394,8 @@ class SchedulerWarmupMixin:
else:
warmup_desc = self._format_warmup_req(req_or_group)
logger.warning("%s processing failed: %s", warmup_desc, output_batch.error)
if not server_based_warmup:
self._req_based_warmup_failed = True
def process_received_reqs_with_req_based_warmup(
self, recv_reqs: list[tuple[bytes, Any]]
@@ -65,6 +65,9 @@ class RequestMetrics:
self.active_stage_name: str | None = None
self.total_duration_ms: float = 0.0
self.suppress_stage_breakdown: bool = False
# Set on the first request after a failed request-based warmup: its
# timing includes first-use cost the warmup was meant to absorb.
self.warmup_failed: bool = False
# memory tracking: {checkpoint_name: MemorySnapshot}
self.memory_snapshots: Dict[str, MemorySnapshot] = {}
@@ -116,6 +119,7 @@ class RequestMetrics:
"denoising_stages": sorted(self.denoising_stages),
"steps": self.steps,
"total_duration_ms": self.total_duration_ms,
"warmup_failed": self.warmup_failed,
"memory_snapshots": {
name: snapshot.to_dict()
for name, snapshot in self.memory_snapshots.items()
@@ -0,0 +1,111 @@
"""Warmup requests must stay valid for models with a step floor, and a failed
request-based warmup must not be reported as a warmed-up timing."""
import logging
from types import SimpleNamespace
from unittest.mock import Mock
from sglang.multimodal_gen.configs.sample.minimax_h3 import MiniMaxH3SamplingParams
from sglang.multimodal_gen.configs.sample.sampling_params import SamplingParams
from sglang.multimodal_gen.runtime.entrypoints.diffusion_generator import (
DiffGenerator,
)
from sglang.multimodal_gen.runtime.managers.scheduler import Scheduler
from sglang.multimodal_gen.runtime.pipelines_core.schedule_batch import OutputBatch, Req
from sglang.multimodal_gen.runtime.utils.perf_logger import RequestMetrics
def _req(sampling_params: SamplingParams, steps: int) -> Req:
req = Req(sampling_params=sampling_params)
req.num_inference_steps = steps
return req
def test_generic_warmup_keeps_the_requested_steps():
warmup = _req(SamplingParams(prompt="p"), 50).copy_as_warmup(1)
assert warmup.num_inference_steps == 1
assert warmup.extra["warmup_target_num_inference_steps"] == 50
def test_h3_warmup_is_raised_to_its_floor():
assert MiniMaxH3SamplingParams.min_num_inference_steps == 2
warmup = _req(MiniMaxH3SamplingParams(prompt="p"), 50).copy_as_warmup(1)
assert warmup.num_inference_steps == 2
assert warmup.extra["warmup_target_num_inference_steps"] == 50
def test_explicit_steps_above_the_floor_are_kept():
warmup = _req(MiniMaxH3SamplingParams(prompt="p"), 50).copy_as_warmup(4)
assert warmup.num_inference_steps == 4
def _scheduler() -> Scheduler:
scheduler = Scheduler.__new__(Scheduler)
scheduler.metrics = None
scheduler.return_result = Mock()
scheduler._should_return_lightweight_warmup_result = lambda req: False
scheduler._warmup_total = 1
scheduler._warmup_processed = 0
scheduler._warmup_progress_bar = None
scheduler._show_warmup_progress = False
scheduler._logged_server_ready_after_warmup = False
return scheduler
def _request_warmup_req() -> Req:
req = _req(SamplingParams(prompt="p"), 50).copy_as_warmup(1)
req.request_id = "warmup-req"
return req
def _output(error=None) -> OutputBatch:
return OutputBatch(error=error, metrics=RequestMetrics("r"))
def test_failed_request_warmup_marks_only_the_next_request_cold():
scheduler = _scheduler()
scheduler._return_item_result((None, _request_warmup_req()), _output("boom"))
cold, later = _output(), _output()
scheduler._return_item_result((None, _req(SamplingParams(prompt="a"), 50)), cold)
scheduler._return_item_result((None, _req(SamplingParams(prompt="b"), 50)), later)
assert cold.metrics.warmup_failed is True
assert cold.metrics.to_dict()["warmup_failed"] is True
assert later.metrics.warmup_failed is False
def test_successful_request_warmup_leaves_the_request_warm():
scheduler = _scheduler()
scheduler._return_item_result((None, _request_warmup_req()), _output())
real = _output()
scheduler._return_item_result((None, _req(SamplingParams(prompt="a"), 50)), real)
assert real.metrics.warmup_failed is False
def _summary_log(caplog, warmup_failed: bool) -> list[logging.LogRecord]:
generator = DiffGenerator.__new__(DiffGenerator)
generator.server_args = SimpleNamespace(warmup_mode="request")
result = SimpleNamespace(
metrics={"total_duration_ms": 80_000.0, "warmup_failed": warmup_failed},
peak_memory_mb=None,
)
with caplog.at_level(logging.INFO):
generator._log_summary([result])
return caplog.records
def test_summary_does_not_claim_a_warm_timing_after_a_failed_warmup(caplog):
records = _summary_log(caplog, warmup_failed=True)
text = " ".join(r.getMessage() for r in records)
assert "ran cold" in text
assert "Warmed-up request processed" not in text
assert any(r.levelno == logging.WARNING for r in records)
def test_summary_reports_the_warm_timing_after_a_successful_warmup(caplog):
records = _summary_log(caplog, warmup_failed=False)
text = " ".join(r.getMessage() for r in records)
assert "Warmed-up request processed" in text
assert "ran cold" not in text