Пример #1
0
def get_bprop_tanh(self):
    """Grad definition for `Tanh` operation."""
    tanh_grad = SG.TanhGrad()

    def bprop(x, out, dout):
        dx = tanh_grad(out, dout)
        return (dx, )

    return bprop
Пример #2
0
def get_bprop_mish(self):
    """Grad definition for `Mish` operation."""
    tanh = P.Tanh()
    tanh_grad = SG.TanhGrad()
    softplus = P.Softplus()
    softplus_grad = G.SoftplusGrad()

    def bprop(x, out, dout):
        dx1 = tanh(softplus(x))
        dx2 = softplus_grad(tanh_grad(dx1, x * dout), x)
        dx = (dx1 * dout + dx2)
        return (dx, )

    return bprop