Code cleanup

This commit is contained in:
Shangtong Zhang
2017-10-05 21:42:27 -06:00
parent dd2443c1c3
commit 8b9fd8d24f
4 changed files with 0 additions and 199 deletions
-17
View File
@@ -1,17 +0,0 @@
# adapted from https://github.com/alexis-jacq/Pytorch-DPPO/blob/master/model.py
import torch
class SharedGrad():
def __init__(self, model):
self.grads = {}
for name, p in model.named_parameters():
self.grads[name+'_grad'] = torch.ones(p.size()).share_memory_()
def add_gradient(self, model):
for name, p in model.named_parameters():
self.grads[name+'_grad'] += p.grad.data
def reset(self):
for name,grad in self.grads.items():
self.grads[name].fill_(0)