{"record":{"id":"05e81e7b1a8fb8a1","repo":"Lightning-AI/pytorch-lightning","slug":"device-ids-gpu-tpu-must-be-an-int-a-string-a-s","errorCode":null,"errorMessage":"Device IDs (GPU/TPU) must be an int, a string, a sequence of ints, but you passed None","messagePattern":"Device IDs \\(GPU/TPU\\) must be an int, a string, a sequence of ints, but you passed None","errorType":"validation","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"src/lightning/fabric/utilities/device_parser.py","lineNumber":199,"sourceCode":"    \"\"\"\n    if len(device_ids) != len(set(device_ids)):\n        raise MisconfigurationException(\"Device ID's (GPU) must be unique.\")\n\n\ndef _check_data_type(device_ids: object) -> None:\n    \"\"\"Checks that the device_ids argument is one of the following: int, string, or sequence of integers.\n\n    Args:\n        device_ids: gpus/tpu_cores parameter as passed to the Trainer\n\n    Raises:\n        TypeError:\n            If ``device_ids`` of GPU/TPUs aren't ``int``, ``str`` or sequence of ``int```\n\n    \"\"\"\n    msg = \"Device IDs (GPU/TPU) must be an int, a string, a sequence of ints, but you passed\"\n    if device_ids is None:\n        raise TypeError(f\"{msg} None\")\n    if isinstance(device_ids, (MutableSequence, tuple)):\n        for id_ in device_ids:\n            id_type = type(id_)  # because `isinstance(False, int)` -> True\n            if id_type is not int:\n                raise TypeError(f\"{msg} a sequence of {type(id_).__name__}.\")\n    elif type(device_ids) not in (int, str):\n        raise TypeError(f\"{msg} {device_ids!r}.\")\n\n\ndef _select_auto_accelerator() -> str:\n    \"\"\"Choose the accelerator type (str) based on availability.\"\"\"\n    from lightning.fabric.accelerators.cuda import CUDAAccelerator\n    from lightning.fabric.accelerators.mps import MPSAccelerator\n    from lightning.fabric.accelerators.xla import XLAAccelerator\n\n    if XLAAccelerator.is_available():\n        return \"tpu\"\n    if MPSAccelerator.is_available():","sourceCodeStart":181,"sourceCodeEnd":217,"githubUrl":"https://github.com/Lightning-AI/pytorch-lightning/blob/9fed5c27d2a62ff0efd6c3573599921d6ff67c14/src/lightning/fabric/utilities/device_parser.py#L181-L217","documentation":"_check_data_type validates the devices argument type before parsing. None is not a valid device specification (int, str, or sequence of ints are), so passing devices=None (as opposed to omitting it or using 'auto') raises TypeError. It is raised from both the GPU parser (_parse_gpu_ids) and the TPU parser (_parse_tpu_devices).","triggerScenarios":"Fabric(devices=None) or Trainer(devices=None); passing a variable that defaults to None and was never set, e.g. devices=os.getenv('DEVICES') with the env var undefined; forwarding None from a config system (YAML/Hydra) where devices was left empty.","commonSituations":"Optional config fields that resolve to None; env-var-driven configs with missing variables; Hydra/OmegaConf merges that null out devices.","solutions":["Set devices explicitly: an int (e.g. 1), a string ('0,1'), or 'auto'","If devices is optional in your config, default it to 'auto' or 1 instead of None","Check env vars: devices=os.getenv('DEVICES', 'auto')"],"exampleFix":"# before\nfabric = Fabric(accelerator=\"gpu\", devices=os.getenv(\"N_GPUS\"))  # None if unset\n\n# after\nfabric = Fabric(accelerator=\"gpu\", devices=os.getenv(\"N_GPUS\", \"auto\"))","handlingStrategy":"type-guard","validationCode":"import os\ndevices = os.getenv(\"DEVICES\", \"auto\")\nassert devices is not None, \"devices must be int, str, or sequence of ints, not None\"","typeGuard":"def valid_devices(d) -> bool:\n    if d is None: return False\n    if isinstance(d, int) and not isinstance(d, bool): return True\n    if isinstance(d, str): return True\n    return isinstance(d, (list, tuple)) and all(type(x) is int for x in d)","tryCatchPattern":null,"preventionTips":["Default optional config values to 'auto' or 1, never None","Assert on config values before constructing Fabric/Trainer"],"tags":["devices","typeerror","null-config","lightning"],"backgroundTag":"invalid-devices-argument","analyzedSha":"9fed5c27d2a62ff0efd6c3573599921d6ff67c14","analyzedAt":"2026-08-28T11:52:41.083Z","schemaVersion":2},"datasetVersion":"2026-08-28T16:17:29.566Z"}