{"record":{"id":"14d229d74f97897b","repo":"Lightning-AI/pytorch-lightning","slug":"device-ids-gpu-tpu-must-be-an-int-a-string-a-s-14d229","errorCode":null,"errorMessage":"Device IDs (GPU/TPU) must be an int, a string, a sequence of ints, but you passed a sequence of {type(id_).__name__}.","messagePattern":"Device IDs \\(GPU/TPU\\) must be an int, a string, a sequence of ints, but you passed a sequence of (.+?)\\.","errorType":"validation","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"src/lightning/fabric/utilities/device_parser.py","lineNumber":204,"sourceCode":"def _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():\n        return \"mps\"\n    if CUDAAccelerator.is_available():\n        return \"cuda\"\n    return \"cpu\"\n","sourceCodeStart":186,"sourceCodeEnd":222,"githubUrl":"https://github.com/Lightning-AI/pytorch-lightning/blob/9fed5c27d2a62ff0efd6c3573599921d6ff67c14/src/lightning/fabric/utilities/device_parser.py#L186-L222","documentation":"When devices is a sequence, Lightning requires every element to be a real int (checked with type(id_) is int, so bools and numpy integers fail too). If any element is another type, TypeError is raised naming the offending element's type. This guards the parser from ambiguous inputs like ['0','1'], [True, False], or numpy arrays.","triggerScenarios":"devices=['0', '1'] (strings inside a list); devices=[True, False]; devices=np.array([0, 1]) (elements are np.int64, not int); devices=[0.0, 1.0] floats.","commonSituations":"Parsing device ids from CLI/config as strings and not converting to int; passing numpy arrays or numpy ints from scientific pipelines; JSON configs where ids become strings.","solutions":["Convert elements to int: devices=[int(d) for d in devices] or list(map(int, devices))","For string specs use the string form devices='0,1' instead of a list of strings","Cast numpy arrays: devices=device_array.tolist()"],"exampleFix":"# before\nFabric(accelerator=\"gpu\", devices=np.array([0, 1]))  # np.int64 elements\n\n# after\nFabric(accelerator=\"gpu\", devices=[int(d) for d in np.array([0, 1])])","handlingStrategy":"validation","validationCode":"devices = [int(d) for d in devices] if isinstance(devices, (list, tuple)) else devices\nassert all(type(d) is int and not isinstance(d, bool) for d in devices)","typeGuard":"def is_int_sequence(d) -> bool:\n    return isinstance(d, (list, tuple)) and all(type(x) is int for x in d)","tryCatchPattern":null,"preventionTips":["Convert string config values to int early (map(int, ...))","Call .tolist() on numpy arrays before passing as devices","Remember booleans and np.int64 are rejected: type(x) must be exactly int"],"tags":["devices","typeerror","numpy","sequence-validation"],"backgroundTag":"invalid-devices-argument","analyzedSha":"9fed5c27d2a62ff0efd6c3573599921d6ff67c14","analyzedAt":"2026-08-28T11:52:41.083Z","schemaVersion":2},"datasetVersion":"2026-08-28T16:17:29.566Z"}