Unable to run Diffusers while offline
I am running into the error below when I try to run my Diffusers model completely offline (without any internet connection). However, my code works perfectly if I have internet.I work in very remote locations for a few weeks out of every month and I don’t always have access to the internet while I am away. How can I avoid this error?Traceback (most recent call last):File “C:\Users\User\PycharmProjects\runinf\venv\lib\site-packages\urllib3\connection.py”, line 174, in _new_connconn = connection.create_connection(File “C:\Users\User\PycharmProjects\runinf\venv\lib\site-packages\urllib3\util\connection.py”, line 72, in create_connectionfor res in socket.getaddrinfo(host, port, family, socket.SOCK_STREAM):File “C:\Users\User\AppData\Local\Programs\Python\Python310\lib\socket.py”, line 955, in getaddrinfofor res in _socket.getaddrinfo(host, port, family, type, proto, flags):socket.gaierror: [Errno 11001] getaddrinfo failedDuring handling of the above exception, another exception occurred:Traceback (most recent call last):File “C:\Users\User\PycharmProjects\runinf\venv\lib\site-packages\urllib3\connectionpool.py”, line 703, in urlopenhttplib_response = self._make_request(File “C:\Users\User\PycharmProjects\runinf\venv\lib\site-packages\urllib3\connectionpool.py”, line 386, in _make_requestself._validate_conn(conn)File “C:\Users\User\PycharmProjects\runinf\venv\lib\site-packages\urllib3\connectionpool.py”, line 1042, in _validate_connconn.connect()File “C:\Users\User\PycharmProjects\runinf\venv\lib\site-packages\urllib3\connection.py”, line 358, in connectself.sock = conn = self._new_conn()File “C:\Users\User\PycharmProjects\runinf\venv\lib\site-packages\urllib3\connection.py”, line 186, in _new_connraise NewConnectionError(urllib3.exceptions.NewConnectionError: <urllib3.connection.HTTPSConnection object at 0x00000257B6781EA0>: Failed to establish a new connection: [Errno 11001] getaddrinfo failedDuring handling of the above exception, another exception occurred:Traceback (most recent call last):File “C:\Users\User\PycharmProjects\runinf\venv\lib\site-packages\requests\adapters.py”, line 489, in sendresp = conn.urlopen(File “C:\Users\User\PycharmProjects\runinf\venv\lib\site-packages\urllib3\connectionpool.py”, line 787, in urlopenretries = retries.increment(File “C:\Users\User\PycharmProjects\runinf\venv\lib\site-packages\urllib3\util\retry.py”, line 592, in incrementraise MaxRetryError(_pool, url, error or ResponseError(cause))urllib3.exceptions.MaxRetryError: HTTPSConnectionPool(host=‘raw.githubusercontent.com’, port=443): Max retries exceeded with url: /CompVis/stable-diffusion/main/configs/stable-diffusion/v1-inference.yaml (Caused by NewConnectionError(‘<urllib3.connection.HTTPSConnection object at 0x00000257B6781EA0>: Failed to establish a new connection: [Errno 11001] getaddrinfo failed’))During handling of the above exception, another exception occurred:Traceback (most recent call last):File “C:\Users\User\PycharmProjects\runinf\main.py”, line 8, inimport gen_imgFile “C:\Users\User\PycharmProjects\runinf\gen_img.py”, line 17, inpipe = StableDiffusionImg2ImgPipeline.from_single_file(pretrained_model_link_or_path=model_id_or_path, torch_dtype=torch.float16, local_files_only=True)File “C:\Users\User\PycharmProjects\runinf\venv\lib\site-packages\diffusers\loaders.py”, line 1924, in from_single_filepipe = download_from_original_stable_diffusion_ckpt(File “C:\Users\User\PycharmProjects\runinf\venv\lib\site-packages\diffusers\pipelines\stable_diffusion\convert_from_ckpt.py”, line 1253, in download_from_original_stable_diffusion_ckptoriginal_config_file = BytesIO(requests.get(config_url).content)File “C:\Users\User\PycharmProjects\runinf\venv\lib\site-packages\requests\api.py”, line 73, in getreturn request(“get”, url, params=params, **kwargs)File “C:\Users\User\PycharmProjects\runinf\venv\lib\site-packages\requests\api.py”, line 59, in requestreturn session.request(method=method, url=url, **kwargs)File “C:\Users\User\PycharmProjects\runinf\venv\lib\site-packages\requests\sessions.py”, line 587, in requestresp = self.send(prep, **send_kwargs)File “C:\Users\User\PycharmProjects\runinf\venv\lib\site-packages\requests\sessions.py”, line 701, in sendr = adapter.send(request, **kwargs)File “C:\Users\User\PycharmProjects\runinf\venv\lib\site-packages\requests\adapters.py”, line 565, in sendraise ConnectionError(e, request=request)requests.exceptions.ConnectionError: HTTPSConnectionPool(host=‘raw.githubusercontent.com’, port=443): Max retries exceeded with url: /CompVis/stable-diffusion/main/configs/stable-diffusion/v1-inference.yaml (Caused by NewConnectionError(‘<urllib3.connection.HTTPSConnection object at 0x00000257B6781EA0>: Failed to establish a new connection: [Errno 11001] getaddrinfo failed’))Process finished with exit code 1I am using the following code to establish my pipeline:model_id_or_path = “./model/diff_model_3.safetensors”pipe = StableDiffusionImg2ImgPipeline.from_single_file(pretrained_model_link_or_path=model_id_or_path, torch_dtype=torch.float16, local_files_only=True)print(pipe.config.values())pipe.scheduler = EulerAncestralDiscreteScheduler.from_config(pipe.scheduler.config)pipe = pipe.to(device)
2023-08-26T17:32:16Z
For anyone encountering the issue of the Huggingface diffusers library not working with local models when there’s no internet connection, I’ve identified a solution.I initially intended to submit a Pull Request to GitHub but noticed that another contributor has already submitted a similar fix. I can confirm that the proposed changes effectively resolve the issue.If you are currently having the same issue and want a quick fix, you can make the following changes to the loaders.py file:Modifyfrom_single_file()functionAdd a keyword argument to the function definition as follows:original_config_file = kwargs.pop("original_config_file", None)Modifydownload_from_original_stable_diffusion_ckpt()function at the end of the  ‘from_single_file()’ functionPass the new keyword argument like this:original_config_file=original_config_fileThis will allow you to specify a local.yamlfile for the original configuration of the model.You can find the URLs for the.yamlfiles in theconvert_from_ckpt.pyfile. This is what the library attempts to download, causing the error.As of the time of writing, relevant URLs are located as follows:For model_type = “v1”:https://raw.githubusercontent.com/CompVis/stable-diffusion/main/configs/stable-diffusion/v1-inference.yamlFor model_type = “v2”:https://raw.githubusercontent.com/Stability-AI/stablediffusion/main/configs/stable-diffusion/v2-inference-v.yamlFor model_type = “sd_xl_base”:https://raw.githubusercontent.com/Stability-AI/generative-models/main/configs/inference/sd_xl_base.yamlFor model_type = “sd_xl_refiner”:https://raw.githubusercontent.com/Stability-AI/generative-models/main/configs/inference/sd_xl_refiner.yamlOr, you can use the .yaml’s packaged in Automatic1111’s stable-diffusion-webui/configs if you are already using their GUI.
2023-08-26T18:37:15Z
Hi@BoltMonkey! Is this the PR you were referring to?add config_file to from_single_file by zuojianghua · Pull Request #4614 · huggingface/diffusers · GitHubIf so, then I think the problem would be resolved, right?
2023-08-26T18:43:40Z
Yes, that is the one.