{"record":{"id":"72576b160a2619a8","repo":"Lightning-AI/pytorch-lightning","slug":"raise-modulenotfounderror-str-xla-available","errorCode":null,"errorMessage":"raise ModuleNotFoundError(str(_XLA_AVAILABLE))","messagePattern":"raise ModuleNotFoundError\\(str\\(_XLA_AVAILABLE\\)\\)","errorType":"exception","errorClass":"ModuleNotFoundError","httpStatus":null,"severity":"critical","filePath":"src/lightning/pytorch/strategies/launchers/xla.py","lineNumber":55,"sourceCode":"    r\"\"\"Launches processes that run a given function in parallel on XLA supported hardware, and joins them all at the\n    end.\n\n    The main process in which this launcher is invoked creates N so-called worker processes (using the\n    `torch_xla` :func:`xmp.spawn`) that run the given function.\n    Worker processes have a rank that ranges from 0 to N - 1.\n\n    Note:\n        - This launcher requires all objects to be pickleable.\n        - It is important that the entry point to the program/script is guarded by ``if __name__ == \"__main__\"``.\n\n    Args:\n        strategy: A reference to the strategy that is used together with this launcher\n\n    \"\"\"\n\n    def __init__(self, strategy: \"pl.strategies.XLAStrategy\") -> None:\n        if not _XLA_AVAILABLE:\n            raise ModuleNotFoundError(str(_XLA_AVAILABLE))\n        super().__init__(strategy=strategy, start_method=\"fork\")\n\n    @property\n    @override\n    def is_interactive_compatible(self) -> bool:\n        return True\n\n    @override\n    def launch(self, function: Callable, *args: Any, trainer: Optional[\"pl.Trainer\"] = None, **kwargs: Any) -> Any:\n        \"\"\"Launches processes that run the given function in parallel.\n\n        The function is allowed to have a return value. However, when all processes join, only the return value\n        of worker process 0 gets returned from this `launch` method in the main process.\n\n        Arguments:\n            function: The entry point for all launched processes.\n            *args: Optional positional arguments to be passed to the given function.\n            trainer: Optional reference to the :class:`~lightning.pytorch.trainer.trainer.Trainer` for which","sourceCodeStart":37,"sourceCodeEnd":73,"githubUrl":"https://github.com/Lightning-AI/pytorch-lightning/blob/9fed5c27d2a62ff0efd6c3573599921d6ff67c14/src/lightning/pytorch/strategies/launchers/xla.py#L37-L73","documentation":"The XLA launcher (_XLALauncher) requires torch_xla. Lightning gates imports via the _XLA_AVAILABLE message; if torch_xla is not installed, constructing the launcher raises ModuleNotFoundError with that explanatory message.","triggerScenarios":"Instantiating XLAStrategy (which creates an _XLALauncher) without torch_xla installed, e.g. on a GPU box or CI without XLA libs; using lightning-cloud / accelerator='tpu' without the xla extra.","commonSituations":"Selecting the TPU/XLA strategy in a plain PyTorch environment; missing 'lightning[xla]' or torch_xla wheel for the PyTorch version in use.","solutions":["Install torch_xla matching your torch version (e.g. pip install torch_xla==<matching version>) or the extra: pip install lightning[xla]","Verify with python -c \"import torch_xla\"","If you didn't intend XLA, switch the strategy/accelerator to the CPU/GPU ones"],"exampleFix":"# before\nstrategy = XLAStrategy()  # ModuleNotFoundError without torch_xla\n\n# after\npip install lightning[xla]\nstrategy = XLAStrategy()","handlingStrategy":"validation","validationCode":"from lightning.fabric.utilities.imports import _XLA_AVAILABLE\nassert _XLA_AVAILABLE, \"install torch_xla / pip install lightning[xla]\"","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Install the xla extra in any environment that touches XLA strategies","Gate XLA-specific code paths behind _XLA_AVAILABLE checks"],"tags":["xla","tpu","missing-dependency","pytorch-lightning"],"backgroundTag":"missing-optional-dependency","analyzedSha":"9fed5c27d2a62ff0efd6c3573599921d6ff67c14","analyzedAt":"2026-08-28T11:52:41.083Z","schemaVersion":2},"datasetVersion":"2026-08-28T16:17:29.566Z"}