Skip to content

Impossible to load WanTransformer3DModel when offline using the 'from_pretrained' function. #11948

Closed

Description

@guillaumejs2403

Describe the bug

Hi!
I am using the Wan2.1-1.3B-Diffusers transformer for a project. When I load the transformer (but not the complete pipeline), I receive a ConnectionError, even when I pass the local_files_only=True input. However, when I load the complete pipeline, I do not receive an error. Please note that the server I use does not have internet access and, even, when I use the HF_HUB_OFFLINE=1 environment variable, I receive an error message about offline mode.

Reproduction

import torch
from diffusers import WanTransformer3DModel
transformer = WanTransformer3DModel.from_pretrained("Wan-AI/Wan2.1-T2V-1.3B-Diffusers", subfolder="transformer", torch_dtype=torch.bfloat16, local_files_only=True)

Logs

Error log without HF_HUB_OFFLINE=1

---------------------------------------------------------------------------
OSError                                   Traceback (most recent call last)
File ~/.conda/envs/video/lib/python3.11/site-packages/urllib3/connection.py:198, in HTTPConnection._new_conn(self)
    197 try:
--> 198     sock = connection.create_connection(
    199         (self._dns_host, self.port),
    200         self.timeout,
    201         source_address=self.source_address,
    202         socket_options=self.socket_options,
    203     )
    204 except socket.gaierror as e:

File ~/.conda/envs/video/lib/python3.11/site-packages/urllib3/util/connection.py:85, in create_connection(address, timeout, source_address, socket_options)
     84 try:
---> 85     raise err
     86 finally:
     87     # Break explicitly a reference cycle

File ~/.conda/envs/video/lib/python3.11/site-packages/urllib3/util/connection.py:73, in create_connection(address, timeout, source_address, socket_options)
     72     sock.bind(source_address)
---> 73 sock.connect(sa)
     74 # Break explicitly a reference cycle

OSError: [Errno 101] Network is unreachable

The above exception was the direct cause of the following exception:

NewConnectionError                        Traceback (most recent call last)
File ~/.conda/envs/video/lib/python3.11/site-packages/urllib3/connectionpool.py:787, in HTTPConnectionPool.urlopen(self, method, url, body, headers, retries, redirect, assert_same_host, timeout, pool_timeout, release_conn, chunked, body_pos, preload_content, decode_content, **response_kw)
    786 # Make the request on the HTTPConnection object
--> 787 response = self._make_request(
    788     conn,
    789     method,
    790     url,
    791     timeout=timeout_obj,
    792     body=body,
    793     headers=headers,
    794     chunked=chunked,
    795     retries=retries,
    796     response_conn=response_conn,
    797     preload_content=preload_content,
    798     decode_content=decode_content,
    799     **response_kw,
    800 )
    802 # Everything went great!

File ~/.conda/envs/video/lib/python3.11/site-packages/urllib3/connectionpool.py:488, in HTTPConnectionPool._make_request(self, conn, method, url, body, headers, retries, timeout, chunked, response_conn, preload_content, decode_content, enforce_content_length)
    487         new_e = _wrap_proxy_error(new_e, conn.proxy.scheme)
--> 488     raise new_e
    490 # conn.request() calls http.client.*.request, not the method in
    491 # urllib3.request. It also calls makefile (recv) on the socket.

File ~/.conda/envs/video/lib/python3.11/site-packages/urllib3/connectionpool.py:464, in HTTPConnectionPool._make_request(self, conn, method, url, body, headers, retries, timeout, chunked, response_conn, preload_content, decode_content, enforce_content_length)
    463 try:
--> 464     self._validate_conn(conn)
    465 except (SocketTimeout, BaseSSLError) as e:

File ~/.conda/envs/video/lib/python3.11/site-packages/urllib3/connectionpool.py:1093, in HTTPSConnectionPool._validate_conn(self, conn)
   1092 if conn.is_closed:
-> 1093     conn.connect()
   1095 # TODO revise this, see https://github.com/urllib3/urllib3/issues/2791

File ~/.conda/envs/video/lib/python3.11/site-packages/urllib3/connection.py:753, in HTTPSConnection.connect(self)
    752 sock: socket.socket | ssl.SSLSocket
--> 753 self.sock = sock = self._new_conn()
    754 server_hostname: str = self.host

File ~/.conda/envs/video/lib/python3.11/site-packages/urllib3/connection.py:213, in HTTPConnection._new_conn(self)
    212 except OSError as e:
--> 213     raise NewConnectionError(
    214         self, f"Failed to establish a new connection: {e}"
    215     ) from e
    217 sys.audit("http.client.connect", self, self.host, self.port)

NewConnectionError: <urllib3.connection.HTTPSConnection object at 0x14832727e950>: Failed to establish a new connection: [Errno 101] Network is unreachable

The above exception was the direct cause of the following exception:

MaxRetryError                             Traceback (most recent call last)
File ~/.conda/envs/video/lib/python3.11/site-packages/requests/adapters.py:667, in HTTPAdapter.send(self, request, stream, timeout, verify, cert, proxies)
    666 try:
--> 667     resp = conn.urlopen(
    668         method=request.method,
    669         url=url,
    670         body=request.body,
    671         headers=request.headers,
    672         redirect=False,
    673         assert_same_host=False,
    674         preload_content=False,
    675         decode_content=False,
    676         retries=self.max_retries,
    677         timeout=timeout,
    678         chunked=chunked,
    679     )
    681 except (ProtocolError, OSError) as err:

File ~/.conda/envs/video/lib/python3.11/site-packages/urllib3/connectionpool.py:841, in HTTPConnectionPool.urlopen(self, method, url, body, headers, retries, redirect, assert_same_host, timeout, pool_timeout, release_conn, chunked, body_pos, preload_content, decode_content, **response_kw)
    839     new_e = ProtocolError("Connection aborted.", new_e)
--> 841 retries = retries.increment(
    842     method, url, error=new_e, _pool=self, _stacktrace=sys.exc_info()[2]
    843 )
    844 retries.sleep()

File ~/.conda/envs/video/lib/python3.11/site-packages/urllib3/util/retry.py:519, in Retry.increment(self, method, url, response, error, _pool, _stacktrace)
    518     reason = error or ResponseError(cause)
--> 519     raise MaxRetryError(_pool, url, reason) from reason  # type: ignore[arg-type]
    521 log.debug("Incremented Retry for (url='%s'): %r", url, new_retry)

MaxRetryError: HTTPSConnectionPool(host='huggingface.co', port=443): Max retries exceeded with url: /api/models/Wan-AI/Wan2.1-T2V-1.3B-Diffusers (Caused by NewConnectionError('<urllib3.connection.HTTPSConnection object at 0x14832727e950>: Failed to establish a new connection: [Errno 101] Network is unreachable'))

During handling of the above exception, another exception occurred:

ConnectionError                           Traceback (most recent call last)
Cell In[3], line 1
----> 1 transformer = WanTransformer3DModel.from_pretrained("Wan-AI/Wan2.1-T2V-1.3B-Diffusers", subfolder="transformer", torch_dtype=torch.bfloat16, local_files_only=True)

File ~/.conda/envs/video/lib/python3.11/site-packages/huggingface_hub/utils/_validators.py:114, in validate_hf_hub_args.<locals>._inner_fn(*args, **kwargs)
    111 if check_use_auth_token:
    112     kwargs = smoothly_deprecate_use_auth_token(fn_name=fn.__name__, has_token=has_token, kwargs=kwargs)
--> 114 return fn(*args, **kwargs)

File ~/.conda/envs/video/lib/python3.11/site-packages/diffusers/models/modeling_utils.py:1109, in ModelMixin.from_pretrained(cls, pretrained_model_name_or_path, **kwargs)
   1106 else:
   1107     # in the case it is sharded, we have already the index
   1108     if is_sharded:
-> 1109         resolved_model_file, sharded_metadata = _get_checkpoint_shard_files(
   1110             pretrained_model_name_or_path,
   1111             index_file,
   1112             cache_dir=cache_dir,
   1113             proxies=proxies,
   1114             local_files_only=local_files_only,
   1115             token=token,
   1116             user_agent=user_agent,
   1117             revision=revision,
   1118             subfolder=subfolder or "",
   1119             dduf_entries=dduf_entries,
   1120         )
   1121     elif use_safetensors:
   1122         try:

File ~/.conda/envs/video/lib/python3.11/site-packages/diffusers/utils/hub_utils.py:407, in _get_checkpoint_shard_files(pretrained_model_name_or_path, index_filename, cache_dir, proxies, local_files_only, token, user_agent, revision, subfolder, dduf_entries)
    405 ignore_patterns = ["*.json", "*.md"]
    406 # `model_info` call must guarded with the above condition.
--> 407 model_files_info = model_info(pretrained_model_name_or_path, revision=revision, token=token)
    408 for shard_file in original_shard_filenames:
    409     shard_file_present = any(shard_file in k.rfilename for k in model_files_info.siblings)

File ~/.conda/envs/video/lib/python3.11/site-packages/huggingface_hub/utils/_validators.py:114, in validate_hf_hub_args.<locals>._inner_fn(*args, **kwargs)
    111 if check_use_auth_token:
    112     kwargs = smoothly_deprecate_use_auth_token(fn_name=fn.__name__, has_token=has_token, kwargs=kwargs)
--> 114 return fn(*args, **kwargs)

File ~/.conda/envs/video/lib/python3.11/site-packages/huggingface_hub/hf_api.py:2628, in HfApi.model_info(self, repo_id, revision, timeout, securityStatus, files_metadata, expand, token)
   2626 if expand:
   2627     params["expand"] = expand
-> 2628 r = get_session().get(path, headers=headers, timeout=timeout, params=params)
   2629 hf_raise_for_status(r)
   2630 data = r.json()

File ~/.conda/envs/video/lib/python3.11/site-packages/requests/sessions.py:602, in Session.get(self, url, **kwargs)
    594 r"""Sends a GET request. Returns :class:`Response` object.
    595 
    596 :param url: URL for the new :class:`Request` object.
    597 :param \*\*kwargs: Optional arguments that ``request`` takes.
    598 :rtype: requests.Response
    599 """
    601 kwargs.setdefault("allow_redirects", True)
--> 602 return self.request("GET", url, **kwargs)

File ~/.conda/envs/video/lib/python3.11/site-packages/requests/sessions.py:589, in Session.request(self, method, url, params, data, headers, cookies, files, auth, timeout, allow_redirects, proxies, hooks, stream, verify, cert, json)
    584 send_kwargs = {
    585     "timeout": timeout,
    586     "allow_redirects": allow_redirects,
    587 }
    588 send_kwargs.update(settings)
--> 589 resp = self.send(prep, **send_kwargs)
    591 return resp

File ~/.conda/envs/video/lib/python3.11/site-packages/requests/sessions.py:703, in Session.send(self, request, **kwargs)
    700 start = preferred_clock()
    702 # Send the request
--> 703 r = adapter.send(request, **kwargs)
    705 # Total elapsed time of the request (approximately)
    706 elapsed = preferred_clock() - start

File ~/.conda/envs/video/lib/python3.11/site-packages/huggingface_hub/utils/_http.py:96, in UniqueRequestIdAdapter.send(self, request, *args, **kwargs)
     94     logger.debug(f"Send: {_curlify(request)}")
     95 try:
---> 96     return super().send(request, *args, **kwargs)
     97 except requests.RequestException as e:
     98     request_id = request.headers.get(X_AMZN_TRACE_ID)

File ~/.conda/envs/video/lib/python3.11/site-packages/requests/adapters.py:700, in HTTPAdapter.send(self, request, stream, timeout, verify, cert, proxies)
    696     if isinstance(e.reason, _SSLError):
    697         # This branch is for urllib3 v1.22 and later.
    698         raise SSLError(e, request=request)
--> 700     raise ConnectionError(e, request=request)
    702 except ClosedPoolError as e:
    703     raise ConnectionError(e, request=request)

ConnectionError: (MaxRetryError("HTTPSConnectionPool(host='huggingface.co', port=443): Max retries exceeded with url: /api/models/Wan-AI/Wan2.1-T2V-1.3B-Diffusers (Caused by NewConnectionError('<urllib3.connection.HTTPSConnection object at 0x14832727e950>: Failed to establish a new connection: [Errno 101] Network is unreachable'))"), '(Request ID: d6755ad3-a0a5-4e2c-b147-d8903ad9ef3f)')

ERROR LOG WITH HF_HUB_OFFLINE=1

---------------------------------------------------------------------------
OfflineModeIsEnabled                      Traceback (most recent call last)
Cell In[3], line 1
----> 1 transformer = WanTransformer3DModel.from_pretrained("Wan-AI/Wan2.1-T2V-1.3B-Diffusers", subfolder="transformer", torch_dtype=torch.bfloat16, local_files_only=True)

File ~/.conda/envs/video/lib/python3.11/site-packages/huggingface_hub/utils/_validators.py:114, in validate_hf_hub_args.<locals>._inner_fn(*args, **kwargs)
    111 if check_use_auth_token:
    112     kwargs = smoothly_deprecate_use_auth_token(fn_name=fn.__name__, has_token=has_token, kwargs=kwargs)
--> 114 return fn(*args, **kwargs)

File ~/.conda/envs/video/lib/python3.11/site-packages/diffusers/models/modeling_utils.py:1109, in ModelMixin.from_pretrained(cls, pretrained_model_name_or_path, **kwargs)
   1106 else:
   1107     # in the case it is sharded, we have already the index
   1108     if is_sharded:
-> 1109         resolved_model_file, sharded_metadata = _get_checkpoint_shard_files(
   1110             pretrained_model_name_or_path,
   1111             index_file,
   1112             cache_dir=cache_dir,
   1113             proxies=proxies,
   1114             local_files_only=local_files_only,
   1115             token=token,
   1116             user_agent=user_agent,
   1117             revision=revision,
   1118             subfolder=subfolder or "",
   1119             dduf_entries=dduf_entries,
   1120         )
   1121     elif use_safetensors:
   1122         try:

File ~/.conda/envs/video/lib/python3.11/site-packages/diffusers/utils/hub_utils.py:407, in _get_checkpoint_shard_files(pretrained_model_name_or_path, index_filename, cache_dir, proxies, local_files_only, token, user_agent, revision, subfolder, dduf_entries)
    405 ignore_patterns = ["*.json", "*.md"]
    406 # `model_info` call must guarded with the above condition.
--> 407 model_files_info = model_info(pretrained_model_name_or_path, revision=revision, token=token)
    408 for shard_file in original_shard_filenames:
    409     shard_file_present = any(shard_file in k.rfilename for k in model_files_info.siblings)

File ~/.conda/envs/video/lib/python3.11/site-packages/huggingface_hub/utils/_validators.py:114, in validate_hf_hub_args.<locals>._inner_fn(*args, **kwargs)
    111 if check_use_auth_token:
    112     kwargs = smoothly_deprecate_use_auth_token(fn_name=fn.__name__, has_token=has_token, kwargs=kwargs)
--> 114 return fn(*args, **kwargs)

File ~/.conda/envs/video/lib/python3.11/site-packages/huggingface_hub/hf_api.py:2628, in HfApi.model_info(self, repo_id, revision, timeout, securityStatus, files_metadata, expand, token)
   2626 if expand:
   2627     params["expand"] = expand
-> 2628 r = get_session().get(path, headers=headers, timeout=timeout, params=params)
   2629 hf_raise_for_status(r)
   2630 data = r.json()

File ~/.conda/envs/video/lib/python3.11/site-packages/requests/sessions.py:602, in Session.get(self, url, **kwargs)
    594 r"""Sends a GET request. Returns :class:`Response` object.
    595 
    596 :param url: URL for the new :class:`Request` object.
    597 :param \*\*kwargs: Optional arguments that ``request`` takes.
    598 :rtype: requests.Response
    599 """
    601 kwargs.setdefault("allow_redirects", True)
--> 602 return self.request("GET", url, **kwargs)

File ~/.conda/envs/video/lib/python3.11/site-packages/requests/sessions.py:589, in Session.request(self, method, url, params, data, headers, cookies, files, auth, timeout, allow_redirects, proxies, hooks, stream, verify, cert, json)
    584 send_kwargs = {
    585     "timeout": timeout,
    586     "allow_redirects": allow_redirects,
    587 }
    588 send_kwargs.update(settings)
--> 589 resp = self.send(prep, **send_kwargs)
    591 return resp

File ~/.conda/envs/video/lib/python3.11/site-packages/requests/sessions.py:703, in Session.send(self, request, **kwargs)
    700 start = preferred_clock()
    702 # Send the request
--> 703 r = adapter.send(request, **kwargs)
    705 # Total elapsed time of the request (approximately)
    706 elapsed = preferred_clock() - start

File ~/.conda/envs/video/lib/python3.11/site-packages/huggingface_hub/utils/_http.py:107, in OfflineAdapter.send(self, request, *args, **kwargs)
    106 def send(self, request: PreparedRequest, *args, **kwargs) -> Response:
--> 107     raise OfflineModeIsEnabled(
    108         f"Cannot reach {request.url}: offline mode is enabled. To disable it, please unset the `HF_HUB_OFFLINE` environment variable."
    109     )

OfflineModeIsEnabled: Cannot reach https://huggingface.co/api/models/Wan-AI/Wan2.1-T2V-1.3B-Diffusers: offline mode is enabled. To disable it, please unset the `HF_HUB_OFFLINE` environment variable.

System Info

  • python=3.11
  • diffusers=0.34
  • pytorch=2.7.1+cu128

Who can help?

@a-r-r-o-w

Activity

  1. asomoza commented on Jul 17, 2025

    @asomoza
    Member

    Hi, if the server doesn't have internet access, did you manually download the model files and put them in the cache folder?

    You can't use a hub repo Wan-AI/Wan2.1-T2V-1.3B-Diffusers if you haven't cached the files first.

    You can also manually download the repo to a local path and just use the local path instead of a repository id.

  2. guillaumejs2403 commented on Jul 17, 2025

    @guillaumejs2403
    Author

    Thanks for the response! Yes, I had downloaded and added them to the cache manually beforehand. I can load the full pipeline without any trouble. However, when I only load the transformer, as in the example, it does not work. I solved this problem by loading the full pipeline and deleting the other components. In my opinion, I thought this issue might be suitable for a bug report. If not, feel free to close it :)

  3. asomoza commented on Jul 17, 2025

    @asomoza
    Member

    no need to close it, I was just making sure that it wasn't the cause of your problem since most of the time is that.

    I found that the problem is because you're using a repository id, the code here is trying to connect to get the sharded information of the model.

    If you use a local path, this issue doesn't trigger, for example I downloaded the transformer model to models/wan_transformer and after disconnecting the internet, this code works:

    import torch
    
    from diffusers import WanTransformer3DModel
    
    
    transformer = WanTransformer3DModel.from_pretrained(
        "./models/wan_transformer", torch_dtype=torch.bfloat16, local_files_only=True
    )

    ccing @sayakpaul or @DN6 to check if this is intended or an issue

    P.S.: Also my mistake, I didn't see the part where you said you could load the whole pipeline without a problem, sorry if my answer sounded a little too harsh.

  4. sayakpaul commented on Jul 17, 2025

    @sayakpaul
    Member

    Yeah sadly model_info() won't work in this case.

    So, the best bet would be first download the model locally as @asomoza mentioned and then passing the direct local path with internet disabled. We could try loading it from the cache_dir but I guess that would make things a little complicated.

  5. guillaumejs2403 commented on Jul 18, 2025

    @guillaumejs2403
    Author

    Thanks for the tip! I tried two ways:

    1. @asomoza's way.
    2. Creating a symlink to the cached checkpoint and loading it.

    Both methods worked as expected. Thanks again! :)

  6. sayakpaul commented on Jul 18, 2025

    @sayakpaul
    Member

    Thank you for getting back!

    @DN6 WDYT of #11948 (comment)?

  7. DN6 commented on Jul 23, 2025

    @DN6
    Collaborator

    @sayakpaul Hmm yeah we should probably have an offline equivalent for that that check if the model exists in cache_dir

  8. sayakpaul commented on Jul 23, 2025

    @sayakpaul
    Member

    I will open a PR.

  9. sayakpaul commented on Jul 28, 2025

    @sayakpaul
    Member

    @asomoza @guillaumejs2403 could you check #12005?

    To test in a minimal yet faithful fashion, I did the following. I first ran the code below with my internet connection on:

    from diffusers import AutoModel
    
    model = AutoModel.from_pretrained(
        "hf-internal-testing/tiny-sd-unet-sharded-latest-format", 
        variant="fp16"
    )

    And then I turned off my internet connection and ran:

    from diffusers import AutoModel
    
    model = AutoModel.from_pretrained(
        "hf-internal-testing/tiny-sd-unet-sharded-latest-format", 
        variant="fp16",
        local_files_only=True
    )
  10. guillaumejs2403 commented on Jul 29, 2025

    @guillaumejs2403
    Author

    I tested it, @sayakpaul, and it didn't work with the official 0.34.0 release. For a sanity check, I also tested it with diffusers installed directly from Git, and it still did not work.

    I got the same error:

    ConnectionError: (MaxRetryError('HTTPSConnectionPool(host=\'huggingface.co\', port=443): Max retries exceeded with url: /api/models/hf-internal-testing/tiny-sd-unet-sharded-latest-format (Caused by NameResolutionError("<urllib3.connection.HTTPSConnection object at 0x7f2506f29fd0>: Failed to resolve \'huggingface.co\' ([Errno -2] Name or service not known)"))'), '(Request ID: c15660d8-5b85-4fda-ac48-23ef1e14192a)')

    PD: @asomoza I saw that you excused yourself. Don't worry!

  11. sayakpaul commented on Jul 29, 2025

    @sayakpaul
    Member

    Oh you need to actually install diffusers from the PR branch:

    pip uninstall diffuser -y
    pip install git+https://github.com/huggingface/diffusers@local-model-info
  12. guillaumejs2403 commented on Jul 29, 2025

    @guillaumejs2403
    Author

    Hehe didn't know. I reinstalled it and got the same error.

  13. sayakpaul commented on Jul 29, 2025

    @sayakpaul
    Member

    @asomoza could you check?

  14. asomoza commented on Jul 29, 2025

    @asomoza
    Member

    for me it worked without a problem, using the same code as the initial one.

    @guillaumejs2403 please check that you have the correct wheel installed, note that in @sayakpaul command there's a typo:

    pip uninstall diffuser -y

    should be:

    pip uninstall diffusers -y

    Also if you install it like this, you can check that is installed from that branch if you check the commit hash with pip freeze:

    diffusers @ git+https://github.com/huggingface/diffusers@2d993b71d5bc59077b7c07ae9bc0484f7a1d71f6
    

    The 2d993b71d5bc59077b7c07ae9bc0484f7a1d71f6 is the commit hash and should be the same exact one.

  15. guillaumejs2403 commented on Jul 29, 2025

    @guillaumejs2403
    Author

    Thanks! The commit hash was actually different. I did it blindly and didn't see the typo. I re-ran the installation, and it worked this time.

  16. github-actions commented on Jan 9, 2026

    @github-actions
    Contributor

    This issue has been automatically marked as stale because it has not had recent activity. If you think this still needs to be addressed please comment on this thread.

    Please note that issues that do not follow the contributing guidelines are likely to be ignored.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingstaleIssues that haven't received updates

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions