sgl-project/sglang · error · ValueError

Cosmos3 I2V image list is empty

Error message

Cosmos3 I2V image list is empty

What it means

Cosmos3 I2V mode builds a batch of conditioning images from image_path, but after normalization the source list is empty (e.g. image_path == []). Rather than stacking a zero-size tensor, the stage fails fast.

Source

Thrown at python/sglang/multimodal_gen/runtime/pipelines_core/stages/model_specific_stages/cosmos3.py:185

        if isinstance(video_path, list):
            video_path = video_path[0] if video_path else None

        if image_path and video_path:
            raise ValueError(
                "Cosmos3 accepts either --image-path (I2V) or --video-path "
                "(V2V), not both"
            )

        target_h, target_w = batch.height, batch.width

        if image_path is not None:
            image_sources = (
                list(image_path)
                if isinstance(image_path, (list, tuple))
                else [image_path]
            )
            if not image_sources:
                raise ValueError("Cosmos3 I2V image list is empty")
            tensors: list[torch.Tensor] = []
            for src in image_sources:
                image = load_image(src)
                image = _resize_crop_pil(image, target_w, target_h)
                tensors.append(_pil_to_normalized_tensor(image))
            batch.preprocessed_image = torch.stack(tensors, dim=0).contiguous()
            self.log_info(
                f"Preprocessed {len(tensors)} conditioning image(s) to "
                f"{target_w}x{target_h}"
            )
            return batch

        if isinstance(video_path, str) and video_path:
            frames = load_video(video_path)
            if not frames:
                raise ValueError(f"No frames decoded from video: {video_path!r}")

            keep = (

View on GitHub (pinned to 0132848349)

Solutions

  1. Pass at least one valid image path: image_path=["frame.jpg"] or image_path="frame.jpg"
  2. If images are optional for your flow, omit image_path entirely instead of sending []
  3. Fix upstream list construction (glob filters, dataset splits) that can yield zero entries

Example fix

# before
req = {"image_path": [], "prompt": "..."}
# after
req = {"image_path": ["input/frame.jpg"], "prompt": "..."}
Defensive patterns

Strategy: validation

Validate before calling

imgs = req.get("image_path") or []
imgs = [imgs] if isinstance(imgs, str) else list(imgs)
assert imgs, "I2V requires at least one image"

Type guard

def nonempty_image_list(image_path) -> bool:
    if image_path is None: return False
    items = [image_path] if isinstance(image_path, str) else list(image_path)
    return len(items) > 0 and all(items)

Prevention

When it happens

Trigger: Passing image_path as an empty list (or a list containing only falsy entries) while not in action-policy mode, so image_sources ends up empty in the I2V branch.

Common situations: Programmatic clients building image lists from glob/dataset iteration that return zero matches; a UI sending [] when no image is selected; default mutable argument leaking an empty list.

Related errors


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