{"record":{"id":"3699dc2f8926226a","repo":"Lightning-AI/pytorch-lightning","slug":"gpu-parallel-devices-set-through-self-strategy-f-3699dc","errorCode":null,"errorMessage":"GPU parallel_devices set through {self._strategy_flag.__class__.__name__} class, but accelerator set to {self._accelerator_flag}, please choose one device type","messagePattern":"GPU parallel_devices set through (.+?) class, but accelerator set to (.+?), please choose one device type","errorType":"validation","errorClass":"MisconfigurationException","httpStatus":null,"severity":"error","filePath":"src/lightning/pytorch/trainer/connectors/accelerator_connector.py","lineNumber":305,"sourceCode":"                self.checkpoint_io = self._strategy_flag._checkpoint_io\n            if getattr(self._strategy_flag, \"cluster_environment\", None):\n                if self._cluster_environment_flag:\n                    raise MisconfigurationException(\n                        \"cluster_environment set through both strategy class and plugins, choose one\"\n                    )\n                self._cluster_environment_flag = getattr(self._strategy_flag, \"cluster_environment\")\n\n            if hasattr(self._strategy_flag, \"parallel_devices\") and self._strategy_flag.parallel_devices:\n                if self._strategy_flag.parallel_devices[0].type == \"cpu\":\n                    if self._accelerator_flag and self._accelerator_flag not in (\"auto\", \"cpu\"):\n                        raise MisconfigurationException(\n                            f\"CPU parallel_devices set through {self._strategy_flag.__class__.__name__} class,\"\n                            f\" but accelerator set to {self._accelerator_flag}, please choose one device type\"\n                        )\n                    self._accelerator_flag = \"cpu\"\n                if self._strategy_flag.parallel_devices[0].type == \"cuda\":\n                    if self._accelerator_flag and self._accelerator_flag not in (\"auto\", \"cuda\", \"gpu\"):\n                        raise MisconfigurationException(\n                            f\"GPU parallel_devices set through {self._strategy_flag.__class__.__name__} class,\"\n                            f\" but accelerator set to {self._accelerator_flag}, please choose one device type\"\n                        )\n                    self._accelerator_flag = \"cuda\"\n                self._parallel_devices = self._strategy_flag.parallel_devices\n\n    def _check_device_config_and_set_final_flags(self, devices: Union[list[int], str, int], num_nodes: int) -> None:\n        if not isinstance(num_nodes, int) or num_nodes < 1:\n            raise ValueError(f\"`num_nodes` must be a positive integer, but got {num_nodes}.\")\n\n        self._num_nodes_flag = num_nodes\n        self._devices_flag = devices\n\n        if self._devices_flag in ([], 0, \"0\"):\n            accelerator_name = (\n                self._accelerator_flag.__class__.__qualname__\n                if isinstance(self._accelerator_flag, Accelerator)\n                else self._accelerator_flag","sourceCodeStart":287,"sourceCodeEnd":323,"githubUrl":"https://github.com/Lightning-AI/pytorch-lightning/blob/9fed5c27d2a62ff0efd6c3573599921d6ff67c14/src/lightning/pytorch/trainer/connectors/accelerator_connector.py#L287-L323","documentation":"The strategy instance lists CUDA devices in parallel_devices but the accelerator flag names a non-GPU accelerator (not 'auto'/'cuda'/'gpu'). The connector detects the contradiction between devices and accelerator.","triggerScenarios":"DDPStrategy(parallel_devices=[torch.device('cuda', i) for i in range(2)]) with Trainer(strategy=..., accelerator='cpu') or 'mps'/'tpu'.","commonSituations":"Defaulting accelerator='cpu' in configs while a strategy factory injects CUDA devices; running GPU-oriented configs on mismatched accelerator settings.","solutions":["Remove the explicit accelerator= flag (auto-detection will resolve to cuda)","Or align accelerator with the devices: 'cuda'/'gpu' for CUDA parallel_devices"],"exampleFix":"# before\nstrategy = DDPStrategy(parallel_devices=[torch.device(\"cuda\", 0)])\ntrainer = Trainer(strategy=strategy, accelerator=\"cpu\")\n# after\nstrategy = DDPStrategy(parallel_devices=[torch.device(\"cuda\", 0)])\ntrainer = Trainer(strategy=strategy)","handlingStrategy":"validation","validationCode":"if hasattr(strategy, \"parallel_devices\") and strategy.parallel_devices:\n    dev_type = strategy.parallel_devices[0].type\n    if dev_type == \"cuda\" and accelerator not in (None, \"auto\", \"cuda\", \"gpu\"):\n        accelerator = \"auto\"","typeGuard":"def gpu_devices_accelerator_mismatch(strategy, accelerator) -> bool:\n    devs = getattr(strategy, \"parallel_devices\", None)\n    return bool(devs) and devs[0].type == \"cuda\" and accelerator not in (None, \"auto\", \"cuda\", \"gpu\")","tryCatchPattern":null,"preventionTips":["Do not default accelerator='cpu' in shared configs that may run on GPU nodes","Build parallel_devices from the same availability check that decides the accelerator flag"],"tags":["pytorch-lightning","strategy","parallel-devices","device-mismatch"],"backgroundTag":"device-type-mismatch","analyzedSha":"9fed5c27d2a62ff0efd6c3573599921d6ff67c14","analyzedAt":"2026-08-28T11:52:41.083Z","schemaVersion":2},"datasetVersion":"2026-08-28T16:17:29.566Z"}