{"record":{"id":"570aa3916858876c","repo":"Lightning-AI/pytorch-lightning","slug":"the-deepspeed-strategy-is-only-supported-on-cuda-g-570aa3","errorCode":null,"errorMessage":"The DeepSpeed strategy is only supported on CUDA GPUs but `{self.accelerator.__class__.__name__}` is used.","messagePattern":"The DeepSpeed strategy is only supported on CUDA GPUs but `(.+?)` is used\\.","errorType":"exception","errorClass":"RuntimeError","httpStatus":null,"severity":"critical","filePath":"src/lightning/pytorch/strategies/deepspeed.py","lineNumber":343,"sourceCode":"\n        self._config_initialized = False\n        deepspeed.utils.logging.logger.setLevel(logging_level)\n\n        self.remote_device = remote_device\n        self.load_full_weights = load_full_weights\n        self.exclude_frozen_parameters = exclude_frozen_parameters\n\n        # default FP16 parameters.\n        self.loss_scale = loss_scale\n        self.initial_scale_power = initial_scale_power\n        self.loss_scale_window = loss_scale_window\n        self.hysteresis = hysteresis\n        self.min_loss_scale = min_loss_scale\n\n    @override\n    def setup_environment(self) -> None:\n        if not isinstance(self.accelerator, CUDAAccelerator):\n            raise RuntimeError(\n                f\"The DeepSpeed strategy is only supported on CUDA GPUs but `{self.accelerator.__class__.__name__}`\"\n                \" is used.\"\n            )\n        super().setup_environment()\n\n    @override\n    def setup_distributed(self) -> None:\n        assert self.parallel_devices is not None\n        _validate_device_index_selection(self.parallel_devices)\n        reset_seed()\n        self.set_world_ranks()\n        self._init_deepspeed_distributed()\n\n    @override\n    def setup(self, trainer: \"pl.Trainer\") -> None:\n        self._init_config_if_needed()\n        assert self.accelerator is not None\n        self.accelerator.setup(trainer)","sourceCodeStart":325,"sourceCodeEnd":361,"githubUrl":"https://github.com/Lightning-AI/pytorch-lightning/blob/9fed5c27d2a62ff0efd6c3573599921d6ff67c14/src/lightning/pytorch/strategies/deepspeed.py#L325-L361","documentation":"DeepSpeed's engine only accelerates on NVIDIA CUDA GPUs, so DeepSpeedStrategy.setup_environment validates that the configured accelerator is CUDAAccelerator and raises RuntimeError otherwise. This surfaces early (during environment setup) instead of failing obscurely inside DeepSpeed kernels.","triggerScenarios":"`Trainer(strategy=DeepSpeedStrategy(...), accelerator=\"cpu\")` or `accelerator=\"tpu\"`/`accelerator=\"mps\"` — any non-CUDA accelerator reaching `setup_environment()`. Also when devices are configured such that Lightning auto-selects a non-CUDA accelerator.","commonSituations":"Testing a DeepSpeed config on a CPU-only laptop/CI box; copy-pasted Trainer flags with `accelerator` left at default on a machine without GPUs; MPS Macs.","solutions":["Set `accelerator=\"gpu\", devices=...` and run on a CUDA machine","If you only need CPU, use the default single-device strategy instead of DeepSpeed","Gate DeepSpeed usage on GPU availability before building the Trainer"],"exampleFix":"# before\ntrainer = Trainer(strategy=DeepSpeedStrategy(), accelerator=\"auto\")  # resolves to CPU\n\n# after\ntrainer = Trainer(strategy=DeepSpeedStrategy(), accelerator=\"gpu\", devices=2)","handlingStrategy":"validation","validationCode":"import torch\nuse_deepspeed = torch.cuda.is_available()\nstrategy = DeepSpeedStrategy(...) if use_deepspeed else \"auto\"","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always pass accelerator=\"gpu\" explicitly when selecting DeepSpeed","Skip DeepSpeed in CPU-only test jobs instead of forcing the strategy"],"tags":["deepspeed","accelerator","cuda","hardware-requirement"],"backgroundTag":"accelerator-device-mismatch","analyzedSha":"9fed5c27d2a62ff0efd6c3573599921d6ff67c14","analyzedAt":"2026-08-28T11:52:41.083Z","schemaVersion":2},"datasetVersion":"2026-08-28T16:17:29.566Z"}