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

NaN errors for simply using this extension #15

Closed girllover2154 closed 1 year ago

girllover2154 commented 1 year ago

WebUI just straight gives me NaN instead of actually making images because of (according to the message I get) an error in unet when using this extension in the prompt. And when I tried using the --no-half command line, it just gives me this thing in the attached file. image_2023-08-16_170146186 Just the heck is going on?

cheald commented 1 year ago

Can you check the "Plot lora weights" option and provide a chart of the weights used?

I need as many specifics - versions used, other extensions used, any relevant log messages, etc. Without a reproduction case, there's not a whole lot I can do.

girllover2154 commented 1 year ago

Opera Snapshot_2023-08-16_202739_colab research google com Opera Snapshot_2023-08-16_202823_colab research google com Opera Snapshot_2023-08-16_202846_colab research google com

This are the errors I was given. Other Extensions used are ControlNet and Lora Weight Blocks

This is the prompt used: masterpiece, best quality, best aesthetic, anime, ultra detailed, hy1, hair ornament, multicolored hair, 1girl, solo, 18-year old girl, short twintails, large breasts, wide hips, eyebrows visible through hair, midriff, long legs, large blue eyes, (black bra with white lace and straps:1.2), black bra, (pink boyshorts with black and white lines on the hips:1.2), pink shorts, short shorts, (taking off a pink open hoodie:1.1), jacket, hoodie, hood down, standing, looking seductively at the viewer, slight smile, sexy posing, (relaxed eyes:1.2), white background, yu-gi-oh! arc-v, illustration, front view, cowboy-shot, lora:hiiragi_yuzu_v1:te=0.5@0.5,0.7@0.5,0.8@0.8:lbw=OUTALL:unet=1@0,0.7@0.5,0.8@0.8, lora:more_details:te=0.5@0.5,0.7@0.5,0.8@0.8:unet=-0.5@-0.5

cheald commented 1 year ago

lora-block-weight and composable-lora are not compatible with the 1.5-style syntax or with loractl's step syntax. lora-block-weight in particular is breaking there, as you can see in that "ValueError: Could not convert string to float" error. It cannot handle string lora weights.

girllover2154 commented 1 year ago

So, should I unistall them or simply stop using them?

cheald commented 1 year ago

You'll likely need to disable them to use the 1.5 split unit/te syntax or the loractl step control syntax.

girllover2154 commented 1 year ago

Very well. I could if only the extensions page wouldn't so long to load. But anyway, thanks for the help.

girllover2154 commented 1 year ago

Even without the "Lora Weight BLock" and "Composable Lora" extensions, I'm still getting these f@%%*ing NaN errors. I'm thinking there's something else being the non-sensical errors. This is what I got now: Error completing request Arguments: ('task(xcyaray7btz3azh)', 0, 'masterpiece, best quality, best aesthetic, anime, ultra detailed, yu-gi-oh! arc-v, \nhy1, hair ornament, multicolored hair, hiiragi yuzu, 1girl, solo, 18-year old girl, (pink hair:1.21551), short twintails, (blue hairclips:1.1), large breasts, wide hips, long legs, pink pubic hair, (blue eyes:1.2), (nude:1.2), nipples, female focus, (nsfw:1.15763), straddling, wariza, (open mouth:1.21551), bedroom setting, illustration, on bed, looking at viewer, , ', 'lowres, (bad anatomy:1.1025), (bad hands:1.1025), text, missing finger, extra digits, fewer digits, blurry, (mutated hands and fingers:1.1025), (poorly drawn face:1.05), (mutation:1.1025), (deformed face:1.1025), (ugly:1.05), (bad proportions:1.1025), (extra limbs:1.1025), extra face, (double head:1.05), (extra head:1.05), (extra feet:1.1025), monster, logo, cropped, worst quality, low quality, normal quality, jpeg, humpbacked, long body, long neck, (jpeg artifacts:1.1025), denim shorts, skirt, side slit shorts, EasyNegative, tattoo, (shoulder tattoo:1.0), (number tattoo:1.3), frills, long hair, (clothes:1.21551), futanari, (shirt:1.21551), (dress:1.21551)', [], <PIL.Image.Image image mode=RGBA size=512x800 at 0x78918D3A33A0>, None, None, None, None, None, None, 28, 16, 4, 0, 1, False, False, 5, 1, 7, 1.5, 0.6, -1.0, -1.0, 0, 0, 0, False, 1, 800, 512, 2, 0, 0, 32, 0, '', '', '', [], False, [], '', <gradio.routes.Request object at 0x78918d152d40>, 0, False, 2, 0, 0, 0, 0, '', 'None', 1, False, 20, False, False, True, True, False, True, False, False, False, 'LoRA', 'None', 0.5, 0.5, 'LoRA', 'None', 0, 0, 'LoRA', 'None', 0, 0, 'LoRA', 'None', 0, 0, 'LoRA', 'None', 0, 0, None, 'Refresh models', False, {'ad_model': 'face_yolov8n.pt', 'ad_prompt': '', 'ad_negative_prompt': '', 'ad_confidence': 0.3, 'ad_mask_k_largest': 0, 'ad_mask_min_ratio': 0, 'ad_mask_max_ratio': 1, 'ad_x_offset': 0, 'ad_y_offset': 0, 'ad_dilate_erode': 32, 'ad_mask_merge_invert': 'None', 'ad_mask_blur': 4, 'ad_denoising_strength': 0.4, 'ad_inpaint_only_masked': True, 'ad_inpaint_only_masked_padding': 32, 'ad_use_inpaint_width_height': False, 'ad_inpaint_width': 512, 'ad_inpaint_height': 512, 'ad_use_steps': False, 'ad_steps': 28, 'ad_use_cfg_scale': False, 'ad_cfg_scale': 7, 'ad_use_sampler': False, 'ad_sampler': 'Euler a', 'ad_use_noise_multiplier': False, 'ad_noise_multiplier': 1, 'ad_use_clip_skip': False, 'ad_clip_skip': 1, 'ad_restore_face': False, 'ad_controlnet_model': 'None', 'ad_controlnet_module': 'inpaint_global_harmonious', 'ad_controlnet_weight': 1, 'ad_controlnet_guidance_start': 0, 'ad_controlnet_guidance_end': 1, 'is_api': ()}, {'ad_model': 'None', 'ad_prompt': '', 'ad_negative_prompt': '', 'ad_confidence': 0.3, 'ad_mask_k_largest': 0, 'ad_mask_min_ratio': 0, 'ad_mask_max_ratio': 1, 'ad_x_offset': 0, 'ad_y_offset': 0, 'ad_dilate_erode': 32, 'ad_mask_merge_invert': 'None', 'ad_mask_blur': 4, 'ad_denoising_strength': 0.4, 'ad_inpaint_only_masked': True, 'ad_inpaint_only_masked_padding': 32, 'ad_use_inpaint_width_height': False, 'ad_inpaint_width': 512, 'ad_inpaint_height': 512, 'ad_use_steps': False, 'ad_steps': 28, 'ad_use_cfg_scale': False, 'ad_cfg_scale': 7, 'ad_use_sampler': False, 'ad_sampler': 'Euler a', 'ad_use_noise_multiplier': False, 'ad_noise_multiplier': 1, 'ad_use_clip_skip': False, 'ad_clip_skip': 1, 'ad_restore_face': False, 'ad_controlnet_model': 'None', 'ad_controlnet_module': 'inpaint_global_harmonious', 'ad_controlnet_weight': 1, 'ad_controlnet_guidance_start': 0, 'ad_controlnet_guidance_end': 1, 'is_api': ()}, False, [], [], [], 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, False, 'MultiDiffusion', False, True, 1024, 1024, 112, 112, 60, 8, '4x_fatal_Anime_500000_G', 2, False, 10, 1, 1, 64, False, False, False, False, False, 0.4, 0.4, 0.2, 0.2, '', '', 'Background', 0.2, -1.0, False, 0.4, 0.4, 0.2, 0.2, '', '', 'Background', 0.2, -1.0, False, 0.4, 0.4, 0.2, 0.2, '', '', 'Background', 0.2, -1.0, False, 0.4, 0.4, 0.2, 0.2, '', '', 'Background', 0.2, -1.0, False, 0.4, 0.4, 0.2, 0.2, '', '', 'Background', 0.2, -1.0, False, 0.4, 0.4, 0.2, 0.2, '', '', 'Background', 0.2, -1.0, False, 0.4, 0.4, 0.2, 0.2, '', '', 'Background', 0.2, -1.0, False, 0.4, 0.4, 0.2, 0.2, '', '', 'Background', 0.2, -1.0, False, 1024, 128, True, True, True, False, 0, False, False, 'Matrix', 'Horizontal', 'Mask', 'Prompt', '1,1', '0.2', False, False, False, 'Attention', False, '0', '0', '0.4', None, '0', '0', 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0, '', False, True, 30, 100, 'Half Cosine Up', 10, 'Linear Down', 0, 4, True, 'MEAN', 'AD', 1, <scripts.controlnet_ui.controlnet_ui_group.UiControlNetUnit object at 0x78918d31af50>, <scripts.controlnet_ui.controlnet_ui_group.UiControlNetUnit object at 0x78918d810be0>, <scripts.controlnet_ui.controlnet_ui_group.UiControlNetUnit object at 0x78918d813af0>, <scripts.controlnet_ui.controlnet_ui_group.UiControlNetUnit object at 0x78918d35f5b0>, True, False, False, False, False, '1:1,1:2,1:2', '0:0,0:0,0:1', '0.2,0.8,0.8', 20, 0.2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, '

\n', True, True, '', '', True, 50, True, 1, 0, False, 4, 0.5, 'Linear', 'None', '

Recommended settings: Sampling Steps: 80-100, Sampler: Euler a, Denoising strength: 0.8

', 128, 8, ['left', 'right', 'up', 'down'], 1, 0.05, 128, 4, 0, ['left', 'right', 'up', 'down'], False, False, 'positive', 'comma', 0, False, False, '', '

Will upscale the image by the selected scale factor; use width and height sliders to set tile size

', 64, 0, 2, 1, '', [], 0, '', [], 0, '', [], True, False, False, False, 0, None, None, False, None, None, False, None, None, False, None, None, False, 50, '

Will upscale the image depending on the selected target size type

', 512, 0, 8, 32, 64, 0.35, 32, 0, True, 2, False, 8, 0, 0, 2048, 2048, 2) {} Traceback (most recent call last): File "/content/sdw/modules/call_queue.py", line 58, in f res = list(func(*args, kwargs)) File "/content/sdw/modules/call_queue.py", line 37, in f res = func(*args, *kwargs) File "/content/sdw/modules/img2img.py", line 232, in img2img processed = process_images(p) File "/content/sdw/modules/processing.py", line 677, in process_images res = process_images_inner(p) File "/content/sdw/extensions/sd-webui-controlnet/scripts/batch_hijack.py", line 42, in processing_process_images_hijack return getattr(processing, '__controlnet_original_process_images_inner')(p, args, kwargs) File "/content/sdw/modules/processing.py", line 794, in process_images_inner samples_ddim = p.sample(conditioning=p.c, unconditional_conditioning=p.uc, seeds=p.seeds, subseeds=p.subseeds, subseed_strength=p.subseed_strength, prompts=p.prompts) File "/content/sdw/extensions/sd-webui-controlnet/scripts/hook.py", line 350, in process_sample return process.sample_before_CN_hack(*args, kwargs) File "/content/sdw/modules/processing.py", line 1381, in sample samples = self.sampler.sample_img2img(self, self.init_latent, x, conditioning, unconditional_conditioning, image_conditioning=self.image_conditioning) File "/content/sdw/modules/sd_samplers_kdiffusion.py", line 434, in sample_img2img samples = self.launch_sampling(t_enc + 1, lambda: self.func(self.model_wrap_cfg, xi, extra_args=extra_args, disable=False, callback=self.callback_state, extra_params_kwargs)) File "/content/sdw/modules/sd_samplers_kdiffusion.py", line 303, in launch_sampling return func() File "/content/sdw/modules/sd_samplers_kdiffusion.py", line 434, in samples = self.launch_sampling(t_enc + 1, lambda: self.func(self.model_wrap_cfg, xi, extra_args=extra_args, disable=False, callback=self.callback_state, extra_params_kwargs)) File "/usr/local/lib/python3.10/dist-packages/torch/utils/_contextlib.py", line 115, in decorate_context return func(*args, *kwargs) File "/content/sdw/repositories/k-diffusion/k_diffusion/sampling.py", line 594, in sample_dpmpp_2m denoised = model(x, sigmas[i] s_in, extra_args) File "/usr/local/lib/python3.10/dist-packages/torch/nn/modules/module.py", line 1501, in _call_impl return forward_call(*args, **kwargs) File "/content/sdw/modules/sd_samplers_kdiffusion.py", line 215, in forward devices.test_for_nans(x_out, "unet") File "/content/sdw/modules/devices.py", line 155, in test_for_nans raise NansException(message) modules.devices.NansException: A tensor with all NaNs was produced in Unet. This could be either because there's not enough precision to represent the picture, or because your video card does not support half type. Try setting the "Upcast cross attention layer to float32" option in Settings > Stable Diffusion or using the --no-half commandline argument to fix this. Use --disable-nan-check commandline argument to disable this check.

And this was the prompt I attempted to use: masterpiece, best quality, best aesthetic, anime, ultra detailed, yu-gi-oh! arc-v, hy1, hair ornament, multicolored hair, hiiragi yuzu, 1girl, solo, 18-year old girl, (pink hair:1.21551), short twintails, (blue hairclips:1.1), large breasts, wide hips, long legs, pink pubic hair, (blue eyes:1.2), (nude:1.2), nipples, female focus, (nsfw:1.15763), straddling, wariza, (open mouth:1.21551), bedroom setting, illustration, on bed, looking at viewer, ,

Daemon0ps commented 1 year ago
    """
    Called by processing on every run. Whatever the extra network is meant to do should be activated here.
    Passes arguments related to this extra network in params_list.
    User passes arguments by specifying this in his prompt:

    <name:arg1:arg2:arg3>

    Where name matches the name of this ExtraNetwork object, and arg1:arg2:arg3 are any natural number of text arguments
    separated by colon.

    Even if the user does not mention this ExtraNetwork in his prompt, the call will stil be made, with empty params_list -
    in this case, all effects of this extra networks should be disabled.

    Can be called multiple times before deactivate() - each new call should override the previous call completely.

    For example, if this ExtraNetwork's name is 'hypernet' and user's prompt is:

    > "1girl, <hypernet:agm:1.1> <extrasupernet:master:12:13:14> <hypernet:ray>"

    params_list will be:

    [
        ExtraNetworkParams(items=["agm", "1.1"]),
        ExtraNetworkParams(items=["ray"])
    ]

    """

https://github.com/AUTOMATIC1111/stable-diffusion-webui/blob/master/modules/extra_networks.py

sd-webui-loract does not process activation, and only processes weight changes according to the steps and weights passed as specific values instead of attempting to parse the prompt itself to fix any potential user errors.

Personally, I noticed I kept forgetting "0." so i was nuking some of my renders because yes. So I idiot-proofed it against myself

for x in pr_lo[:-1:].replace('>','\n').replace('<lora:','').replace('te=','').replace('unet=','').split('\n'): lr_fix = r'<lora:'+x.split(':')[0].strip()+r':'+','.join(r'0.'+str(f).replace(r'0.',r'').replace(r'@',r'@0.') for f in x.split(':')[1].strip().split(r','))+r':'+','.join('0.'+str(f).replace('0.','').replace('@ ','@0.') for f in x.split(':')[2].strip().split(','))+r'>'

all the loras: re.findall(r'([<].*?[>])',f))

all the N@N,Non-NaNs: re.findall(r'\D([^:][\d.])@([\d.])[\D]',f)

'lora:__loraname__:te=1@0,0@1:unet=1@0,0@1' broken af (Though, I now understand why your examples only used either <:te=:N> OR <:N:unet=>, as I was confused why you did not declare all of the keyword arguments in your Readme.MD.

works fine works fine works fine works fine that one breaks loractl, badly, as there is zero sanitization in the extension to account for irregular data representations. also, the dyn_dim item. You could at least try to network_patch.apply() dyn_dim as None. You are already handling **te_multipliers/**unet_multipliers. You could pass back clean data instead of 'ray' :P lol (sorry, havent slept in a couple days)... GIGO! Though... whether that means "Garbage In, Garbage Out" or the ETL credo of "Garbage In, Gold Out" depends on parsing and verification, I suppose. networks.load_networks( names, te_multipliers, unet_multipliers, ...dyn_dims) # :'( sad lonely variable is lonely dyn_dim = int(params.positional[3]) if len(params.positional) > 3 else None net.te_multiplier = te_multipliers[i] if te_multipliers else 1.0 net.unet_multiplier = unet_multipliers[i] if unet_multipliers else 1.0 net.dyn_dim = dyn_dims[i] if dyn_dims else 1.0 loaded_networks.append(net) #if you passed back None, at least it would load anyways? maybe? You're already changing things for the un-set values anyways # If unet ended up unset, then use the te value weights["unet"] = weights["unet"] if weights["unet"] is not None else weights["te"] # If hrunet ended up unset, use unet value weights["hrunet"] = weights["hrunet"] if weights["hrunet"] is not None else weights["unet"] # If hrte ended up unset, use te value weights["hrte"] = weights["hrte"] if weights["hrte"] is not None else weights["te"] 100%|█████████████████████████████████████████████████████████████| 20/20 [00:02<00:00, 7.79it/s] activating extra network lora with arguments []: ValueError Traceback (most recent call last): File "F:\sd\modules\extra_networks.py", line 106, in activate extra_network.activate(p, extra_network_args) File "F:\sd\extensions\sd-webui-loractl\loractl\lib\lora_ctl_network.py", line 28, in activate lora_weights[name] = utils.params_to_weights(params) File "F:\sd\extensions\sd-webui-loractl\loractl\lib\utils.py", line 43, in params_to_weights weights["te"] = sorted_positions(params.positional[1]) File "F:\sd\extensions\sd-webui-loractl\loractl\lib\utils.py", line 8, in sorted_positions steps = [[float(s.strip()) for s in x.split("@")] File "F:\sd\extensions\sd-webui-loractl\loractl\lib\utils.py", line 8, in steps = [[float(s.strip()) for s in x.split("@")] File "F:\sd\extensions\sd-webui-loractl\loractl\lib\utils.py", line 8, in steps = [[float(s.strip()) for s in x.split("@")] ValueError: could not convert string to float: '' def sorted_positions(raw_steps): steps = [[float(s.strip()) for s in x.split("@")] 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] you're splitting on a semi-colon ? O.o (Jet Brains Mono ExtraBold ftw?) steps = [[float(s.strip()) for s in x.split("@")] for x in re.split(f"[,{chr(58)}]", str(raw_steps))] # If we just got a single number, just return it if len(steps[0]) == 1: return steps[0][0]
girllover2154 commented 1 year ago

Mmmmm.... a too complex of an explanation. Just tell what should avoid using, that'll be it for me.

cheald commented 1 year ago

I'd be happy for a pull request to add some of that sanitization/bad data-proofing.

The semicolon splitting is there as an alternate delimiter for usage in X/Y grids, which use commas for delimiting the variants to iterate through.

girllover2154 commented 1 year ago

I'd be happy for a pull request to add some of that sanitization/bad data-proofing.

The semicolon splitting is there as an alternate delimiter for usage in X/Y grids, which use commas for delimiting the variants to iterate through.

That'll be helpful, thanks