Script for finding candidate models for deprecation
Author: amyeroberts
Pull request: yes

# What does this PR do?

Adds a script to find a list of candidate models to deprecate. By default, the list of models are those which are over a year old and have had fewer than 5,000 downloads over the last month. 

Things to note: 
- As the script iterates over all of the checkpoints on the hub, it can be fairly slow to run (a few mins). The option to save the retrieved information `--save_model_info` is added, which will save all of the models, alongside their date of first commit and number of downloads. This is useful when changing the threshold date of number of downloads to select models as you can run `--use_cache` to iterate quickly
- There are assumptions made about the model file structures and names. Therefore some "models" will be found for deprecation, even if they many downloads e.g. "data2vec" as there's many separate data2vec modeling files e.g. `modeling_data2vec_vision.py`

 

Comments:
The docs for this PR live [here](https://moon-ci-docs.huggingface.co/docs/transformers/pr_29686). All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update.

Gentle ping @ydshieh 

Sorry, didn't notice this PR. Will review asap. 

Thanks for the review @ydshieh! I've addressed all your comments

> There are assumptions made about the model file structures and names. Therefore some "models" will be found for deprecation, even if they many downloads e.g. "data2vec" as there's many separate data2vec modeling files e.g. modeling_data2vec_vision.py

If IIRC, the dictionary `model_info` use the model directory (so it is `data2vec`) but the tags of models on the Hub could be `data2vec-vision` etc, so it won't be added to the dictionary.

@ydshieh I updated a little bit, so that we filter the hub requests based on model tags in [da62f7e](https://github.com/huggingface/transformers/pull/29686/commits/da62f7e7114c64ffb11383fb5bc395d772a53bc5). Running this way, it ran in 161 seconds. Previously it was 240s. Not ideal - not sure of a faster way to get the downloads info - but as we're running sporadically I don't think too bad either 

OK, I was wondering why you pushed the last commit but now I understand it is to make things a bit fast. Nice!

My only left question is just about if the download number is over the last month. I don't seem to find this is mentioned in the `HfApi`. But since it is mentioned in your PR, let's wait @Wauplin to confirm. (or if it's urgent, you can merge and we check with him later)

Ah, sorry.

Would be nice to have something like

```python
# Copyright 2024 The HuggingFace Team. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
```


> let's wait @Wauplin to confirm. (or if it's urgent, you can merge and we check with him later)

Yep, let's wait 👍 It's not urgent - just a few other PRs lined up after this one to handle automated deprecation and one which will deprecate a bunch of models that are flagged from this script 

Didn't want to make you wait longer to [I replied](https://github.com/huggingface/transformers/pull/29686#discussion_r1579115735) :smile: And it's all good :+1: 


OK, thanks for confirmation. BTW, for `class ModelInfo:`, my local file shows 

```
        downloads (`int`):
            Number of downloads of the dataset.
```
Might be better to make it more precise (if not done yet on the latest version)

Opened https://github.com/huggingface/huggingface_hub/pull/2250 to fix that :hugs: