{"record":{"id":"c05d80e01a22c038","repo":"Lightning-AI/pytorch-lightning","slug":"device-should-be-cuda-got-device-instead","errorCode":null,"errorMessage":"Device should be CUDA, got {device} instead.","messagePattern":"Device should be CUDA, got (.+?) instead\\.","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"src/lightning/fabric/accelerators/cuda.py","lineNumber":36,"sourceCode":"from typing_extensions import override\n\nfrom lightning.fabric.accelerators.accelerator import Accelerator\nfrom lightning.fabric.accelerators.registry import _AcceleratorRegistry\nfrom lightning.fabric.utilities.rank_zero import rank_zero_info\n\n\nclass CUDAAccelerator(Accelerator):\n    \"\"\"Accelerator for NVIDIA CUDA devices.\"\"\"\n\n    @override\n    def setup_device(self, device: torch.device) -> None:\n        \"\"\"\n        Raises:\n            ValueError:\n                If the selected device is not of type CUDA.\n        \"\"\"\n        if device.type != \"cuda\":\n            raise ValueError(f\"Device should be CUDA, got {device} instead.\")\n        _check_cuda_matmul_precision(device)\n        torch.cuda.set_device(device)\n\n    @override\n    def teardown(self) -> None:\n        _clear_cuda_memory()\n\n    @staticmethod\n    @override\n    def parse_devices(devices: Union[int, str, list[int]]) -> Optional[list[int]]:\n        \"\"\"Accelerator device parsing logic.\"\"\"\n        from lightning.fabric.utilities.device_parser import _parse_gpu_ids\n\n        return _parse_gpu_ids(devices, include_cuda=True)\n\n    @staticmethod\n    @override\n    def get_parallel_devices(devices: list[int]) -> list[torch.device]:","sourceCodeStart":18,"sourceCodeEnd":54,"githubUrl":"https://github.com/Lightning-AI/pytorch-lightning/blob/9fed5c27d2a62ff0efd6c3573599921d6ff67c14/src/lightning/fabric/accelerators/cuda.py#L18-L54","documentation":"Trainer._init_debugging_flags validates fast_dev_run: when passed as an int it must be >= 0. Negative integers such as fast_dev_run=-1 are rejected immediately at Trainer construction because a negative run count is meaningless.","triggerScenarios":"Constructing Trainer(fast_dev_run=-1) or any negative int; computing fast_dev_run programmatically (e.g. from a config or CLI arg) where a subtraction/default yields a negative value.","commonSituations":"Sweep/search configs generating fast_dev_run from expressions; typos; porting scripts where fast_dev_run was derived from a dataset size that can be 0 or negative; passing a float like -1.0 is not caught here (only int is checked) but negatives should be avoided regardless.","solutions":["Set fast_dev_run to a valid value: True, False, or a non-negative int like 1 or 5","If computing it dynamically, clamp: fast_dev_run = max(0, int(value))","Use fast_dev_run=0 or False to disable it instead of -1"],"exampleFix":"# before\ntrainer = Trainer(fast_dev_run=-1)\n\n# after\ntrainer = Trainer(fast_dev_run=False)  # or 1, 5, True, 0","handlingStrategy":"validation","validationCode":"def sanitize_fast_dev_run(v):\n    if isinstance(v, bool):\n        return v\n    if isinstance(v, int):\n        if v < 0:\n            raise ValueError(\"fast_dev_run must be >= 0\")\n        return v\n    return bool(v)","typeGuard":"def is_valid_fast_dev_run(v) -> bool:\n    return v is None or isinstance(v, bool) or (isinstance(v, int) and v >= 0)","tryCatchPattern":null,"preventionTips":["Treat fast_dev_run as a tri-state: True/False or a small positive int","Clamp programmatically derived values with max(0, int(x))","Validate sweep configs before constructing the Trainer"],"tags":["pytorch-lightning","trainer","fast-dev-run","validation"],"backgroundTag":"invalid-config-value","analyzedSha":"9fed5c27d2a62ff0efd6c3573599921d6ff67c14","analyzedAt":"2026-08-28T11:52:41.083Z","schemaVersion":2},"datasetVersion":"2026-08-28T16:17:29.566Z"}