{"record":{"id":"911734f7d1156835","repo":"Lightning-AI/pytorch-lightning","slug":"cpu-parallel-devices-set-through-self-strategy-f-911734","errorCode":null,"errorMessage":"CPU parallel_devices set through {self._strategy_flag.__class__.__name__} class, but accelerator set to {self._accelerator_flag}, please choose one device type","messagePattern":"CPU 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":298,"sourceCode":"                    raise MisconfigurationException(\"precision set through both strategy class and plugins, choose one\")\n                self._precision_plugin_flag = self._strategy_flag._precision_plugin\n            if self._strategy_flag._checkpoint_io:\n                if self.checkpoint_io:\n                    raise MisconfigurationException(\n                        \"checkpoint_io set through both strategy class and plugins, choose one\"\n                    )\n                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","sourceCodeStart":280,"sourceCodeEnd":316,"githubUrl":"https://github.com/Lightning-AI/pytorch-lightning/blob/9fed5c27d2a62ff0efd6c3573599921d6ff67c14/src/lightning/pytorch/trainer/connectors/accelerator_connector.py#L280-L316","documentation":"The passed strategy instance has CPU devices in parallel_devices, but the accelerator flag was set to a non-CPU accelerator (anything besides 'auto'/'cpu'). The connector refuses the CPU/GPU mismatch and asks you to pick one device type.","triggerScenarios":"DDPStrategy(parallel_devices=[torch.device('cpu')]*4) with Trainer(strategy=..., accelerator='gpu'). Also accelerator set to 'cuda', 'tpu', 'mps', etc.","commonSituations":"Hard-coded CPU device lists in shared strategy builders running on machines where accelerator='gpu' is the default; switching hardware without updating parallel_devices.","solutions":["Remove the accelerator= flag or set it to 'cpu' to match the CPU parallel_devices","Or set parallel_devices to actual cuda devices (torch.device('cuda', i)) when targeting GPU"],"exampleFix":"# before\nstrategy = DDPStrategy(parallel_devices=[torch.device(\"cpu\")] * 4)\ntrainer = Trainer(strategy=strategy, accelerator=\"gpu\")\n# after\nstrategy = DDPStrategy(parallel_devices=[torch.device(\"cpu\")] * 4)\ntrainer = Trainer(strategy=strategy, accelerator=\"cpu\")","handlingStrategy":"validation","validationCode":"if hasattr(strategy, \"parallel_devices\") and strategy.parallel_devices:\n    dev_type = strategy.parallel_devices[0].type\n    if dev_type == \"cpu\" and accelerator not in (None, \"auto\", \"cpu\"):\n        accelerator = \"cpu\"  # match devices, or fail fast with your own message","typeGuard":"def cpu_devices_accelerator_mismatch(strategy, accelerator) -> bool:\n    devs = getattr(strategy, \"parallel_devices\", None)\n    return bool(devs) and devs[0].type == \"cpu\" and accelerator not in (None, \"auto\", \"cpu\")","tryCatchPattern":null,"preventionTips":["Derive parallel_devices from torch.device('cuda', i) only when GPUs are actually available","Prefer auto devices and let Lightning pick, rather than hard-coding CPU device lists"],"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"}