Coder Social home page Coder Social logo

'LatentDiffusion' object has no attribute 'lora_layer_mapping' after today git pull stable-diffusion-webui about a1111-sd-webui-locon HOT 6 OPEN

kohakublueleaf avatar kohakublueleaf commented on July 23, 2024 2
'LatentDiffusion' object has no attribute 'lora_layer_mapping' after today git pull stable-diffusion-webui

from a1111-sd-webui-locon.

Comments (6)

aetherwu avatar aetherwu commented on July 23, 2024 1

the previous version scripts\main.py Add these lines:

**def assign_lora_names_to_compvis_modules(sd_model): lora_layer_mapping = {}

for name, module in shared.sd_model.cond_stage_model.wrapped.named_modules():
    lora_name = name.replace(".", "_")
    lora_layer_mapping[lora_name] = module
    module.lora_layer_name = lora_name

for name, module in shared.sd_model.model.named_modules():
    lora_name = name.replace(".", "_")
    lora_layer_mapping[lora_name] = module
    module.lora_layer_name = lora_name

sd_model.lora_layer_mapping = lora_layer_mapping**

def load_lora(name, filename): print('locon load lora method') lora = LoraModule(name) lora.mtime = os.path.getmtime(filename)

sd = sd_models.read_state_dict(filename)

**if not hasattr(shared.sd_model, 'lora_layer_mapping'):
    assign_lora_names_to_compvis_modules(shared.sd_model)**

It works for me.
Let me clear the code for others:

Add one function before 'def load_lora'

def assign_lora_names_to_compvis_modules(sd_model):
    lora_layer_mapping = {}

    for name, module in shared.sd_model.cond_stage_model.wrapped.named_modules():
        lora_name = name.replace(".", "_")
        lora_layer_mapping[lora_name] = module
        module.lora_layer_name = lora_name

    for name, module in shared.sd_model.model.named_modules():
        lora_name = name.replace(".", "_")
        lora_layer_mapping[lora_name] = module
        module.lora_layer_name = lora_name

    sd_model.lora_layer_mapping = lora_layer_mapping

Replace first a few lins o 'def load_lora'

as

def load_lora(name, lora_on_disk):
    print('locon load lora method')
    lora = LoraModule(name, lora_on_disk)
    lora.mtime = os.path.getmtime(lora_on_disk.filename)
    sd = sd_models.read_state_dict(lora_on_disk.filename)

    if not hasattr(shared.sd_model, 'lora_layer_mapping'):
        assign_lora_names_to_compvis_modules(shared.sd_model)

    is_sd2 = True  // I don't really know what this is for anther function ask for it.

The 'lora_on_disk' part is compatible with latest PR:
https://github.com/KohakuBlueleaf/a1111-sd-webui-locon/pull/39/files

The error reported disppeared.

AttributeError: 'LatentDiffusion' object has no attribute 'lora_layer_mapping'

However one new errror emerged:

Failed to match keys when loading Lora models\Lora.....

Magically, it does not effect final result. All LoRA models works fine to me...

from a1111-sd-webui-locon.

rangedreign avatar rangedreign commented on July 23, 2024

I also get this error, running on windows 10 with gtx 1660 ti.
COMMANDLINE_ARGS= --theme dark --autolaunch --precision full --no-half --no-half-vae --medvram --disable-safe-unpickle --reinstall-torch --xformers --always-batch-cond-uncond

from a1111-sd-webui-locon.

hoodady avatar hoodady commented on July 23, 2024

loading Lora Z:\sd\stable-diffusion-webui\models\Lora\locon_angelina_v1_from_v3_64_32.safetensors: AssertionError ?it/s]
Traceback (most recent call last):
File "Z:\sd\stable-diffusion-webui\extensions-builtin\Lora\lora.py", line 222, in load_loras
lora = load_lora(name, lora_on_disk.filename)
File "Z:\sd\stable-diffusion-webui\extensions-builtin\Lora\lora.py", line 192, in load_lora
assert False, f'Bad Lora layer name: {key_diffusers} - must end in lora_up.weight, lora_down.weight or alpha'
AssertionError: Bad Lora layer name: lora_unet_down_blocks_0_downsamplers_0_conv.lora_mid.weight - must end in lora_up.w

I get this random error? whats going on?

from a1111-sd-webui-locon.

Kadah avatar Kadah commented on July 23, 2024

The extension seems to be broken in a few ways with upstream A1111 changes, though I haven't gotten any of them except the following one.

Another breaking change in dev is AUTOMATIC1111/stable-diffusion-webui@39ec4f0, which I've made a RP for: #39

from a1111-sd-webui-locon.

duhast123 avatar duhast123 commented on July 23, 2024

the previous version
scripts\main.py
Add these lines:

**def assign_lora_names_to_compvis_modules(sd_model):
lora_layer_mapping = {}

for name, module in shared.sd_model.cond_stage_model.wrapped.named_modules():
    lora_name = name.replace(".", "_")
    lora_layer_mapping[lora_name] = module
    module.lora_layer_name = lora_name

for name, module in shared.sd_model.model.named_modules():
    lora_name = name.replace(".", "_")
    lora_layer_mapping[lora_name] = module
    module.lora_layer_name = lora_name

sd_model.lora_layer_mapping = lora_layer_mapping**

def load_lora(name, filename):
print('locon load lora method')
lora = LoraModule(name)
lora.mtime = os.path.getmtime(filename)

sd = sd_models.read_state_dict(filename)

**if not hasattr(shared.sd_model, 'lora_layer_mapping'):
    assign_lora_names_to_compvis_modules(shared.sd_model)**

from a1111-sd-webui-locon.

NoppaiKohai avatar NoppaiKohai commented on July 23, 2024

I'm getting this error too, anyone figure out how to fix it

from a1111-sd-webui-locon.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.