The target contains negative values but no error is raised. But if I change target[1] to other negative values, e.g. -1, -10, then the error can be raised correctly. Why is -100 so magic?
ignore_index (int,optional) – Specifies a target value that is ignored
and does not contribute to the input gradient. When size_average
is True, the loss is averaged over non-ignored targets. Note that ignore_index is only applicable when the target contains class indices.
That is, -100 is the “magic value” that ignore_index is set to by default, so
those targets are ignored (including the fact that the label would otherwise
be an invalid negative value).