This might be a bug, as it seems the values are uninitialized.
I cannot reproduce it using your (modified) code for N = 5000
.
Also note, that your criterion should get the prediction as the first argument and the target as the second.
reduction
should be set as 'none'
(lowercase n).