sgl-project/sglang · error · RuntimeError

RealESRGAN batch upscale did not produce all frames

Error message

RealESRGAN batch upscale did not produce all frames

What it means

RuntimeError raised by upscale_batched after processing resolution-grouped batches: at least one output slot is still None, meaning the underlying upscale_batch returned fewer outputs than input frames — an internal invariant violation, not user input error.

Source

Thrown at python/sglang/multimodal_gen/runtime/postprocess/realesrgan_upscaler.py:675

        output_frames: list[np.ndarray | None] = [None] * len(frames)
        groups: dict[tuple[int, ...], list[int]] = {}
        for idx, frame in enumerate(frames):
            groups.setdefault(tuple(frame.shape), []).append(idx)

        for shape, indices in groups.items():
            logger.info(
                "RealESRGAN upscale group: frames=%d shape=%s indices=%s",
                len(indices),
                shape,
                indices,
            )
            group_frames = [frames[idx] for idx in indices]
            group_outputs = model.upscale_batch(group_frames, outscale=outscale)
            for idx, output in zip(indices, group_outputs):
                output_frames[idx] = output

        if any(frame is None for frame in output_frames):
            raise RuntimeError("RealESRGAN batch upscale did not produce all frames")

        total_duration_s = time.perf_counter() - total_start_time
        logger.info(
            "RealESRGAN batch_upscale_frames completed in %.3f seconds for %d frames across %d groups",
            total_duration_s,
            len(frames),
            len(groups),
        )
        return [frame for frame in output_frames if frame is not None]


# ---------------------------------------------------------------------------
# HF download helper
# ---------------------------------------------------------------------------


def _resolve_model_path(model_path: str) -> str:
    """Return a local .pth file path.

View on GitHub (pinned to 0132848349)

Solutions

  1. Verify with a plain upscale_batch call on the same frames that outputs match input count
  2. Update sglang to pick up fixes to the batching wrapper
  3. File a bug with the frame group that produced the short output
Defensive patterns

Strategy: try-catch

Validate before calling

out = upscaler.upscale_batch(group)
assert len(out) == len(group)

Try / catch

try:
    frames = upscaler.upscale_batched(frames)
except RuntimeError as e:
    if "did not produce all frames" in str(e):
        return [upscaler.upscale(f) for f in frames]  # per-frame fallback
    raise

Prevention

When it happens

Trigger: Calling upscale_batched (via batch_upscale_frames) where model.upscale_batch for some group returns an empty or short list; typically a backend/model bug or an unexpected exception path that silently short-circuits a group.

Common situations: Custom monkeypatched or subclassed upscaler returning wrong-length lists; edge case with a single-frame group; version mismatch in the upscaler wrapper.

Related errors


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