Lightning-AI/pytorch-lightning · error · ValueError

Unsupported mode {mode!r}, please select one of: {list(_SUPP

Error message

Unsupported mode {mode!r}, please select one of: {list(_SUPPORTED_MODES)}.

What it means

CombinedLoader only supports specific combination modes (min_size, max_size_cycle, etc.). Constructing it with an unknown mode string raises ValueError listing the supported modes.

Source

Thrown at src/lightning/pytorch/utilities/combined_loader.py:286

        {'a': tensor([4, 5]), 'b': tensor([5, 6, 7, 8, 9])}, batch_idx=1, dataloader_idx=0

        >>> combined_loader = CombinedLoader(iterables, 'sequential')
        >>> _ = iter(combined_loader)
        >>> len(combined_loader)
        5
        >>> for batch, batch_idx, dataloader_idx in combined_loader:
        ...     print(f"{batch}, {batch_idx=}, {dataloader_idx=}")
        tensor([0, 1, 2, 3]), batch_idx=0, dataloader_idx=0
        tensor([4, 5]), batch_idx=1, dataloader_idx=0
        tensor([0, 1, 2, 3, 4]), batch_idx=0, dataloader_idx=1
        tensor([5, 6, 7, 8, 9]), batch_idx=1, dataloader_idx=1
        tensor([10, 11, 12, 13, 14]), batch_idx=2, dataloader_idx=1

    """

    def __init__(self, iterables: Any, mode: _LITERAL_SUPPORTED_MODES = "min_size") -> None:
        if mode not in _SUPPORTED_MODES:
            raise ValueError(f"Unsupported mode {mode!r}, please select one of: {list(_SUPPORTED_MODES)}.")
        self._iterables = iterables
        self._flattened, self._spec = _tree_flatten(iterables)
        self._mode = mode
        self._iterator: Optional[_ModeIterator] = None
        self._limits: Optional[list[Union[int, float]]] = None

    @property
    def iterables(self) -> Any:
        """Return the original collection of iterables."""
        return self._iterables

    @property
    def sampler(self) -> Any:
        """Return a collections of samplers extracted from iterables."""
        return _map_and_unflatten(lambda x: getattr(x, "sampler", None), self.flattened, self._spec)

    @property
    def batch_sampler(self) -> Any:

View on GitHub (pinned to 9fed5c27d2)

Solutions

  1. Use an exact supported mode string, e.g. 'min_size' or 'max_size_cycle'
  2. Print/list _SUPPORTED_MODES keys for your installed version to see valid names

Example fix

# before
cl = CombinedLoader([dl1, dl2], mode="max_size")
# after
cl = CombinedLoader([dl1, dl2], mode="max_size_cycle")
Defensive patterns

Strategy: type-guard

Validate before calling

from lightning.pytorch.utilities.combined_loader import _SUPPORTED_MODES
assert mode in _SUPPORTED_MODES, f"use one of {list(_SUPPORTED_MODES)}"

Type guard

from typing import Literal
SupportedMode = Literal["min_size", "max_size_cycle", "max_size", "permissive"]
def is_supported_mode(m: str) -> bool:
    from lightning.pytorch.utilities.combined_loader import _SUPPORTED_MODES
    return m in _SUPPORTED_MODES

Prevention

When it happens

Trigger: CombinedLoader([dl1, dl2], mode='max_size') or any mode not in _SUPPORTED_MODES (typos, outdated names).

Common situations: Using a mode name from an old version or inventing one; 'max_size' instead of 'max_size_cycle'.

Understand the failure class

Background: "Must be a positive integer", "Invalid value", "Unsupported": the invalid-argument-value error family, when a library rejects the value you pass — this error's family across 35 libraries.

Related errors


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