Lightning-AI/pytorch-lightning · error · ValueError

You set `strategy={strategy}` but strategies from the DDP fa

Error message

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.

What it means

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.

Source

Thrown at src/lightning/pytorch/trainer/connectors/accelerator_connector.py:217

        if (
            accelerator not in self._accelerator_types
            and accelerator not in ("auto", "gpu")
            and not isinstance(accelerator, Accelerator)
        ):
            raise ValueError(
                f"You selected an invalid accelerator name: `accelerator={accelerator!r}`."
                f" Available names are: auto, {', '.join(self._accelerator_types)}."
            )

        # MPS accelerator is incompatible with DDP family of strategies. It supports single-device operation only.
        is_ddp_str = isinstance(strategy, str) and "ddp" in strategy
        is_deepspeed_str = isinstance(strategy, str) and "deepspeed" in strategy
        is_parallel_strategy = isinstance(strategy, ParallelStrategy) or is_ddp_str or is_deepspeed_str
        is_mps_accelerator = MPSAccelerator.is_available() and (
            accelerator in ("mps", "auto", "gpu", None) or isinstance(accelerator, MPSAccelerator)
        )
        if is_mps_accelerator and is_parallel_strategy:
            raise ValueError(
                f"You set `strategy={strategy}` but strategies from the DDP family are not supported on the"
                f" MPS accelerator. Either explicitly set `accelerator='cpu'` or change the strategy."
            )

        self._accelerator_flag = accelerator

        precision_flag = _convert_precision_to_unified_args(precision)

        if plugins:
            plugins_flags_types: dict[str, int] = Counter()
            for plugin in plugins:
                if isinstance(plugin, Precision):
                    self._precision_plugin_flag = plugin
                    plugins_flags_types[Precision.__name__] += 1
                elif isinstance(plugin, CheckpointIO):
                    self.checkpoint_io = plugin
                    plugins_flags_types[CheckpointIO.__name__] += 1
                elif isinstance(plugin, ClusterEnvironment):

View on GitHub (pinned to 9fed5c27d2)

Solutions

  1. On the Mac, drop the distributed strategy: `Trainer(strategy='auto', accelerator='mps', devices=1)`.
  2. If you really want CPU + DDP for testing, explicitly set `accelerator='cpu'`.
  3. Gate the strategy by hardware in your launch script so DDP is only used on CUDA machines.

Example fix

# before
trainer = Trainer(strategy='ddp', accelerator='auto', devices='auto')  # on Apple Silicon
# after
trainer = Trainer(strategy='auto', accelerator='mps', devices=1)
# or force CPU DDP for local testing:
trainer = Trainer(strategy='ddp', accelerator='cpu', devices=2)
Defensive patterns

Strategy: validation

Validate before calling

import torch
from lightning.pytorch.strategies import ParallelStrategy

def guard_mps(strategy, accelerator):
    mps = torch.backends.mps.is_available() and (accelerator in ('mps','auto','gpu', None))
    is_par = isinstance(strategy, ParallelStrategy) or (isinstance(strategy, str) and ('ddp' in strategy or 'deepspeed' in strategy))
    if mps and is_par:
        return 'auto', 'mps', 1  # sane fallback
    return strategy, accelerator, None

Type guard

def mps_single_device_only(strategy, accelerator, mps_available: bool) -> bool:
    is_parallel = isinstance(strategy, ParallelStrategy) or (isinstance(strategy, str) and ('ddp' in strategy or 'deepspeed' in strategy))
    return mps_available and is_parallel and accelerator in ('mps','auto','gpu', None)

Try / catch

except ValueError as e: if 'MPS accelerator' in str(e): trainer = Trainer(strategy='auto', accelerator='cpu'); trainer.fit(model)

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of Lightning-AI/pytorch-lightning@9fed5c27d2 (2026-08-28). Data as JSON: /api/errors/6d365c5fc72e4d95. Report an issue: GitHub.