sd-scripts icon indicating copy to clipboard operation
sd-scripts copied to clipboard

resize_lora.py scale = network_alpha / network_dim TypeError: unsupported operand type(s) for /: 'NoneType' and 'NoneType'

Open tazztone opened this issue 4 months ago • 1 comments

some loras seem incompatible with the resize utility? the script can't detect the original dimension and alpha of the LoRA models from the model's metadata?

17:29:00-754074 INFO     Executing command:                                    
                         C:\_stability_matrix\Data\Packages\kohya\venv\Scripts\
                         python.exe                                            
                         C:/_stability_matrix/Data/Packages/kohya/sd-scripts/ne
                         tworks/resize_lora.py --save_precision fp16 --save_to 
                         C:/_stability_matrix/Data/Models/Lora/t4zz-v23-test.sa
                         fetensors --model                                     
                         C:/_stability_matrix/Data/Models/Lora/t4zz-v23.safeten
                         sors --new_rank 32 --device cuda --dynamic_method     
                         sv_fro --dynamic_param 0.94 --verbose                 
2025-08-05 17:29:09 INFO     loading Model...                resize_lora.py:321
2025-08-05 17:29:10 INFO     Resizing Lora...                resize_lora.py:324
Traceback (most recent call last):
  File "C:\_stability_matrix\Data\Packages\kohya\sd-scripts\networks\resize_lora.py", line 412, in <module>
    resize(args)
  File "C:\_stability_matrix\Data\Packages\kohya\sd-scripts\networks\resize_lora.py", line 325, in resize
    state_dict, old_dim, new_alpha = resize_lora_model(
  File "C:\_stability_matrix\Data\Packages\kohya\sd-scripts\networks\resize_lora.py", line 211, in resize_lora_model
    scale = network_alpha / network_dim
TypeError: unsupported operand type(s) for /: 'NoneType' and 'NoneType'

i trained the lora with ai-toolkit with these parameters.

linear: 128
linear_alpha: 128

i can provide the lora if it helps.

tazztone avatar Aug 05 '25 15:08 tazztone

ok so it is a known issue that the loras from ai-toolkit (diffusers) version need to be converted so the resize script can automatically determine network_dim and network_alpha. my LoRA model uses lora_A and lora_B in its keys instead of lora_down and lora_up, and it doesn't have explicit alpha keys. This is why the script is leading to the TypeError.

endet up using this conversion script https://cnb.cool/zhanzhangtuijian/SDTrain_bdsqlsz/-/blob/02bb6e31103f563ee521e29f80c6475387dd5faf/sd-scripts/networks/convert_flux_lora.py and it worked the main branch doesn't have one but there is one in the SD3 branch i found later. i didn't test. may even be the same tho https://github.com/kohya-ss/sd-scripts/blob/sd3/networks/convert_flux_lora.py

in case anyone needs my .bat scripts it's here: https://github.com/tazztone/sd-scripts/tree/main/_BAT the resulting resized lora was tested and confirmed working

tazztone avatar Aug 06 '25 10:08 tazztone