Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
lshqqytiger committed Apr 17, 2024
1 parent 8ee05a8 commit 7478723
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions modules/dml/hijack/torch.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,3 +49,17 @@ def pow_(self: torch.Tensor, *args, **kwargs):
return _pow_(self.cpu(), *args, **kwargs).to(self.device)
return _pow_(self, *args, **kwargs)
torch.Tensor.pow_ = pow_


_load = torch.load
def load(f, map_location, *args, **kwargs):
if type(map_location) in (str, torch.device,):
device = torch.device(map_location)
if device.type == "privateuseone":
data = _load(f, *args, map_location="cpu", **kwargs)
for k in data:
for weight in data[k]:
data[k][weight] = data[k][weight].to(device)
return data
return _load(f, *args, map_location=map_location, **kwargs)
torch.load = load

0 comments on commit 7478723

Please sign in to comment.