-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
[core
] Fix peft multi-gpu issue
#145
Merged
Merged
Changes from 6 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
9ea7519
add multi-gpu support
younesbelkada 47acddd
rm deepcopy
younesbelkada 6f40411
Merge remote-tracking branch 'upstream/main' into temp-2
younesbelkada be12bac
tryo to comment
younesbelkada a6b3968
Merge remote-tracking branch 'upstream/main' into temp-2
younesbelkada ae7c42f
style
younesbelkada 01cfe6b
fix nits
younesbelkada File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -200,6 +200,11 @@ def _replace_module(self, parent_module, child_name, new_module, old_module): | |
new_module.state = old_module.state | ||
new_module.to(old_module.weight.device) | ||
|
||
# dispatch to correct device | ||
for name, module in new_module.named_modules(): | ||
if "lora_" in name: | ||
module.to(old_module.weight.device) | ||
|
||
def __getattr__(self, name: str): | ||
"""Forward missing attributes to the wrapped module.""" | ||
try: | ||
|
@@ -339,17 +344,20 @@ def eval(self): | |
self.lora_B.eval() | ||
|
||
def forward(self, x: torch.Tensor): | ||
|
||
if self.disable_adapters: | ||
if self.r > 0 and self.merged: | ||
self.weight.data -= ( | ||
transpose(self.lora_B.weight @ self.lora_A.weight, self.fan_in_fan_out) * self.scaling | ||
) | ||
self.merged = False | ||
|
||
return F.linear(x, transpose(self.weight, self.fan_in_fan_out), bias=self.bias) | ||
elif self.r > 0 and not self.merged: | ||
result = F.linear(x, transpose(self.weight, self.fan_in_fan_out), bias=self.bias) | ||
if self.r > 0: | ||
result += self.lora_B(self.lora_A(self.lora_dropout(x))) * self.scaling | ||
result = result | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This can be removed I think |
||
return result | ||
else: | ||
return F.linear(x, transpose(self.weight, self.fan_in_fan_out), bias=self.bias) | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
This can be removed I think