{"record":{"id":"d5f307672b7fdd01","repo":"Lightning-AI/pytorch-lightning","slug":"you-requested-to-find-num-devices-devices-but-th-d5f307","errorCode":null,"errorMessage":"You requested to find {num_devices} devices but this machine only has {len(visible_devices)} GPUs.","messagePattern":"You requested to find (.+?) devices but this machine only has (.+?) GPUs\\.","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"src/lightning/fabric/accelerators/cuda.py","lineNumber":110,"sourceCode":"\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)\n        if len(available_devices) == num_devices:\n            # exit early if we found the right number of GPUs\n            break\n","sourceCodeStart":92,"sourceCodeEnd":128,"githubUrl":"https://github.com/Lightning-AI/pytorch-lightning/blob/9fed5c27d2a62ff0efd6c3573599921d6ff67c14/src/lightning/fabric/accelerators/cuda.py#L92-L128","documentation":"The Trainer profiler parameter accepts a Profiler instance or a string. Strings are lowercased and looked up in a fixed registry (simple, advanced, pytorch, xla). Any string not in PROFILERS raises MisconfigurationException listing the allowed keys.","triggerScenarios":"Trainer(profiler='tensorboard'), Trainer(profiler='PyTorchProfiler'), Trainer(profiler='') or any misspelled/unregistered profiler name.","commonSituations":"Typos and case/spelling mistakes; assuming a profiler exists that this Lightning version doesn't register; passing the class name string instead of the class; older/newer versions where the available profiler set differs.","solutions":["Use one of the registered names: 'simple', 'advanced', 'pytorch', 'xla' (lowercase)","Pass a Profiler instance for anything custom: from lightning.pytorch.profilers import PyTorchProfiler; Trainer(profiler=PyTorchProfiler())","Omit profiler (or profiler=None) to disable profiling"],"exampleFix":"# before\ntrainer = Trainer(profiler=\"PyTorch\")\n\n# after\ntrainer = Trainer(profiler=\"pytorch\")\n# or\nfrom lightning.pytorch.profilers import PyTorchProfiler\ntrainer = Trainer(profiler=PyTorchProfiler())","handlingStrategy":"type-guard","validationCode":"ALLOWED_PROFILERS = {\"simple\", \"advanced\", \"pytorch\", \"xla\"}\n\ndef valid_profiler(p):\n    if isinstance(p, str):\n        assert p.lower() in ALLOWED_PROFILERS, f\"profiler must be one of {ALLOWED_PROFILERS}\"\n    return p","typeGuard":"from lightning.pytorch.profilers import Profiler\n\nALLOWED = {\"simple\", \"advanced\", \"pytorch\", \"xla\"}\n\ndef is_valid_profiler(p) -> bool:\n    return p is None or isinstance(p, Profiler) or (isinstance(p, str) and p.lower() in ALLOWED)","tryCatchPattern":null,"preventionTips":["Use lowercase strings: 'simple', 'advanced', 'pytorch', 'xla'","Pass a Profiler instance for custom setups","Fail fast on config load by checking against the allowed set"],"tags":["pytorch-lightning","trainer","profiler","invalid-argument"],"backgroundTag":"invalid-enum-value","analyzedSha":"9fed5c27d2a62ff0efd6c3573599921d6ff67c14","analyzedAt":"2026-08-28T11:52:41.083Z","schemaVersion":2},"datasetVersion":"2026-08-28T16:17:29.566Z"}