sgl-project/sglang · error · ValueError
All frames in a batch must have the same resolution
Error message
All frames in a batch must have the same resolution
What it means
Raised by RealESRGANUpscaler.upscale_batch when frames passed in one batch do not all share the same (H, W), since the implementation stacks them into a single numpy array for one batched forward pass.
Source
Thrown at python/sglang/multimodal_gen/runtime/postprocess/realesrgan_upscaler.py:456
target_h = int(h * outscale)
target_w = int(w * outscale)
out = F.interpolate(
out, size=(target_h, target_w), mode="bicubic", align_corners=False
)
out_np = out.squeeze(0).permute(1, 2, 0).clamp(0.0, 1.0).cpu().numpy()
return (out_np * 255.0).astype(np.uint8)
def upscale_batch(
self, frames: list[np.ndarray], outscale: float | None = None
) -> list[np.ndarray]:
"""Upscale same-resolution HWC uint8 frames in one batched forward pass."""
if not frames:
return []
h, w = frames[0].shape[:2]
if any(frame.shape[:2] != (h, w) for frame in frames):
raise ValueError("All frames in a batch must have the same resolution")
total_start_time = time.perf_counter()
start_time = time.perf_counter()
imgs = np.stack(frames, axis=0)
stack_duration_s = time.perf_counter() - start_time
start_time = time.perf_counter()
h2d_timer = self._start_cuda_timer()
imgs_t = self._copy_input_to_device(imgs)
self._stop_cuda_timer(h2d_timer)
h2d_wall_duration_s = time.perf_counter() - start_time
start_time = time.perf_counter()
input_preprocess_timer = self._start_cuda_timer()
imgs_t = self._preprocess_input_tensor(imgs_t)
self._stop_cuda_timer(input_preprocess_timer)
input_preprocess_wall_duration_s = time.perf_counter() - start_timeView on GitHub (pinned to 0132848349)
Solutions
- Resize/pad all frames to a common resolution before batching
- Group frames by resolution and call upscale_batch once per group
Example fix
# before outs = upscaler.upscale_batch([f1080, f720]) # after from torchvision.transforms import functional as F frames = [cv2.resize(f, (W, H)) for f in frames] outs = upscaler.upscale_batch(frames)
Defensive patterns
Strategy: validation
Validate before calling
from itertools import groupby
frames.sort(key=lambda f: f.shape[:2]) # or group explicitly
shapes = {f.shape[:2] for f in frames}
assert len(shapes) <= 1 or batched_per_group, "mixed resolutions" Type guard
def frames_uniform(frames: list) -> bool:
return all(f.shape[:2] == frames[0].shape[:2] for f in frames) Prevention
- Normalize frame resolution upstream in the video pipeline
- Group frames by resolution before calling upscale_batch
When it happens
Trigger: Calling upscale_batch (or upscale_batched which groups frames) with a list containing frames of differing resolutions, e.g. mixing 1080p and 720p frames or portrait/landscape variants.
Common situations: Feeding raw video frames without normalization; mixing images from mixed sources; upstream crop/reszie step skipped.
Related errors
- RealESRGAN batch upscale did not produce all frames
- Unsupported activation type: {act_type}
- Unsupported RRDBNet conv_first input channels: {in_channels}
- Failed to load Real-ESRGAN checkpoint from '{resolved_path}'
- Real-ESRGAN weight file '{resolved_path}' is not compatible
AI-assisted analysis of sgl-project/sglang@0132848349 (2026-08-28).
Data as JSON: /api/errors/1afdb5e8177ab403.
Report an issue: GitHub.