lllyasviel / ControlNet

Let us control diffusion models!
Apache License 2.0
30.44k stars 2.73k forks source link

Error when transferring control #91

Open f8upd8 opened 1 year ago

f8upd8 commented 1 year ago

Traceback:

(control) malo@win11-f8:/mnt/i/source/ControlNet$ python tool_transfer_control.py
logging improved.
Loaded state_dict from [/mnt/i/ckpt/native/sd1-5pruned.ckpt]
Loaded state_dict from [/mnt/i/source/automatic-ui/extensions/sd-webui-controlnet/models/control_sd15_canny.pth]
Loaded state_dict from [/mnt/i/ckpt/native/novelai-pruned.ckpt]
Traceback (most recent call last):
  File "tool_transfer_control.py", line 42, in <module>
    final_state_dict[key] = input_state_dict[key]
KeyError: 'first_stage_model.encoder.conv_in.weight'

I suggest changing

if is_first_stage or is_cond_stage:
    final_state_dict[key] = input_state_dict[key]
    continue

to

if is_first_stage or is_cond_stage:
    if not input_state_dict.get(key):
        continue
    final_state_dict[key] = input_state_dict[key]
    continue

This will ensure script does not die if one model has a state key that other does not. This helped me to transfer models to novelai.

Sorry for being lazy with PRs

Escenda commented 1 year ago

Hi,

I encountered an error with your pull request code as shown below.

Traceback (most recent call last):
  File "tool_transfer_control.py", line 42, in <module>
    if not input_state_dict.get(key):
RuntimeError: Boolean value of Tensor with more than one value is ambiguous

Therefore, I suggest modifying your code as follows.

From:

if is_first_stage or is_cond_stage:
    if not input_state_dict.get(key):
        continue
    final_state_dict[key] = input_state_dict[key]
    continue

To:

if is_first_stage or is_cond_stage:
    if key not in input_state_dict:
        continue
    final_state_dict[key] = input_state_dict[key]
    continue

I made some modifications based on your code and successfully managed to convert the model I wanted.

tysm