{"record":{"id":"ede0cba98d36ff17","repo":"Lightning-AI/pytorch-lightning","slug":"cpu-parallel-devices-set-through-self-strategy-f","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":"ValueError","httpStatus":null,"severity":"error","filePath":"src/lightning/fabric/connector.py","lineNumber":284,"sourceCode":"                self._accelerator_flag = self._strategy_flag._accelerator\n            if self._strategy_flag._precision:\n                # [RFC] handle precision plugin set up conflict?\n                if self._precision_instance:\n                    raise ValueError(\"precision set through both strategy class and plugins, choose one\")\n                self._precision_instance = self._strategy_flag._precision\n            if self._strategy_flag._checkpoint_io:\n                if self.checkpoint_io:\n                    raise ValueError(\"checkpoint_io set through both strategy class and plugins, choose one\")\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 ValueError(\"cluster_environment set through both strategy class and plugins, choose one\")\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 ValueError(\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 ValueError(\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":266,"sourceCodeEnd":302,"githubUrl":"https://github.com/Lightning-AI/pytorch-lightning/blob/9fed5c27d2a62ff0efd6c3573599921d6ff67c14/src/lightning/fabric/connector.py#L266-L302","documentation":"The passed Strategy instance (e.g. DDPStrategy) has `parallel_devices` whose first device is a CPU torch.device, but the `accelerator=` flag was explicitly set to something other than \"auto\"/\"cpu\" (typically \"gpu\"/\"cuda\"). Fabric detects a device-type contradiction and refuses to continue.","triggerScenarios":"DDPStrategy(parallel_devices=[torch.device(\"cpu\")]*4) with Fabric(strategy=strategy, accelerator=\"gpu\") — or reusing a CPU-configured strategy object with accelerator=\"cuda\".","commonSituations":"Reusing a strategy built on a CPU-only machine or in a test on a GPU box; setting accelerator=\"gpu\" while parallel_devices defaults to CPU devices because GPUs weren't visible (CUDA_VISIBLE_DEVICES empty); copy-pasted strategy configs across environments.","solutions":["Remove the explicit accelerator flag and let the strategy's parallel_devices decide (it will be set to \"cpu\")","Or fix parallel_devices to match: parallel_devices=[torch.device(\"cuda\", i) for i in range(...)] when accelerator is gpu","Check CUDA_VISIBLE_DEVICES / GPU availability if you expected GPU devices in the strategy"],"exampleFix":"# before\nstrategy = DDPStrategy(parallel_devices=[torch.device(\"cpu\")] * 4)\nfabric = Fabric(strategy=strategy, accelerator=\"gpu\")\n\n# after\nstrategy = DDPStrategy(parallel_devices=[torch.device(\"cuda\", i) for i in range(4)])\nfabric = Fabric(strategy=strategy, accelerator=\"gpu\")","handlingStrategy":"validation","validationCode":"devs = getattr(strategy, \"parallel_devices\", None)\nif devs and devs[0].type == \"cpu\" and accelerator not in (None, \"auto\", \"cpu\"):\n    raise SystemExit(f\"CPU parallel_devices conflict with accelerator={accelerator}\")","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Check torch.cuda.is_available() and CUDA_VISIBLE_DEVICES before building CPU-strategies on GPU nodes","Never hardcode accelerator when a strategy pins parallel_devices"],"tags":["lightning","fabric","strategy","accelerator","device-mismatch","cpu"],"backgroundTag":"device-type-mismatch","analyzedSha":"9fed5c27d2a62ff0efd6c3573599921d6ff67c14","analyzedAt":"2026-08-28T11:52:41.083Z","schemaVersion":2},"datasetVersion":"2026-08-28T16:17:29.566Z"}