Skip to content

Commit

Permalink
p.add_(torch.sign(update), alpha=-group['lr']) has been made more eff…
Browse files Browse the repository at this point in the history
…icient by using the torch.sign function's inplace mode. This will prevent the need to create a new tensor for the updated parameter, which can save a significant amount of time for large models. (#1193)
  • Loading branch information
sachinspanicker committed Aug 9, 2023
1 parent 4398750 commit c7392f2
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion lion/lion_pytorch.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,12 @@ def step(self, closure=None):

# Weight update
update = exp_avg * beta1 + grad * (1 - beta1)
p.add_(torch.sign(update), alpha=-group['lr'])

p.add_(torch.sign(update), alpha=-group['lr'], inplace=True)
#This has been made more efficient by using the torch.sign function's inplace mode.
#This will prevent the need to create a new tensor for the updated parameter,
#which can save a significant amount of time for large models.

# Decay the momentum running average coefficient
exp_avg.mul_(beta2).add_(grad, alpha=1 - beta2)

Expand Down

0 comments on commit c7392f2

Please sign in to comment.