{"record":{"id":"eee9c1572e5275a2","repo":"Lightning-AI/pytorch-lightning","slug":"the-kubeflow-environment-can-t-be-detected-automat","errorCode":null,"errorMessage":"The Kubeflow environment can't be detected automatically.","messagePattern":"The Kubeflow environment can't be detected automatically\\.","errorType":"exception","errorClass":"NotImplementedError","httpStatus":null,"severity":"error","filePath":"src/lightning/fabric/plugins/environments/kubeflow.py","lineNumber":54,"sourceCode":"    @property\n    @override\n    def creates_processes_externally(self) -> bool:\n        return True\n\n    @property\n    @override\n    def main_address(self) -> str:\n        return os.environ[\"MASTER_ADDR\"]\n\n    @property\n    @override\n    def main_port(self) -> int:\n        return int(os.environ[\"MASTER_PORT\"])\n\n    @staticmethod\n    @override\n    def detect() -> bool:\n        raise NotImplementedError(\"The Kubeflow environment can't be detected automatically.\")\n\n    @override\n    def world_size(self) -> int:\n        return int(os.environ[\"WORLD_SIZE\"])\n\n    @override\n    def set_world_size(self, size: int) -> None:\n        log.debug(\"KubeflowEnvironment.set_world_size was called, but setting world size is not allowed. Ignored.\")\n\n    @override\n    def global_rank(self) -> int:\n        return int(os.environ[\"RANK\"])\n\n    @override\n    def set_global_rank(self, rank: int) -> None:\n        log.debug(\"KubeflowEnvironment.set_global_rank was called, but setting global rank is not allowed. Ignored.\")\n\n    @override","sourceCodeStart":36,"sourceCodeEnd":72,"githubUrl":"https://github.com/Lightning-AI/pytorch-lightning/blob/9fed5c27d2a62ff0efd6c3573599921d6ff67c14/src/lightning/fabric/plugins/environments/kubeflow.py#L36-L72","documentation":"`KubeflowEnvironment.detect()` deliberately raises NotImplementedError because the Kubeflow MPI environment cannot be auto-detected from ambient signals — Kubeflow sets the same env vars (RANK, WORLD_SIZE) as other launchers, making detection ambiguous. You must explicitly instantiate/choose this ClusterEnvironment.","triggerScenarios":"Running launcher auto-detection that calls `detect()` on `KubeflowEnvironment`, e.g. letting Lightning infer the cluster environment in a Kubeflow MPIJob pod, or calling `KubeflowEnvironment.detect()` manually.","commonSituations":"Training inside Kubeflow/MPIOperator pods where users expect automatic environment detection; custom launcher logic that iterates over all environment classes calling detect().","solutions":["Pass the environment explicitly: `KubeflowEnvironment()` to your strategy/accelerator (e.g. `DDPStrategy(cluster_environment=KubeflowEnvironment())` or the Fabric equivalents)","Never rely on auto-detection inside Kubeflow; select the environment by config","If writing generic detection loops, skip environments whose detect raises NotImplementedError"],"exampleFix":"# before\nenv = next(e for e in envs if e.detect())  # hits KubeflowEnvironment.detect -> NotImplementedError\n\n# after\nfrom lightning.fabric.plugins.environments import KubeflowEnvironment\nenv = KubeflowEnvironment()  # explicit selection","handlingStrategy":"try-catch","validationCode":"from lightning.fabric.plugins.environments import KubeflowEnvironment\nenv = KubeflowEnvironment()  # never call .detect() on it","typeGuard":null,"tryCatchPattern":"try:\n    ok = env_cls.detect()\nexcept NotImplementedError:\n    ok = False  # requires explicit selection","preventionTips":["Select cluster environments by configuration, not auto-detection, on Kubeflow","Skip detect() for environments that document it as unsupported"],"tags":["pytorch-lightning","kubeflow","cluster-environment","distributed"],"backgroundTag":"environment-detection-unsupported","analyzedSha":"9fed5c27d2a62ff0efd6c3573599921d6ff67c14","analyzedAt":"2026-08-28T11:52:41.083Z","schemaVersion":2},"datasetVersion":"2026-08-28T16:17:29.566Z"}