I have a model in which the Loss is maximizing the Entropy(not cross-entropy) of the output. ie. I’m trying to minimize the negative Entropy.
H = - sum(p(x).log(p(x)))
Let’s say:
def HLoss(res):
	S = nn.Softmax(dim = 1)
	LS = nn.LogSoftmax(dim = 1)
	b = S(res) * LS(res)
	b = torch.mean(b,1)
	b = torch.sum(b)
    return b

m = model()
#m is [BatchSize*3] output.
g = HLoss(m)
g.backward()

Would this calculate the gradients for m -> model() ?
Is there some way to check if the gradients are calculated?