{"record":{"id":"6d365c5fc72e4d95","repo":"Lightning-AI/pytorch-lightning","slug":"you-set-strategy-strategy-but-strategies-from-6d365c","errorCode":null,"errorMessage":"You set `strategy={strategy}` but strategies from the DDP family are not supported on the MPS accelerator. Either explicitly set `accelerator='cpu'` or change the strategy.","messagePattern":"You set `strategy=(.+?)` but strategies from the DDP family are not supported on the MPS accelerator\\. Either explicitly set `accelerator='cpu'` or change the strategy\\.","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"src/lightning/pytorch/trainer/connectors/accelerator_connector.py","lineNumber":217,"sourceCode":"        if (\n            accelerator not in self._accelerator_types\n            and accelerator not in (\"auto\", \"gpu\")\n            and not isinstance(accelerator, Accelerator)\n        ):\n            raise ValueError(\n                f\"You selected an invalid accelerator name: `accelerator={accelerator!r}`.\"\n                f\" Available names are: auto, {', '.join(self._accelerator_types)}.\"\n            )\n\n        # MPS accelerator is incompatible with DDP family of strategies. It supports single-device operation only.\n        is_ddp_str = isinstance(strategy, str) and \"ddp\" in strategy\n        is_deepspeed_str = isinstance(strategy, str) and \"deepspeed\" in strategy\n        is_parallel_strategy = isinstance(strategy, ParallelStrategy) or is_ddp_str or is_deepspeed_str\n        is_mps_accelerator = MPSAccelerator.is_available() and (\n            accelerator in (\"mps\", \"auto\", \"gpu\", None) or isinstance(accelerator, MPSAccelerator)\n        )\n        if is_mps_accelerator and is_parallel_strategy:\n            raise ValueError(\n                f\"You set `strategy={strategy}` but strategies from the DDP family are not supported on the\"\n                f\" MPS accelerator. Either explicitly set `accelerator='cpu'` or change the strategy.\"\n            )\n\n        self._accelerator_flag = accelerator\n\n        precision_flag = _convert_precision_to_unified_args(precision)\n\n        if plugins:\n            plugins_flags_types: dict[str, int] = Counter()\n            for plugin in plugins:\n                if isinstance(plugin, Precision):\n                    self._precision_plugin_flag = plugin\n                    plugins_flags_types[Precision.__name__] += 1\n                elif isinstance(plugin, CheckpointIO):\n                    self.checkpoint_io = plugin\n                    plugins_flags_types[CheckpointIO.__name__] += 1\n                elif isinstance(plugin, ClusterEnvironment):","sourceCodeStart":199,"sourceCodeEnd":235,"githubUrl":"https://github.com/Lightning-AI/pytorch-lightning/blob/9fed5c27d2a62ff0efd6c3573599921d6ff67c14/src/lightning/pytorch/trainer/connectors/accelerator_connector.py#L199-L235","documentation":"macOS Metal (MPS) is a single-device accelerator; distributed data-parallel strategies cannot run on it. If MPS is available and the effective accelerator resolves to mps while the strategy is any DDP-family or parallel strategy (ddp, ddp_spawn, deepspeed, ParallelStrategy instances), Lightning rejects the combination at init.","triggerScenarios":"Running on an Apple Silicon Mac with `Trainer(strategy='ddp')` and accelerator left as 'auto'/'gpu'/None or set to 'mps'/'gpu'; also with DeepSpeed strings or ParallelStrategy instances.","commonSituations":"Running multi-GPU training scripts unchanged on an M1/M2/M3 laptop; CI defaults that add DDP on all platforms; MPS machines where 'auto' resolves to mps and the script hardcodes ddp.","solutions":["On the Mac, drop the distributed strategy: `Trainer(strategy='auto', accelerator='mps', devices=1)`.","If you really want CPU + DDP for testing, explicitly set `accelerator='cpu'`.","Gate the strategy by hardware in your launch script so DDP is only used on CUDA machines."],"exampleFix":"# before\ntrainer = Trainer(strategy='ddp', accelerator='auto', devices='auto')  # on Apple Silicon\n# after\ntrainer = Trainer(strategy='auto', accelerator='mps', devices=1)\n# or force CPU DDP for local testing:\ntrainer = Trainer(strategy='ddp', accelerator='cpu', devices=2)","handlingStrategy":"validation","validationCode":"import torch\nfrom lightning.pytorch.strategies import ParallelStrategy\n\ndef guard_mps(strategy, accelerator):\n    mps = torch.backends.mps.is_available() and (accelerator in ('mps','auto','gpu', None))\n    is_par = isinstance(strategy, ParallelStrategy) or (isinstance(strategy, str) and ('ddp' in strategy or 'deepspeed' in strategy))\n    if mps and is_par:\n        return 'auto', 'mps', 1  # sane fallback\n    return strategy, accelerator, None","typeGuard":"def mps_single_device_only(strategy, accelerator, mps_available: bool) -> bool:\n    is_parallel = isinstance(strategy, ParallelStrategy) or (isinstance(strategy, str) and ('ddp' in strategy or 'deepspeed' in strategy))\n    return mps_available and is_parallel and accelerator in ('mps','auto','gpu', None)","tryCatchPattern":"except ValueError as e: if 'MPS accelerator' in str(e): trainer = Trainer(strategy='auto', accelerator='cpu'); trainer.fit(model)","preventionTips":["Choose strategy from torch.cuda.device_count(), not unconditionally.","Keep a hardware-detection helper that returns Trainer kwargs per platform.","Test launch scripts on macOS before committing DDP defaults."],"tags":["pytorch-lightning","mps","apple-silicon","ddp","strategy-mismatch"],"backgroundTag":"unsupported-device-strategy-combination","analyzedSha":"9fed5c27d2a62ff0efd6c3573599921d6ff67c14","analyzedAt":"2026-08-28T11:52:41.083Z","schemaVersion":2},"datasetVersion":"2026-08-28T16:17:29.566Z"}