Lightning-AI/pytorch-lightning · error · TypeError

Expected a list as "videos", found {type(videos)}

Error message

Expected a list as "videos", found {type(videos)}

What it means

WandbLogger.log_video requires videos to be a Python list; each element is passed to wandb.Video with zipped per-item kwargs. A tensor, numpy array (even a single video), tuple, or path string raises TypeError.

Source

Thrown at src/lightning/pytorch/loggers/wandb.py:544

        metrics = {key: [wandb.Audio(audio, **kwarg) for audio, kwarg in zip(audios, kwarg_list)]}
        self.log_metrics(metrics, step)  # type: ignore[arg-type]

    @rank_zero_only
    def log_video(self, key: str, videos: list[Any], step: Optional[int] = None, **kwargs: Any) -> None:
        """Log videos (numpy arrays, or file paths).

        Args:
            key: The key to be used for logging the video files
            videos: The list of video file paths, or numpy arrays to be logged
            step: The step number to be used for logging the video files
            **kwargs: Optional kwargs are lists passed to each Wandb.Video instance (ex: caption, fps, format).

        Optional kwargs are lists passed to each video (ex: caption, fps, format).

        """
        if not isinstance(videos, list):
            raise TypeError(f'Expected a list as "videos", found {type(videos)}')
        n = len(videos)
        for k, v in kwargs.items():
            if len(v) != n:
                raise ValueError(f"Expected {n} items but only found {len(v)} for {k}")
        kwarg_list = [{k: kwargs[k][i] for k in kwargs} for i in range(n)]

        import wandb

        metrics = {key: [wandb.Video(video, **kwarg) for video, kwarg in zip(videos, kwarg_list)]}
        self.log_metrics(metrics, step)  # type: ignore[arg-type]

    @property
    @override
    def save_dir(self) -> Optional[str]:
        """Gets the save directory.

        Returns:
            The path to the save directory.

View on GitHub (pinned to 9fed5c27d2)

Solutions

  1. Wrap into a list: list(video_tensor)
  2. For a single video: logger.log_video([video], ...)
  3. For file paths pass a list of path strings

Example fix

# before
logger.log_video(video_batch_tensor)
# after
logger.log_video(list(video_batch_tensor))
Defensive patterns

Strategy: type-guard

Validate before calling

videos = [videos] if not isinstance(videos, list) else videos

Type guard

def is_video_list(x) -> bool:
    return isinstance(x, list)

Prevention

When it happens

Trigger: logger.log_image-style call with videos as a (B,T,C,H,W) torch tensor, a single numpy video, or a lone file path string.

Common situations: Logging a batch of generated video tensors directly; must split into per-video elements.

Related errors


AI-assisted analysis of Lightning-AI/pytorch-lightning@9fed5c27d2 (2026-08-28). Data as JSON: /api/errors/611844bc2e084f7f. Report an issue: GitHub.