Skip to content

T2I Multiadapter example not working #4427

@amrakm

Description

@amrakm

Describe the bug

I tried running the example provided in documentation here for multi adapters, I'm getting this error:

AttributeError: 'MultiAdapter' object has no attribute 'total_downscale_factor'

Reproduction

import torch
from PIL import Image
from diffusers.utils import load_image
from diffusers import StableDiffusionAdapterPipeline, MultiAdapter

cond_keypose = load_image(
    "https://huggingface.co/datasets/diffusers/docs-images/resolve/main/t2i-adapter/keypose_sample_input.png"
)
cond_depth = load_image(
    "https://huggingface.co/datasets/diffusers/docs-images/resolve/main/t2i-adapter/depth_sample_input.png"
)
cond = [[cond_keypose, cond_depth]]

prompt = ["A man walking in an office room with a nice view"]


adapters = MultiAdapter(
    [
        T2IAdapter.from_pretrained("TencentARC/t2iadapter_keypose_sd14v1"),
        T2IAdapter.from_pretrained("TencentARC/t2iadapter_depth_sd14v1"),
    ]
)

adapters = adapters.to(torch.float16)

pipe = StableDiffusionAdapterPipeline.from_pretrained(
    "CompVis/stable-diffusion-v1-4",
    torch_dtype=torch.float16,
    adapter=adapters,
)

images = pipe(prompt, cond, adapter_conditioning_scale=[0.8, 0.8])

Logs

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
Cell In[11], line 18
     10 adapters = adapters.to(torch.float16)
     12 pipe = StableDiffusionAdapterPipeline.from_pretrained(
     13     "CompVis/stable-diffusion-v1-4",
     14     torch_dtype=torch.float16,
     15     adapter=adapters,
     16 )
---> 18 images = pipe(prompt, cond, adapter_conditioning_scale=[0.8, 0.8])

File ~/anaconda3/envs/diff-t2i/lib/python3.10/site-packages/torch/utils/_contextlib.py:115, in context_decorator..decorate_context(*args, **kwargs)
    112 @functools.wraps(func)
    113 def decorate_context(*args, **kwargs):
    114     with ctx_factory():
--> 115         return func(*args, **kwargs)

File ~/anaconda3/envs/diff-t2i/lib/python3.10/site-packages/diffusers/pipelines/t2i_adapter/pipeline_stable_diffusion_adapter.py:644, in StableDiffusionAdapterPipeline.__call__(self, prompt, image, height, width, num_inference_steps, guidance_scale, negative_prompt, num_images_per_prompt, eta, generator, latents, prompt_embeds, negative_prompt_embeds, output_type, return_dict, callback, callback_steps, cross_attention_kwargs, adapter_conditioning_scale)
    566 r"""
    567 Function invoked when calling the pipeline for generation.
    568 
   (...)
    641     "not-safe-for-work" (nsfw) content, according to the `safety_checker`.
    642 """
    643 # 0. Default height and width to unet
--> 644 height, width = self._default_height_width(height, width, image)
    645 device = self._execution_device
    647 # 1. Check inputs. Raise error if not correct

File ~/anaconda3/envs/diff-t2i/lib/python3.10/site-packages/diffusers/pipelines/t2i_adapter/pipeline_stable_diffusion_adapter.py:529, in StableDiffusionAdapterPipeline._default_height_width(self, height, width, image)
    526         height = image.shape[-2]
    528     # round down to nearest multiple of `self.adapter.total_downscale_factor`
--> 529     height = (height // self.adapter.total_downscale_factor) * self.adapter.total_downscale_factor
    531 if width is None:
    532     if isinstance(image, PIL.Image.Image):

File ~/anaconda3/envs/diff-t2i/lib/python3.10/site-packages/diffusers/models/modeling_utils.py:186, in ModelMixin.__getattr__(self, name)
    183     return self._internal_dict[name]
    185 # call PyTorch's https://pytorch.org/docs/stable/_modules/torch/nn/modules/module.html#Module
--> 186 return super().__getattr__(name)

File ~/anaconda3/envs/diff-t2i/lib/python3.10/site-packages/torch/nn/modules/module.py:1614, in Module.__getattr__(self, name)
   1612     if name in modules:
   1613         return modules[name]
-> 1614 raise AttributeError("'{}' object has no attribute '{}'".format(
   1615     type(self).__name__, name))

AttributeError: 'MultiAdapter' object has no attribute 'total_downscale_factor'```

System Info

Python 3.10.12
diffusers==0.19.3

Who can help?

@williamberman

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions