Skip to content

为unet训练第二阶段添加lora微调方法、加载lora权重推理方法#129

Closed
Ustinianer wants to merge 2 commits intobytedance:mainfrom
Ustinianer:main
Closed

为unet训练第二阶段添加lora微调方法、加载lora权重推理方法#129
Ustinianer wants to merge 2 commits intobytedance:mainfrom
Ustinianer:main

Conversation

@Ustinianer
Copy link

使用lora方法,可将显存占用降到40g以下,实现在A100-40g设备上微调
实测在以下配置下使用lora微调,A100-40g显存占用约38g
target_modules: ["to_q", "to_k", "to_v"]
lora_alpha: 1
lora_dropout: 0.0
bias: "none"
r: 8

@itzhoujun
Copy link

你好,能分享一下训练方法吗?好像除了准备数据,还需要改一些配置啥的,我折腾了一下没弄出来

@Ustinianer
Copy link
Author

Ustinianer commented Mar 3, 2025

你好,能分享一下训练方法吗?好像除了准备数据,还需要改一些配置啥的,我折腾了一下没弄出来

首先拉取代码,然后安装一下peft库
pip install peft
这版代码是无缝插入到原来的unet的训练脚本中的,只需要把配置文件configs/unet/second_stage.yaml中的use_lora置为true即可,启动方式和原训练Unet-stage2相同(因为是微调,故不进行第一阶段的训练)
resume_lora_path用于中断后的恢复训练,lora其他参数可自行调整
image
启用成功控制台会有如下输出
image

@itzhoujun
Copy link

你好,能分享一下训练方法吗?好像除了准备数据,还需要改一些配置啥的,我折腾了一下没弄出来

首先拉取代码,然后安装一下peft库 pip install peft 这版代码是无缝插入到原来的unet的训练脚本中的,只需要把配置文件configs/unet/second_stage.yaml中的use_lora置为true即可,启动方式和原训练Unet-stage2相同(因为是微调,故不进行第一阶段的训练) resume_lora_path用于中断后的恢复训练,lora其他参数可自行调整 image 启用成功控制台会有如下输出 image

微调效果好吗

@Ustinianer
Copy link
Author

你好,能分享一下训练方法吗?好像除了准备数据,还需要改一些配置啥的,我折腾了一下没弄出来

首先拉取代码,然后安装一下peft库 pip install peft 这版代码是无缝插入到原来的unet的训练脚本中的,只需要把配置文件configs/unet/second_stage.yaml中的use_lora置为true即可,启动方式和原训练Unet-stage2相同(因为是微调,故不进行第一阶段的训练) resume_lora_path用于中断后的恢复训练,lora其他参数可自行调整 image 启用成功控制台会有如下输出 image

微调效果好吗

你好,能分享一下训练方法吗?好像除了准备数据,还需要改一些配置啥的,我折腾了一下没弄出来

首先拉取代码,然后安装一下peft库 pip install peft 这版代码是无缝插入到原来的unet的训练脚本中的,只需要把配置文件configs/unet/second_stage.yaml中的use_lora置为true即可,启动方式和原训练Unet-stage2相同(因为是微调,故不进行第一阶段的训练) resume_lora_path用于中断后的恢复训练,lora其他参数可自行调整 image 启用成功控制台会有如下输出 image

微调效果好吗

在中文数据集上微调中文表现有提升,具体效果和数据集的质量和规模相关

@itzhoujun
Copy link

@Ustinianer 你好,请教下,如果只使用某个人3-5分钟的视频做lora训练,能不能让这个数字人嘴唇更像本人呢

@itzhoujun
Copy link

load lora config报错啦:

[rank0]: Traceback (most recent call last):
[rank0]:   File "<frozen runpy>", line 198, in _run_module_as_main
[rank0]:   File "<frozen runpy>", line 88, in _run_code
[rank0]:   File "/root/LatentSync/scripts/train_unet.py", line 548, in <module>
[rank0]:     main(config)
[rank0]:   File "/root/LatentSync/scripts/train_unet.py", line 165, in main
[rank0]:     lora_config = LoraConfig(
[rank0]:                   ^^^^^^^^^^^
[rank0]:   File "<string>", line 31, in __init__
[rank0]:   File "/usr/local/miniconda3/envs/py312/lib/python3.12/site-packages/peft/tuners/lora/config.py", line 418, in __post_init__
[rank0]:     super().__post_init__()
[rank0]:   File "/usr/local/miniconda3/envs/py312/lib/python3.12/site-packages/peft/config.py", line 67, in __post_init__
[rank0]:     raise ValueError(
[rank0]: ValueError: Invalid task type: 'IMAGE_GENERATION'. Must be one of the following task types: SEQ_CLS, SEQ_2_SEQ_LM, CAUSAL_LM, TOKEN_CLS, QUESTION_ANS, FEATURE_EXTRACTION.

@itzhoujun
Copy link

latentsysc更新到1.5版本了。大佬啥时候有空适配一下

@itzhoujun
Copy link

大佬,help

@Ustinianer
Copy link
Author

大佬,help
作者已经做了训练优化了,看下readme:
reduces the VRAM requirement of the stage2 training to 20 GB through a series of optimizations. Learn more details here.

@Ustinianer Ustinianer closed this Mar 23, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants