sgl-project/sglang · critical · RuntimeError

Expected {len(reqs)} grouped outputs, got {len(output_batch.

Error message

Expected {len(reqs)} grouped outputs, got {len(output_batch.output)}

What it means

Before saving grouped outputs, the worker asserts that the OutputBatch's output list length equals the number of requests in the batch; a mismatch means the pipeline silently lost or duplicated outputs, so saving would misattribute files and the run aborts.

Source

Thrown at python/sglang/multimodal_gen/runtime/managers/gpu_worker.py:823

            output_compression=req.output_compression,
            enable_frame_interpolation=req.enable_frame_interpolation,
            frame_interpolation_exp=req.frame_interpolation_exp,
            frame_interpolation_scale=req.frame_interpolation_scale,
            frame_interpolation_model_path=req.frame_interpolation_model_path,
            enable_upscaling=req.enable_upscaling,
            upscaling_model_path=req.upscaling_model_path,
            upscaling_scale=req.upscaling_scale,
        )

    def _save_group_output_paths(
        self,
        reqs: list[Req],
        output_batch: OutputBatch,
    ) -> None:
        if not self.is_output_rank or output_batch.output is None:
            return
        if len(output_batch.output) != len(reqs):
            raise RuntimeError(
                f"Expected {len(reqs)} grouped outputs, got {len(output_batch.output)}"
            )

        first_req = reqs[0]
        output_batch.output_file_paths = save_outputs(
            output_batch.output,
            first_req.data_type,
            first_req.fps,
            True,
            lambda idx: reqs[idx].output_file_path(1, 0),
            audio=output_batch.audio,
            audio_sample_rate=output_batch.audio_sample_rate,
            output_compression=first_req.output_compression,
            enable_frame_interpolation=first_req.enable_frame_interpolation,
            frame_interpolation_exp=first_req.frame_interpolation_exp,
            frame_interpolation_scale=first_req.frame_interpolation_scale,
            frame_interpolation_model_path=first_req.frame_interpolation_model_path,
            enable_upscaling=first_req.enable_upscaling,

View on GitHub (pinned to 0132848349)

Solutions

  1. Inspect logs for the preceding pipeline exception or drop point; this check is the symptom, not the cause
  2. Reduce the batch size or disable grouping to isolate the request that gets dropped
  3. Check for version mismatch between the pipeline implementation and gpu_worker after upgrading sglang
  4. File an issue with the exact request batch that reproduces the count mismatch
Defensive patterns

Strategy: try-catch

Try / catch

try:
    worker._execute_forward_batch(batch)
except RuntimeError as e:
    if "grouped outputs" in str(e):
        log_and_alert("output/req count mismatch", batch_ids=batch.ids)
        raise

Prevention

When it happens

Trigger: _execute_forward_batch reaching _save_group_output_paths with len(output_batch.output) != len(reqs) on the output rank (e.g. 3 requests but only 2 generated outputs).

Common situations: Same root causes as the StopIteration wrapper: a pipeline stage dropping items, or output filtering (e.g. empty results removed) applied before this check; reproducible with specific grouped request mixes.

Related errors


AI-assisted analysis of sgl-project/sglang@0132848349 (2026-08-28). Data as JSON: /api/errors/0099ec35b5510c50. Report an issue: GitHub.