Open iamalbert opened 8 years ago
Well, it's a reasonable requirement. It's clearly stated in the documentation that you should call backward, after calling forward, with the same input. It's perfectly valid for any module to compute bad gradients if you don't call :forward
earlier.
And it's the case for not only CrossEntropyCritetion
but also many modules such as SpatialConvolution
.
You should call forward
properly before backward
.
Unlike other classification criterion, CrossEntropyCriterion is not stateless, as a result of which a
backward
call that does not follow aforward
with same input and target leads to an error. it would be better and more convenience if we can callbackward
directly.