From 272605d61d6fafdbb1dc8d7d6f00a03041e47703 Mon Sep 17 00:00:00 2001 From: Thomas Viehmann Date: Thu, 7 Nov 2024 09:53:27 +0100 Subject: [PATCH] also for pytorch lightning no distributed --- tests/tests_pytorch/utilities/test_imports.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/tests/tests_pytorch/utilities/test_imports.py b/tests/tests_pytorch/utilities/test_imports.py index 43a3fad916086..56ee326f076dc 100644 --- a/tests/tests_pytorch/utilities/test_imports.py +++ b/tests/tests_pytorch/utilities/test_imports.py @@ -117,6 +117,13 @@ def test_import_pytorch_lightning_with_torch_dist_unavailable(): code = dedent( """ import torch + try: + # PyTorch 2.5 relies on torch,distributed._composable.fsdp not + # existing with USE_DISTRIBUTED=0 + import torch._dynamo.variables.functions + torch._dynamo.variables.functions._fsdp_param_group = None + except ImportError: + pass # pretend torch.distributed not available for name in list(torch.distributed.__dict__.keys()): @@ -125,6 +132,11 @@ def test_import_pytorch_lightning_with_torch_dist_unavailable(): torch.distributed.is_available = lambda: False + # needed for Dynamo in PT 2.5+ compare the torch.distributed source + class _ProcessGroupStub: + pass + torch.distributed.ProcessGroup = _ProcessGroupStub + import lightning.pytorch """ )