{"record":{"id":"480554fc94931ca7","repo":"Lightning-AI/pytorch-lightning","slug":"datafetcher-is-unsupported-for-trainer-state-stag","errorCode":null,"errorMessage":"DataFetcher is unsupported for {trainer.state.stage}","messagePattern":"DataFetcher is unsupported for (.+?)","errorType":"exception","errorClass":"RuntimeError","httpStatus":null,"severity":"error","filePath":"src/lightning/pytorch/loops/utilities.py","lineNumber":146,"sourceCode":"    for v in vars(loop).values():\n        if isinstance(v, _BaseProgress):\n            v.reset()\n        elif isinstance(v, _Loop):\n            _reset_progress(v)\n\n\ndef _select_data_fetcher(trainer: \"pl.Trainer\", stage: RunningStage) -> _DataFetcher:\n    lightning_module = trainer.lightning_module\n    if stage == RunningStage.TESTING:\n        step_fx_name = \"test_step\"\n    elif stage == RunningStage.TRAINING:\n        step_fx_name = \"training_step\"\n    elif stage in (RunningStage.VALIDATING, RunningStage.SANITY_CHECKING):\n        step_fx_name = \"validation_step\"\n    elif stage == RunningStage.PREDICTING:\n        step_fx_name = \"predict_step\"\n    else:\n        raise RuntimeError(f\"DataFetcher is unsupported for {trainer.state.stage}\")\n    step_fx = getattr(lightning_module, step_fx_name)\n    if is_param_in_hook_signature(step_fx, \"dataloader_iter\", explicit=True):\n        rank_zero_warn(\n            f\"Found `dataloader_iter` argument in the `{step_fx_name}`. Note that the support for \"\n            \"this signature is experimental and the behavior is subject to change.\"\n        )\n        return _DataLoaderIterDataFetcher()\n    return _PrefetchDataFetcher()\n\n\ndef _no_grad_context(loop_run: Callable) -> Callable:\n    def _decorator(self: _Loop, *args: Any, **kwargs: Any) -> Any:\n        if not isinstance(self, _Loop):\n            raise TypeError(f\"`{type(self).__name__}` needs to be a Loop.\")\n        if not hasattr(self, \"inference_mode\"):\n            raise TypeError(f\"`{type(self).__name__}.inference_mode` needs to be defined\")\n        context_manager: type[AbstractContextManager]\n        if _distributed_is_initialized() and dist.get_backend() == \"gloo\":","sourceCodeStart":128,"sourceCodeEnd":164,"githubUrl":"https://github.com/Lightning-AI/pytorch-lightning/blob/9fed5c27d2a62ff0efd6c3573599921d6ff67c14/src/lightning/pytorch/loops/utilities.py#L128-L164","documentation":"Raised by _select_data_fetcher when the current trainer running stage is not one of TRAINING, VALIDATING, SANITY_CHECKING, or PREDICTING. The data fetcher must be chosen based on the step function name for a known stage; an unrecognized/None stage (e.g. testing or an unset state) cannot be mapped to a step hook.","triggerScenarios":"Internal/library misuse such as invoking a loop's reset/setup_data while trainer.state.stage is None or TESTING; custom loops running outside the four supported stages; calling internal loop APIs directly instead of via trainer.fit/validate/predict.","commonSituations":"Subclassing Lightning loops or calling private APIs in plugins/callbacks; version mismatches between lightning core and a plugin expecting different stage enumeration.","solutions":["Use the public entry points trainer.fit/validate/predict rather than driving loops manually","If writing a custom loop, set trainer.state.stage to a supported RunningStage before data setup","Align lightning package versions (pip check; reinstall matching versions)"],"exampleFix":null,"handlingStrategy":"validation","validationCode":"from lightning.pytorch.trainer.states import RunningStage\nassert trainer.state.stage in (\n    RunningStage.TRAINING, RunningStage.VALIDATING,\n    RunningStage.SANITY_CHECKING, RunningStage.PREDICTING,\n), f'unsupported stage {trainer.state.stage}'","typeGuard":"def stage_supported(stage) -> bool:\n    return stage in {RunningStage.TRAINING, RunningStage.VALIDATING, RunningStage.SANITY_CHECKING, RunningStage.PREDICTING}","tryCatchPattern":null,"preventionTips":["Drive training/evaluation through public Trainer APIs rather than loop internals","Pin matching lightning package versions in your environment"],"tags":["pytorch-lightning","internal","running-stage","data-fetcher"],"backgroundTag":"invalid-library-internal-state","analyzedSha":"9fed5c27d2a62ff0efd6c3573599921d6ff67c14","analyzedAt":"2026-08-28T11:52:41.083Z","schemaVersion":2},"datasetVersion":"2026-08-28T16:17:29.566Z"}