Fix the test for corrupted checkpoints in from_pretrained
# What does this PR do?

As pointed out in #19974, there is a bug in `from_pretrained` when the model with head contains the same key as the base model, the checkpoint is then detected as corrupted. This PR fixes it and introduces a test to make sure there is no regression.

Fixes #19974
cc @NielsRogge 
_The documentation is not available anymore as the PR was closed or merged._