Lightning-AI/pytorch-lightning · error · ValueError

You selected an invalid strategy name: `strategy={strategy!r

Error message

You selected an invalid strategy name: `strategy={strategy!r}`. It must be either a string or an instance of `lightning.pytorch.strategies.Strategy`. Example choices: auto, ddp, ddp_spawn, deepspeed, ... Find a complete list of options in our documentation at https://lightning.ai

What it means

Raised by AcceleratorConnector when the `strategy` argument to Trainer is neither the string 'auto', a registered strategy name, nor a Strategy instance. Strings are lowercased first, so only typos, unsupported names, or wrong types (e.g. a strategy class instead of instance) reach this check.

Source

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

        2. accelerator: if the value of the accelerator argument is a type of accelerator (instance or string),
            set self._accelerator_flag accordingly.
        3. precision: The final value of the precision flag may be determined either by the precision argument or
            by a plugin instance.
        4. plugins: The list of plugins may contain a Precision plugin, CheckpointIO, ClusterEnvironment and others.
            Additionally, other flags such as `precision` or `sync_batchnorm` can populate the list with the
            corresponding plugin instances.

        """
        if plugins is not None:
            plugins = [plugins] if not isinstance(plugins, Iterable) else plugins

        if isinstance(strategy, str):
            strategy = strategy.lower()

        self._strategy_flag = strategy

        if strategy != "auto" and strategy not in self._registered_strategies and not isinstance(strategy, Strategy):
            raise ValueError(
                f"You selected an invalid strategy name: `strategy={strategy!r}`."
                " It must be either a string or an instance of `lightning.pytorch.strategies.Strategy`."
                " Example choices: auto, ddp, ddp_spawn, deepspeed, ..."
                " Find a complete list of options in our documentation at https://lightning.ai"
            )

        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

View on GitHub (pinned to 9fed5c27d2)

Solutions

  1. Use a valid name: 'auto', 'ddp', 'ddp_spawn', 'deepspeed', 'fsdp', or check `lightning.pytorch.strategies` for registered options.
  2. If passing a custom strategy, pass an instance: `Trainer(strategy=DDPStrategy(find_unused_parameters=True))`, not the class.
  3. Fix the typo or update removed names (e.g. 'ddp2' → 'ddp', 'tpu_spawn' → 'tpu' strategy via XLA).

Example fix

# before
trainer = Trainer(strategy='ddp2')
# after
trainer = Trainer(strategy='ddp')
# or an instance:
from lightning.pytorch.strategies import DDPStrategy
trainer = Trainer(strategy=DDPStrategy(find_unused_parameters=True))
Defensive patterns

Strategy: validation

Validate before calling

from lightning.pytorch.strategies import Strategy
import lightning.pytorch as pl

valid = {'auto'} | set(pl.trainer.connectors.accelerator_connector._AcceleratorConnector__dict__ if False else set(getattr(
    __import__('lightning.pytorch.trainer.connectors.accelerator_connector', fromlist=['_AcceleratorConnector']),
    '_ACCELERATOR_CONNECTOR_STRATEGY_NAMES', set()))) or {'auto','ddp','ddp_spawn','deepspeed','fsdp'}
assert strategy_name in valid or isinstance(strategy_obj, Strategy), f'bad strategy {strategy_name!r}'

Type guard

from lightning.pytorch.strategies import Strategy

def is_valid_strategy(s) -> bool:
    return s == 'auto' or isinstance(s, Strategy) or (isinstance(s, str) and s.lower() in KNOWN_STRATEGY_NAMES)

Try / catch

except ValueError as e: if 'invalid strategy name' in str(e): fall back to strategy='auto' and log a warning

Prevention

When it happens

Trigger: `Trainer(strategy='ddp2')` (removed name), `Trainer(strategy='DDP')` is fine after lowercasing but e.g. `strategy='horovod'` on installs without it, `Trainer(strategy=DDPStrategy)` (class not instance), or a misspelled name like `strategy='dpd'`.

Common situations: Copying strategy names from older Lightning versions (ddp2, tpu_spawn renamed), passing the class instead of an instance, or names from other frameworks that Lightning doesn't register.

Understand the failure class

Background: "Invalid configuration value" and "Unsupported/Unknown setting value" errors: why libraries reject your config strings, numbers, and types — this error's family across 30 libraries.

Related errors


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