Recover when the `sha` of the local file is not correct.
Author: Narsil
Pull request: no

## Environment info
<!-- You can run the command `transformers-cli env` and copy-and-paste its output below.
     Don't forget to fill out the missing fields in that output! -->

- `transformers` version: `master` (probably any version)
- Platform: ubuntu
- Python version: 3.9
- PyTorch version (GPU?): 1.10
- Tensorflow version (GPU?): X
- Using GPU in script?:no
- Using distributed or parallel set-up in script?:no

### Who can help

@LysandreJik 

<!-- Your issue will be replied to more quickly if you can figure out the right person to tag with @
 If you know how to use git blame, that is the easiest way, otherwise, here is a rough guide of **who to tag**.
 Please tag fewer than 3 people.

Models:

- ALBERT, BERT, XLM, DeBERTa, DeBERTa-v2, ELECTRA, MobileBert, SqueezeBert: @LysandreJik
- encoder-decoder models (For example, BlenderBot, BART, Marian, Pegasus, T5, ByT5): @patrickvonplaten, @patil-suraj
- Longformer, Reformer, TransfoXL, XLNet, FNet: @patrickvonplaten
- FSMT: @stas00
- Funnel: @sgugger
- GPT-2, GPT: @patrickvonplaten, @LysandreJik
- RAG, DPR: @patrickvonplaten, @lhoestq
- TensorFlow: @Rocketknight1
- JAX/Flax: @patil-suraj @patrickvonplaten 
- TAPAS, LayoutLM, LayoutLMv2, LUKE, ViT, BEiT, DEiT, DETR, CANINE: @NielsRogge
- GPT-Neo, GPT-J, CLIP: @patil-suraj
- Wav2Vec2, HuBERT, SpeechEncoderDecoder: @patrickvonplaten, @anton-l

If the model isn't in the list, ping @LysandreJik who will redirect you to the correct contributor.

Library:

- Benchmarks: @patrickvonplaten
- Deepspeed: @stas00
- Ray/raytune: @richardliaw, @amogkam
- Text generation: @patrickvonplaten
- Tokenizers: @LysandreJik
- Trainer: @sgugger
- Pipelines: @Narsil
- Speech: @patrickvonplaten, @anton-l
- Vision: @NielsRogge, @sgugger

Documentation: @sgugger

Model hub:

- for issues with a model, report at https://discuss.huggingface.co/ and tag the model's creator.

HF projects:

- datasets: [different repo](https://github.com/huggingface/datasets)
- rust tokenizers: [different repo](https://github.com/huggingface/tokenizers)

Examples:

- maintained examples (not research project or legacy): @sgugger, @patil-suraj

For research projetcs, please ping the contributor directly. For example, on the following projects:

- research_projects/bert-loses-patience: @JetRunner
- research_projects/distillation: @VictorSanh

 -->

## Information

Model I am using (Bert, XLNet ...):

The problem arises when using:
* [x] the official example scripts: (give details below)
* [ ] my own modified scripts: (give details below)

The tasks I am working on is:
* [ ] an official GLUE/SQUaD task: (give the name)
* [x] my own task or dataset: (give details below)

## To reproduce

Steps to reproduce the behavior:



1. If a model get incorrectly downloaded or corrupted later. You will end up in an incorrect state where `from_pretrained` won't work anymore.

Script to create incorrect state artificially:
```python
  import os
  from transformers import AutoModel
  from transformers.file_utils import cached_path, hf_bucket_url


model_id = "Narsil/small2"
  model = AutoModel.from_pretrained(model_id)
  path = cached_path(hf_bucket_url(model_id, "pytorch_model.bin"))
  os.remove(path)
  with open(path, "w") as f:
      f.write("")

  model = AutoModel.from_pretrained(model_id) # Triggers an unrecoverable error
```

<!-- If you have code snippets, error messages, stack traces please provide them here as well.
     Important! Use code tags to correctly format your code. See https://help.github.com/en/github/writing-on-github/creating-and-highlighting-code-blocks#syntax-highlighting
     Do not use screenshots, as they are hard to read and (more importantly) don't allow others to copy-and-paste your code.-->

## Expected behavior

Since we still have `.json` that contains the  expected `etag` we can actually check the file against it and trigger a redownload in such situations instead.

Roughly I expect to get a warning that something was wrong with my local file compared to what was expected and that it will attempt to download again, download again and work (if there's nothing obviously wrong there).

(I actually expect for the sha to be run regularly too, even if it's expensive, if someone modified my weights under me, and they're still loadable, I can have big mistakes occurring, no ? I can see users doing cp `mymodel/pytorch_model.bin ~/.cache/..../232323.232aedc`.)

<!-- A clear and concise description of what you would expect to happen. -->


Comments:
That's interesting. We have the `force_download` option which you can use to force a redownload in case of a corrupted file, but your approach doesn't have any drawbacks that I am aware of.

This issue has been automatically marked as stale because it has not had recent activity. If you think this still needs to be addressed please comment on this thread.

Please note that issues that do not follow the [contributing guidelines](https://github.com/huggingface/transformers/blob/master/CONTRIBUTING.md) are likely to be ignored.