AttributeError: 'FluxMultiControlNetModel' object has no attribute 'config'

#20
by LiamDonnellyMV - opened
base_model = "/archive/me_flux_shallow/FLUX.1-dev"
controlnet_model_union = 'Shakker-Labs/FLUX.1-dev-ControlNet-Union-Pro'

controlnet_union = FluxControlNetModel.from_pretrained(controlnet_model_union, torch_dtype=torch.bfloat16)
controlnet = FluxMultiControlNetModel([controlnet_union])

pipe = FluxControlNetPipeline.from_pretrained(base_model, controlnet=controlnet, torch_dtype=torch.bfloat16)
pipe.to("cuda:0")

prompt = 'A bohemian-style female travel blogger with sun-kissed skin and messy beach waves.'
control_image_depth = load_image("/home/me/repos/flux_control_net/assets_depth.jpg")
control_mode_depth = 2

control_image_canny = load_image("/home/me/repos/flux_control_net/assets_canny.jpg")
control_mode_canny = 0

width, height = control_image_depth.size


image = pipe(
    prompt, 
    control_image=[control_image_depth, control_image_canny],
    control_mode=[control_mode_depth, control_mode_canny],
    width=width,
    height=height,
    controlnet_conditioning_scale=0.6,
    num_inference_steps=24, 
    guidance_scale=3.5,
    generator=torch.manual_seed(42),
).images[0]

Full error:

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
Cell In[8], line 1
----> 1 image = pipe(
      2     prompt, 
      3     control_image=[control_image_depth, control_image_canny],
      5     control_mode=[control_mode_depth, control_mode_canny],
      6     width=width,
      7     height=height,
      8     controlnet_conditioning_scale=0.6,
      9     num_inference_steps=24, 
     10     guidance_scale=3.5,
     11     generator=torch.manual_seed(42),
     12 ).images[0]

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

File ~/.local/lib/python3.10/site-packages/diffusers/pipelines/flux/pipeline_flux_controlnet.py:844, in FluxControlNetPipeline.__call__(self, prompt, prompt_2, height, width, num_inference_steps, timesteps, guidance_scale, control_image, control_mode, controlnet_conditioning_scale, num_images_per_prompt, generator, latents, prompt_embeds, pooled_prompt_embeds, output_type, return_dict, joint_attention_kwargs, callback_on_step_end, callback_on_step_end_tensor_inputs, max_sequence_length)
    840 # broadcast to batch dimension in a way that's compatible with ONNX/Core ML
    841 timestep = t.expand(latents.shape[0]).to(latents.dtype)
    843 guidance = (
--> 844     torch.tensor([guidance_scale], device=device) if self.controlnet.config.guidance_embeds else None
    845 )
    846 guidance = guidance.expand(latents.shape[0]) if guidance is not None else None
    848 # controlnet

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

File ~/.local/lib/python3.10/site-packages/torch/nn/modules/module.py:1729, in Module.__getattr__(self, name)
   1727     if name in modules:
   1728         return modules[name]
-> 1729 raise AttributeError(f"'{type(self).__name__}' object has no attribute '{name}'")

AttributeError: 'FluxMultiControlNetModel' object has no attribute 'config'

Any help here would be massively appreciated. Thanks!

In my case, I am using the non-Pro version, and the normal pipeline inference works fine, but only when I use the newly implemented image-to-image, I get the same error as above.
I wonder if there is a conflict with something in the dev version of Diffusers.

Code

from diffusers import FluxControlNetPipeline, FluxControlNetModel, FluxMultiControlNetModel, FluxControlNetImg2ImgPipeline
~
controlnet_model_union_repo = 'InstantX/FLUX.1-dev-Controlnet-Union'
dtype = torch.bfloat16
good_vae = AutoencoderKL.from_pretrained(base_model, subfolder="vae", torch_dtype=dtype)
pipe_i2i = AutoPipelineForImage2Image.from_pretrained(base_model, vae=good_vae, transformer=pipe.transformer, text_encoder=pipe.text_encoder,
 tokenizer=pipe.tokenizer, text_encoder_2=pipe.text_encoder_2, tokenizer_2=pipe.tokenizer_2, torch_dtype=dtype)
~
                pipe_i2i.to("cuda")
                pipe_i2i.vae = good_vae
                image_input = load_image(image_input_path)
                if controlnet_union is not None: controlnet_union.to("cuda")
                if controlnet is not None: controlnet.to("cuda")
                pipe_i2i.enable_model_cpu_offload()
                progress(0, desc="Start I2I Inference with ControlNet.")
                final_image = pipe_i2i( # HERE!
                    prompt=prompt_mash,
                    control_image=images,
                    control_mode=modes,
                    image=image_input,
                    strength=image_strength,
                    num_inference_steps=steps,
                    guidance_scale=cfg_scale,
                    width=width,
                    height=height,
                    controlnet_conditioning_scale=scales,
                    generator=generator,
                    joint_attention_kwargs={"scale": lora_scale},
                    output_type="pil",
                ).images[0]
                return final_image

Dependencies

spaces
torch
git+https://github.com/huggingface/diffusers@aa73072f1f7014635e3de916cbcf47858f4c37a0
transformers
peft
sentencepiece
torchvision
huggingface_hub
timm
einops
controlnet_aux
kornia
numpy
opencv-python
deepspeed
mediapipe
openai==1.37.0
translatepy
accelerate

I'm looking at this commit https://github.com/huggingface/diffusers/commit/14a1b86fc7de53ff1dbf803f616cbb16ad530e45 and seems to have changed pipeline_flux_controlnet.py:844 . You might have to revert diffusers to an earlier commit

I see. So this is the culprit.
If there was no controlnet.config and controlnet.config.guidance_embeds, it would be a crash.

torch.tensor([guidance_scale], device=device) if self.controlnet.config.guidance_embeds else None

If it were like this, crashes would be avoided, but oh well, it will heal in time.

torch.tensor([guidance_scale], device=device) if hasattr(self.controlnet, "config") and hasattr(self.controlnet.config, "guidance_embeds") and self.controlnet.config.guidance_embeds else None

Reverting back to the previous commit on main in the diffusers repo did the trick! Thanks both. Hopefully that'll get fixed

But multimodalart actually uses it in his space, and maybe it will be merged into main one of these days...

Started an issue on diffusers about this here:
https://github.com/huggingface/diffusers/issues/9534

All right. We are safe now. I don't have a github account, but a coder could come up with the above code in 3 seconds once the issue is raised. It's as good as solved.

Sign up or log in to comment