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

[core] Fix peft multi-gpu issue #145

Merged
merged 7 commits into from
Mar 14, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/peft/tuners/lora.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -345,6 +350,7 @@ def forward(self, x: torch.Tensor):
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)
Expand Down