I think the first two pieces of code should work fine and have the same net effect. The last one seems incorrect as it would duplicate the backward computation. You can refer to post below for more explanations