Compatibility Problems with Diffusers and SD-XL Model
Closed this issue · 1 comments
Problem Description:
In diffusers == 0.20.2:
Unable to import the SD-XL model due to an outdated or incompatible API in the huggingface_hub library.
The error traceback indicates that cached_download cannot be imported:
(sliders) (base) jintao@dg04:~/rjtproject/sliders$ python eval-scripts/generate_images_xl.py
Traceback (most recent call last):
File "/home/jintao/rjtproject/sliders/eval-scripts/generate_images_xl.py", line 15, in
import diffusers
File "/home/jintao/miniconda3/envs/sliders/lib/python3.9/site-packages/diffusers/init.py", line 3, in
from .configuration_utils import ConfigMixin
File "/home/jintao/miniconda3/envs/sliders/lib/python3.9/site-packages/diffusers/configuration_utils.py", line 34, in
from .utils import (
File "/home/jintao/miniconda3/envs/sliders/lib/python3.9/site-packages/diffusers/utils/init.py", line 37, in
from .dynamic_modules_utils import get_class_from_dynamic_module
File "/home/jintao/miniconda3/envs/sliders/lib/python3.9/site-packages/diffusers/utils/dynamic_modules_utils.py", line 28, in
from huggingface_hub import HfFolder, cached_download, hf_hub_download, model_info
ImportError: cannot import name 'cached_download' from 'huggingface_hub' (/home/jintao/miniconda3/envs/sliders/lib/python3.9/site-packages/huggingface_hub/init.py)
In diffusers == 0.31.0:
While the SD-XL model can be imported, running the script results in an error
(sliders) (base) jintao@dg04:~/rjtproject/sliders$ python eval-scripts/generate_images_xl.py
Loading pipeline components...: 100%|███████████████████████████████████████████████████████████████████████████████████████████████████████████████| 7/7 [00:00<00:00, 12.56it/s]
Loading pipeline components...: 100%|███████████████████████████████████████████████████████████████████████████████████████████████████████████████| 7/7 [00:01<00:00, 6.52it/s]
create LoRA for U-Net: 346 modules.
image of a person 58583
Traceback (most recent call last):
File "/home/jintao/rjtproject/sliders/eval-scripts/generate_images_xl.py", line 506, in
images = pipe(prompt, num_images_per_prompt=args.num_samples, num_inference_steps=50, generator=generator, network=network, start_noise=start_noise, scale=scale, unet=unet).images
File "/home/jintao/miniconda3/envs/sliders/lib/python3.9/site-packages/torch/utils/_contextlib.py", line 115, in decorate_context
return func(*args, **kwargs)
File "/home/jintao/rjtproject/sliders/eval-scripts/generate_images_xl.py", line 289, in call
add_time_ids = self._get_add_time_ids(
File "/home/jintao/miniconda3/envs/sliders/lib/python3.9/site-packages/diffusers/pipelines/stable_diffusion_xl/pipeline_stable_diffusion_xl.py", line 735, in _get_add_time_ids
self.unet.config.addition_time_embed_dim * len(add_time_ids) + text_encoder_projection_dim
TypeError: unsupported operand type(s) for +: 'int' and 'NoneType'
I have solved it
add code to this
# 7. Prepare added time ids & embeddings
add_text_embeds = pooled_prompt_embeds
if self.text_encoder_2 is None:
text_encoder_projection_dim = int(pooled_prompt_embeds.shape[-1])
else:
text_encoder_projection_dim = self.text_encoder_2.config.projection_dim
add_time_ids = self._get_add_time_ids(
original_size, crops_coords_top_left, target_size, dtype=prompt_embeds.dtype, text_encoder_projection_dim=text_encoder_projection_dim
)
if negative_original_size is not None and negative_target_size is not None:
negative_add_time_ids = self._get_add_time_ids(
negative_original_size,
negative_crops_coords_top_left,
negative_target_size,
dtype=prompt_embeds.dtype,
text_encoder_projection_dim = text_encoder_projection_dim
)