{"record":{"id":"e7385251faae94b2","repo":"Lightning-AI/pytorch-lightning","slug":"fabric-devices-self-devices-flag-r-value-is","errorCode":null,"errorMessage":"`Fabric(devices={self._devices_flag!r})` value is not a valid input using {accelerator_name} accelerator.","messagePattern":"`Fabric\\(devices=(.+?)\\)` value is not a valid input using (.+?) accelerator\\.","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"src/lightning/fabric/connector.py","lineNumber":311,"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 ValueError(\n                f\"`Fabric(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 when ``accelerator='auto'``.\"\"\"\n        if XLAAccelerator.is_available():\n            return \"tpu\"\n        if MPSAccelerator.is_available():\n            return \"mps\"\n        if CUDAAccelerator.is_available():\n            return \"cuda\"\n        return \"cpu\"\n\n    @staticmethod\n    def _choose_gpu_accelerator_backend() -> str:\n        if MPSAccelerator.is_available():","sourceCodeStart":293,"sourceCodeEnd":329,"githubUrl":"https://github.com/Lightning-AI/pytorch-lightning/blob/9fed5c27d2a62ff0efd6c3573599921d6ff67c14/src/lightning/fabric/connector.py#L293-L329","documentation":"Fabric rejects empty/falsy device specifications: `devices=[]`, `devices=0`, or `devices=\"0\"` are not valid for any accelerator. The connector checks this right after storing the flags and names the resolved accelerator in the message.","triggerScenarios":"Fabric(devices=0), Fabric(devices=[]), or Fabric(devices=\"0\") with any accelerator (e.g. accelerator=\"gpu\", devices=0).","commonSituations":"devices computed from GPU count on a machine with no visible GPUs (torch.cuda.device_count() == 0) yielding 0; CUDA_VISIBLE_DEVICES=\"\" in slurm/docker; config templates defaulting devices to 0 or an empty list.","solutions":["Pass a concrete value: devices=1 (or devices=\"auto\" to let Fabric pick)","If GPU count is 0 unexpectedly, check CUDA_VISIBLE_DEVICES and torch.cuda.is_available() before choosing devices","Fall back to CPU explicitly: accelerator=\"cpu\", devices=1 when no GPUs are available"],"exampleFix":"# before\nfabric = Fabric(accelerator=\"gpu\", devices=torch.cuda.device_count())  # 0 on CPU box\n\n# after\nndev = torch.cuda.device_count()\nfabric = Fabric(accelerator=\"gpu\" if ndev else \"cpu\", devices=ndev or 1)","handlingStrategy":"validation","validationCode":"if devices in ([], 0, \"0\", None):\n    ndev = torch.cuda.device_count()\n    accelerator = \"gpu\" if ndev else \"cpu\"\n    devices = ndev or 1\nfabric = Fabric(accelerator=accelerator, devices=devices)","typeGuard":"def is_valid_devices(d) -> bool:\n    return d not in ([], 0, \"0\") and d is not None","tryCatchPattern":null,"preventionTips":["Never pass torch.cuda.device_count() directly without a zero check","Audit CUDA_VISIBLE_DEVICES in container/SLURM jobs when GPUs are expected"],"tags":["lightning","fabric","devices","argument-validation","no-gpus"],"backgroundTag":"invalid-argument-value","analyzedSha":"9fed5c27d2a62ff0efd6c3573599921d6ff67c14","analyzedAt":"2026-08-28T11:52:41.083Z","schemaVersion":2},"datasetVersion":"2026-08-28T16:17:29.566Z"}