[MaskFormer] PoC of AutoBackbone API to support ResNet + Swin
Author: NielsRogge
Pull request: yes

# What does this PR do?

This PR adds support for more backbones than just Swin for the MaskFormer framework. The MaskFormer authors released checkpoints that leverage either ResNet or Swin as backbones, however we currently only support Swin. To support various backbones, this PR introduces the AutoBackbone API.

It introduces the following improvements:

- [x] adding AutoBackbone, ResNetBackbone
- [x] move MaskFormerSwin to its own modeling files and add MaskFormerSwinBackbone
- [x] make MaskFormer use the AutoBackbone API to leverage any backbone, including ResNet

## AutoBackbone API

The API is implemented as follows. For a given model, one should implement an additional class, `xxxBackbone`, for instance `ResNetBackbone`, in addition to the regular classes like `xxxModel` and `xxxForImageClassification`. The backbone class turns the `xxxModel` into a generic backbone to be consumed by a framework, like DETR or MaskFormer. 

The API is inspired by the one used in [Detectron2](https://github.com/facebookresearch/detectron2/blob/main/detectron2/modeling/backbone/backbone.py). This means that any backbone should implement a `forward` and an `output_shape` method:

* the `forward` method returns the hidden states for each of the desired stages
* the `output_shape` method returns the channel dimension + strides for each of the desired stages.

There are additional methods like `size_divisibility` and `padding_constraints` which could be added in the future, for now they don't seem necessary.

## Usage

An example can be found below. Basically, the user can specify which layers/stages to get the feature maps from.

```
from transformers import ResNetConfig, ResNetBackbone
import torch

config = ResNetConfig(out_features=["stem", "stage1", "stage2", "stage3", "stage4"])
model = ResNetBackbone(config)

pixel_values = torch.randn(1, 3, 224, 224)

outputs = model(pixel_values)
for key, value in outputs.items():
    print(key, value.shape)
```
which prints:
```
stem torch.Size([1, 64, 56, 56])
stage1 torch.Size([1, 256, 56, 56])
stage2 torch.Size([1, 512, 28, 28])
stage3 torch.Size([1, 1024, 14, 14])
stage4 torch.Size([1, 2048, 7, 7])
```
One can check the output specification as follows:
```
print(model.output_shape())
```
which prints:
```
{'stem': ShapeSpec(channels=64, height=None, width=None, stride=2), 'stage1': ShapeSpec(channels=256, height=None, width=None, stride=4), 'stage2': ShapeSpec(channels=512, height=None, width=None, stride=4), 'stage3': ShapeSpec(channels=1024, height=None, width=None, stride=4), 'stage4': ShapeSpec(channels=2048, height=None, width=None, stride=4)}
```
This is useful for frameworks, as they oftentimes require to know these things at initialization.

The Backbone API has a corresponding Auto class, which means that the following also works:
```
from transformers import ResNetConfig, AutoBackbone

config = ResNetConfig(out_features=["stem", "stage1", "stage2", "stage3", "stage4"])
model = AutoBackbone.from_config(config)
```
The AutoBackbone class also supports loading pre-trained weights, like so:
```
from transformers import AutoBackbone

backbone = AutoBackbone.from_pretrained("microsoft/resnet-50")
```
As the backbone also uses the same `base_model_prefix` like other head models.

## To do's

- [ ] Add tests for backbones. Backbone classes should not be tested with all tests defined in `test_modeling_common.py`, instead they should have separate tests. Here I'd like to discuss the best way to add these tests.
- [ ] make fixup is currently complaining about the following:
```
Exception: There were 2 failures:
MaskFormerSwinBackbone is defined in 
transformers.models.maskformer.modeling_maskformer_swin but is not present in 
any of the auto mapping. If that is intended behavior, add its name to 
`IGNORE_NON_AUTO_CONFIGURED` in the file `utils/check_repo.py`.
ResNetBackbone is defined in transformers.models.resnet.modeling_resnet but is 
not present in any of the auto mapping. If that is intended behavior, add its 
name to `IGNORE_NON_AUTO_CONFIGURED` in the file `utils/check_repo.py`
```
=> however I added both MaskFormerSwinBackbone and ResNetBackbone to modeling_auto.py, so not sure why this fails. cc @sgugger 

## MaskFormer specifics

MaskFormer supports both ResNet and Swin as backbone. It does support native ResNets, but it doesn't use the native Swin as backbone, which is why we have a separate `MaskFormerSwinModel` class in the library, as well as a `MaskFormerSwinBackbone` class in this PR. 

Happy to discuss the design!

Comments:
The docs for this PR live [here](https://moon-ci-docs.huggingface.co/docs/transformers/pr_20204). All of your documentation changes will be reflected on that endpoint.

Closing this PR as it has been added in smaller separate PRs.

Thanks again for splitting it, it was really better this way!