kohya-ss / sd-scripts

Apache License 2.0
5.31k stars 880 forks source link

Issue for convert_flux_lora.py: RuntimeError: Some tensors share memory... #1614

Closed terrificdm closed 1 month ago

terrificdm commented 2 months ago

After flux lora training, I used convert_flux_lora.py to convert sd-scripts lora to diffusers type lora, but encountered below error:

RuntimeError: 
            Some tensors share memory, this will lead to duplicate memory on disk and potential differences when loading them again: [{'transformer.transformer_blocks.0.attn.to_k.lora_A.weight......
A potential way to correctly save your model is to use `save_model`.
More information at https://huggingface.co/docs/safetensors/torch_shared_tensors'

My running script is as below:

python networks/convert_flux_lora.py --src sd-scripts --dst ai-toolkit --src_path ../checkpoint/flux_lora_abc
flux_lora_abc.safetensors 
Weifeng-Chen commented 2 months ago

+1 meet same errors ... @kohya-ss . any solutions now? @terrificdm

kohya-ss commented 2 months ago

Is there somewhere I can download safetensors that are causing the error? I'd like to test with it.

terrificdm commented 2 months ago

+1 meet same errors ... @kohya-ss . any solutions now? @terrificdm

Since the newest diffusers lib supports loading Kohya flux lora directly, you don't need to convert lora format before loading it. The weird thing is that I noticed the newest diffusers lib also leveraged codes from convert_flux_lora.py and it worked well...

terrificdm commented 2 months ago

Is there somewhere I can download safetensors that are causing the error? I'd like to test with it.

You can try this one. Thanks. https://huggingface.co/terrificdm/example/blob/main/flux_lora_wta-000004.safetensors

kohya-ss commented 1 month ago

I've added a workaround for this error, please give it a try.