MCPcopy Create free account
hub / github.com/BIT-MCS/DRL-eFresh / add_gradient

Method add_gradient

methods/model.py:314–320  ·  view source on GitHub ↗
(self, model)

Source from the content-addressed store, hash-verified

312 self.grads[name + '_grad'] = torch.zeros(p.size()).share_memory_().to(device)
313
314 def add_gradient(self, model):
315 self.counter.increment()
316 for name, p in model.named_parameters():
317 if p.requires_grad:
318 # print("name:",name)
319 # print("data:", p.grad)
320 self.grads[name + '_grad'] += p.grad.data
321
322 def average_gradient(self):
323 counter_num = self.counter.get()

Callers 1

trainFunction · 0.80

Calls 1

incrementMethod · 0.80

Tested by

no test coverage detected