torch / nn

Other
1.34k stars 967 forks source link

make nn.CrossEntropyCriterion stateless #807

Open iamalbert opened 8 years ago

iamalbert commented 8 years ago

Unlike other classification criterion, CrossEntropyCriterion is not stateless, as a result of which a backward call that does not follow a forward with same input and target leads to an error. it would be better and more convenience if we can call backward directly.

apaszke commented 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.

yangky11 commented 8 years ago

And it's the case for not only CrossEntropyCritetion but also many modules such as SpatialConvolution. You should call forward properly before backward.