Lightning-AI/pytorch-lightning · error · RuntimeError

`{type(self).__name__}` does not own a group to destroy.

Error message

`{type(self).__name__}` does not own a group to destroy.

What it means

Raised by `Collective.teardown()` when `self._group` is None — i.e. there is no process group to destroy. Teardown must be paired with a successful `create_group`.

Source

Thrown at src/lightning/fabric/plugins/collectives/collective.py:116

        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

  1. Only call teardown after a successful create_group; guard with `if collective._group is not None`
  2. Set `collective._group = None`-equivalent state tracking, or recreate the collective per phase
  3. Restructure cleanup so teardown only runs on the success path of group creation

Example fix

# before
finally:
    collective.teardown()  # may not own a group

# after
finally:
    if collective._group is not None:
        collective.teardown()
Defensive patterns

Strategy: validation

Validate before calling

if collective._group is not None:
    collective.teardown()

Prevention

When it happens

Trigger: Calling `collective.teardown()` on a freshly constructed collective, or calling teardown twice without recreating the group; cleanup paths in try/finally blocks that run even when group creation failed or was skipped.

Common situations: Generic cleanup code in `finally` blocks; re-running teardown in tests; error paths where create_group raised before assigning the group.

Related errors


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