Your code looks alright, at least the parts I’ve tried to debug.
It’s probably not an issue, but I’m also cautious if you are reshaping a tensor which should already be in the right shape as is done in your loss_fct:
loss_fct(logits.view(-1, self.num_labels), labels.view(-1, self.num_labels))

At least logits should already be in the right shape. Could you check that these view calls do not mess up your data and target?