{"record":{"id":"a803aca4a212acd1","repo":"Lightning-AI/pytorch-lightning","slug":"gpu-parallel-devices-set-through-self-strategy-f","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":"ValueError","httpStatus":null,"severity":"error","filePath":"src/lightning/fabric/connector.py","lineNumber":291,"sourceCode":"                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\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":273,"sourceCodeEnd":309,"githubUrl":"https://github.com/Lightning-AI/pytorch-lightning/blob/9fed5c27d2a62ff0efd6c3573599921d6ff67c14/src/lightning/fabric/connector.py#L273-L309","documentation":"The passed Strategy instance has `parallel_devices` whose first device is a CUDA torch.device, but the `accelerator=` flag was explicitly set to something other than \"auto\", \"cuda\", or \"gpu\" (e.g. \"cpu\" or \"tpu\"). The connector refuses contradictory device specifications.","triggerScenarios":"DDPStrategy(parallel_devices=[torch.device(\"cuda\", 0)]) with Fabric(strategy=strategy, accelerator=\"cpu\") — a GPU-configured strategy combined with a non-GPU accelerator flag.","commonSituations":"Forcing accelerator=\"cpu\" for debugging while the strategy was auto-built with CUDA devices; reusing a GPU strategy object in CPU-only tests; cluster scripts that override accelerator without rebuilding the strategy.","solutions":["Drop the accelerator flag (it will be inferred as \"cuda\" from parallel_devices)","Or set parallel_devices to CPU devices if you truly want CPU execution","Ensure the strategy object matches the target hardware when reusing configs"],"exampleFix":"# before\nstrategy = DDPStrategy(parallel_devices=[torch.device(\"cuda\", 0)])\nfabric = Fabric(strategy=strategy, accelerator=\"cpu\")\n\n# after\nstrategy = DDPStrategy(parallel_devices=[torch.device(\"cuda\", 0)])\nfabric = Fabric(strategy=strategy)","handlingStrategy":"validation","validationCode":"devs = getattr(strategy, \"parallel_devices\", None)\nif devs and devs[0].type == \"cuda\" and accelerator not in (None, \"auto\", \"cuda\", \"gpu\"):\n    raise SystemExit(f\"GPU parallel_devices conflict with accelerator={accelerator}\")","typeGuard":null,"tryCatchPattern":null,"preventionTips":["For CPU debug runs, rebuild the strategy with CPU parallel_devices instead of forcing accelerator=\"cpu\"","Derive the accelerator flag from the strategy's devices rather than hardcoding"],"tags":["lightning","fabric","strategy","accelerator","device-mismatch","gpu"],"backgroundTag":"device-type-mismatch","analyzedSha":"9fed5c27d2a62ff0efd6c3573599921d6ff67c14","analyzedAt":"2026-08-28T11:52:41.083Z","schemaVersion":2},"datasetVersion":"2026-08-28T16:17:29.566Z"}