{"record":{"id":"d97c2644fe80d26d","repo":"Lightning-AI/pytorch-lightning","slug":"trainer-predict-only-supports-the-combinedloa","errorCode":null,"errorMessage":"`trainer.predict()` only supports the `CombinedLoader(mode=\"sequential\")` mode.","messagePattern":"`trainer\\.predict\\(\\)` only supports the `CombinedLoader\\(mode=\"sequential\"\\)` mode\\.","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"src/lightning/pytorch/loops/prediction_loop.py","lineNumber":177,"sourceCode":"            dataloaders.append(dl)\n\n            # determine number of batches\n            length = len(dl) if has_len_all_ranks(dl, trainer.strategy, allow_zero_length) else float(\"inf\")\n            num_batches = _parse_num_batches(stage, length, trainer.limit_predict_batches)\n            self.max_batches.append(num_batches)\n        combined_loader.flattened = dataloaders\n        self._combined_loader = combined_loader\n\n    def reset(self) -> None:\n        \"\"\"Resets the internal state of the loop for a new run.\"\"\"\n        self.batch_progress.reset_on_run()\n\n        assert self.trainer.state.stage is not None\n        data_fetcher = _select_data_fetcher(self.trainer, self.trainer.state.stage)\n        combined_loader = self._combined_loader\n        assert combined_loader is not None\n        if combined_loader._mode != \"sequential\":\n            raise ValueError('`trainer.predict()` only supports the `CombinedLoader(mode=\"sequential\")` mode.')\n\n        # set the per-dataloader limits\n        combined_loader.limits = self.max_batches\n        data_fetcher.setup(combined_loader)\n        iter(data_fetcher)  # creates the iterator inside the fetcher\n\n        # add the previous `fetched` value to properly track `is_last_batch` with no prefetching\n        data_fetcher.fetched += self.batch_progress.current.ready\n        data_fetcher._start_profiler = self._on_before_fetch\n        data_fetcher._stop_profiler = self._on_after_fetch\n        self._data_fetcher = data_fetcher\n\n        num_dataloaders = self.num_dataloaders\n        self.epoch_batch_indices = [[] for _ in range(num_dataloaders)]\n        self._predictions = [[] for _ in range(num_dataloaders)]\n\n    def on_run_start(self) -> None:\n        \"\"\"Calls ``_on_predict_model_eval``, ``_on_predict_start`` and ``_on_predict_epoch_start`` hooks.\"\"\"","sourceCodeStart":159,"sourceCodeEnd":195,"githubUrl":"https://github.com/Lightning-AI/pytorch-lightning/blob/9fed5c27d2a62ff0efd6c3573599921d6ff67c14/src/lightning/pytorch/loops/prediction_loop.py#L159-L195","documentation":"Raised by _PredictionLoop.reset when the CombinedLoader used for prediction was created with any mode other than 'sequential'. Unlike training, prediction iterates each dataloader fully and independently, so only the sequential mode (run loaders one after another) is supported by trainer.predict.","triggerScenarios":"Passing multiple dataloaders to `trainer.predict(model, dataloaders=[dl1, dl2])` where the resulting CombinedLoader uses 'max_size'/'min_size'/'max_size_cycle'; constructing a CombinedLoader manually with a cycling mode and handing it to predict.","commonSituations":"Reusing a multi-loader configuration built for training (cycling modes) at inference time; assuming symmetric mode support between fit and predict.","solutions":["Use `CombinedLoader(dataloaders, mode='sequential')` for prediction","Or call trainer.predict once per dataloader in a loop instead of combining them"],"exampleFix":"# before\nloader = CombinedLoader([dl1, dl2], mode='max_size_cycle')\ntrainer.predict(model, loader)\n\n# after\nloader = CombinedLoader([dl1, dl2], mode='sequential')\ntrainer.predict(model, loader)","handlingStrategy":"validation","validationCode":"assert combined_loader._mode == 'sequential', 'trainer.predict requires sequential mode'","typeGuard":"def is_sequential(cl) -> bool:\n    return getattr(cl, '_mode', None) == 'sequential'","tryCatchPattern":null,"preventionTips":["Use sequential CombinedLoader mode for prediction, cycling modes for training","Or loop trainer.predict over individual dataloaders"],"tags":["pytorch-lightning","predict","combined-loader","multi-dataloader"],"backgroundTag":"unsupported-loader-mode","analyzedSha":"9fed5c27d2a62ff0efd6c3573599921d6ff67c14","analyzedAt":"2026-08-28T11:52:41.083Z","schemaVersion":2},"datasetVersion":"2026-08-28T16:17:29.566Z"}