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

sd_api_pictures can't connect to stable diffusion on wsl #573

Closed
1 task done
laughinggaschambers opened this issue Mar 25, 2023 · 5 comments
Closed
1 task done
Labels
bug Something isn't working

Comments

@laughinggaschambers
Copy link

Describe the bug

Running the sd api natively on windows 10 works
but when doing it via wsl it's not able to connect to the stable diffusion address(sd is being run on windows 10 natively)

Is there an existing issue for this?

  • I have searched the existing issues

Reproduction

Run stable diffusion on windows 10
Run the webui in wsl

Screenshot

No response

Logs

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/doom/miniconda3/envs/textgen/lib/python3.10/site-packages/gradio/routes.py", line 374, in run_predict
    output = await app.get_blocks().process_api(
  File "/home/doom/miniconda3/envs/textgen/lib/python3.10/site-packages/gradio/blocks.py", line 1017, in process_api
    result = await self.call_function(
  File "/home/doom/miniconda3/envs/textgen/lib/python3.10/site-packages/gradio/blocks.py", line 849, in call_function
    prediction = await anyio.to_thread.run_sync(
  File "/home/doom/miniconda3/envs/textgen/lib/python3.10/site-packages/anyio/to_thread.py", line 31, in run_sync
    return await get_asynclib().run_sync_in_worker_thread(
  File "/home/doom/miniconda3/envs/textgen/lib/python3.10/site-packages/anyio/_backends/_asyncio.py", line 937, in run_sync_in_worker_thread
    return await future
  File "/home/doom/miniconda3/envs/textgen/lib/python3.10/site-packages/anyio/_backends/_asyncio.py", line 867, in run
    result = context.run(func, *args)
  File "/home/doom/miniconda3/envs/textgen/lib/python3.10/site-packages/gradio/utils.py", line 453, in async_iteration
    return next(iterator)
  File "/home/doom/text-generation-webui/modules/chat.py", line 167, in cai_chatbot_wrapper
    for _history in chatbot_wrapper(text, max_new_tokens, do_sample, temperature, top_p, typical_p, repetition_penalty, encoder_repetition_penalty, top_k, min_length, no_repeat_ngram_size, num_beams, penalty_alpha, length_penalty, early_stopping, seed, name1, name2, context, check, chat_prompt_size, chat_generation_attempts):
  File "/home/doom/text-generation-webui/modules/chat.py", line 125, in chatbot_wrapper
    visible_reply = apply_extensions(visible_reply, "output")
  File "/home/doom/text-generation-webui/modules/extensions.py", line 36, in apply_extensions
    text = extension.output_modifier(text)
  File "/home/doom/text-generation-webui/extensions/sd_api_pictures/script.py", line 125, in output_modifier
    image = get_SD_pictures(string)
  File "/home/doom/text-generation-webui/extensions/sd_api_pictures/script.py", line 81, in get_SD_pictures
    response = requests.post(url=f'{params["address"]}/sdapi/v1/txt2img', json=payload)
  File "/home/doom/miniconda3/envs/textgen/lib/python3.10/site-packages/requests/api.py", line 115, in post
    return request("post", url, data=data, json=json, **kwargs)
  File "/home/doom/miniconda3/envs/textgen/lib/python3.10/site-packages/requests/api.py", line 59, in request
    return session.request(method=method, url=url, **kwargs)
  File "/home/doom/miniconda3/envs/textgen/lib/python3.10/site-packages/requests/sessions.py", line 587, in request
    resp = self.send(prep, **send_kwargs)
  File "/home/doom/miniconda3/envs/textgen/lib/python3.10/site-packages/requests/sessions.py", line 701, in send
    r = adapter.send(request, **kwargs)
  File "/home/doom/miniconda3/envs/textgen/lib/python3.10/site-packages/requests/adapters.py", line 565, in send
    raise ConnectionError(e, request=request)
requests.exceptions.ConnectionError: HTTPConnectionPool(host='127.0.0.1', port=8000): Max retries exceeded with url: /sdapi/v1/txt2img (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x7f0d0e1fdfc0>: Failed to establish a new connection: [Errno 111] Connection refused'))

System Info

GTX 3090 
Windows 10 wsl
@laughinggaschambers laughinggaschambers added the bug Something isn't working label Mar 25, 2023
@Brawlence
Copy link
Contributor

Try the script.py from here:
#596

Disable Manage VRAM, paste the address into the box and press enter. What does it report?

@laughinggaschambers
Copy link
Author

Prompting the image generator via the API on 127.0.0.1:8000…
Output generated in 12.24 seconds (16.34 tokens/s, 200 tokens, context 385)
Traceback (most recent call last):
File "/home/doom/miniconda3/envs/textgen/lib/python3.10/site-packages/urllib3/connection.py", line 174, in _new_conn
conn = connection.create_connection(
File "/home/doom/miniconda3/envs/textgen/lib/python3.10/site-packages/urllib3/util/connection.py", line 95, in create_connection
raise err
File "/home/doom/miniconda3/envs/textgen/lib/python3.10/site-packages/urllib3/util/connection.py", line 85, in create_connection
sock.connect(sa)
ConnectionRefusedError: [Errno 111] Connection refused

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "/home/doom/miniconda3/envs/textgen/lib/python3.10/site-packages/urllib3/connectionpool.py", line 703, in urlopen
httplib_response = self._make_request(
File "/home/doom/miniconda3/envs/textgen/lib/python3.10/site-packages/urllib3/connectionpool.py", line 398, in _make_request
conn.request(method, url, **httplib_request_kw)
File "/home/doom/miniconda3/envs/textgen/lib/python3.10/site-packages/urllib3/connection.py", line 244, in request
super(HTTPConnection, self).request(method, url, body=body, headers=headers)
File "/home/doom/miniconda3/envs/textgen/lib/python3.10/http/client.py", line 1282, in request
self._send_request(method, url, body, headers, encode_chunked)
File "/home/doom/miniconda3/envs/textgen/lib/python3.10/http/client.py", line 1328, in _send_request
self.endheaders(body, encode_chunked=encode_chunked)
File "/home/doom/miniconda3/envs/textgen/lib/python3.10/http/client.py", line 1277, in endheaders
self._send_output(message_body, encode_chunked=encode_chunked)
File "/home/doom/miniconda3/envs/textgen/lib/python3.10/http/client.py", line 1037, in _send_output
self.send(msg)
File "/home/doom/miniconda3/envs/textgen/lib/python3.10/http/client.py", line 975, in send
self.connect()
File "/home/doom/miniconda3/envs/textgen/lib/python3.10/site-packages/urllib3/connection.py", line 205, in connect
conn = self._new_conn()
File "/home/doom/miniconda3/envs/textgen/lib/python3.10/site-packages/urllib3/connection.py", line 186, in _new_conn
raise NewConnectionError(
urllib3.exceptions.NewConnectionError: <urllib3.connection.HTTPConnection object at 0x7fa4e3570820>: Failed to establish a new connection: [Errno 111] Connection refused

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "/home/doom/miniconda3/envs/textgen/lib/python3.10/site-packages/requests/adapters.py", line 489, in send
resp = conn.urlopen(
File "/home/doom/miniconda3/envs/textgen/lib/python3.10/site-packages/urllib3/connectionpool.py", line 787, in urlopen
retries = retries.increment(
File "/home/doom/miniconda3/envs/textgen/lib/python3.10/site-packages/urllib3/util/retry.py", line 592, in increment
raise MaxRetryError(_pool, url, error or ResponseError(cause))
urllib3.exceptions.MaxRetryError: HTTPConnectionPool(host='127.0.0.1', port=8000): Max retries exceeded with url: /sdapi/v1/txt2img (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x7fa4e3570820>: Failed to establish a new connection: [Errno 111] Connection refused'))

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "/home/doom/miniconda3/envs/textgen/lib/python3.10/site-packages/gradio/routes.py", line 374, in run_predict
output = await app.get_blocks().process_api(
File "/home/doom/miniconda3/envs/textgen/lib/python3.10/site-packages/gradio/blocks.py", line 1017, in process_api
result = await self.call_function(
File "/home/doom/miniconda3/envs/textgen/lib/python3.10/site-packages/gradio/blocks.py", line 849, in call_function
prediction = await anyio.to_thread.run_sync(
File "/home/doom/miniconda3/envs/textgen/lib/python3.10/site-packages/anyio/to_thread.py", line 31, in run_sync
return await get_asynclib().run_sync_in_worker_thread(
File "/home/doom/miniconda3/envs/textgen/lib/python3.10/site-packages/anyio/_backends/_asyncio.py", line 937, in run_sync_in_worker_thread
return await future
File "/home/doom/miniconda3/envs/textgen/lib/python3.10/site-packages/anyio/_backends/_asyncio.py", line 867, in run
result = context.run(func, *args)
File "/home/doom/miniconda3/envs/textgen/lib/python3.10/site-packages/gradio/utils.py", line 453, in async_iteration
return next(iterator)
File "/home/doom/text-generation-webui/modules/chat.py", line 188, in regenerate_wrapper
for _history in chatbot_wrapper(last_internal[0], max_new_tokens, do_sample, temperature, top_p, typical_p, repetition_penalty, encoder_repetition_penalty, top_k, min_length, no_repeat_ngram_size, num_beams, penalty_alpha, length_penalty, early_stopping, seed, name1, name2, context, check, chat_prompt_size, chat_generation_attempts, regenerate=True):
File "/home/doom/text-generation-webui/modules/chat.py", line 128, in chatbot_wrapper
visible_reply = apply_extensions(visible_reply, "output")
File "/home/doom/text-generation-webui/modules/extensions.py", line 37, in apply_extensions
text = extension.output_modifier(text)
File "/home/doom/text-generation-webui/extensions/sd_api_pictures/script.py", line 151, in output_modifier
string = get_SD_pictures(string) + "\n" + text
File "/home/doom/text-generation-webui/extensions/sd_api_pictures/script.py", line 93, in get_SD_pictures
response = requests.post(url=f'http://{params["address"]}/sdapi/v1/txt2img', json=payload)
File "/home/doom/miniconda3/envs/textgen/lib/python3.10/site-packages/requests/api.py", line 115, in post
return request("post", url, data=data, json=json, **kwargs)
File "/home/doom/miniconda3/envs/textgen/lib/python3.10/site-packages/requests/api.py", line 59, in request
return session.request(method=method, url=url, **kwargs)
File "/home/doom/miniconda3/envs/textgen/lib/python3.10/site-packages/requests/sessions.py", line 587, in request
resp = self.send(prep, **send_kwargs)
File "/home/doom/miniconda3/envs/textgen/lib/python3.10/site-packages/requests/sessions.py", line 701, in send
r = adapter.send(request, **kwargs)
File "/home/doom/miniconda3/envs/textgen/lib/python3.10/site-packages/requests/adapters.py", line 565, in send
raise ConnectionError(e, request=request)
requests.exceptions.ConnectionError: HTTPConnectionPool(host='127.0.0.1', port=8000): Max retries exceeded with url: /sdapi/v1/txt2img (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x7fa4e3570820>: Failed to establish a new connection: [Errno 111] Connection refused'))

@Brawlence
Copy link
Contributor

As far as I can tell, that's a general problem with WSL — sometimes it's refusing to form connection between native and WSL sockets.

Let's try this workaround then:
Are you on LAN or WLAN? Do you know your local IP address? Smth like 10.10.10.2 or 192.168.1.4 ? You can look it up in Control Panel → Ethernet → {your connection} → IPv4 address (in the Properties table below).

Use it instead of 127.0.0.1, force the packets to go via your router

@laughinggaschambers
Copy link
Author

it works

@Brawlence
Copy link
Contributor

Brawlence commented Mar 28, 2023

Yup, then it's a WSL sockets <> native sockets problem.

I can't really reliably detect and mitigate that so for now the best solution would be simply to write a warning about this issue in the planned README.MD with this workaround as a band-aid

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants