-
Notifications
You must be signed in to change notification settings - Fork 6.5k
Fix Unfuse Lora #4833
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 Unfuse Lora #4833
Conversation
| attn_module.k_proj = attn_module.k_proj.regular_linear_layer | ||
| attn_module.v_proj = attn_module.v_proj.regular_linear_layer | ||
| attn_module.out_proj = attn_module.out_proj.regular_linear_layer | ||
| attn_module.q_proj.lora_linear_layer = None |
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.
If we remove the whole patched layer when unloading LoRAs we cannot unfuse it anymore. Let's just set the LoRA linear layer to None.
| self.w_up = self.w_up.to(device=device, dtype=dtype) | ||
| self.w_down = self.w_down.to(device, dtype=dtype) | ||
| unfused_weight = fused_weight - torch.bmm(self.w_up[None, :], self.w_down[None, :])[0] | ||
| w_up = self.w_up.to(device=device).float() |
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.
Improve precision to fp32
| self.w_up = self.w_up.to(device=device, dtype=dtype) | ||
| self.w_down = self.w_down.to(device, dtype=dtype) | ||
| unfused_weight = fused_weight - torch.bmm(self.w_up[None, :], self.w_down[None, :])[0] | ||
| w_up = self.w_up.to(device=device).float() |
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.
Improve precision
|
The documentation is not available anymore as the PR was closed or merged. |
| def state_dict(self, *args, destination=None, prefix="", keep_vars=False): | ||
| if self.lora_linear_layer is None: | ||
| return self.regular_linear_layer.state_dict( | ||
| *args, destination=destination, prefix=prefix, keep_vars=keep_vars | ||
| ) | ||
|
|
||
| return super().state_dict(*args, destination=destination, prefix=prefix, keep_vars=keep_vars) |
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.
Nice. TIL.
|
Thanks a lot. |
* Fix Unfuse Lora * add tests * Fix more * Fix more * Fix all * make style * make style
* Fix Unfuse Lora * add tests * Fix more * Fix more * Fix all * make style * make style
What does this PR do?
This PR fixes the unfusing issue as discovered by @apolinario here