{"record":{"id":"ad4d399ac4eda1d5","repo":"Lightning-AI/pytorch-lightning","slug":"type-self-name-already-owns-a-group","errorCode":null,"errorMessage":"`{type(self).__name__}` already owns a group.","messagePattern":"`(.+?)` already owns a group\\.","errorType":"exception","errorClass":"RuntimeError","httpStatus":null,"severity":"error","filePath":"src/lightning/fabric/plugins/collectives/collective.py","lineNumber":110,"sourceCode":"\n    @classmethod\n    @abstractmethod\n    def _convert_to_native_op(cls, op: str) -> Any: ...\n\n    def setup(self, **kwargs: Any) -> Self:\n        if not self.is_initialized():\n            self.init_group(**kwargs)\n        return self\n\n    def create_group(self, **kwargs: Any) -> Self:\n        \"\"\"Create a group.\n\n        This assumes that :meth:`~lightning.fabric.plugins.collectives.Collective.init_group` has been\n        called already by the user.\n\n        \"\"\"\n        if self._group is not None:\n            raise RuntimeError(f\"`{type(self).__name__}` already owns a group.\")\n        self._group = self.new_group(**kwargs)\n        return self\n\n    def teardown(self) -> Self:\n        if self._group is None:\n            raise RuntimeError(f\"`{type(self).__name__}` does not own a group to destroy.\")\n        self.destroy_group(self._group)\n        self._group = None\n        return self\n","sourceCodeStart":92,"sourceCodeEnd":120,"githubUrl":"https://github.com/Lightning-AI/pytorch-lightning/blob/9fed5c27d2a62ff0efd6c3573599921d6ff67c14/src/lightning/fabric/plugins/collectives/collective.py#L92-L120","documentation":"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.","triggerScenarios":"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).","commonSituations":"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.","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"],"exampleFix":"# before\ncollective.create_group(ranks=ranks)\ncollective.create_group(ranks=new_ranks)  # RuntimeError\n\n# after\ncollective.create_group(ranks=ranks)\ncollective.teardown()\ncollective.create_group(ranks=new_ranks)","handlingStrategy":"validation","validationCode":"if collective._group is not None:\n    collective.teardown()\ncollective.create_group(ranks=ranks)","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Pair create_group/teardown strictly; teardown before recreating","Use a fresh TorchCollective per group lifetime"],"tags":["pytorch-lightning","distributed","process-group","collectives","double-setup"],"backgroundTag":"double-initialization","analyzedSha":"9fed5c27d2a62ff0efd6c3573599921d6ff67c14","analyzedAt":"2026-08-28T11:52:41.083Z","schemaVersion":2},"datasetVersion":"2026-08-28T16:17:29.566Z"}