Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RuntimeError: Cannot add middleware after an application has started #42

Open
tommyjohn81 opened this issue Feb 10, 2023 · 3 comments
Open

Comments

@tommyjohn81
Copy link

Issue:

At Run Script step, the following error occurs:

Running on local URL: http://127.0.0.1:7860/
Running on public URL: https://c52af886-9da1-47f6.gradio.live/

This share link expires in 72 hours. For free permanent hosting and GPU upgrades (NEW!), check out Spaces: https://huggingface.co/spaces
Traceback (most recent call last):
File "/content/stable-diffusion-webui/launch.py", line 361, in
start()
File "/content/stable-diffusion-webui/launch.py", line 356, in start
webui.webui()
File "/content/stable-diffusion-webui/webui.py", line 232, in webui
app.add_middleware(GZipMiddleware, minimum_size=1000)
File "/opt/conda/lib/python3.10/site-packages/starlette/applications.py", line 135, in add_middleware
raise RuntimeError("Cannot add middleware after an application has started")
RuntimeError: Cannot add middleware after an application has started
Killing tunnel 127.0.0.1:7860 <> https://c52af886-9da1-47f6.gradio.live/
Traceback (most recent call last):
File "/opt/conda/bin/accelerate", line 8, in
sys.exit(main())
File "/opt/conda/lib/python3.10/site-packages/accelerate/commands/accelerate_cli.py", line 43, in main
args.func(args)
File "/opt/conda/lib/python3.10/site-packages/accelerate/commands/launch.py", line 837, in launch_command
simple_launcher(args)
File "/opt/conda/lib/python3.10/site-packages/accelerate/commands/launch.py", line 354, in simple_launcher
raise subprocess.CalledProcessError(returncode=process.returncode, cmd=cmd)
subprocess.CalledProcessError: Command '['/opt/conda/bin/python', 'launch.py']' returned non-zero exit status 1.

Apparently this is fixed by adding to python script:
-m pip install --upgrade fastapi==0.90.1

but thats beyond me hence why I used a colab.
More details of other users with same error here:

https://www.reddit.com/r/StableDiffusion/comments/10yurxl/help_with_error_please/

@changhefirst
Copy link

changhefirst commented Feb 11, 2023

I have the same errors. When 2023/02/08, the code run almost well, with auto1111 master branch and SD1.5 model, only SD2.1 512 model did not work. But when 02/10, it reported errors, and totally did not work. I reinstalled the colab environment multiple times, and no auto1111 extension installed.

First, it reported that it can not find SD1.5 model in safetensors formate, I redownload the ckpt model. Then, it reported middleware errors as the logs below. I tried to unselect the "apply_lowram_patch", but still not work. I tried "git checkout ea9bd9f", which is working commit last time I run, but still not work.

logs:

`/content/stable-diffusion-webui
You are not currently on a branch.
Please specify which branch you want to merge with.
See git-pull(1) for details.

git pull <remote> <branch>

The following values were not passed to accelerate launch and had defaults used instead:
--num_processes was set to a value of 1
--num_machines was set to a value of 1
--mixed_precision was set to a value of 'no'
To avoid this warning pass in values for each of the problematic parameters or run accelerate config.
Python 3.10.9 (main, Jan 11 2023, 15:21:40) [GCC 11.2.0]
Commit hash: ea9bd9fc7409109adcd61b897abc2c8881161256
Installing requirements for Web UI
Launching Web UI with arguments: --no-half-vae --xformers --share --gradio-queue --disable-safe-unpickle --enable-insecure-extension-access --api --cors-allow-origins=http://127.0.0.1:3456/
Loading weights [cc6cb27103] from /content/stable-diffusion-webui/models/Stable-diffusion/v1-5-pruned-emaonly.ckpt
Creating model from config: /content/stable-diffusion-webui/models/Stable-diffusion/v1-5-pruned-emaonly.yaml
LatentDiffusion: Running in eps-prediction mode
DiffusionWrapper has 859.52 M params.
Loading VAE weights found near the checkpoint: /content/stable-diffusion-webui/models/Stable-diffusion/v1-5-pruned-emaonly.vae.pt
Applying xformers cross attention optimization.
Textual inversion embeddings loaded(0):
Model loaded in 30.5s (load weights from disk: 18.2s, create model: 9.0s, apply weights to model: 1.2s, load VAE: 1.9s).
Running on local URL: http://127.0.0.1:7860/
Running on public URL: https://b71e7549-092b-45dc.gradio.live/

This share link expires in 72 hours. For free permanent hosting and GPU upgrades (NEW!), check out Spaces: https://huggingface.co/spaces
Traceback (most recent call last):
File "/content/stable-diffusion-webui/launch.py", line 361, in
start()
File "/content/stable-diffusion-webui/launch.py", line 356, in start
webui.webui()
File "/content/stable-diffusion-webui/webui.py", line 230, in webui
setup_cors(app)
File "/content/stable-diffusion-webui/webui.py", line 160, in setup_cors
app.add_middleware(CORSMiddleware, allow_origins=cmd_opts.cors_allow_origins.split(','), allow_methods=[''], allow_credentials=True, allow_headers=[''])
File "/opt/conda/lib/python3.10/site-packages/starlette/applications.py", line 135, in add_middleware
raise RuntimeError("Cannot add middleware after an application has started")
RuntimeError: Cannot add middleware after an application has started
Killing tunnel 127.0.0.1:7860 <> https://b71e7549-092b-45dc.gradio.live/
Traceback (most recent call last):
File "/opt/conda/bin/accelerate", line 8, in
sys.exit(main())
File "/opt/conda/lib/python3.10/site-packages/accelerate/commands/accelerate_cli.py", line 43, in main
args.func(args)
File "/opt/conda/lib/python3.10/site-packages/accelerate/commands/launch.py", line 837, in launch_command
simple_launcher(args)
File "/opt/conda/lib/python3.10/site-packages/accelerate/commands/launch.py", line 354, in simple_launcher
raise subprocess.CalledProcessError(returncode=process.returncode, cmd=cmd)
subprocess.CalledProcessError: Command '['/opt/conda/bin/python', 'launch.py']' returned non-zero exit status 1.`

@changhefirst
Copy link

changhefirst commented Feb 11, 2023

After reading this post : https://www.reddit.com/r/StableDiffusion/comments/10yurxl/help_with_error_please/

I changed codes in "Setup environment" cell, added "fastapi==0.90.1":

install_script = f""" eval "$({conda_bin} shell.bash hook)" cd stable-diffusion-webui python3 -m pip install --upgrade tensorrt triton fastapi==0.90.1 python -c 'from launch import prepare_environment; prepare_environment()'""" ! {install_script}

It works.

@tommyjohn81
Copy link
Author

Dreambooth and training is completely broken even with fastapi==0.90.1 settting

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants