{"record":{"id":"e4e5ba078cc3c9f0","repo":"Lightning-AI/pytorch-lightning","slug":"predict-returned-none-if-it-was-on-purpose-ignore","errorCode":null,"errorMessage":"predict returned None if it was on purpose, ignore this warning...","messagePattern":"predict returned None if it was on purpose, ignore this warning\\.\\.\\.","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"src/lightning/pytorch/loops/prediction_loop.py","lineNumber":257,"sourceCode":"\n        # the `_step` methods don't take a batch_idx when `dataloader_iter` is used, but all other hooks still do,\n        # so we need different kwargs\n        hook_kwargs = self._build_kwargs(batch, batch_idx, dataloader_idx if self.num_dataloaders > 1 else None)\n\n        call._call_callback_hooks(trainer, \"on_predict_batch_start\", *hook_kwargs.values())\n        call._call_lightning_module_hook(trainer, \"on_predict_batch_start\", *hook_kwargs.values())\n\n        self.batch_progress.increment_started()\n\n        # configure step_kwargs\n        step_args = (\n            self._build_step_args_from_hook_kwargs(hook_kwargs, \"predict_step\")\n            if not using_dataloader_iter\n            else (dataloader_iter,)\n        )\n        predictions = call._call_strategy_hook(trainer, \"predict_step\", *step_args)\n        if predictions is None:\n            self._warning_cache.warn(\"predict returned None if it was on purpose, ignore this warning...\")\n\n        self.batch_progress.increment_processed()\n\n        if using_dataloader_iter:\n            # update the hook kwargs now that the step method might have consumed the iterator\n            batch = data_fetcher._batch\n            batch_idx = data_fetcher._batch_idx\n            dataloader_idx = data_fetcher._dataloader_idx\n            hook_kwargs = self._build_kwargs(batch, batch_idx, dataloader_idx if self.num_dataloaders > 1 else None)\n\n        call._call_callback_hooks(trainer, \"on_predict_batch_end\", predictions, *hook_kwargs.values())\n        call._call_lightning_module_hook(trainer, \"on_predict_batch_end\", predictions, *hook_kwargs.values())\n\n        self.batch_progress.increment_completed()\n\n        if self._return_predictions or any_on_epoch:\n            self._predictions[dataloader_idx].append(move_data_to_device(predictions, torch.device(\"cpu\")))\n","sourceCodeStart":239,"sourceCodeEnd":275,"githubUrl":"https://github.com/Lightning-AI/pytorch-lightning/blob/9fed5c27d2a62ff0efd6c3573599921d6ff67c14/src/lightning/pytorch/loops/prediction_loop.py#L239-L275","documentation":"Prediction loop warns when the strategy's predict_step returns None for a batch — no predictions were stored for it. Usually means predict_step didn't return, or returned None via custom logic.","triggerScenarios":"LightningModule.predict_step without a return, or overriding predict_step to conditionally return None; also returning a tuple the framework doesn't recognize in older patterns.","commonSituations":"Writing predict_step for the first time and forgetting the return; custom nested inference logic that discards outputs.","solutions":["Return the predictions from predict_step (default implementation returns model(x), so only overrides hit this)","If None is intentional for some batches, ignore the warning","Verify you didn't shadow 'outputs' vs return"],"exampleFix":"# before\ndef predict_step(self, batch, i):\n    x = batch\n    self.model(x)  # forgot return\n# after\ndef predict_step(self, batch, i):\n    x = batch\n    return self.model(x)","handlingStrategy":"validation","validationCode":"out = model.predict_step(batch, 0)\nassert out is not None, 'predict_step returned None'","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Return predictions from predict_step overrides","Smoke-test predict_step with one batch before full runs"],"tags":["predict-step","inference","lightning"],"backgroundTag":"step-returned-none","analyzedSha":"9fed5c27d2a62ff0efd6c3573599921d6ff67c14","analyzedAt":"2026-08-28T11:52:41.083Z","schemaVersion":2},"datasetVersion":"2026-08-28T16:17:29.566Z"}