Lightning-AI/pytorch-lightning · error · ValueError

You selected `Trainer(strategy='{strategy_flag}')` but proce

Error message

You selected `Trainer(strategy='{strategy_flag}')` but process forking is not supported on this platform. We recommend `Trainer(strategy='ddp_spawn')` instead.

What it means

DDP fork-based strategies (names in _DDP_FORK_ALIASES like 'ddp_fork', 'fork') require the 'fork' process start method, which is unavailable on this platform (notably Windows, where only spawn is offered). The connector raises ValueError at config time.

Source

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

        return "ddp"

    def _check_strategy_and_fallback(self) -> None:
        """Checks edge cases when the strategy selection was a string input, and we need to fall back to a different
        choice depending on other parameters or the environment."""
        # current fallback and check logic only apply to user pass in str config and object config
        # TODO this logic should apply to both str and object config
        strategy_flag = "" if isinstance(self._strategy_flag, Strategy) else self._strategy_flag

        if (
            strategy_flag in FSDPStrategy.get_registered_strategies() or type(self._strategy_flag) is FSDPStrategy
        ) and not (self._accelerator_flag in ("cuda", "gpu") or isinstance(self._accelerator_flag, CUDAAccelerator)):
            raise ValueError(
                f"The strategy `{FSDPStrategy.strategy_name}` requires a GPU accelerator, but received "
                f"`accelerator={self._accelerator_flag!r}`. Please set `accelerator='cuda'`, `accelerator='gpu'`,"
                " or pass a `CUDAAccelerator()` instance to use FSDP."
            )
        if strategy_flag in _DDP_FORK_ALIASES and "fork" not in torch.multiprocessing.get_all_start_methods():
            raise ValueError(
                f"You selected `Trainer(strategy='{strategy_flag}')` but process forking is not supported on this"
                f" platform. We recommend `Trainer(strategy='ddp_spawn')` instead."
            )
        if strategy_flag:
            self._strategy_flag = strategy_flag

    def _init_strategy(self) -> None:
        """Instantiate the Strategy given depending on the setting of ``_strategy_flag``."""
        # The validation of `_strategy_flag` already happened earlier on in the connector
        assert isinstance(self._strategy_flag, (str, Strategy))
        if isinstance(self._strategy_flag, str):
            self.strategy = StrategyRegistry.get(self._strategy_flag)
        else:
            self.strategy = self._strategy_flag

    def _check_and_init_precision(self) -> Precision:
        self._validate_precision_choice()
        if isinstance(self._precision_plugin_flag, Precision):

View on GitHub (pinned to 9fed5c27d2)

Solutions

  1. Use the recommended alternative: Trainer(strategy='ddp_spawn')
  2. In notebooks on supported platforms use 'ddp_notebook'; otherwise prefer plain 'ddp' in scripts

Example fix

# before
trainer = Trainer(strategy="ddp_fork")
# after
trainer = Trainer(strategy="ddp_spawn")
Defensive patterns

Strategy: fallback

Validate before calling

import platform, torch.multiprocessing as mp
if strategy in ("ddp_fork", "fork") and "fork" not in mp.get_all_start_methods():
    strategy = "ddp_spawn"
trainer = Trainer(strategy=strategy)

Type guard

def fork_strategy_supported(strategy) -> bool:
    import torch.multiprocessing as mp
    return strategy not in ("ddp_fork", "fork") or "fork" in mp.get_all_start_methods()

Try / catch

try:
    trainer = Trainer(strategy="ddp_fork")
except ValueError as e:
    if "forking is not supported" in str(e):
        trainer = Trainer(strategy="ddp_spawn")
    else:
        raise

Prevention

When it happens

Trigger: Trainer(strategy='ddp_fork') on Windows or any platform where torch.multiprocessing.get_all_start_methods() lacks 'fork'.

Common situations: Cross-platform code developed on Linux/macOS and run on Windows; tutorials recommending ddp_fork for Jupyter that fail on Windows setups.

Related errors


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