Backbone kwargs in config
Author: amyeroberts
Pull request: yes

# What does this PR do?

This enables configuring the backbones through the config directly e.g. passing in `out_indices` to the backbone. This enables configuring a model's backbone when it's loaded from a pretrained checkpoint. At the moment, this is only possible when loading from a `backbone_config`.

Example:

```py
model = MaskFormer.from_pretrained(
    "facebook/maskformer-swin-base-ade",
    backbone="facebook/maskformer-swin-large-ade",
    backbone_kwargs={"out_indices": (-2, -1)}
)
```

This is necessary to replace th `timm` code currently there for models like DETR e.g. [here](https://github.com/huggingface/transformers/blob/fe861e578f50dc9c06de33cd361d2f625017e624/src/transformers/models/detr/modeling_detr.py#L341), which is often hard coded. 


## Before submitting
- [ ] This PR fixes a typo or improves the docs (you can dismiss the other checks if that's the case).
- [x] Did you read the [contributor guideline](https://github.com/huggingface/transformers/blob/main/CONTRIBUTING.md#start-contributing-pull-requests),
      Pull Request section?
- [ ] Was this discussed/approved via a Github issue or the [forum](https://discuss.huggingface.co/)? Please add a link
      to it if that's the case.
- [ ] Did you make sure to update the documentation with your changes? Here are the
      [documentation guidelines](https://github.com/huggingface/transformers/tree/main/docs), and
      [here are tips on formatting docstrings](https://github.com/huggingface/transformers/tree/main/docs#writing-source-documentation).
- [ ] Did you write any new necessary tests?


## Who can review?

Anyone in the community is free to review the PR once the tests have passed. Feel free to tag
members/contributors who may be interested in your PR.

<!-- Your PR 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:

- text models: @ArthurZucker and @younesbelkada
- vision models: @amyeroberts
- speech models: @sanchit-gandhi
- graph models: @clefourrier

Library:

- flax: @sanchit-gandhi
- generate: @gante
- pipelines: @Narsil
- tensorflow: @gante and @Rocketknight1
- tokenizers: @ArthurZucker
- trainer: @muellerzr and @pacman100

Integrations:

- deepspeed: HF Trainer/Accelerate: @pacman100
- ray/raytune: @richardliaw, @amogkam
- Big Model Inference: @SunMarc
- quantization (bitsandbytes, autogpt): @SunMarc and @younesbelkada

Documentation: @stevhliu and @MKhalusova

HF projects:

- accelerate: [different repo](https://github.com/huggingface/accelerate)
- datasets: [different repo](https://github.com/huggingface/datasets)
- diffusers: [different repo](https://github.com/huggingface/diffusers)
- rust tokenizers: [different repo](https://github.com/huggingface/tokenizers)

Maintained examples (not research project or legacy):

- Flax: @sanchit-gandhi
- PyTorch: See Models above and tag the person corresponding to the modality of the example.
- TensorFlow: @Rocketknight1

 -->


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

@ArthurZucker Sure! 

We want to remove the hard-coded conditional logic inside of models like DETR and be able to fully configure the backbone's behaviour. The use case is: image I want to create a new model to train. Instead of the default architecture of DETR, I want to use a different timm backbone, and I want the backbone to return different feature maps from the default. 

At the moment this isn't possible because: 
* `use_timm_backbone` behaviour is hard coded, so we can't load different timm backbones easily e.g. [here](https://github.com/huggingface/transformers/blob/fe861e578f50dc9c06de33cd361d2f625017e624/src/transformers/models/detr/modeling_detr.py#L341) i.e. I can't pass timm specific arguments to configure the [backbone e.g. `output_stride`](https://github.com/huggingface/transformers/blob/abf8f54a019ce14b5eaffa68c6dd883be13fe66e/src/transformers/models/detr/modeling_detr.py#L349). 
* I can't configure the backbone by passing in `out_indices` to set the feature maps. 

I completely agree that it would be better to have this all as one argument! For context: when the backbones were first added, there were four arguments: 
* `backbone` which specifies a checkpoint e.g. `"facebook/detr-resnet-50"`
* `use_timm_backbone` - whether or not to load the backbone from timm. 
* `use_pretrained_backbone` which was ill-defined, but controlled the behaviour JUST for the timm backbones
* `backbone_config` a model config which defines a backbone e.g. ResNet. 

The `backbone_config` is just a model config, and used to load backbone models from config:

```py
backbone = AutoBackbone.from_config(backbone_config)
```

and `backbone` is a checkpoint used to load from pretrained:

```py
backbone = AutoBackbone.from_pretrained(backbone)
```

So `backbone` and `backbone_config` are mutually exclusive. And `backbone_config` is of type `PretrainedConfig` so can  only configure transformers models. 

Adding `backbone_kwargs` isn't ideal, but I think it's the simplest solution. The alternative is creating a new backbone config which contains everything. Because the old values are used in 100s of configs, we wouldn't be able to immediately deprecate, so it'd be a case of having code which ingested old config arguments. 

If you want, I'm happy to code something up and we can decide which is best from the two :) 

For more context, here's an example of the final step for removing timm in the modeling files: https://github.com/amyeroberts/transformers/pull/114/files#diff-bdc82cb85f491576a99a341adabaf42260eac9cd797d70d0a2c564b0d4ee2930

You can see how all we need is a single call `backbone = load_backbone(config)` in a modules init.