Can't load the model

#1
by jerpint - opened

I'm trying to load ControlNet-XS based on the example here:

from diffusers import StableDiffusionControlNetXSPipeline, ControlNetXSAdapter
from diffusers.utils import load_image
import numpy as np
import torch

import cv2
from PIL import Image

prompt = "aerial view, a futuristic research complex in a bright foggy jungle, hard lighting"
negative_prompt = "low quality, bad quality, sketches"

# download an image
image = load_image(
    "https://hf.co/datasets/hf-internal-testing/diffusers-images/resolve/main/sd_controlnet/hf-logo.png"
)

# initialize the models and pipeline
controlnet_conditioning_scale = 0.5

controlnet = ControlNetXSAdapter.from_pretrained(
    "UmerHA/Testing-ConrolNetXS-SD2.1-canny", torch_dtype=torch.float16
)
pipe = StableDiffusionControlNetXSPipeline.from_pretrained(
    "stabilityai/stable-diffusion-2-1-base", controlnet=controlnet, torch_dtype=torch.float16
)
pipe.enable_model_cpu_offload()

However, I get an error message suggesting the model doesn't exist:

---------------------------------------------------------------------------
HTTPError                                 Traceback (most recent call last)
File ~/opt/miniconda3/envs/py11/lib/python3.11/site-packages/huggingface_hub/utils/_errors.py:304, in hf_raise_for_status(response, endpoint_name)
    303 try:
--> 304     response.raise_for_status()
    305 except HTTPError as e:

File ~/opt/miniconda3/envs/py11/lib/python3.11/site-packages/requests/models.py:1024, in Response.raise_for_status(self)
   1023 if http_error_msg:
-> 1024     raise HTTPError(http_error_msg, response=self)

HTTPError: 401 Client Error: Unauthorized for url: https://huggingface.co/UmerHA/Testing-ConrolNetXS-SD2.1-canny/resolve/main/config.json

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

RepositoryNotFoundError                   Traceback (most recent call last)
File ~/opt/miniconda3/envs/py11/lib/python3.11/site-packages/diffusers/configuration_utils.py:383, in ConfigMixin.load_config(cls, pretrained_model_name_or_path, return_unused_kwargs, return_commit_hash, **kwargs)
    381 try:
    382     # Load from URL or cache if already cached
--> 383     config_file = hf_hub_download(
    384         pretrained_model_name_or_path,
    385         filename=cls.config_name,
    386         cache_dir=cache_dir,
    387         force_download=force_download,
    388         proxies=proxies,
    389         resume_download=resume_download,
    390         local_files_only=local_files_only,
    391         token=token,
    392         user_agent=user_agent,
    393         subfolder=subfolder,
    394         revision=revision,
    395         local_dir=local_dir,
    396         local_dir_use_symlinks=local_dir_use_symlinks,
    397     )
    398 except RepositoryNotFoundError:

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

File ~/opt/miniconda3/envs/py11/lib/python3.11/site-packages/huggingface_hub/file_download.py:1221, in hf_hub_download(repo_id, filename, subfolder, repo_type, revision, library_name, library_version, cache_dir, local_dir, user_agent, force_download, proxies, etag_timeout, token, local_files_only, headers, endpoint, legacy_cache_layout, resume_download, force_filename, local_dir_use_symlinks)
   1220 else:
-> 1221     return _hf_hub_download_to_cache_dir(
   1222         # Destination
   1223         cache_dir=cache_dir,
   1224         # File info
   1225         repo_id=repo_id,
   1226         filename=filename,
   1227         repo_type=repo_type,
   1228         revision=revision,
   1229         # HTTP info
   1230         headers=headers,
   1231         proxies=proxies,
   1232         etag_timeout=etag_timeout,
   1233         endpoint=endpoint,
   1234         # Additional options
   1235         local_files_only=local_files_only,
   1236         force_download=force_download,
   1237     )

File ~/opt/miniconda3/envs/py11/lib/python3.11/site-packages/huggingface_hub/file_download.py:1325, in _hf_hub_download_to_cache_dir(cache_dir, repo_id, filename, repo_type, revision, headers, proxies, etag_timeout, endpoint, local_files_only, force_download)
   1324     # Otherwise, raise appropriate error
-> 1325     _raise_on_head_call_error(head_call_error, force_download, local_files_only)
   1327 # From now on, etag, commit_hash, url and size are not None.

File ~/opt/miniconda3/envs/py11/lib/python3.11/site-packages/huggingface_hub/file_download.py:1823, in _raise_on_head_call_error(head_call_error, force_download, local_files_only)
   1821 elif isinstance(head_call_error, RepositoryNotFoundError) or isinstance(head_call_error, GatedRepoError):
   1822     # Repo not found or gated => let's raise the actual error
-> 1823     raise head_call_error
   1824 else:
   1825     # Otherwise: most likely a connection issue or Hub downtime => let's warn the user

File ~/opt/miniconda3/envs/py11/lib/python3.11/site-packages/huggingface_hub/file_download.py:1722, in _get_metadata_or_catch_error(repo_id, filename, repo_type, revision, endpoint, proxies, etag_timeout, headers, local_files_only, relative_filename, storage_folder)
   1721 try:
-> 1722     metadata = get_hf_file_metadata(url=url, proxies=proxies, timeout=etag_timeout, headers=headers)
   1723 except EntryNotFoundError as http_error:

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

File ~/opt/miniconda3/envs/py11/lib/python3.11/site-packages/huggingface_hub/file_download.py:1645, in get_hf_file_metadata(url, token, proxies, timeout, library_name, library_version, user_agent, headers)
   1644 # Retrieve metadata
-> 1645 r = _request_wrapper(
   1646     method="HEAD",
   1647     url=url,
   1648     headers=headers,
   1649     allow_redirects=False,
   1650     follow_relative_redirects=True,
   1651     proxies=proxies,
   1652     timeout=timeout,
   1653 )
   1654 hf_raise_for_status(r)

File ~/opt/miniconda3/envs/py11/lib/python3.11/site-packages/huggingface_hub/file_download.py:372, in _request_wrapper(method, url, follow_relative_redirects, **params)
    371 if follow_relative_redirects:
--> 372     response = _request_wrapper(
    373         method=method,
    374         url=url,
    375         follow_relative_redirects=False,
    376         **params,
    377     )
    379     # If redirection, we redirect only relative paths.
    380     # This is useful in case of a renamed repository.

File ~/opt/miniconda3/envs/py11/lib/python3.11/site-packages/huggingface_hub/file_download.py:396, in _request_wrapper(method, url, follow_relative_redirects, **params)
    395 response = get_session().request(method=method, url=url, **params)
--> 396 hf_raise_for_status(response)
    397 return response

File ~/opt/miniconda3/envs/py11/lib/python3.11/site-packages/huggingface_hub/utils/_errors.py:352, in hf_raise_for_status(response, endpoint_name)
    344     message = (
    345         f"{response.status_code} Client Error."
    346         + "\n\n"
   (...)
    350         " make sure you are authenticated."
    351     )
--> 352     raise RepositoryNotFoundError(message, response) from e
    354 elif response.status_code == 400:

RepositoryNotFoundError: 401 Client Error. (Request ID: Root=1-665d2420-507e29162e6b03c67e6a8149;22f23aa6-cb79-4f50-b03b-27a228f87f07)

Repository Not Found for url: https://huggingface.co/UmerHA/Testing-ConrolNetXS-SD2.1-canny/resolve/main/config.json.
Please make sure you specified the correct `repo_id` and `repo_type`.
If you are trying to access a private or gated repo, make sure you are authenticated.
User Access Token "github-spaces" is expired

During handling of the above exception, another exception occurred:

OSError                                   Traceback (most recent call last)
Cell In[17], line 1
----> 1 controlnet = ControlNetXSAdapter.from_pretrained(
      2     "UmerHA/Testing-ConrolNetXS-SD2.1-canny", torch_dtype=torch.float16
      3 )

File ~/opt/miniconda3/envs/py11/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 ~/opt/miniconda3/envs/py11/lib/python3.11/site-packages/diffusers/models/modeling_utils.py:549, in ModelMixin.from_pretrained(cls, pretrained_model_name_or_path, **kwargs)
    542 user_agent = {
    543     "diffusers": __version__,
    544     "file_type": "model",
    545     "framework": "pytorch",
    546 }
    548 # load config
--> 549 config, unused_kwargs, commit_hash = cls.load_config(
    550     config_path,
    551     cache_dir=cache_dir,
    552     return_unused_kwargs=True,
    553     return_commit_hash=True,
    554     force_download=force_download,
    555     resume_download=resume_download,
    556     proxies=proxies,
    557     local_files_only=local_files_only,
    558     token=token,
    559     revision=revision,
    560     subfolder=subfolder,
    561     user_agent=user_agent,
    562     **kwargs,
    563 )
    565 # load model
    566 model_file = None

File ~/opt/miniconda3/envs/py11/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 ~/opt/miniconda3/envs/py11/lib/python3.11/site-packages/diffusers/configuration_utils.py:399, in ConfigMixin.load_config(cls, pretrained_model_name_or_path, return_unused_kwargs, return_commit_hash, **kwargs)
    383     config_file = hf_hub_download(
    384         pretrained_model_name_or_path,
    385         filename=cls.config_name,
   (...)
    396         local_dir_use_symlinks=local_dir_use_symlinks,
    397     )
    398 except RepositoryNotFoundError:
--> 399     raise EnvironmentError(
    400         f"{pretrained_model_name_or_path} is not a local folder and is not a valid model identifier"
    401         " listed on 'https://huggingface.co/models'\nIf this is a private repository, make sure to pass a"
    402         " token having permission to this repo with `token` or log in with `huggingface-cli login`."
    403     )
    404 except RevisionNotFoundError:
    405     raise EnvironmentError(
    406         f"{revision} is not a valid git identifier (branch name, tag name or commit id) that exists for"
    407         " this model name. Check the model page at"
    408         f" 'https://huggingface.co/{pretrained_model_name_or_path}' for available revisions."
    409     )

OSError: UmerHA/Testing-ConrolNetXS-SD2.1-canny is not a local folder and is not a valid model identifier listed on 'https://huggingface.co/models'
If this is a private repository, make sure to pass a token having permission to this repo with `token` or log in with `huggingface-cli login`.

I don't understand why it would say the model doesn't exist, since this is the exact same URL, any help is appreciated

Hey, I just tested in in a fresh google colab notebook, and it worked - see https://colab.research.google.com/drive/1PSLPn2PiV2O3ibSwX-tKWXHYcLkp-LcI?usp=sharing.

I think you might be better off asking in the diffusers GitHub.

As a workaround, you can download the model manually, and load it from local files. E.g., if you download it to MY_REPOSITORY, you'd load it with

controlnet = ControlNetXSAdapter.from_pretrained(
    MY_REPOSITORY, torch_dtype=torch.float16
)

thanks, indeed might be a local thing, i'm using apple silicon so maybe related to that? thanks for looking into it!

jerpint changed discussion status to closed

Sign up or log in to comment