{"record":{"id":"e0032425c6c5915d","repo":"Lightning-AI/pytorch-lightning","slug":"trainer-devices-self-devices-flag-r-value-is","errorCode":null,"errorMessage":"`Trainer(devices={self._devices_flag!r})` value is not a valid input using {accelerator_name} accelerator.","messagePattern":"`Trainer\\(devices=(.+?)\\)` value is not a valid input using (.+?) accelerator\\.","errorType":"validation","errorClass":"MisconfigurationException","httpStatus":null,"severity":"error","filePath":"src/lightning/pytorch/trainer/connectors/accelerator_connector.py","lineNumber":325,"sourceCode":"                            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\n            )\n            raise MisconfigurationException(\n                f\"`Trainer(devices={self._devices_flag!r})` value is not a valid input\"\n                f\" using {accelerator_name} accelerator.\"\n            )\n\n    @staticmethod\n    def _choose_auto_accelerator() -> str:\n        \"\"\"Choose the accelerator type (str) based on availability.\"\"\"\n        return _select_auto_accelerator()\n\n    @staticmethod\n    def _choose_gpu_accelerator_backend() -> str:\n        if MPSAccelerator.is_available():\n            return \"mps\"\n        if CUDAAccelerator.is_available():\n            return \"cuda\"\n        raise MisconfigurationException(\"No supported gpu backend found!\")\n\n    def _set_parallel_devices_and_init_accelerator(self) -> None:","sourceCodeStart":307,"sourceCodeEnd":343,"githubUrl":"https://github.com/Lightning-AI/pytorch-lightning/blob/9fed5c27d2a62ff0efd6c3573599921d6ff67c14/src/lightning/pytorch/trainer/connectors/accelerator_connector.py#L307-L343","documentation":"devices must be a meaningful value: an empty list, integer 0, or string '0' is rejected for the chosen accelerator. The connector requires at least one device to be requested.","triggerScenarios":"Trainer(devices=0), Trainer(devices=[]), Trainer(devices='0') with any accelerator setting (e.g. accelerator='gpu').","commonSituations":"devices derived from CUDA_VISIBLE_DEVICES parsing that yields 0 GPUs; dynamic device counts on machines without the expected hardware; configs intended to disable training.","solutions":["Pass a valid count/index/list, e.g. devices=1 or devices='auto'","If the machine truly has no devices of that accelerator, switch accelerator='cpu' with devices=1 or fix the environment (GPU visibility)"],"exampleFix":"# before\ntrainer = Trainer(accelerator=\"gpu\", devices=0)\n# after\ntrainer = Trainer(accelerator=\"gpu\", devices=1)","handlingStrategy":"validation","validationCode":"if devices in ([], 0, \"0\"):\n    devices = \"auto\"  # or raise a clear early config error\ntrainer = Trainer(devices=devices)","typeGuard":"def invalid_devices(d) -> bool:\n    return d in ([], 0, \"0\")","tryCatchPattern":null,"preventionTips":["Validate computed device counts before passing them to Trainer","Use devices='auto' when hardware availability is uncertain"],"tags":["pytorch-lightning","devices","config-validation"],"backgroundTag":"invalid-argument-value","analyzedSha":"9fed5c27d2a62ff0efd6c3573599921d6ff67c14","analyzedAt":"2026-08-28T11:52:41.083Z","schemaVersion":2},"datasetVersion":"2026-08-28T16:17:29.566Z"}