Since upgrading PyTorch (to ‘0.5.0a0+a24163a’), I am getting the following warning:
/usr/lib/python3.7/site-packages/torch/nn/functional.py:52: UserWarning: size_average and reduce args will be deprecated, please use reduction='sum' instead.
warnings.warn(warning.format(ret))
Is this due to the new pytorch version or is it due to python-3.7? Is there anything I need to do or is it going to be fixed in newer versions?
@ptrblck the docs still say size_average is required in order to use ignore_index in F.cross_entropy. It’s not clear how size_average is replaced by reduction in this case. How are we meant to use ignore_index?
Yeah, the documentation might be a bit misleading, as size_average is mentioned, while this argument is deprecated and reduction should be used instead.
There are basically the three reduction types, i.e. 'none', 'sum', and 'mean'. ignore_index will be applied as:
reduction='none': the loss will not be reduced, so you will get a loss tensor in the shape [batch_size]. The entries, where target==ignore_index, will have a zero loss.
reduction='mean': the reduced loss will be the average of all entries, where target!=ignore_index.
reduction='sum': the reduced loss will be the sum of the “raw loss”. Since the samples with ignored targets will get a zero loss, the sum should not change, if you filter them out or just sum over all values.
Here is a small code snippet to demonstrate my understanding: