I have just implemented the copy and past grad function.
def copy_grad(optimizer):
    grad_list = []
    for ppp in optimizer.param_groups[0]['params']:
        gradd = ppp.grad.clone()
        grad_list.append(gradd)

    return grad_list

def paste_grad(optimizer, grad_list):
    for index, ppp in enumerate(optimizer.param_groups[0]['params']):
        ppp.grad = grad_list[index]
        
    return