Skip to content

fix: 'PaintByExampleImageEncoder' object has no attribute 'all_tied_w…#13252

Open
kaixuanliu wants to merge 3 commits intohuggingface:mainfrom
kaixuanliu:paint_by_example
Open

fix: 'PaintByExampleImageEncoder' object has no attribute 'all_tied_w…#13252
kaixuanliu wants to merge 3 commits intohuggingface:mainfrom
kaixuanliu:paint_by_example

Conversation

@kaixuanliu
Copy link
Contributor

@yiyixuxu and @asomoza, pls help review, thx! This PR fixes bug for following sample code:

import torch
from diffusers import PaintByExamplePipeline
from PIL import Image, ImageDraw

# Load the pipeline
pipe = PaintByExamplePipeline.from_pretrained(
    "Fantasy-Studio/Paint-by-Example",
    torch_dtype=torch.float16,
)
pipe.to("cuda")

# 1. Source image (the image to be edited)
image = Image.new("RGB", (512, 512), color="white")

# 2. Mask image (white = replace, black = keep)
mask = Image.new("RGB", (512, 512), color="black")
draw = ImageDraw.Draw(mask)
draw.rectangle([128, 128, 384, 384], fill="white")

# 3. Example image (reference content to paint in masked area)
example_image = Image.new("RGB", (256, 256), color="blue")

# Run inference
output = pipe(
    image=image,
    mask_image=mask,
    example_image=example_image,
    num_inference_steps=30,
).images[0]

output.save("output.png")

Before this PR, it will throw error:

Traceback (most recent call last):
  File "/root/upstream/diffusers/test.py", line 6, in <module>                                                                     pipe = PaintByExamplePipeline.from_pretrained(                                                                               File "/usr/local/lib/python3.10/dist-packages/huggingface_hub/utils/_validators.py", line 89, in _inner_fn
    return fn(*args, **kwargs)
  File "/root/upstream/diffusers/src/diffusers/pipelines/pipeline_utils.py", line 1049, in from_pretrained
    loaded_sub_model = load_sub_model(                                                                                           File "/root/upstream/diffusers/src/diffusers/pipelines/pipeline_loading_utils.py", line 885, in load_sub_model
    loaded_sub_model = load_method(os.path.join(cached_folder, name), **loading_kwargs)
  File "/usr/local/lib/python3.10/dist-packages/transformers/modeling_utils.py", line 4138, in from_pretrained
    loading_info = cls._finalize_model_loading(model, load_config, loading_info)
  File "/usr/local/lib/python3.10/dist-packages/transformers/modeling_utils.py", line 4279, in _finalize_model_loading
    model.mark_tied_weights_as_initialized(loading_info)
  File "/usr/local/lib/python3.10/dist-packages/transformers/modeling_utils.py", line 4598, in mark_tied_weights_as_initialized
    for tied_param in self.all_tied_weights_keys.keys():
  File "/usr/local/lib/python3.10/dist-packages/torch/nn/modules/module.py", line 1965, in __getattr__
    raise AttributeError(
AttributeError: 'PaintByExampleImageEncoder' object has no attribute 'all_tied_weights_keys'. Did you mean: '_tied_weights_keys
'?

…eights_keys'

Signed-off-by: Liu, Kaixuan <kaixuan.liu@intel.com>
Signed-off-by: Liu, Kaixuan <kaixuan.liu@intel.com>
@kaixuanliu
Copy link
Contributor Author

And the same case w/ LDMBertModel

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant