Lightning-AI/pytorch-lightning · error · MisconfigurationException
A single `Optimizer` cannot have multiple parameter groups w
Error message
A single `Optimizer` cannot have multiple parameter groups with identical `name` values. {name} has duplicated parameter group names {duplicates} What it means
LearningRateMonitor derives names for each optimizer's param groups from an optional 'name' entry in the group dicts. If a single optimizer has multiple param groups whose `name` values collide, names would be ambiguous, so `_check_duplicates_and_update_name` raises MisconfigurationException listing the duplicates.
Source
Thrown at src/lightning/pytorch/callbacks/lr_monitor.py:364
def _check_duplicates_and_update_name(
self,
optimizer: Optimizer,
name: str,
seen_optimizers: list[Optimizer],
seen_optimizer_types: defaultdict[type[Optimizer], int],
lr_scheduler_config: Optional[LRSchedulerConfig],
) -> list[str]:
seen_optimizers.append(optimizer)
optimizer_cls = type(optimizer)
if lr_scheduler_config is None or lr_scheduler_config.name is None:
seen_optimizer_types[optimizer_cls] += 1
# Multiple param groups for the same optimizer
param_groups = optimizer.param_groups
duplicates = self._duplicate_param_group_names(param_groups)
if duplicates:
raise MisconfigurationException(
"A single `Optimizer` cannot have multiple parameter groups with identical "
f"`name` values. {name} has duplicated parameter group names {duplicates}"
)
name = self._add_prefix(name, optimizer_cls, seen_optimizer_types)
names = [self._add_suffix(name, param_groups, i) for i in range(len(param_groups))]
if self.log_key_prefix:
names = [f"{self.log_key_prefix}{n}" for n in names]
return names
View on GitHub (pinned to 9fed5c27d2)
Solutions
- Give each param group a unique 'name' value (or remove the 'name' keys so Lightning auto-generates suffixed names)
- If groups genuinely should share a name, merge them into one group
- Check the `duplicates` list in the message against your `configure_optimizers` output
Example fix
# before
optimizer = torch.optim.AdamW([
{'params': head_params, 'lr': 1e-3, 'name': 'head'},
{'params': tail_params, 'lr': 1e-4, 'name': 'head'},
])
# after
optimizer = torch.optim.AdamW([
{'params': head_params, 'lr': 1e-3, 'name': 'head'},
{'params': tail_params, 'lr': 1e-4, 'name': 'tail'},
]) Defensive patterns
Strategy: validation
Validate before calling
names = [g.get('name') for g in optimizer.param_groups if 'name' in g]
assert len(names) == len(set(names)), 'duplicate param-group names in optimizer' Type guard
def no_duplicate_group_names(optimizer) -> bool:
names = [g.get('name') for g in optimizer.param_groups if 'name' in g]
return len(names) == len(set(names)) Prevention
- Assign unique 'name' keys whenever building multi-group optimizers
- Unit-test configure_optimizers output for group-name uniqueness
When it happens
Trigger: An optimizer like `Adam([{...,'name':'head'}, {...,'name':'head'}])` — two param groups with the same `name` key. Triggered when the monitor inspects schedulers/optimizers at train start (or first logging).
Common situations: Duplicating param groups by mistake when building grouped optimizers; forgetting to set 'name' at all on multiple groups after Lightning's internal name extraction collapses them; refactor copying a group dict without changing the name.
Related errors
- An optimizer should be passed only once to the `setup` metho
- logging_interval should be `step` or `epoch` or `None`.
- Cannot use `LearningRateMonitor` callback with `Trainer` tha
- When `optimizer.step(closure)` is called, the closure should
- Training with multiple optimizers is only supported with man
AI-assisted analysis of Lightning-AI/pytorch-lightning@9fed5c27d2 (2026-08-28).
Data as JSON: /api/errors/53d41f34afcbc561.
Report an issue: GitHub.