Two piece code will get different results, is there any one can give me some tips about the difference between autograd.backward()
and mx.nd.backward()
.
First piece code:
cls_mask = mx.nd.one_hot(cls_id, 1000, on_value=1, off_value=0)
img.attach_grad()
with autograd.record():
logit = net(img)
logit = logit * cls_mask
autograd.backward(logit)
grad = img.grad
...
Second piece code:
cls_mask = mx.nd.one_hot(cid, 1000, on_value=1, off_value=0)
img.attach_grad()
with autograd.record():
logit = net(img)
logit.backward(cls_mask)
grad = img.grad
...
i.e., my question is, why logit.backward(cls_mask)
is different from autograd.backward(logit)
??