Neuron StableDiffusion ControlNet Pipeline fails when used with 2 controlnets

I want to use 2 ControlNets with SD1.5 on AWS Inferentia2 / Neuron. It seems to be supported but at runtime it fails with:

Loading only U-Net into both Neuron Cores...
Traceback (most recent call last):
  File "test-controlnet.py", line 40, in <module>
    image = pipe(
            ^^^^^
  File .../optimum/neuron/pipelines/diffusers/pipeline_controlnet.py", line 352, in __call__
    else controlnet.nets[0].config.global_pool_conditions
         ^^^^^^^^^^^^^^^^^^^^^^^^^
  File ".../torch/nn/modules/module.py", line 1695, in __getattr__
    raise AttributeError(f"'{type(self).__name__}' object has no attribute '{name}'")
AttributeError: 'DataParallel' object has no attribute 'config'
Segmentation fault (core dumped)

I tried to fix that line to controlnet.config[0].global_pool_conditions but it still failed later on in the same module.

Any idea how to use 2 controlnets at the same time?


This is how I compiled the model for Neuron:

optimum-cli export neuron \
	--inline-weights-neff \
	--model jyoung105/stable-diffusion-v1-5 \
	--task stable-diffusion \
	--auto_cast=matmul --auto_cast_type=bf16 \
	--batch_size 1 --num_images_per_prompt 1 \
	--controlnet_ids \
		lllyasviel/control_v11p_sd15_openpose \
		lllyasviel/control_v11f1p_sd15_depth \
	--height 512 --width 512 \
	sd15-512x512-bf16-openpose+depth.neuron

And this is my test code:

from optimum.neuron import NeuronStableDiffusionControlNetPipeline
from diffusers import UniPCMultistepScheduler
from diffusers.utils import load_image

# OpenPose+Depth ControlNet
MODEL = "sd15-512x512-bf16-openpose+depth.neuron"
OPENPOSE_IMAGE = "openpose-512x512.png"
DEPTH_IMAGE = "depth-512x512.png"

# Load ControlNet images
images = []
for image in [OPENPOSE_IMAGE, DEPTH_IMAGE]:
    print(f"Loading control image: {image}")
    images.append(load_image(image))

pipe = NeuronStableDiffusionControlNetPipeline.from_pretrained(MODEL)
pipe.scheduler = UniPCMultistepScheduler.from_config(pipe.scheduler.config)
prompt = "futuristic looking female"

image = pipe(prompt=prompt, image=images).images[0]

Am I doing something wrong or is the multi-controlnet support broken?

It鈥檚 not supposed to work. I left some placeholders for multi controlnet but have never tested it. Could you open an issue in Optimum Neuron鈥檚 GitHub repo? I can help with the support there. Thx!

@hgfckwla The support for multiple controlnets and some guides will be added in this PR: Add support for multiple controlnet by JingyaHuang 路 Pull Request #691 路 huggingface/optimum-neuron 路 GitHub. Feel free to try out!

Thanks for the fix, @Jingya :slight_smile:

This topic was automatically closed 12 hours after the last reply. New replies are no longer allowed.