Skip to content

Working offline once the models have been downloaded #232

@leszekhanusz

Description

@leszekhanusz

I thought that once the models had been downloaded once, they would be cached and it would be possible to use it offline.

Using this code, you need to have internet working at the beginning of the program.

Once it runs, internet is no more needed and you can generate images locally.

If you're not online at the start, the following exception happens:

Traceback (most recent call last):
  File "/home/leszek/miniconda3/envs/ldm/lib/python3.8/site-packages/urllib3/connection.py", line 174, in _new_conn
    conn = connection.create_connection(
  File "/home/leszek/miniconda3/envs/ldm/lib/python3.8/site-packages/urllib3/util/connection.py", line 72, in create_connection
    for res in socket.getaddrinfo(host, port, family, socket.SOCK_STREAM):
  File "/home/leszek/miniconda3/envs/ldm/lib/python3.8/socket.py", line 918, in getaddrinfo
    for res in _socket.getaddrinfo(host, port, family, type, proto, flags):
socket.gaierror: [Errno -3] Temporary failure in name resolution

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/leszek/miniconda3/envs/ldm/lib/python3.8/site-packages/urllib3/connectionpool.py", line 703, in urlopen
    httplib_response = self._make_request(
  File "/home/leszek/miniconda3/envs/ldm/lib/python3.8/site-packages/urllib3/connectionpool.py", line 386, in _make_request
    self._validate_conn(conn)
  File "/home/leszek/miniconda3/envs/ldm/lib/python3.8/site-packages/urllib3/connectionpool.py", line 1042, in _validate_conn
    conn.connect()
  File "/home/leszek/miniconda3/envs/ldm/lib/python3.8/site-packages/urllib3/connection.py", line 358, in connect
    self.sock = conn = self._new_conn()
  File "/home/leszek/miniconda3/envs/ldm/lib/python3.8/site-packages/urllib3/connection.py", line 186, in _new_conn
    raise NewConnectionError(
urllib3.exceptions.NewConnectionError: <urllib3.connection.HTTPSConnection object at 0x7f17bf089e80>: Failed to establish a new connection: [Errno -3] Temporary failure in name resolution

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/leszek/miniconda3/envs/ldm/lib/python3.8/site-packages/requests/adapters.py", line 489, in send
    resp = conn.urlopen(
  File "/home/leszek/miniconda3/envs/ldm/lib/python3.8/site-packages/urllib3/connectionpool.py", line 787, in urlopen
    retries = retries.increment(
  File "/home/leszek/miniconda3/envs/ldm/lib/python3.8/site-packages/urllib3/util/retry.py", line 592, in increment
    raise MaxRetryError(_pool, url, error or ResponseError(cause))
urllib3.exceptions.MaxRetryError: HTTPSConnectionPool(host='huggingface.co', port=443): Max retries exceeded with url: /api/models/CompVis/stable-diffusion-v1-4/revision/fp16 (Caused by NewConnectionError('<urllib3.connection.HTTPSConnection object at 0x7f17bf089e80>: Failed to establish a new connection: [Errno -3] Temporary failure in name resolution'))

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "test.py", line 13, in <module>
    pipe = StableDiffusionPipeline.from_pretrained(
  File "/mnt/tera/git-repos/diffusers/src/diffusers/pipeline_utils.py", line 154, in from_pretrained
    cached_folder = snapshot_download(
  File "/home/leszek/miniconda3/envs/ldm/lib/python3.8/site-packages/huggingface_hub/_snapshot_download.py", line 182, in snapshot_download
    repo_info = _api.repo_info(
  File "/home/leszek/miniconda3/envs/ldm/lib/python3.8/site-packages/huggingface_hub/hf_api.py", line 1289, in repo_info
    return self.model_info(
  File "/home/leszek/miniconda3/envs/ldm/lib/python3.8/site-packages/huggingface_hub/hf_api.py", line 1133, in model_info
    r = requests.get(
  File "/home/leszek/miniconda3/envs/ldm/lib/python3.8/site-packages/requests/api.py", line 73, in get
    return request("get", url, params=params, **kwargs)
  File "/home/leszek/miniconda3/envs/ldm/lib/python3.8/site-packages/requests/api.py", line 59, in request
    return session.request(method=method, url=url, **kwargs)
  File "/home/leszek/miniconda3/envs/ldm/lib/python3.8/site-packages/requests/sessions.py", line 587, in request
    resp = self.send(prep, **send_kwargs)
  File "/home/leszek/miniconda3/envs/ldm/lib/python3.8/site-packages/requests/sessions.py", line 701, in send
    r = adapter.send(request, **kwargs)
  File "/home/leszek/miniconda3/envs/ldm/lib/python3.8/site-packages/requests/adapters.py", line 565, in send
    raise ConnectionError(e, request=request)
requests.exceptions.ConnectionError: HTTPSConnectionPool(host='huggingface.co', port=443): Max retries exceeded with url: /api/models/CompVis/stable-diffusion-v1-4/revision/fp16 (Caused by NewConnectionError('<urllib3.connection.HTTPSConnection object at 0x7f17bf089e80>: Failed to establish a new connection: [Errno -3] Temporary failure in name resolution'))

It would be nice that diffusers could detect that the models are available locally and work without internet.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions