Lightning-AI/pytorch-lightning · error · RuntimeError
`{type(self).__name__}` already owns a group.
Error message
`{type(self).__name__}` already owns a group. What it means
Raised by `Collective.create_group()` when the collective already owns a process group (`self._group is not None`). Creating a second group over the same collective would leak/duplicate groups, so it is rejected.
Source
Thrown at src/lightning/fabric/plugins/collectives/collective.py:110
@classmethod
@abstractmethod
def _convert_to_native_op(cls, op: str) -> Any: ...
def setup(self, **kwargs: Any) -> Self:
if not self.is_initialized():
self.init_group(**kwargs)
return self
def create_group(self, **kwargs: Any) -> Self:
"""Create a group.
This assumes that :meth:`~lightning.fabric.plugins.collectives.Collective.init_group` has been
called already by the user.
"""
if self._group is not None:
raise RuntimeError(f"`{type(self).__name__}` already owns a group.")
self._group = self.new_group(**kwargs)
return self
def teardown(self) -> Self:
if self._group is None:
raise RuntimeError(f"`{type(self).__name__}` does not own a group to destroy.")
self.destroy_group(self._group)
self._group = None
return self
View on GitHub (pinned to 9fed5c27d2)
Solutions
- Call `collective.teardown()` before creating a new group
- Use a fresh `TorchCollective()` instance for each group you need
- Check `collective._group is None` (or track creation state) before calling create_group
Example fix
# before collective.create_group(ranks=ranks) collective.create_group(ranks=new_ranks) # RuntimeError # after collective.create_group(ranks=ranks) collective.teardown() collective.create_group(ranks=new_ranks)
Defensive patterns
Strategy: validation
Validate before calling
if collective._group is not None:
collective.teardown()
collective.create_group(ranks=ranks) Prevention
- Pair create_group/teardown strictly; teardown before recreating
- Use a fresh TorchCollective per group lifetime
When it happens
Trigger: Calling `collective.create_group()` twice without an intervening `teardown()`; loops over strategies that reuse one collective instance; tests that recreate groups (as seen in the many test callers).
Common situations: Retrying initialization logic on failure that already created a group; running multiple sequential distributed phases with the same Collective object; repeated test setups sharing a module-level collective.
Related errors
- `{type(self).__name__}` does not own a group. HINT: try `col
- `{type(self).__name__}` does not own a group to destroy.
- An optimizer should be passed only once to the `setup_optimi
- A dataloader should be passed only once to the `setup_datalo
- Torch distributed is not available.
AI-assisted analysis of Lightning-AI/pytorch-lightning@9fed5c27d2 (2026-08-28).
Data as JSON: /api/errors/ad4d399ac4eda1d5.
Report an issue: GitHub.