Deal with nested configs better in base class
Author: sgugger
Pull request: yes

# What does this PR do?

This PR removes the need to override `to_dict` in model configs by implementing the whole logic in the base class. It also deals better with `to_diff_dict` for those configs, by analyzing the dict of sub-configs key by key and not as a whole. This also removes the `is_composition` flag from configs that do not need it: this flag is used to see if the config can be instantiated without any args (like `EncoderDecoderConfig`) but a CLIP config can be instantiated with `CLIPConfig()`.

Lastly this adds an option to set a custom subconfig using a dict instead of the config class, e.g. if someone wants to do:
```py
from transformers import AutoConfig

config = AutoConfig.from_pretrained("openai/clip-vit-base-patch16", text_config = dict(num_hidden_layers = 2))
```
this will now result in `config.text_config` being a proper `CLIPTextConfig` instead of a dict so loading a model like this:

```py
from transformers import CLIPModel
CLIPModel.from_pretrained("openai/clip-vit-base-patch16", text_config = dict(num_hidden_layers = 2))
```
will now work (well assuming shapes match so probably another text config to pass 😅 )

Comments:
_The documentation is not available anymore as the PR was closed or merged._

@ArthurZucker the `is_composition=True` is not necessary anymore except for configs which have no default for their subconfigs. And it should only be set to `True` in that case, otherwise in `to_diff_dict` we put too much stuff. I adapted the common test to check for that, will also adapt the doc.

I'll also add a test for the instantiation of a subconfig with a dict.

This broke the yet unmerged IDEFICS https://github.com/huggingface/transformers/pull/24796

I created a new issue to track https://github.com/huggingface/transformers/issues/25597

Isn't the `use_diff=True` in [`self.to_json_file(output_config_file, use_diff=True)`](https://github.com/huggingface/transformers/blob/c2123626aa3cd6c1ae4869ec9bc8869d1a408166/src/transformers/configuration_utils.py#L459) by default dangerous? This means that a saved config.json will break in case the default of a config in transformers is modified. This adds a lot of trust in transformers, while being greedy allows to purely rely on the json without having to rely on transformers defaults.

For example, this PR changes the way subconfigs are saved, being greedy before, to not being greedy now.

Similarly, `print(config)` is now much less informative than before:

Before:

```
config SamConfig {
  "_commit_hash": "96a685daa603136baf75b975e0c854e199c07928",
  "_name_or_path": "fxmarty/sam-vit-tiny-random",
  "architectures": [
    "SamModel"
  ],
  "initializer_range": 0.02,
  "mask_decoder_config": {
    "_name_or_path": "",
    "add_cross_attention": false,
    "architectures": null,
    "attention_downsample_rate": 2,
    "bad_words_ids": null,
    "begin_suppress_tokens": null,
    "bos_token_id": null,
    "chunk_size_feed_forward": 0,
    "cross_attention_hidden_size": null,
    "decoder_start_token_id": null,
    "diversity_penalty": 0.0,
    "do_sample": false,
    "early_stopping": false,
    "encoder_no_repeat_ngram_size": 0,
    "eos_token_id": null,
    "exponential_decay_length_penalty": null,
    "finetuning_task": null,
    "forced_bos_token_id": null,
    "forced_eos_token_id": null,
    "hidden_act": "relu",
    "hidden_size": 32,
    "id2label": {
      "0": "LABEL_0",
      "1": "LABEL_1"
    },
    "iou_head_depth": 3,
    "iou_head_hidden_dim": 256,
    "is_decoder": false,
    "is_encoder_decoder": false,
    "label2id": {
      "LABEL_0": 0,
      "LABEL_1": 1
    },
    "layer_norm_eps": 1e-06,
    "length_penalty": 1.0,
    "max_length": 20,
    "min_length": 0,
    "mlp_dim": 2048,
    "model_type": "",
    "no_repeat_ngram_size": 0,
    "num_attention_heads": 8,
    "num_beam_groups": 1,
    "num_beams": 1,
    "num_hidden_layers": 2,
    "num_multimask_outputs": 3,
    "num_return_sequences": 1,
    "output_attentions": false,
    "output_hidden_states": false,
    "output_scores": false,
    "pad_token_id": null,
    "prefix": null,
    "problem_type": null,
    "pruned_heads": {},
    "remove_invalid_values": false,
    "repetition_penalty": 1.0,
    "return_dict": true,
    "return_dict_in_generate": false,
    "sep_token_id": null,
    "suppress_tokens": null,
    "task_specific_params": null,
    "temperature": 1.0,
    "tf_legacy_loss": false,
    "tie_encoder_decoder": false,
    "tie_word_embeddings": true,
    "tokenizer_class": null,
    "top_k": 50,
    "top_p": 1.0,
    "torch_dtype": null,
    "torchscript": false,
    "transformers_version": "4.32.0.dev0",
    "typical_p": 1.0,
    "use_bfloat16": false
  },
  "model_type": "sam",
  "prompt_encoder_config": {
    "_name_or_path": "",
    "add_cross_attention": false,
    "architectures": null,
    "bad_words_ids": null,
    "begin_suppress_tokens": null,
    "bos_token_id": null,
    "chunk_size_feed_forward": 0,
    "cross_attention_hidden_size": null,
    "decoder_start_token_id": null,
    "diversity_penalty": 0.0,
    "do_sample": false,
    "early_stopping": false,
    "encoder_no_repeat_ngram_size": 0,
    "eos_token_id": null,
    "exponential_decay_length_penalty": null,
    "finetuning_task": null,
    "forced_bos_token_id": null,
    "forced_eos_token_id": null,
    "hidden_act": "gelu",
    "hidden_size": 32,
    "id2label": {
      "0": "LABEL_0",
      "1": "LABEL_1"
    },
    "image_embedding_size": 64,
    "image_size": 1024,
    "is_decoder": false,
    "is_encoder_decoder": false,
    "label2id": {
      "LABEL_0": 0,
      "LABEL_1": 1
    },
    "layer_norm_eps": 1e-06,
    "length_penalty": 1.0,
    "mask_input_channels": 16,
    "max_length": 20,
    "min_length": 0,
    "model_type": "",
    "no_repeat_ngram_size": 0,
    "num_beam_groups": 1,
    "num_beams": 1,
    "num_point_embeddings": 4,
    "num_return_sequences": 1,
    "output_attentions": false,
    "output_hidden_states": false,
    "output_scores": false,
    "pad_token_id": null,
    "patch_size": 16,
    "prefix": null,
    "problem_type": null,
    "pruned_heads": {},
    "remove_invalid_values": false,
    "repetition_penalty": 1.0,
    "return_dict": true,
    "return_dict_in_generate": false,
    "sep_token_id": null,
    "suppress_tokens": null,
    "task_specific_params": null,
    "temperature": 1.0,
    "tf_legacy_loss": false,
    "tie_encoder_decoder": false,
    "tie_word_embeddings": true,
    "tokenizer_class": null,
    "top_k": 50,
    "top_p": 1.0,
    "torch_dtype": null,
    "torchscript": false,
    "transformers_version": "4.32.0.dev0",
    "typical_p": 1.0,
    "use_bfloat16": false
  },
  "torch_dtype": "float32",
  "transformers_version": null,
  "vision_config": {
    "_name_or_path": "",
    "add_cross_attention": false,
    "architectures": null,
    "attention_dropout": 0.0,
    "bad_words_ids": null,
    "begin_suppress_tokens": null,
    "bos_token_id": null,
    "chunk_size_feed_forward": 0,
    "cross_attention_hidden_size": null,
    "decoder_start_token_id": null,
    "diversity_penalty": 0.0,
    "do_sample": false,
    "dropout": 0.0,
    "early_stopping": false,
    "encoder_no_repeat_ngram_size": 0,
    "eos_token_id": null,
    "exponential_decay_length_penalty": null,
    "finetuning_task": null,
    "forced_bos_token_id": null,
    "forced_eos_token_id": null,
    "global_attn_indexes": [
      2,
      5,
      8,
      11
    ],
    "hidden_act": "gelu",
    "hidden_size": 96,
    "id2label": {
      "0": "LABEL_0",
      "1": "LABEL_1"
    },
    "image_size": 1024,
    "initializer_factor": 1.0,
    "initializer_range": 1e-10,
    "intermediate_size": 768,
    "is_decoder": false,
    "is_encoder_decoder": false,
    "label2id": {
      "LABEL_0": 0,
      "LABEL_1": 1
    },
    "layer_norm_eps": 1e-06,
    "length_penalty": 1.0,
    "max_length": 20,
    "min_length": 0,
    "mlp_dim": 384,
    "mlp_ratio": 4.0,
    "model_type": "",
    "no_repeat_ngram_size": 0,
    "num_attention_heads": 1,
    "num_beam_groups": 1,
    "num_beams": 1,
    "num_channels": 3,
    "num_hidden_layers": 12,
    "num_pos_feats": 16,
    "num_return_sequences": 1,
    "output_attentions": false,
    "output_channels": 32,
    "output_hidden_states": false,
    "output_scores": false,
    "pad_token_id": null,
    "patch_size": 16,
    "prefix": null,
    "problem_type": null,
    "projection_dim": 64,
    "pruned_heads": {},
    "qkv_bias": true,
    "remove_invalid_values": false,
    "repetition_penalty": 1.0,
    "return_dict": true,
    "return_dict_in_generate": false,
    "sep_token_id": null,
    "suppress_tokens": null,
    "task_specific_params": null,
    "temperature": 1.0,
    "tf_legacy_loss": false,
    "tie_encoder_decoder": false,
    "tie_word_embeddings": true,
    "tokenizer_class": null,
    "top_k": 50,
    "top_p": 1.0,
    "torch_dtype": null,
    "torchscript": false,
    "transformers_version": "4.32.0.dev0",
    "typical_p": 1.0,
    "use_abs_pos": true,
    "use_bfloat16": false,
    "use_rel_pos": true,
    "window_size": 14
  }
}
```

Now:

```
SamConfig {
  "_name_or_path": "fxmarty/sam-vit-tiny-random",
  "architectures": [
    "SamModel"
  ],
  "initializer_range": 0.02,
  "mask_decoder_config": {
    "hidden_size": 32,
    "model_type": ""
  },
  "model_type": "sam",
  "prompt_encoder_config": {
    "hidden_size": 32,
    "model_type": ""
  },
  "torch_dtype": "float32",
  "transformers_version": "4.33.0.dev0",
  "vision_config": {
    "dropout": 0.0,
    "hidden_size": 96,
    "initializer_factor": 1.0,
    "intermediate_size": 768,
    "mlp_dim": 384,
    "model_type": "",
    "num_attention_heads": 1,
    "num_pos_feats": 16,
    "output_channels": 32,
    "projection_dim": 64
  }
}
```