{"record":{"id":"4f7a52cd454bd7b0","repo":"Lightning-AI/pytorch-lightning","slug":"device-ids-gpu-tpu-must-be-an-int-a-string-a-s-4f7a52","errorCode":null,"errorMessage":"Device IDs (GPU/TPU) must be an int, a string, a sequence of ints, but you passed {device_ids!r}.","messagePattern":"Device IDs \\(GPU/TPU\\) must be an int, a string, a sequence of ints, but you passed (.+?)\\.","errorType":"validation","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"src/lightning/fabric/utilities/device_parser.py","lineNumber":206,"sourceCode":"\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():\n        return \"mps\"\n    if CUDAAccelerator.is_available():\n        return \"cuda\"\n    return \"cpu\"\n","sourceCodeStart":188,"sourceCodeEnd":222,"githubUrl":"https://github.com/Lightning-AI/pytorch-lightning/blob/9fed5c27d2a62ff0efd6c3573599921d6ff67c14/src/lightning/fabric/utilities/device_parser.py#L188-L222","documentation":"If devices is neither None, a sequence/tuple, an int, nor a str, the parser rejects it with TypeError showing the repr of the value. Typical offenders are floats (devices=1.0), dicts, or arbitrary objects passed through config systems.","triggerScenarios":"devices=1.0 (float from a config cast); devices={'gpu': 2}; devices=torch.device('cuda'); any custom object reaching the devices parameter of Fabric/Trainer.","commonSituations":"YAML/Hydra configs that coerce counts to floats (devices: 2.0); wrapping devices in a dict or dataclass field and passing it unmodified; passing a torch.device object where an id/count is expected.","solutions":["Coerce to a supported type: int(devices) for counts, str for comma-separated ids, or list of ints","Fix your config schema so devices is int|str|list[int]","Use devices='auto' when unsure"],"exampleFix":"# before\nFabric(accelerator=\"gpu\", devices=float(cfg.n_gpus))  # 2.0\n\n# after\nFabric(accelerator=\"gpu\", devices=int(cfg.n_gpus))","handlingStrategy":"type-guard","validationCode":"if isinstance(devices, float):\n    devices = int(devices)\nassert isinstance(devices, (int, str, list, tuple)), f\"unsupported devices value: {devices!r}\"","typeGuard":"def is_supported_devices(d) -> bool:\n    if isinstance(d, bool): return False\n    if type(d) is int or type(d) is str: return True\n    return isinstance(d, (list, tuple)) and all(type(x) is int for x in d)","tryCatchPattern":null,"preventionTips":["Constrain config schema for devices to int | str | list[int]","Cast floats from YAML/Hydra with int(...) at the boundary"],"tags":["devices","typeerror","config","validation"],"backgroundTag":"invalid-devices-argument","analyzedSha":"9fed5c27d2a62ff0efd6c3573599921d6ff67c14","analyzedAt":"2026-08-28T11:52:41.083Z","schemaVersion":2},"datasetVersion":"2026-08-28T16:17:29.566Z"}