Skip to content

Commit 0d60304

Browse files
committed
Remove dependency version constraints (resolves #1)
1 parent 153ab56 commit 0d60304

7 files changed

+177
-26
lines changed

models_diffusers/controlnet_svd.py

Lines changed: 150 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
from torch.nn import functional as F
2121

2222
from diffusers.configuration_utils import ConfigMixin, register_to_config
23-
from diffusers.loaders import FromOriginalControlnetMixin
23+
# from diffusers.loaders import FromOriginalControlnetMixin
2424
from diffusers.utils import BaseOutput, logging
2525
from diffusers.models.attention_processor import (
2626
ADDED_KV_ATTENTION_PROCESSORS,
@@ -35,9 +35,158 @@
3535
from .unet_3d_blocks import UNetMidBlockSpatioTemporal, get_down_block, get_up_block
3636
from diffusers.models import UNetSpatioTemporalConditionModel
3737

38+
from huggingface_hub import hf_hub_download
39+
from io import BytesIO
40+
import os
41+
import requests
42+
from pathlib import Path
43+
44+
from huggingface_hub.constants import HF_HUB_OFFLINE, HF_HOME
45+
DIFFUSERS_CACHE = os.path.join(HF_HOME, "diffusers")
3846

3947
logger = logging.get_logger(__name__) # pylint: disable=invalid-name
4048

49+
class FromOriginalControlnetMixin:
50+
@classmethod
51+
def from_single_file(cls, pretrained_model_link_or_path, **kwargs):
52+
r"""
53+
Instantiate a [`ControlNetModel`] from pretrained controlnet weights saved in the original `.ckpt` or
54+
`.safetensors` format. The pipeline is set in evaluation mode (`model.eval()`) by default.
55+
56+
Parameters:
57+
pretrained_model_link_or_path (`str` or `os.PathLike`, *optional*):
58+
Can be either:
59+
- A link to the `.ckpt` file (for example
60+
`"https://huggingface.co/<repo_id>/blob/main/<path_to_file>.ckpt"`) on the Hub.
61+
- A path to a *file* containing all pipeline weights.
62+
torch_dtype (`str` or `torch.dtype`, *optional*):
63+
Override the default `torch.dtype` and load the model with another dtype. If `"auto"` is passed, the
64+
dtype is automatically derived from the model's weights.
65+
force_download (`bool`, *optional*, defaults to `False`):
66+
Whether or not to force the (re-)download of the model weights and configuration files, overriding the
67+
cached versions if they exist.
68+
cache_dir (`Union[str, os.PathLike]`, *optional*):
69+
Path to a directory where a downloaded pretrained model configuration is cached if the standard cache
70+
is not used.
71+
resume_download (`bool`, *optional*, defaults to `False`):
72+
Whether or not to resume downloading the model weights and configuration files. If set to `False`, any
73+
incompletely downloaded files are deleted.
74+
proxies (`Dict[str, str]`, *optional*):
75+
A dictionary of proxy servers to use by protocol or endpoint, for example, `{'http': 'foo.bar:3128',
76+
'http://hostname': 'foo.bar:4012'}`. The proxies are used on each request.
77+
local_files_only (`bool`, *optional*, defaults to `False`):
78+
Whether to only load local model weights and configuration files or not. If set to True, the model
79+
won't be downloaded from the Hub.
80+
use_auth_token (`str` or *bool*, *optional*):
81+
The token to use as HTTP bearer authorization for remote files. If `True`, the token generated from
82+
`diffusers-cli login` (stored in `~/.huggingface`) is used.
83+
revision (`str`, *optional*, defaults to `"main"`):
84+
The specific model version to use. It can be a branch name, a tag name, a commit id, or any identifier
85+
allowed by Git.
86+
use_safetensors (`bool`, *optional*, defaults to `None`):
87+
If set to `None`, the safetensors weights are downloaded if they're available **and** if the
88+
safetensors library is installed. If set to `True`, the model is forcibly loaded from safetensors
89+
weights. If set to `False`, safetensors weights are not loaded.
90+
image_size (`int`, *optional*, defaults to 512):
91+
The image size the model was trained on. Use 512 for all Stable Diffusion v1 models and the Stable
92+
Diffusion v2 base model. Use 768 for Stable Diffusion v2.
93+
upcast_attention (`bool`, *optional*, defaults to `None`):
94+
Whether the attention computation should always be upcasted.
95+
kwargs (remaining dictionary of keyword arguments, *optional*):
96+
Can be used to overwrite load and saveable variables (for example the pipeline components of the
97+
specific pipeline class). The overwritten components are directly passed to the pipelines `__init__`
98+
method. See example below for more information.
99+
100+
Examples:
101+
102+
```py
103+
from diffusers import StableDiffusionControlNetPipeline, ControlNetModel
104+
105+
url = "https://huggingface.co/lllyasviel/ControlNet-v1-1/blob/main/control_v11p_sd15_canny.pth" # can also be a local path
106+
model = ControlNetModel.from_single_file(url)
107+
108+
url = "https://huggingface.co/runwayml/stable-diffusion-v1-5/blob/main/v1-5-pruned.safetensors" # can also be a local path
109+
pipe = StableDiffusionControlNetPipeline.from_single_file(url, controlnet=controlnet)
110+
```
111+
"""
112+
# import here to avoid circular dependency
113+
from diffusers.pipelines.stable_diffusion.convert_from_ckpt import download_controlnet_from_original_ckpt
114+
115+
config_file = kwargs.pop("config_file", None)
116+
cache_dir = kwargs.pop("cache_dir", DIFFUSERS_CACHE)
117+
resume_download = kwargs.pop("resume_download", False)
118+
force_download = kwargs.pop("force_download", False)
119+
proxies = kwargs.pop("proxies", None)
120+
local_files_only = kwargs.pop("local_files_only", HF_HUB_OFFLINE)
121+
use_auth_token = kwargs.pop("use_auth_token", None)
122+
num_in_channels = kwargs.pop("num_in_channels", None)
123+
use_linear_projection = kwargs.pop("use_linear_projection", None)
124+
revision = kwargs.pop("revision", None)
125+
extract_ema = kwargs.pop("extract_ema", False)
126+
image_size = kwargs.pop("image_size", None)
127+
upcast_attention = kwargs.pop("upcast_attention", None)
128+
129+
torch_dtype = kwargs.pop("torch_dtype", None)
130+
131+
use_safetensors = kwargs.pop("use_safetensors", None)
132+
133+
file_extension = pretrained_model_link_or_path.rsplit(".", 1)[-1]
134+
from_safetensors = file_extension == "safetensors"
135+
136+
if from_safetensors and use_safetensors is False:
137+
raise ValueError("Make sure to install `safetensors` with `pip install safetensors`.")
138+
139+
# remove huggingface url
140+
for prefix in ["https://huggingface.co/", "huggingface.co/", "hf.co/", "https://hf.co/"]:
141+
if pretrained_model_link_or_path.startswith(prefix):
142+
pretrained_model_link_or_path = pretrained_model_link_or_path[len(prefix) :]
143+
144+
# Code based on diffusers.pipelines.pipeline_utils.DiffusionPipeline.from_pretrained
145+
ckpt_path = Path(pretrained_model_link_or_path)
146+
if not ckpt_path.is_file():
147+
# get repo_id and (potentially nested) file path of ckpt in repo
148+
repo_id = "/".join(ckpt_path.parts[:2])
149+
file_path = "/".join(ckpt_path.parts[2:])
150+
151+
if file_path.startswith("blob/"):
152+
file_path = file_path[len("blob/") :]
153+
154+
if file_path.startswith("main/"):
155+
file_path = file_path[len("main/") :]
156+
157+
pretrained_model_link_or_path = hf_hub_download(
158+
repo_id,
159+
filename=file_path,
160+
cache_dir=cache_dir,
161+
resume_download=resume_download,
162+
proxies=proxies,
163+
local_files_only=local_files_only,
164+
use_auth_token=use_auth_token,
165+
revision=revision,
166+
force_download=force_download,
167+
)
168+
169+
if config_file is None:
170+
config_url = "https://raw.githubusercontent.com/lllyasviel/ControlNet/main/models/cldm_v15.yaml"
171+
config_file = BytesIO(requests.get(config_url).content)
172+
173+
image_size = image_size or 512
174+
175+
controlnet = download_controlnet_from_original_ckpt(
176+
pretrained_model_link_or_path,
177+
original_config_file=config_file,
178+
image_size=image_size,
179+
extract_ema=extract_ema,
180+
num_in_channels=num_in_channels,
181+
upcast_attention=upcast_attention,
182+
from_safetensors=from_safetensors,
183+
use_linear_projection=use_linear_projection,
184+
)
185+
186+
if torch_dtype is not None:
187+
controlnet.to(dtype=torch_dtype)
188+
189+
return controlnet
41190

42191
@dataclass
43192
class ControlNetOutput(BaseOutput):

models_diffusers/refUnet_spatial_temporal_condition.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,7 @@
2626
from diffusers import __version__
2727
from diffusers.utils import (
2828
CONFIG_NAME,
29-
DIFFUSERS_CACHE,
3029
FLAX_WEIGHTS_NAME,
31-
HF_HUB_OFFLINE,
3230
MIN_PEFT_VERSION,
3331
SAFETENSORS_WEIGHTS_NAME,
3432
WEIGHTS_NAME,
@@ -40,9 +38,12 @@
4038
is_torch_version,
4139
logging,
4240
)
41+
from huggingface_hub.constants import HF_HUB_OFFLINE, HF_HOME
4342
from diffusers.utils.hub_utils import PushToHubMixin
4443
from diffusers.models.modeling_utils import load_model_dict_into_meta, load_state_dict
4544

45+
DIFFUSERS_CACHE = os.path.join(HF_HOME, "diffusers")
46+
4647
if is_torch_version(">=", "1.9.0"):
4748
_LOW_CPU_MEM_USAGE_DEFAULT = True
4849
else:
@@ -860,7 +861,7 @@ def from_pretrained(cls, pretrained_model_name_or_path: Optional[Union[str, os.P
860861
return_unused_kwargs=True,
861862
return_commit_hash=True,
862863
force_download=force_download,
863-
resume_download=resume_download,
864+
# resume_download=resume_download,
864865
proxies=proxies,
865866
local_files_only=local_files_only,
866867
use_auth_token=use_auth_token,
@@ -886,7 +887,7 @@ def from_pretrained(cls, pretrained_model_name_or_path: Optional[Union[str, os.P
886887
weights_name=FLAX_WEIGHTS_NAME,
887888
cache_dir=cache_dir,
888889
force_download=force_download,
889-
resume_download=resume_download,
890+
# resume_download=resume_download,
890891
proxies=proxies,
891892
local_files_only=local_files_only,
892893
use_auth_token=use_auth_token,
@@ -909,7 +910,7 @@ def from_pretrained(cls, pretrained_model_name_or_path: Optional[Union[str, os.P
909910
weights_name=_add_variant(SAFETENSORS_WEIGHTS_NAME, variant),
910911
cache_dir=cache_dir,
911912
force_download=force_download,
912-
resume_download=resume_download,
913+
# resume_download=resume_download,
913914
proxies=proxies,
914915
local_files_only=local_files_only,
915916
use_auth_token=use_auth_token,
@@ -928,7 +929,7 @@ def from_pretrained(cls, pretrained_model_name_or_path: Optional[Union[str, os.P
928929
weights_name=_add_variant(WEIGHTS_NAME, variant),
929930
cache_dir=cache_dir,
930931
force_download=force_download,
931-
resume_download=resume_download,
932+
# resume_download=resume_download,
932933
proxies=proxies,
933934
local_files_only=local_files_only,
934935
use_auth_token=use_auth_token,

models_diffusers/unet_3d_blocks.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,15 @@
2020
from diffusers.utils import is_torch_version
2121
from diffusers.utils.torch_utils import apply_freeu
2222
from diffusers.models.attention import Attention
23-
from diffusers.models.dual_transformer_2d import DualTransformer2DModel
23+
from diffusers.models.transformers.dual_transformer_2d import DualTransformer2DModel
2424
from diffusers.models.resnet import (
2525
Downsample2D,
2626
ResnetBlock2D,
2727
SpatioTemporalResBlock,
2828
TemporalConvLayer,
2929
Upsample2D,
3030
)
31-
from diffusers.models.transformer_2d import Transformer2DModel
31+
from diffusers.models.transformers.transformer_2d import Transformer2DModel
3232
from .transformer_temporal import (
3333
TransformerSpatioTemporalModel,
3434
TransformerTemporalModel,

models_diffusers/unet_spatio_temporal_condition.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,7 @@
2626
from diffusers import __version__
2727
from diffusers.utils import (
2828
CONFIG_NAME,
29-
DIFFUSERS_CACHE,
3029
FLAX_WEIGHTS_NAME,
31-
HF_HUB_OFFLINE,
3230
MIN_PEFT_VERSION,
3331
SAFETENSORS_WEIGHTS_NAME,
3432
WEIGHTS_NAME,
@@ -40,9 +38,12 @@
4038
is_torch_version,
4139
logging,
4240
)
41+
from huggingface_hub.constants import HF_HUB_OFFLINE, HF_HOME
4342
from diffusers.utils.hub_utils import PushToHubMixin
4443
from diffusers.models.modeling_utils import load_model_dict_into_meta, load_state_dict
4544

45+
DIFFUSERS_CACHE = os.path.join(HF_HOME, "diffusers")
46+
4647
if is_torch_version(">=", "1.9.0"):
4748
_LOW_CPU_MEM_USAGE_DEFAULT = True
4849
else:
@@ -860,7 +861,7 @@ def from_pretrained(cls, pretrained_model_name_or_path: Optional[Union[str, os.P
860861
return_unused_kwargs=True,
861862
return_commit_hash=True,
862863
force_download=force_download,
863-
resume_download=resume_download,
864+
# resume_download=resume_download,
864865
proxies=proxies,
865866
local_files_only=local_files_only,
866867
use_auth_token=use_auth_token,
@@ -886,7 +887,7 @@ def from_pretrained(cls, pretrained_model_name_or_path: Optional[Union[str, os.P
886887
weights_name=FLAX_WEIGHTS_NAME,
887888
cache_dir=cache_dir,
888889
force_download=force_download,
889-
resume_download=resume_download,
890+
# resume_download=resume_download,
890891
proxies=proxies,
891892
local_files_only=local_files_only,
892893
use_auth_token=use_auth_token,
@@ -909,7 +910,7 @@ def from_pretrained(cls, pretrained_model_name_or_path: Optional[Union[str, os.P
909910
weights_name=_add_variant(SAFETENSORS_WEIGHTS_NAME, variant),
910911
cache_dir=cache_dir,
911912
force_download=force_download,
912-
resume_download=resume_download,
913+
# resume_download=resume_download,
913914
proxies=proxies,
914915
local_files_only=local_files_only,
915916
use_auth_token=use_auth_token,
@@ -928,7 +929,7 @@ def from_pretrained(cls, pretrained_model_name_or_path: Optional[Union[str, os.P
928929
weights_name=_add_variant(WEIGHTS_NAME, variant),
929930
cache_dir=cache_dir,
930931
force_download=force_download,
931-
resume_download=resume_download,
932+
# resume_download=resume_download,
932933
proxies=proxies,
933934
local_files_only=local_files_only,
934935
use_auth_token=use_auth_token,

models_diffusers/unet_spatio_temporal_condition_interp.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,7 @@
2626
from diffusers import __version__
2727
from diffusers.utils import (
2828
CONFIG_NAME,
29-
DIFFUSERS_CACHE,
3029
FLAX_WEIGHTS_NAME,
31-
HF_HUB_OFFLINE,
3230
MIN_PEFT_VERSION,
3331
SAFETENSORS_WEIGHTS_NAME,
3432
WEIGHTS_NAME,
@@ -40,9 +38,12 @@
4038
is_torch_version,
4139
logging,
4240
)
41+
from huggingface_hub.constants import HF_HUB_OFFLINE, HF_HOME
4342
from diffusers.utils.hub_utils import PushToHubMixin
4443
from diffusers.models.modeling_utils import load_model_dict_into_meta, load_state_dict
4544

45+
DIFFUSERS_CACHE = os.path.join(HF_HOME, "diffusers")
46+
4647
if is_torch_version(">=", "1.9.0"):
4748
_LOW_CPU_MEM_USAGE_DEFAULT = True
4849
else:
@@ -860,7 +861,7 @@ def from_pretrained(cls, pretrained_model_name_or_path: Optional[Union[str, os.P
860861
return_unused_kwargs=True,
861862
return_commit_hash=True,
862863
force_download=force_download,
863-
resume_download=resume_download,
864+
# resume_download=resume_download,
864865
proxies=proxies,
865866
local_files_only=local_files_only,
866867
use_auth_token=use_auth_token,
@@ -886,7 +887,7 @@ def from_pretrained(cls, pretrained_model_name_or_path: Optional[Union[str, os.P
886887
weights_name=FLAX_WEIGHTS_NAME,
887888
cache_dir=cache_dir,
888889
force_download=force_download,
889-
resume_download=resume_download,
890+
# resume_download=resume_download,
890891
proxies=proxies,
891892
local_files_only=local_files_only,
892893
use_auth_token=use_auth_token,
@@ -909,7 +910,7 @@ def from_pretrained(cls, pretrained_model_name_or_path: Optional[Union[str, os.P
909910
weights_name=_add_variant(SAFETENSORS_WEIGHTS_NAME, variant),
910911
cache_dir=cache_dir,
911912
force_download=force_download,
912-
resume_download=resume_download,
913+
# resume_download=resume_download,
913914
proxies=proxies,
914915
local_files_only=local_files_only,
915916
use_auth_token=use_auth_token,
@@ -928,7 +929,7 @@ def from_pretrained(cls, pretrained_model_name_or_path: Optional[Union[str, os.P
928929
weights_name=_add_variant(WEIGHTS_NAME, variant),
929930
cache_dir=cache_dir,
930931
force_download=force_download,
931-
resume_download=resume_download,
932+
# resume_download=resume_download,
932933
proxies=proxies,
933934
local_files_only=local_files_only,
934935
use_auth_token=use_auth_token,

pyproject.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
[project]
22
name = "comfyui-anidoc"
33
description = "ComfyUI Custom Nodes for 'AniDoc: Animation Creation Made Easier'. This approach automates line art video colorization using a novel model that aligns color information from references, ensures temporal consistency, and reduces manual effort in animation production."
4-
version = "1.0.0"
4+
version = "1.0.1"
55
license = {file = "LICENSE"}
6-
dependencies = ["diffusers==0.24.0", "huggingface_hub==0.25.2", "Pillow", "accelerate", "omegaconf", "opencv-python", "einops", "kornia", "git+https://github.com/XPixelGroup/BasicSR.git"]
6+
dependencies = ["diffusers", "huggingface_hub", "Pillow", "accelerate", "omegaconf", "opencv-python", "einops", "kornia", "git+https://github.com/XPixelGroup/BasicSR.git"]
77

88
[project.urls]
99
Repository = "https://github.com/LucipherDev/ComfyUI-AniDoc"

requirements.txt

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
diffusers==0.24.0
2-
huggingface_hub==0.25.2
3-
1+
diffusers
2+
huggingface_hub
43
Pillow
54
accelerate
65
omegaconf

0 commit comments

Comments
 (0)