(self)
Actually back-propagate the gradient.
Actually back-propagate the gradient.
Actually back - propagate the gradient .
def build_grad(self):
        """
        Actually back-propagate the gradient.
        """
        # self.grad_op_tree shall be set by ad or parent grad_node
        assert self.grad_op_tree is not None

        if type(self.op_tree) == OpTreeNode:
            # get increment
            (left_increment, right_increment) = GradUtil.get_grad_back(self)

            # left increment
            if self.left.grad_op_tree is None:
                self.left.grad_op_tree = left_increment
            else:
                self.left.grad_op_tree = self.left.grad_op_tree + \
                    left_increment

            # left recursive
            self.left.build_grad()

            # check if right increment
            if right_increment is None:
                return

            # right increment
            if self.right.grad_op_tree is None:
                self.right.grad_op_tree = right_increment
            else:
                self.right.grad_op_tree = self.right.grad_op_tree + \
                    right_increment

            # right recursive
            self.right.build_grad()

        elif isinstance(self.op_tree, Tensor):
            self.ad.map_tensor_grad_op_tree[self.op_tree._original_base] = self.grad_op_tree
def build_grad ( self ) : # self.grad_op_tree shall be set by ad or parent grad_node assert self . grad_op_tree is not None if type ( self . op_tree ) == OpTreeNode : # get increment ( left_increment , right_increment ) = GradUtil . get_grad_back ( self ) # left increment if self . left . grad_op_tree is None : self . left . grad_op_tree = left_increment else : self . left . grad_op_tree = self . left . grad_op_tree + left_increment # left recursive self . left . build_grad ( ) # check if right increment if right_increment is None : return # right increment if self . right . grad_op_tree is None : self . right . grad_op_tree = right_increment else : self . right . grad_op_tree = self . right . grad_op_tree + right_increment # right recursive self . right . build_grad ( ) elif isinstance ( self . op_tree , Tensor ) : self . ad . map_tensor_grad_op_tree [ self . op_tree . _original_base ] = self . grad_op_tree