Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LoRA保存与加载to_out层时的问题 #599

Open
YAR-sdu opened this issue Oct 22, 2024 · 0 comments
Open

LoRA保存与加载to_out层时的问题 #599

YAR-sdu opened this issue Oct 22, 2024 · 0 comments

Comments

@YAR-sdu
Copy link

YAR-sdu commented Oct 22, 2024

问题描述

当前版本的Jittor,在保存和加载LoRA时,无法正确处理LoRA中的to_out层。
具体而言,在peft库,/peft/tuners/lora/models.py中的_replace_module代码如下
peft
而Jittor的LoRA中,qkv和out层的对应属性如下
Jittor LoRA
可以发现,out层由sequential构建,包括一个linear层和一个dropout层。

setattr()函数会直接替换变量中对应key的value值,但在对to_out层进行处理时,child_name被错误地设置为"0"
2 0)L$VA5W$CLO4_3704I~W

因此,直接使用setattr对to_out层进行替换,实际上只是为parent增加了"0"这个属性,而并不会实际改变to_out层的值。
4Q6T TDQJZ)N04$69D`}6BR

可能的解决方法

如果单纯想暂时解决问题以正常使用LoRA,最简单的方法是修改peft库,在_replace_module中修改部分逻辑
方案1
将原本的setattr()修改,增加对to_out层的逻辑判断,用不同的方式加载即可。

更佳的方案,大概需要进一步查看并修改其余相关的代码逻辑。

此外,对比torch的LoRA实现,torch的LoRA中,qkv层为带dropout属性的Linear,out为不带dropout属性的Linear,与Jittor中略有不同,或许可作为参考?

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

No branches or pull requests

1 participant