From 2a6054f83657d5b55a9f2151cd9b71ef6491fc09 Mon Sep 17 00:00:00 2001 From: Dalton Date: Sun, 17 Mar 2024 22:37:19 -0400 Subject: [PATCH 01/14] Update sd_hijack_ddpm_v1.py --- extensions-builtin/LDSR/sd_hijack_ddpm_v1.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/extensions-builtin/LDSR/sd_hijack_ddpm_v1.py b/extensions-builtin/LDSR/sd_hijack_ddpm_v1.py index 04adc5eb2..21e6c61c8 100644 --- a/extensions-builtin/LDSR/sd_hijack_ddpm_v1.py +++ b/extensions-builtin/LDSR/sd_hijack_ddpm_v1.py @@ -14,7 +14,7 @@ from contextlib import contextmanager from functools import partial from tqdm import tqdm from torchvision.utils import make_grid -from pytorch_lightning.utilities.distributed import rank_zero_only +from pytorch_lightning.utilities.rank_zero import rank_zero_only from ldm.util import log_txt_as_img, exists, default, ismap, isimage, mean_flat, count_params, instantiate_from_config from ldm.modules.ema import LitEma From 51cb20ec39e1ecb40ee8f35bbacf4ecf5c42d1f4 Mon Sep 17 00:00:00 2001 From: Dalton Date: Sun, 17 Mar 2024 22:45:31 -0400 Subject: [PATCH 02/14] Update ddpm_edit.py --- modules/models/diffusion/ddpm_edit.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/models/diffusion/ddpm_edit.py b/modules/models/diffusion/ddpm_edit.py index 6db340da4..526560059 100644 --- a/modules/models/diffusion/ddpm_edit.py +++ b/modules/models/diffusion/ddpm_edit.py @@ -19,7 +19,7 @@ from contextlib import contextmanager from functools import partial from tqdm import tqdm from torchvision.utils import make_grid -from pytorch_lightning.utilities.distributed import rank_zero_only +from pytorch_lightning.utilities.rank_zero import rank_zero_only from ldm.util import log_txt_as_img, exists, default, ismap, isimage, mean_flat, count_params, instantiate_from_config from ldm.modules.ema import LitEma From 61f321756fd3f0bb6310161a2022c9a86a71c2d1 Mon Sep 17 00:00:00 2001 From: Dalton Date: Tue, 19 Mar 2024 14:44:31 -0400 Subject: [PATCH 03/14] Update ddpm_edit.py --- modules/models/diffusion/ddpm_edit.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/modules/models/diffusion/ddpm_edit.py b/modules/models/diffusion/ddpm_edit.py index 526560059..120674238 100644 --- a/modules/models/diffusion/ddpm_edit.py +++ b/modules/models/diffusion/ddpm_edit.py @@ -9,6 +9,7 @@ https://github.com/CompVis/taming-transformers # File modified by authors of InstructPix2Pix from original (https://github.com/CompVis/stable-diffusion). # See more details in LICENSE. +import sys import torch import torch.nn as nn import numpy as np @@ -19,6 +20,8 @@ from contextlib import contextmanager from functools import partial from tqdm import tqdm from torchvision.utils import make_grid +import pytorch_lightning.utilities.rank_zero +sys.modules['pytorch_lightning.utilities.distributed'] = sys.modules['pytorch_lightning.utilities.rank_zero'] from pytorch_lightning.utilities.rank_zero import rank_zero_only from ldm.util import log_txt_as_img, exists, default, ismap, isimage, mean_flat, count_params, instantiate_from_config From 86276832e0204aebb6353b22dcce1c832a2ae865 Mon Sep 17 00:00:00 2001 From: Dalton Date: Tue, 19 Mar 2024 14:45:07 -0400 Subject: [PATCH 04/14] Update sd_hijack_ddpm_v1.py --- extensions-builtin/LDSR/sd_hijack_ddpm_v1.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/extensions-builtin/LDSR/sd_hijack_ddpm_v1.py b/extensions-builtin/LDSR/sd_hijack_ddpm_v1.py index 21e6c61c8..594dbc776 100644 --- a/extensions-builtin/LDSR/sd_hijack_ddpm_v1.py +++ b/extensions-builtin/LDSR/sd_hijack_ddpm_v1.py @@ -4,6 +4,7 @@ # Some models such as LDSR require VQ to work correctly # The classes are suffixed with "V1" and added back to the "ldm.models.diffusion.ddpm" module +import sys import torch import torch.nn as nn import numpy as np @@ -14,6 +15,8 @@ from contextlib import contextmanager from functools import partial from tqdm import tqdm from torchvision.utils import make_grid +import pytorch_lightning.utilities.rank_zero +sys.modules['pytorch_lightning.utilities.distributed'] = sys.modules['pytorch_lightning.utilities.rank_zero'] from pytorch_lightning.utilities.rank_zero import rank_zero_only from ldm.util import log_txt_as_img, exists, default, ismap, isimage, mean_flat, count_params, instantiate_from_config From 8f450321fef86d904626a03a4e38f1719e225e11 Mon Sep 17 00:00:00 2001 From: Dalton Date: Tue, 19 Mar 2024 14:53:30 -0400 Subject: [PATCH 05/14] Formatting ddpm_edit --- modules/models/diffusion/ddpm_edit.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/models/diffusion/ddpm_edit.py b/modules/models/diffusion/ddpm_edit.py index 120674238..935d3564f 100644 --- a/modules/models/diffusion/ddpm_edit.py +++ b/modules/models/diffusion/ddpm_edit.py @@ -14,13 +14,13 @@ import torch import torch.nn as nn import numpy as np import pytorch_lightning as pl +import pytorch_lightning.utilities.rank_zero from torch.optim.lr_scheduler import LambdaLR from einops import rearrange, repeat from contextlib import contextmanager from functools import partial from tqdm import tqdm from torchvision.utils import make_grid -import pytorch_lightning.utilities.rank_zero sys.modules['pytorch_lightning.utilities.distributed'] = sys.modules['pytorch_lightning.utilities.rank_zero'] from pytorch_lightning.utilities.rank_zero import rank_zero_only From 49779413aafecea511cd01b3b253643ff42998ca Mon Sep 17 00:00:00 2001 From: Dalton Date: Tue, 19 Mar 2024 14:54:06 -0400 Subject: [PATCH 06/14] Formatting sd_hijack_ddpm_v1.py --- extensions-builtin/LDSR/sd_hijack_ddpm_v1.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/extensions-builtin/LDSR/sd_hijack_ddpm_v1.py b/extensions-builtin/LDSR/sd_hijack_ddpm_v1.py index 594dbc776..cd54ab4b1 100644 --- a/extensions-builtin/LDSR/sd_hijack_ddpm_v1.py +++ b/extensions-builtin/LDSR/sd_hijack_ddpm_v1.py @@ -9,13 +9,13 @@ import torch import torch.nn as nn import numpy as np import pytorch_lightning as pl +import pytorch_lightning.utilities.rank_zero from torch.optim.lr_scheduler import LambdaLR from einops import rearrange, repeat from contextlib import contextmanager from functools import partial from tqdm import tqdm from torchvision.utils import make_grid -import pytorch_lightning.utilities.rank_zero sys.modules['pytorch_lightning.utilities.distributed'] = sys.modules['pytorch_lightning.utilities.rank_zero'] from pytorch_lightning.utilities.rank_zero import rank_zero_only From 5fd9a40b92c572c357773018cd47b0a7d3b8f9c3 Mon Sep 17 00:00:00 2001 From: Dalton Date: Wed, 20 Mar 2024 23:01:50 -0400 Subject: [PATCH 07/14] Revert sd_hijack_ddpm_v1.py --- extensions-builtin/LDSR/sd_hijack_ddpm_v1.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/extensions-builtin/LDSR/sd_hijack_ddpm_v1.py b/extensions-builtin/LDSR/sd_hijack_ddpm_v1.py index cd54ab4b1..7944fb13c 100644 --- a/extensions-builtin/LDSR/sd_hijack_ddpm_v1.py +++ b/extensions-builtin/LDSR/sd_hijack_ddpm_v1.py @@ -16,8 +16,7 @@ from contextlib import contextmanager from functools import partial from tqdm import tqdm from torchvision.utils import make_grid -sys.modules['pytorch_lightning.utilities.distributed'] = sys.modules['pytorch_lightning.utilities.rank_zero'] -from pytorch_lightning.utilities.rank_zero import rank_zero_only +from pytorch_lightning.utilities.distributed import rank_zero_only from ldm.util import log_txt_as_img, exists, default, ismap, isimage, mean_flat, count_params, instantiate_from_config from ldm.modules.ema import LitEma From f010dfffb9b6021f8b4e4f03f22532f7edef7137 Mon Sep 17 00:00:00 2001 From: Dalton Date: Wed, 20 Mar 2024 23:02:30 -0400 Subject: [PATCH 08/14] Revert ddpm_edit.py --- modules/models/diffusion/ddpm_edit.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/modules/models/diffusion/ddpm_edit.py b/modules/models/diffusion/ddpm_edit.py index 935d3564f..347117cb9 100644 --- a/modules/models/diffusion/ddpm_edit.py +++ b/modules/models/diffusion/ddpm_edit.py @@ -21,8 +21,7 @@ from contextlib import contextmanager from functools import partial from tqdm import tqdm from torchvision.utils import make_grid -sys.modules['pytorch_lightning.utilities.distributed'] = sys.modules['pytorch_lightning.utilities.rank_zero'] -from pytorch_lightning.utilities.rank_zero import rank_zero_only +from pytorch_lightning.utilities.distributed import rank_zero_only from ldm.util import log_txt_as_img, exists, default, ismap, isimage, mean_flat, count_params, instantiate_from_config from ldm.modules.ema import LitEma From b5b04912b523cfa7fd7e93026b1ca6c0d6456c3f Mon Sep 17 00:00:00 2001 From: Dalton Date: Wed, 20 Mar 2024 23:06:00 -0400 Subject: [PATCH 09/14] Include running pytorch lightning check --- modules/initialize.py | 1 + 1 file changed, 1 insertion(+) diff --git a/modules/initialize.py b/modules/initialize.py index f7313ff4d..de92863f3 100644 --- a/modules/initialize.py +++ b/modules/initialize.py @@ -51,6 +51,7 @@ def check_versions(): def initialize(): from modules import initialize_util initialize_util.fix_torch_version() + initialize_util.fix_pytorch_lightning() initialize_util.fix_asyncio_event_loop_policy() initialize_util.validate_tls_options() initialize_util.configure_sigint_handler() From 4eb5e09873720c55003bea89d527f99e62f36cb0 Mon Sep 17 00:00:00 2001 From: Dalton Date: Wed, 20 Mar 2024 23:28:40 -0400 Subject: [PATCH 10/14] Update initialize_util.py --- modules/initialize_util.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/modules/initialize_util.py b/modules/initialize_util.py index b6767138d..63cea137f 100644 --- a/modules/initialize_util.py +++ b/modules/initialize_util.py @@ -24,6 +24,13 @@ def fix_torch_version(): torch.__long_version__ = torch.__version__ torch.__version__ = re.search(r'[\d.]+[\d]', torch.__version__).group(0) +def fix_pytorch_lightning(): + import pytorch_lightning + # Checks if pytorch_lightning.utilities.distributed already exists in the sys.modules cache + if 'pytorch_lightning.utilities.distributed' not in sys.modules: + # Lets the user know that the library was not found and then will set it to pytorch_lightning.utilities.rank_zero + print(f"Pytorch_lightning.distributed not found, attempting pytorch_lightning.rank_zero") + sys.modules["pytorch_lightning.utilities.distributed"] = pytorch_lightning.utilities.rank_zero def fix_asyncio_event_loop_policy(): """ From 4bc296332021cb07ba1fe449d72049604efd7a02 Mon Sep 17 00:00:00 2001 From: Dalton Date: Wed, 20 Mar 2024 23:33:15 -0400 Subject: [PATCH 11/14] Remove unnecessary import --- modules/initialize_util.py | 1 - 1 file changed, 1 deletion(-) diff --git a/modules/initialize_util.py b/modules/initialize_util.py index 63cea137f..7a661476d 100644 --- a/modules/initialize_util.py +++ b/modules/initialize_util.py @@ -25,7 +25,6 @@ def fix_torch_version(): torch.__version__ = re.search(r'[\d.]+[\d]', torch.__version__).group(0) def fix_pytorch_lightning(): - import pytorch_lightning # Checks if pytorch_lightning.utilities.distributed already exists in the sys.modules cache if 'pytorch_lightning.utilities.distributed' not in sys.modules: # Lets the user know that the library was not found and then will set it to pytorch_lightning.utilities.rank_zero From 41907b25f0baa62f773f37a73dc4e656a710bc8a Mon Sep 17 00:00:00 2001 From: Dalton Date: Wed, 20 Mar 2024 23:35:32 -0400 Subject: [PATCH 12/14] Cleanup sd_hijack_ddpm_v1.py Forgot some things to revert --- extensions-builtin/LDSR/sd_hijack_ddpm_v1.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/extensions-builtin/LDSR/sd_hijack_ddpm_v1.py b/extensions-builtin/LDSR/sd_hijack_ddpm_v1.py index 7944fb13c..04adc5eb2 100644 --- a/extensions-builtin/LDSR/sd_hijack_ddpm_v1.py +++ b/extensions-builtin/LDSR/sd_hijack_ddpm_v1.py @@ -4,12 +4,10 @@ # Some models such as LDSR require VQ to work correctly # The classes are suffixed with "V1" and added back to the "ldm.models.diffusion.ddpm" module -import sys import torch import torch.nn as nn import numpy as np import pytorch_lightning as pl -import pytorch_lightning.utilities.rank_zero from torch.optim.lr_scheduler import LambdaLR from einops import rearrange, repeat from contextlib import contextmanager From 4e6e2574aba19a2a1b248601e33fad82fb881523 Mon Sep 17 00:00:00 2001 From: Dalton Date: Wed, 20 Mar 2024 23:36:35 -0400 Subject: [PATCH 13/14] Cleanup ddpm_edit.py Fully reverts this time --- modules/models/diffusion/ddpm_edit.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/modules/models/diffusion/ddpm_edit.py b/modules/models/diffusion/ddpm_edit.py index 347117cb9..6db340da4 100644 --- a/modules/models/diffusion/ddpm_edit.py +++ b/modules/models/diffusion/ddpm_edit.py @@ -9,12 +9,10 @@ https://github.com/CompVis/taming-transformers # File modified by authors of InstructPix2Pix from original (https://github.com/CompVis/stable-diffusion). # See more details in LICENSE. -import sys import torch import torch.nn as nn import numpy as np import pytorch_lightning as pl -import pytorch_lightning.utilities.rank_zero from torch.optim.lr_scheduler import LambdaLR from einops import rearrange, repeat from contextlib import contextmanager From 32ba7575010a3fdd024cc4058650d81988d126f1 Mon Sep 17 00:00:00 2001 From: Dalton Date: Wed, 20 Mar 2024 23:55:04 -0400 Subject: [PATCH 14/14] Re-add import but after if check --- modules/initialize_util.py | 1 + 1 file changed, 1 insertion(+) diff --git a/modules/initialize_util.py b/modules/initialize_util.py index 7a661476d..8abe78814 100644 --- a/modules/initialize_util.py +++ b/modules/initialize_util.py @@ -27,6 +27,7 @@ def fix_torch_version(): def fix_pytorch_lightning(): # Checks if pytorch_lightning.utilities.distributed already exists in the sys.modules cache if 'pytorch_lightning.utilities.distributed' not in sys.modules: + import pytorch_lightning # Lets the user know that the library was not found and then will set it to pytorch_lightning.utilities.rank_zero print(f"Pytorch_lightning.distributed not found, attempting pytorch_lightning.rank_zero") sys.modules["pytorch_lightning.utilities.distributed"] = pytorch_lightning.utilities.rank_zero