DiffSynth-Studio icon indicating copy to clipboard operation
DiffSynth-Studio copied to clipboard

Jointly train LoRA and DiT

Open bchao1 opened this issue 9 months ago • 2 comments

I finetuned a model using LoRA and saved the checkpoint. Is it possible to load that LoRA to a model, and finetune BOTH LoRA and the DiT together? I set my options like the following, but it seems like whenever I specified LoRA-specific arguments, the DiT is never trained, even if i set trainable_models to be dit

--trainable_models "dit" \
--lora_base_model "dit" \
-lora_target_modules "to_q,to_k,to_v,to_out.0,add_q_proj,add_k_proj,add_v_proj,to_add_out,linear_in,linear_out,to_qkv_mlp_proj,single_transformer_blocks.0.attn.to_out,single_transformer_blocks.1.attn.to_out,single_transformer_blocks.2.attn.to_out,single_transformer_blocks.3.attn.to_out,single_transformer_blocks.4.attn.to_out,single_transformer_blocks.5.attn.to_out,single_transformer_blocks.6.attn.to_out,single_transformer_blocks.7.attn.to_out,single_transformer_blocks.8.attn.to_out,single_transformer_blocks.9.attn.to_out,single_transformer_blocks.10.attn.to_out,single_transformer_blocks.11.attn.to_out,single_transformer_blocks.12.attn.to_out,single_transformer_blocks.13.attn.to_out,single_transformer_blocks.14.attn.to_out,single_transformer_blocks.15.attn.to_out,single_transformer_blocks.16.attn.to_out,single_transformer_blocks.17.attn.to_out,single_transformer_blocks.18.attn.to_out,single_transformer_blocks.19.attn.to_out" \
--lora_rank 64 \
--lora_checkpoint ${lora_ckpt}

bchao1 avatar Feb 18 '26 02:02 bchao1

@bchao1 In principle, simultaneous training of LoRA and the base model is supported. You can refer to our code here: https://github.com/modelscope/DiffSynth-Studio/blob/29cd5c7612f2b46e755322b1d0c1c6e0e0409772/diffsynth/diffusion/training_module.py#L191.

If the training results for a specific model do not meet your expectations, please open a new issue with a detailed description so we can reproduce the problem.

However, please note that this renders the LoRA parameters entirely redundant. Additionally, the saved model file will contain a mixture of both LoRA and base model parameters. There is really no need to train in this manner. We assume you may intend to merge the LoRA into the base model first before continuing training. To achieve this, please merge them externally to generate a new base model .safetensors file, and then load that file during training.

Artiprocher avatar Mar 02 '26 02:03 Artiprocher

@Artiprocher Hi, I am facing a similar problem. Specifically, in my setup, I want to use LoRA to train the Cross-Attention modules while fully fine-tuning the parameters of the Self-Attention modules. How can I achieve this?

You mentioned that switch_pipe_to_training_mode supports this setup for training, but I am unsure how to load the weights back into the model for inference. Is there a built-in function that can load this type of hybrid-trained model, or do I need to write a custom loading function?

INV-WZQ avatar Mar 03 '26 06:03 INV-WZQ