preds, defined at the first line, is an empty tensor
pred, defined in your function, is the one containing the predictions
To compute the confusion matrix, only preds is used.
I think the confusion lies there