I`m sorry but i think that i asked wrong question which is not my intention.
Actually, my loss function is constructed like:
def myloss(data):
    tmp = 0
    for i in range(len(data)):
        if data[i] > 0.5:
            tmp += 1
        else:
            tmp += 2
    loss = math.log10(tmp)
    return loss
loss = myloss(output)
loss.backward()

In this case, does it work too?