cheald / sd-webui-loractl

An Automatic1111 extension for dynamically controlling the weights of LoRAs during image generation
MIT License
239 stars 10 forks source link

"TypeError: expected string or bytes-like object" error when trying to use lora and hires.fix? #9

Closed Detrian closed 1 year ago

Detrian commented 1 year ago

I had this working just fine a couple days ago but had to reinstall my setup and sadly this doesn't work anymore. Trying to use it without hires.fix does work but that's not ideal.

activating extra network lora with arguments [<modules.extra_networks.ExtraNetworkParams object at 0x0000021DD418E680>, <modules.extra_networks.ExtraNetworkParams object at 0x0000021DD418E4D0>, <modules.extra_networks.ExtraNetworkParams object at 0x0000021DD418FE80>]: TypeError
Traceback (most recent call last):
  File "C:\Stable Diffusion\stable-diffusion-webui\modules\extra_networks.py", line 104, in activate
    extra_network.activate(p, extra_network_args)
  File "C:\Stable Diffusion\stable-diffusion-webui\extensions\sd-webui-loractl\lib\lora_ctl_network.py", line 27, in activate
    lora_weights[name] = utils.params_to_weights(params)
  File "C:\Stable Diffusion\stable-diffusion-webui\extensions\sd-webui-loractl\lib\utils.py", line 43, in params_to_weights
    weights["te"] = sorted_positions(params.positional[1])
  File "C:\Stable Diffusion\stable-diffusion-webui\extensions\sd-webui-loractl\lib\utils.py", line 9, in sorted_positions
    for x in re.split("[,;]", raw_steps)]
  File "C:\Users\My name\AppData\Local\Programs\Python\Python310\lib\re.py", line 230, in split
    return _compile(pattern, flags).split(string, maxsplit)
TypeError: expected string or bytes-like object
cheald commented 1 year ago

What specific commit of the automatic1111 web UI are you using?

Detrian commented 1 year ago

What specific commit of the automatic1111 web UI are you using?

68f336b

cheald commented 1 year ago

Can you give me a sample prompt (or better yet, a full set of generation params) which breaks it? I can't reproduce the issue on that commit.

Detrian commented 1 year ago

Sure. I made some quick test images.

Works: p 1girl, waving, smile, <lora:Rabbit (wlsdnjs950):1> Negative prompt: easynegative, Steps: 20, Sampler: DPM++ SDE Karras, CFG scale: 7, Seed: 2729349603, Size: 512x768, Model hash: b42b09ff12, Model: cetusMix_v4, Clip skip: 2, Lora hashes: "Rabbit (wlsdnjs950): b617b45520e4", TI hashes: "easynegative: c74b4e810b03", Version: v1.5.1 https://files.catbox.moe/jmkyla.png

Does not work. p 1girl, waving, smile, <lora:Rabbit (wlsdnjs950):1> Negative prompt: easynegative, Steps: 20, Sampler: DPM++ SDE Karras, CFG scale: 7, Seed: 542882972, Size: 512x768, Model hash: b42b09ff12, Model: cetusMix_v4, Denoising strength: 0.35, Clip skip: 2, Hires prompt: "1girl, waving, smile, <lora:Rabbit (wlsdnjs950):1> ", Hires upscale: 2, Hires steps: 10, Hires upscaler: 4x-AnimeSharp, Lora hashes: "Rabbit (wlsdnjs950): b617b45520e4", TI hashes: "easynegative: c74b4e810b03", Version: v1.5.1 https://files.catbox.moe/051rag.png

The Lora/embeddings are these ones but I've tested with several and they all have the issue. https://civitai.com/models/70680/rabbit-or-wlsdnjs950-or-erabi-style-lora https://civitai.com/models/7808/easynegative

Checkpoint is this one but I tried others and have the same issue. https://civitai.com/models/6755?modelVersionId=78676

Issue happens regardless of scaler too.

cheald commented 1 year ago

Hm. I still can't reproduce it. The stack trace would suggest that raw_steps isn't a string. I suspect you might have another extension somewhere messing with it, but if you feel comfortable hand-applying a patch, would you try this and see if it fixes it?

diff --git a/lib/utils.py b/lib/utils.py
index 415e400..9eff43d 100644
--- a/lib/utils.py
+++ b/lib/utils.py
@@ -6,7 +6,7 @@ import re

 def sorted_positions(raw_steps):
     steps = [[float(s.strip()) for s in x.split("@")]
-             for x in re.split("[,;]", raw_steps)]
+             for x in re.split("[,;]", str(raw_steps))]
     # If we just got a single number, just return it
     if len(steps[0]) == 1:
         return steps[0][0]
Detrian commented 1 year ago

I'm afraid I have absolutely no idea how to do that and can't seem to find how, sorry. I did try removing all the other extensions except this one but the problem persisted. I'm thinking of reinstalling the UI again and see how that goes.

cheald commented 1 year ago

Open the file extensions/sd-webui-loractl/lib/utils.py in a text editor. On line 9, replace for x in re.split("[,;]", raw_steps)] with for x in re.split("[,;]", str(raw_steps))], save, and restart the web UI.

Sorry, without a means to reproduce the issue I'm mostly just guessing here.

Detrian commented 1 year ago

Oh, that's easier. Well, there is no error anymore but the lora does not apply, same as before.

cheald commented 1 year ago

I'm out of ideas; without a means to reproduce the error, I'm not sure I can offer further help :/

Detrian commented 1 year ago

Sounds like a freak error for sure. I'll try reinstalling the whole thing and see how it goes. Thank you so much.

cheald commented 1 year ago

I'm going to close this ticket for now; let me know if you manage to fix it (or get more information on the error).

Detrian commented 1 year ago

I did a complete wipe and reinstall of git, python, the webui and accompanying extensions. It fixed the problem and I made images for a couple of hours but then the issue began to present itself again. I'm not sure why. What I discovered is that reloading the UI, either through the button in the UI's settings menu or the one at the bottom of the UI, fixes the issue. Closing and reopening the console/browser frontend does not fix it, so the issue persists until you do a manual reload. I haven't tested if the issue persists through a PC reboot, might do later if the opportunity presents itself.

I've taken to reloading the Ui every hour or so, just in case.

cheald commented 1 year ago

That is extraordinarily odd. Let me know if you come up with a solid reproduction procedure.