Repository: stable-diffusion-webui
Issue: [Bug]: ModuleNotFoundError: No module named 'pytorch_lightning.utilities.distributed' (with dev aa4a451)
Labels: bug-report

### Checklist

- [X] The issue exists after disabling all extensions
- [X] The issue exists on a clean installation of webui
- [ ] The issue is caused by an extension, but I believe it is caused by a bug in the webui
- [X] The issue exists in the current version of the webui
- [ ] The issue has not been reported before recently
- [X] The issue has been reported before but has not been fixed yet

### What happened?

Running the WebUI yields the following error:

```
ModuleNotFoundError: No module named 'pytorch_lightning.utilities.distributed'
```

### Steps to reproduce the problem

1. Try to run the webui on a fresh installation with the version locked requirements.txt

### What should have happened?

The WebUI should not crash.

### What browsers do you use to access the UI ?

_No response_

### Sysinfo

Unable to provide, crashes before even being able to dump

### Console logs

```Shell
no module 'xformers'. Processing without...
no module 'xformers'. Processing without...
Warning: k_diffusion not found at path /nix/store/xikw87zzszkl8amyr9r1igggj28qw8mw-stable-diffusion-webui-git/repositories/k-diffusion/k_diffusion/sampling.py
Traceback (most recent call last):
  File "/nix/store/xikw87zzszkl8amyr9r1igggj28qw8mw-stable-diffusion-webui-git/webui.py", line 13, in <module>
    initialize.imports()
  File "/nix/store/xikw87zzszkl8amyr9r1igggj28qw8mw-stable-diffusion-webui-git/modules/initialize.py", line 35, in imports
    from modules import shared_init
  File "/nix/store/xikw87zzszkl8amyr9r1igggj28qw8mw-stable-diffusion-webui-git/modules/shared_init.py", line 5, in <module>
    from modules import shared
  File "/nix/store/xikw87zzszkl8amyr9r1igggj28qw8mw-stable-diffusion-webui-git/modules/shared.py", line 6, in <module>
    from modules import shared_cmd_options, shared_gradio_themes, options, shared_items, sd_models_types
  File "/nix/store/xikw87zzszkl8amyr9r1igggj28qw8mw-stable-diffusion-webui-git/modules/sd_models_types.py", line 1, in <module>
    from ldm.models.diffusion.ddpm import LatentDiffusion
  File "/nix/store/xikw87zzszkl8amyr9r1igggj28qw8mw-stable-diffusion-webui-git/repositories/stable-diffusion-stability-ai/ldm/models/diffusion/ddpm.py", line 20, in <module>
    from pytorch_lightning.utilities.distributed import rank_zero_only
ModuleNotFoundError: No module named 'pytorch_lightning.utilities.distributed'
```


### Additional information

This is caused by the import call here:
https://github.com/AUTOMATIC1111/stable-diffusion-webui/blob/aa4a45187eda51fe564139e0087d119b981ca66d/modules/initialize.py#L35

The WebUI attempts to apply a fix here:
https://github.com/AUTOMATIC1111/stable-diffusion-webui/blob/aa4a45187eda51fe564139e0087d119b981ca66d/modules/initialize.py#L54

However, since the `imports()` function is called before `initialize()` is called, this doesn't fix the issue.

Locations:
https://github.com/AUTOMATIC1111/stable-diffusion-webui/blob/aa4a45187eda51fe564139e0087d119b981ca66d/webui.py#L13
Implicitly called (due to importing) before this:
https://github.com/AUTOMATIC1111/stable-diffusion-webui/blob/aa4a45187eda51fe564139e0087d119b981ca66d/webui.py#L52