MCPcopy Create free account
hub / github.com/10Ring/LAA-Net / second_step

Method second_step

lib/optimizers/sam.py:47–55  ·  view source on GitHub ↗
(self, zero_grad=False)

Source from the content-addressed store, hash-verified

45
46 @torch.no_grad()
47 def second_step(self, zero_grad=False):
48 for group in self.param_groups:
49 for p in group["params"]:
50 if p.grad is None: continue
51 p.sub_(self.state[p]["e_w"]) # get back to "w" from "w + e(w)"
52
53 self.base_optimizer.step() # do the actual "sharpness-aware" update
54
55 if zero_grad: self.zero_grad()
56
57 @torch.no_grad()
58 def step(self, closure=None):

Callers 2

stepMethod · 0.95
trainFunction · 0.80

Calls 1

stepMethod · 0.80

Tested by

no test coverage detected