Lightning-AI/pytorch-lightning · error · TypeError
`name` must be a str, found {name}
Error message
`name` must be a str, found {name} What it means
StrategyRegistry.register validates that the registered strategy's `name` is a string (or None). Passing any non-str name (int, tuple, etc.) raises this TypeError immediately, before any registration occurs.
Source
Thrown at src/lightning/fabric/strategies/registry.py:63
self,
name: str,
strategy: Optional[Callable] = None,
description: Optional[str] = None,
override: bool = False,
**init_params: Any,
) -> Callable:
"""Registers a strategy mapped to a name and with required metadata.
Args:
name : the name that identifies a strategy, e.g. "deepspeed_stage_3"
strategy : strategy class
description : strategy description
override : overrides the registered strategy, if True
init_params: parameters to initialize the strategy
"""
if not (name is None or isinstance(name, str)):
raise TypeError(f"`name` must be a str, found {name}")
if name in self and not override:
raise ValueError(f"'{name}' is already present in the registry. HINT: Use `override=True`.")
data: dict[str, Any] = {}
data["description"] = description if description is not None else ""
data["init_params"] = init_params
def do_register(strategy: Callable) -> Callable:
data["strategy"] = strategy
data["strategy_name"] = name
self[name] = data
return strategy
if strategy is not None:
return do_register(strategy)
View on GitHub (pinned to 9fed5c27d2)
Solutions
- Pass a plain string name: register('my_strategy', MyStrategy)
- Coerce: register(str(name), ...) if the name comes from dynamic input
Example fix
# before register(name=123, strategy=MyStrategy) # after register(name='my_strategy', strategy=MyStrategy)
Defensive patterns
Strategy: type-guard
Validate before calling
assert name is None or isinstance(name, str), f'name must be str, got {type(name)}' Type guard
def is_valid_registry_name(name) -> bool:
return name is None or isinstance(name, str) Prevention
- Coerce dynamic names with str(name) before registering
When it happens
Trigger: Calling StrategyRegistry.register(name=123, strategy=...) or any non-string name; a custom plugin/extension registering strategies computed names of the wrong type.
Common situations: Third-party extensions or user scripts registering custom strategies with typos like name=('ddp', 'custom') or variables that evaluate to non-strings.
Related errors
- '{name}' is already present in the registry. HINT: Use `over
- '{}' not found in registry. Available names: {}
- Received multiple values for {', '.join(duplicated_plugin_ke
- Received both `precision={precision_input}` and `plugins={se
- accelerator set through both strategy class and accelerator
AI-assisted analysis of Lightning-AI/pytorch-lightning@9fed5c27d2 (2026-08-28).
Data as JSON: /api/errors/16b8ff6e9ef25fbf.
Report an issue: GitHub.