{"record":{"id":"c2725ddd9854503f","repo":"Lightning-AI/pytorch-lightning","slug":"you-requested-to-find-num-devices-devices-but-th","errorCode":null,"errorMessage":"You requested to find {num_devices} devices but there are no visible CUDA devices on this machine.","messagePattern":"You requested to find (.+?) devices but there are no visible CUDA devices on this machine\\.","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"src/lightning/fabric/accelerators/cuda.py","lineNumber":106,"sourceCode":"    tests for each GPU on the system until the target number of usable devices is found.\n\n    A subset of GPUs on the system might be used by other processes, and if the GPU is configured to operate in\n    'exclusive' mode (configurable by the admin), then only one process is allowed to occupy it.\n\n    Args:\n        num_devices: The number of devices you want to request. By default, this function will return as many as there\n            are usable CUDA GPU devices available.\n\n    Warning:\n        If multiple processes call this function at the same time, there can be race conditions in the case where\n        both processes determine that the device is unoccupied, leading into one of them crashing later on.\n\n    \"\"\"\n    if num_devices == 0:\n        return []\n    visible_devices = _get_all_visible_cuda_devices()\n    if not visible_devices:\n        raise ValueError(\n            f\"You requested to find {num_devices} devices but there are no visible CUDA devices on this machine.\"\n        )\n    if num_devices > len(visible_devices):\n        raise ValueError(\n            f\"You requested to find {num_devices} devices but this machine only has {len(visible_devices)} GPUs.\"\n        )\n\n    available_devices = []\n    unavailable_devices = []\n\n    for gpu_idx in visible_devices:\n        try:\n            torch.tensor(0, device=torch.device(\"cuda\", gpu_idx))\n        except RuntimeError:\n            unavailable_devices.append(gpu_idx)\n            continue\n\n        available_devices.append(gpu_idx)","sourceCodeStart":88,"sourceCodeEnd":124,"githubUrl":"https://github.com/Lightning-AI/pytorch-lightning/blob/9fed5c27d2a62ff0efd6c3573599921d6ff67c14/src/lightning/fabric/accelerators/cuda.py#L88-L124","documentation":"_determine_batch_limits validates percentage-like Trainer arguments (limit_train_batches, limit_val_batches, limit_test_batches, limit_predict_batches, val_check_interval, overfit_batches). A value must be either a fraction in [0.0, 1.0] or an integral count (> 1 and a whole number). Anything else (e.g. 1.5, 2.5, -1) raises this MisconfigurationException.","triggerScenarios":"Trainer(limit_train_batches=2.5); Trainer(overfit_batches=-1); Trainer(val_check_interval=1.2) treated through this path; any float > 1 that is not a whole number, or a negative number.","commonSituations":"Confusing fraction vs count semantics (thinking 2.0 means '2x the dataset'); config files with floats from sweeps; converting '80%' to 80 instead of 0.8; arithmetic producing fractional counts like len(loader)/2 when odd.","solutions":["Use a fraction 0.0-1.0 for percentages (0.8, not 80)","Use a whole integer for exact batch counts (limit_train_batches=100)","Round fractional counts: int(count) or math.floor before passing"],"exampleFix":"# before\ntrainer = Trainer(limit_train_batches=2.5)\n\n# after\ntrainer = Trainer(limit_train_batches=0.5)  # half the batches\n# or\ntrainer = Trainer(limit_train_batches=2)  # exactly 2 batches","handlingStrategy":"validation","validationCode":"def validate_batches(v: float, name: str) -> Union[int, float]:\n    if 0 <= v <= 1:\n        return v\n    if v > 1 and float(v).is_integer():\n        return int(v)\n    raise ValueError(f\"{name}={v!r} must be in [0.0, 1.0] or an int\")","typeGuard":"def is_valid_batch_limit(v) -> bool:\n    return isinstance(v, (int, float)) and (0 <= v <= 1 or (v > 1 and float(v).is_integer()))","tryCatchPattern":null,"preventionTips":["Remember: floats <=1.0 are fractions, ints are counts","Convert percentages: divide by 100 (80% -> 0.8)","Round derived counts with int() before passing"],"tags":["pytorch-lightning","trainer","limit-batches","validation"],"backgroundTag":"invalid-config-value","analyzedSha":"9fed5c27d2a62ff0efd6c3573599921d6ff67c14","analyzedAt":"2026-08-28T11:52:41.083Z","schemaVersion":2},"datasetVersion":"2026-08-28T16:17:29.566Z"}