-
Notifications
You must be signed in to change notification settings - Fork 112
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
fix bug of dual module (setattr, and compatible with DualModule input) #613
Conversation
…Inc/diffusers into dev_wy_lora_support_textencoder
…Inc/diffusers into dev_wy_lora_support_textencoder
[None] * len(torch_attr) if oneflow_attr is None else oneflow_attr | ||
) | ||
if oneflow_attr is None: | ||
oneflow_attr = flow.nn.ModuleList([None] * len(torch_attr)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这里原来的方法创建的 oneflow_attr 是个 list,在下面 DualModule 的 setattr 中,setattr(self._oneflow_module, key, value) 对于 key='0' 会挂掉。这里本意应该是也创建一个 flow.nn.ModuleList
@torch2oflow.register | ||
def _(mod: DualModule, verbose=False): | ||
return torch2oflow(mod._torch_module, verbose) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
转换 torch model 在那种情况会出现 DualModule ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
转换 torch model 在那种情况会出现 DualModule ?
PEFT 这里有一处逻辑是,找到 LoRA 对应的 Linear,用自己定义的 LoRALinear 包一下。
“找到 LoRA 对应的 Linear” 这里会导致 DualModule getattr 返回一个 DualModule
“用自己定义的 LoRALinear 包一下” 这里会生成一个 torch module,但它的 submodule 包含 DualModule,再创建 DualModule 的时候,会导致这里 torch2oflow 接受一个 DualModule
适配 PEFT 中暴露出了一些问题:
PEFT 创建 LoRA model 时候,会把对应的 Linear(也包含 Conv2d 等其他 module,这里以 Linear 为例)拿出来,然后创建一个 LoRALinear,把这个 Linear 包一层,放在原来这个 Linear 的位置。
当使用 DeployableModule 的时候,拿出来的 Linear 是个 DualModule,用 LoRALinear 包完一层之后,就变成了 torch module 包 DualModule 的情况。
在后续 torch2oflow 以及创建 DualModule 的时候,会报错。
这里是拿 Linear 时候的现场:
这里是用 LoRALinear 包起来的现场: