ikostrikov / pytorch-a3c

PyTorch implementation of Asynchronous Advantage Actor Critic (A3C) from "Asynchronous Methods for Deep Reinforcement Learning".
MIT License
1.23k stars 279 forks source link

if there's no "if shared_param.grad is not None: return" what will happen? #79

Open yinqinghai opened 1 year ago

yinqinghai commented 1 year ago
        if shared_param.grad is not None:
            return
        shared_param._grad = param.grad

in this code, if there's no if shared_param.grad is not None: return shared_param._grad will be assigned each time? maybe just some performance loss? maybe a stupid question, but i'm curious, thanks in advance.

zhuzhu18 commented 1 year ago

我也感觉这个if语句没啥作用,每个子进程中的shared_model的梯度在zero_grad后都被置为None了,而且在进程之间还不共享