TimmWrapper model
Author: amyeroberts
Pull request: yes
Labels: name: Vision

name: run-slow

# What does this PR do?

Adds a TimmWrapper set of classes such that timm models can be loaded in as transformer models into the library. 

The models can now be used with the Trainer class and pipeline. There's still some integration todos: 
* Model loading appears to not work for vit-models because of the gamma parameter e.g. loading `timm/vit_mediumd_patch16_reg4_gap_256.sbb2_e200_in12k_ft_in1k` will result in the error message: 
```
Some weights of TimmWrapperForImageClassification were not initialized from the model checkpoint at timm/vit_mediumd_patch16_reg4_gap_256.sbb2_e200_in12k_ft_in1k and are newly initialized: ['blocks.0.ls1.gamma', 'blocks.0.ls2.gamma', 'blocks.1.ls1.gamma', 'blocks.1.ls2.gamma', 'blocks.10.ls1.gamma', 'blocks.10.ls2.gamma', 'blocks.11.ls1.gamma', 'blocks.11.ls2.gamma', 'blocks.12.ls1.gamma', 'blocks.12.ls2.gamma', 'blocks.13.ls1.gamma', 'blocks.13.ls2.gamma', 'blocks.14.ls1.gamma', 'blocks.14.ls2.gamma', 'blocks.15.ls1.gamma', 'blocks.15.ls2.gamma', 'blocks.16.ls1.gamma', 'blocks.16.ls2.gamma', 'blocks.17.ls1.gamma', 'blocks.17.ls2.gamma', 'blocks.18.ls1.gamma', 'blocks.18.ls2.gamma', 'blocks.19.ls1.gamma', 'blocks.19.ls2.gamma', 'blocks.2.ls1.gamma', 'blocks.2.ls2.gamma', 'blocks.3.ls1.gamma', 'blocks.3.ls2.gamma', 'blocks.4.ls1.gamma', 'blocks.4.ls2.gamma', 'blocks.5.ls1.gamma', 'blocks.5.ls2.gamma', 'blocks.6.ls1.gamma', 'blocks.6.ls2.gamma', 'blocks.7.ls1.gamma', 'blocks.7.ls2.gamma', 'blocks.8.ls1.gamma', 'blocks.8.ls2.gamma', 'blocks.9.ls1.gamma', 'blocks.9.ls2.gamma']
You should probably TRAIN this model on a down-stream task to be able to use it for predictions and inference.
```
* Is not compatible with quantization yet - I suspect because of how the weights are loaded 

### General Usage

```py
import torch
from urllib.request import urlopen
from PIL import Image
from transformers import AutoConfig, AutoModelForImageClassification, AutoImageProcessor

checkpoint = "timm/resnet50.a1_in1k"
img = Image.open(urlopen(
    'https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/beignets-task-guide.png'
))

image_processor = AutoImageProcessor.from_pretrained(checkpoint)
inputs = image_processor(img, return_tensors="pt")
model = AutoModelForImageClassification.from_pretrained(checkpoint)

with torch.no_grad():
    logits = model(**inputs).logits

top5_probabilities, top5_class_indices = torch.topk(logits.softmax(dim=1) * 100, k=5)
```


### Pipeline

Timm models can now be used in the image classification (if a classification model) and image feature extraction pipelines

```py
import torch
from urllib.request import urlopen
from PIL import Image

from transformers import pipeline

img = Image.open(urlopen(
    'https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/beignets-task-guide.png'
))
pipe = pipeline("image-classification", model="timm/resnet18.a1_in1k")
print(pipe(img))
```

### Trainer

Timm models can now be loaded and trained with the trainer class. 

Example model trained with the trainer running the script command below:
https://huggingface.co/amyeroberts/vit-base-beans/tree/main

```
python run_image_classification.py \                
    --dataset_name beans \
    --output_dir ./beans_outputs/ \
    --remove_unused_columns False \
    --label_column_name labels \
    --do_train \
    --do_eval \
    --push_to_hub \
    --push_to_hub_model_id vit-base-beans \
    --learning_rate 2e-5 \
    --num_train_epochs 5 \
    --per_device_train_batch_size 8 \
    --per_device_eval_batch_size 8 \
    --logging_strategy steps \
    --logging_steps 10 \
    --eval_strategy epoch \
    --save_strategy epoch \
    --load_best_model_at_end True \
    --save_total_limit 3 \
    --seed 1337 \
    --model_name_or_path timm/resnet18.a1_in1k \
    --ignore_mismatched_sizes
```

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

Hey! 🤗 Thanks for your contribution to the `transformers` library!

Before merging this pull request, slow tests CI should be triggered. To enable this:
- Add the `run-slow` label to the PR
- When your PR is ready for merge and all reviewers' comments have been addressed, push an empty commit with the command `[run-slow]` followed by a comma separated list of all the models to be tested, i.e. `[run_slow] model_to_test_1, model_to_test_2`
  - If the pull request affects a lot of models, put at most 10 models in the commit message
- A `transformers` maintainer will then approve the workflow to start the tests

(For maintainers) The documentation for slow tests CI on PRs is [here](https://www.notion.so/huggingface2/CI-for-pull-requests-8335bd9217d24d1e8ed1d3a016f39804).