Lightning-AI/pytorch-lightning · error · MisconfigurationException
`{self.__class__.__name__}` should have been `setup` with a
Error message
`{self.__class__.__name__}` should have been `setup` with a `CombinedLoader`. What it means
DataFetcher.combined_loader raises MisconfigurationException when its _combined_loader attribute is None, i.e. setup(combined_loader) was never called (or reset) before the property was accessed. The fetcher must be set up by the training/eval loop before iteration.
Source
Thrown at src/lightning/pytorch/loops/fetchers.py:42
def _profile_nothing() -> None:
pass
class _DataFetcher(Iterator):
def __init__(self) -> None:
self._combined_loader: Optional[CombinedLoader] = None
self.iterator: Optional[Iterator] = None
self.fetched: int = 0
self.done: bool = False
self.length: Optional[int] = None
self._start_profiler = _profile_nothing
self._stop_profiler = _profile_nothing
@property
def combined_loader(self) -> CombinedLoader:
if self._combined_loader is None:
raise MisconfigurationException(
f"`{self.__class__.__name__}` should have been `setup` with a `CombinedLoader`."
)
return self._combined_loader
def setup(self, combined_loader: CombinedLoader) -> None:
self._combined_loader = combined_loader
@override
def __iter__(self) -> "_DataFetcher":
self.iterator = iter(self.combined_loader)
self.reset()
return self
@override
def __next__(self) -> _ITERATOR_RETURN:
assert self.iterator is not None
self._start_profiler()
try:View on GitHub (pinned to 9fed5c27d2)
Solutions
- Call fetcher.setup(CombinedLoader(dataloaders)) before accessing combined_loader
- Let the Trainer own fetcher setup — don't access it before trainer.state is RUNNING
- If writing a custom loop, mirror the setup order used in lightning's fit_loop
Example fix
# before fetcher = _DataFetcher() cl = fetcher.combined_loader # raises # after from lightning.pytorch.loops.utilities import _DataFetcher from lightning.pytorch.overrides.distributed import CombinedLoader # illustrative fetcher.setup(CombinedLoader(dataloader)) cl = fetcher.combined_loader
Defensive patterns
Strategy: validation
Validate before calling
if fetcher._combined_loader is None:
fetcher.setup(CombinedLoader(train_dataloader)) Prevention
- Don't touch loop internals before trainer.fit/validate has started setup
- In custom loops, always call setup() on fetchers before reading combined_loader
When it happens
Trigger: Accessing fetcher.combined_loader on a freshly constructed _DataFetcher (or after resetting) without calling fetcher.setup(loader); typically from custom loop code that subclasses or drives the fetcher manually.
Common situations: Custom training loops or tests that instantiate a fetcher and skip the Trainer's setup sequence; also calling internal loop APIs outside a running fit/validate.
Related errors
- No models were set up for backward. Did you forget to call `
- You need to set up the model first before you can call `fabr
- f"`{hook_name}` is not a shared hook within `LightningModule
- Received multiple values for {', '.join(duplicated_plugin_ke
- Received both `precision={precision_input}` and `plugins={se
AI-assisted analysis of Lightning-AI/pytorch-lightning@9fed5c27d2 (2026-08-28).
Data as JSON: /api/errors/b2e7cb0575bca496.
Report an issue: GitHub.