MCPcopy Create free account
hub / github.com/OpenDriveLab/ReSim / step

Method step

SwissArmyTransformer/examples/mae/util/lars.py:23–47  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

21
22 @torch.no_grad()
23 def step(self):
24 for g in self.param_groups:
25 for p in g['params']:
26 dp = p.grad
27
28 if dp is None:
29 continue
30
31 if p.ndim > 1: # if not normalization gamma/beta or bias
32 dp = dp.add(p, alpha=g['weight_decay'])
33 param_norm = torch.norm(p)
34 update_norm = torch.norm(dp)
35 one = torch.ones_like(param_norm)
36 q = torch.where(param_norm > 0.,
37 torch.where(update_norm > 0,
38 (g['trust_coefficient'] * param_norm / update_norm), one),
39 one)
40 dp = dp.mul(q)
41
42 param_state = self.state[p]
43 if 'mu' not in param_state:
44 param_state['mu'] = torch.zeros_like(p)
45 mu = param_state['mu']
46 mu.mul_(g['momentum']).add_(dp)
47 p.add_(mu, alpha=-g['lr'])

Callers 3

__call__Method · 0.45
training_stepMethod · 0.45
training_stepMethod · 0.45

Calls

no outgoing calls

Tested by

no test coverage detected