Revisions not working as expected
Author: BramVanroy
Pull request: no

We were getting a size mismatch when loading a finetuned checkpoint. After looking at the model config, I found that it had been updated and that the [embedding/vocab size had increased](https://huggingface.co/GroNLP/bert-base-dutch-cased/commit/b23d41bddd4d5c925bec648458cabd7cc578e47e). This is slightly annoying but not the core of this issue. My way of dealing with this, then, was naturally to rely on version control and simply use the previous commit which still had the config that we used for finetuning ([this one](https://huggingface.co/GroNLP/bert-base-dutch-cased/commit/61330c1ca1aa3a688f8aa015059142a1b20d3f63)). I would have expected that I can then load this revised model with the commit as given on the website:

```python
from transformers import AutoModel

model_name = "GroNLP/bert-base-dutch-cased"
revision = "61330c1"
model = AutoModel.from_pretrained(model_name, revision=revision)
```

This does not work an throws an error that the model cannot be found with the following message:

```
OSError: Can't load config for 'GroNLP/bert-base-dutch-cased'. Make sure that:

- 'GroNLP/bert-base-dutch-cased' is a correct model identifier listed on 'https://huggingface.co/models'

- or 'GroNLP/bert-base-dutch-cased' is the correct path to a directory containing a config.json file
```

A **first improvement** would be to add to this error message something about revisions, because obviously `GroNLP/bert-base-dutch-cased` is a correct name. The deeper issue is that the model revision is simply not found when I use the commit tag on the website. By coincidence I noticed that the URL includes a much longer identifier that starts with the commit number that you can see on the website (the full commit hash). When you try that, the code does run and the revision is correctly loaded.

```python
from transformers import AutoModel

model_name = "GroNLP/bert-base-dutch-cased"
revision = "61330c1ca1aa3a688f8aa015059142a1b20d3f63"
model = AutoModel.from_pretrained(model_name, revision=revision)
```

So the bug is either
- the model is not capable of looking up a revision based on the first seven characters of a hash (not sure if it should/could),
- or the model hub website does not provide enough information to make this intuitive for users. 

One way that would help, for instance, is that the "use in transformers" button adapts itself to the current revision that a user is browsing and when clicked it includes the revision (if any) in the example usage. And/or a copy function can be added to the commit identifier that - when clicked - does copies the whole hash.

### Who can help
Note sure who to tag for the model page so tagging @sgugger and @LysandreJik 


Comments:
Just an update (I've already posted it on Twitter):

Git tags or branches should work, such as:

```python
from transformers import AutoModel
model = AutoModel.from_pretrained("dbmdz/german-gpt2", revision="v1.0")
```


Hi @BramVanroy, thanks for opening an issue! This is also tracked in https://github.com/huggingface/huggingface_hub/issues/197 cc @julien-c @Pierrci 

There's definitely an improvement to be done regarding the mention of the revision in the error message, feel free to give it a try if you have the time to, otherwise we'll take care of it ASAP. 

@LysandreJik Great. I wasn't sure what the underlying issue was: `transformers` not correctly loading the short hash, or the web interface not displaying the full hash. Feel free to close this issue if you think that is better. I made a tiny PR for an improved error message.

> So the bug is either
> 
> * the model is not capable of looking up a revision based on the first seven characters of a hash (not sure if it should/could),
> * or the model hub website does not provide enough information to make this intuitive for users 

It's a partial mix of both: the model hub website does not currently have the feature to lookup a revision based on the first seven characters of a hash

(loading a commit from the first few hash characters is a sugar-y feature of git, not a core feature)

> A **first improvement** would be to add to this error message something about revisions, because obviously `GroNLP/bert-base-dutch-cased` is a correct name.

Yes definitely, as @LysandreJik said

EDIT: and your PR looks a great improvement

@julien-c I was reading through the docs on [short commit hashes](https://git-scm.com/book/en/v2/Git-Tools-Revision-Selection#_short_sha_1) (truncated) and this seems important: 

> Git is smart enough to figure out what commit you’re referring to if you provide the first few characters of the SHA-1 hash, as long as that partial hash is at least four characters long **and unambiguous; that is, no other object in the object database can have a hash that begins with the same prefix.**

I don't know how (and if you) you would implement loading revisions from short hashes, but checking for ambiguity seems an important point to consider - even though the chances are quite small that the first 4-7 characters are identical between two commits within the same repo.

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.

Bumping to keep this open.

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.

Not sure if I should try to keep this open. Final bump unless others interact.

It's really on the Hub side of thing, so https://github.com/huggingface/huggingface_hub/issues/197 should be tracking it and it can be closed on this side (unless I'm missing something).

Hey @BramVanroy (and @sgugger) we solved this through better UX, actually:

if you take a look at commit history on https://huggingface.co/bert-base-uncased/commits/main you now have buttons to copy the full commit hash (exactly like on GitHub), thanks to @beurkinger on the Hub team.

see screenshot below:

<img width="1131" alt="Screenshot 2021-10-21 at 18 51 05" src="https://user-images.githubusercontent.com/326577/138322377-5d0a7195-522b-4f50-af35-a663e10390d7.png">

Hope this helps!