Skip to content

StableDiffusion3Pipeline load_lora_weights IndexError #8565

Closed
@Beinsezii

Description

@Beinsezii

Describe the bug

Using load_lora_weights with a single safetensor on StableDiffusion3Pipeline results in an IndexError

Reproduction

StableDiffusion3Pipeline fails at load_lora_weights with IndexError on latest diffusers master

import torch
from diffusers import StableDiffusion3Pipeline

pipe = StableDiffusion3Pipeline.from_pretrained('stabilityai/stable-diffusion-3-medium-diffusers', torch_dtype=torch.float16).to('cuda')

pipe("photo of a woman in a red dress", generator=torch.manual_seed(1)).images[0].save('no_lora.png')

pipe.load_lora_weights("pytorch_lora_weights.safetensors", adapter_name="test_lora")
pipe.set_adapters(["test_lora"], [1.0]) # Also not implemented yet. Being worked on.
pipe.fuse_lora(["test_lora"])

pipe("photo of a woman in a red dress", generator=torch.manual_seed(1)).images[0].save('yes_lora.png')

Same script succeeds on other pipelines

import torch
from diffusers import StableDiffusionXLPipeline

pipe = StableDiffusionXLPipeline.from_pretrained('stabilityai/stable-diffusion-xl-base-1.0', torch_dtype=torch.float16).to('cuda')

pipe("photo of a woman in a red dress", generator=torch.manual_seed(1)).images[0].save('no_lora.png')

pipe.load_lora_weights("pytorch_lora_weights-xl.safetensors", adapter_name="test_lora")
pipe.set_adapters(["test_lora"], [1.0])
pipe.fuse_lora(["test_lora"])

pipe("photo of a woman in a red dress", generator=torch.manual_seed(1)).images[0].save('yes_lora.png')

Logs

Traceback (most recent call last):
  File "/home/beinsezii/Python/quickdif/repro.py", line 8, in <module>
    pipe.load_lora_weights("pytorch_lora_weights.safetensors", adapter_name="test_lora")
  File "/home/beinsezii/Python/quickdif/diffusers/loaders/lora.py", line 1387, in load_lora_weights
    self.load_lora_into_transformer(
  File "/home/beinsezii/Python/quickdif/diffusers/loaders/lora.py", line 1555, in load_lora_into_transformer
    lora_config_kwargs = get_peft_kwargs(rank, network_alpha_dict=None, peft_state_dict=state_dict)
                         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/beinsezii/Python/quickdif/diffusers/utils/peft_utils.py", line 153, in get_peft_kwargs
    r = lora_alpha = list(rank_dict.values())[0]
                     ~~~~~~~~~~~~~~~~~~~~~~~~^^^
IndexError: list index out of range

System Info

  • 🤗 Diffusers version: 0.30.0.dev0
  • Platform: Linux-6.9.4-arch1-1-x86_64-with-glibc2.39
  • Running on a notebook?: No
  • Running on Google Colab?: No
  • Python version: 3.12.3
  • PyTorch version (GPU?): 2.3.1+rocm6.0 (True)
  • Flax version (CPU?/GPU?/TPU?): not installed (NA)
  • Jax version: not installed
  • JaxLib version: not installed
  • Huggingface_hub version: 0.23.3
  • Transformers version: 4.41.2
  • Accelerate version: 0.31.0
  • PEFT version: 0.11.1
  • Bitsandbytes version: 0.43.2.dev
  • Safetensors version: 0.4.3
  • xFormers version: not installed
  • Accelerator: NA
  • Using GPU in script?: gfx1100
  • Using distributed or parallel set-up in script?: False

Who can help?

@DN6

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