class_docstr: Base class for all configuration classes. Handles a few parameters common to all models' configurations as well as
  methods for loading/downloading/saving configurations.
  
  Note:
      A configuration file can be loaded and saved to disk. Loading the configuration file and using this file to
      initialize a model does **not** load the model weights. It only affects the model's configuration.
  
  Class attributes (overridden by derived classes)
  
      - **model_type** (:obj:`str`) -- An identifier for the model type, serialized into the JSON file, and used to
        recreate the correct object in :class:`~transformers.AutoConfig`.
      - **is_composition** (:obj:`bool`) -- Whether the config class is composed of multiple sub-configs. In this
        case the config has to be initialized from two or more configs of type
        :class:`~transformers.PretrainedConfig` like: :class:`~transformers.EncoderDecoderConfig` or
        :class:`~RagConfig`.
      - **keys_to_ignore_at_inference** (:obj:`List[str]`) -- A list of keys to ignore by default when looking at
        dictionary outputs of the model during inference.
      - **attribute_map** (:obj:`Dict[str, str]`) -- A dict that maps model specific attribute names to the
        standardized naming of attributes.
  
  Common attributes (present in all subclasses)
  
      - **vocab_size** (:obj:`int`) -- The number of tokens in the vocabulary, which is also the first dimension of
        the embeddings matrix (this attribute may be missing for models that don't have a text modality like ViT).
      - **hidden_size** (:obj:`int`) -- The hidden size of the model.
      - **num_attention_heads** (:obj:`int`) -- The number of attention heads used in the multi-head attention layers
        of the model.
      - **num_hidden_layers** (:obj:`int`) -- The number of blocks in the model.
  
  Args:
      name_or_path (:obj:`str`, `optional`, defaults to :obj:`""`):
          Store the string that was passed to :func:`~transformers.PreTrainedModel.from_pretrained` or
          :func:`~transformers.TFPreTrainedModel.from_pretrained` as ``pretrained_model_name_or_path`` if the
          configuration was created with such a method.
      output_hidden_states (:obj:`bool`, `optional`, defaults to :obj:`False`):
          Whether or not the model should return all hidden-states.
      output_attentions (:obj:`bool`, `optional`, defaults to :obj:`False`):
          Whether or not the model should returns all attentions.
      return_dict (:obj:`bool`, `optional`, defaults to :obj:`True`):
          Whether or not the model should return a :class:`~transformers.file_utils.ModelOutput` instead of a plain
          tuple.
      is_encoder_decoder (:obj:`bool`, `optional`, defaults to :obj:`False`):
          Whether the model is used as an encoder/decoder or not.
      is_decoder (:obj:`bool`, `optional`, defaults to :obj:`False`):
          Whether the model is used as decoder or not (in which case it's used as an encoder).
      add_cross_attention (:obj:`bool`, `optional`, defaults to :obj:`False`):
          Whether cross-attention layers should be added to the model. Note, this option is only relevant for models
          that can be used as decoder models within the `:class:~transformers.EncoderDecoderModel` class, which
          consists of all models in ``AUTO_MODELS_FOR_CAUSAL_LM``.
      tie_encoder_decoder (:obj:`bool`, `optional`, defaults to :obj:`False`):
          Whether all encoder weights should be tied to their equivalent decoder weights. This requires the encoder
          and decoder model to have the exact same parameter names.
      prune_heads (:obj:`Dict[int, List[int]]`, `optional`, defaults to :obj:`{}`):
          Pruned heads of the model. The keys are the selected layer indices and the associated values, the list of
          heads to prune in said layer.
  
          For instance ``{1: [0, 2], 2: [2, 3]}`` will prune heads 0 and 2 on layer 1 and heads 2 and 3 on layer 2.
      chunk_size_feed_forward (:obj:`int`, `optional`, defaults to :obj:`0`):
          The chunk size of all feed forward layers in the residual attention blocks. A chunk size of :obj:`0` means
          that the feed forward layer is not chunked. A chunk size of n means that the feed forward layer processes
          :obj:`n` < sequence_length embeddings at a time. For more information on feed forward chunking, see `How
          does Feed Forward Chunking work? <../glossary.html#feed-forward-chunking>`__ .
  
  Parameters for sequence generation
  
      - **max_length** (:obj:`int`, `optional`, defaults to 20) -- Maximum length that will be used by default in the
        :obj:`generate` method of the model.
      - **min_length** (:obj:`int`, `optional`, defaults to 10) -- Minimum length that will be used by default in the
        :obj:`generate` method of the model.
      - **do_sample** (:obj:`bool`, `optional`, defaults to :obj:`False`) -- Flag that will be used by default in the
        :obj:`generate` method of the model. Whether or not to use sampling ; use greedy decoding otherwise.
      - **early_stopping** (:obj:`bool`, `optional`, defaults to :obj:`False`) -- Flag that will be used by default
        in the :obj:`generate` method of the model. Whether to stop the beam search when at least ``num_beams``
        sentences are finished per batch or not.
      - **num_beams** (:obj:`int`, `optional`, defaults to 1) -- Number of beams for beam search that will be used by
        default in the :obj:`generate` method of the model. 1 means no beam search.
      - **num_beam_groups** (:obj:`int`, `optional`, defaults to 1) -- Number of groups to divide :obj:`num_beams`
        into in order to ensure diversity among different groups of beams that will be used by default in the
        :obj:`generate` method of the model. 1 means no group beam search.
      - **diversity_penalty** (:obj:`float`, `optional`, defaults to 0.0) -- Value to control diversity for group
        beam search. that will be used by default in the :obj:`generate` method of the model. 0 means no diversity
        penalty. The higher the penalty, the more diverse are the outputs.
      - **temperature** (:obj:`float`, `optional`, defaults to 1) -- The value used to module the next token
        probabilities that will be used by default in the :obj:`generate` method of the model. Must be strictly
        positive.
      - **top_k** (:obj:`int`, `optional`, defaults to 50) -- Number of highest probability vocabulary tokens to keep
        for top-k-filtering that will be used by default in the :obj:`generate` method of the model.
      - **top_p** (:obj:`float`, `optional`, defaults to 1) -- Value that will be used by default in the
        :obj:`generate` method of the model for ``top_p``. If set to float < 1, only the most probable tokens with
        probabilities that add up to ``top_p`` or higher are kept for generation.
      - **repetition_penalty** (:obj:`float`, `optional`, defaults to 1) -- Parameter for repetition penalty that
        will be used by default in the :obj:`generate` method of the model. 1.0 means no penalty.
      - **length_penalty** (:obj:`float`, `optional`, defaults to 1) -- Exponential penalty to the length that will
        be used by default in the :obj:`generate` method of the model.
      - **no_repeat_ngram_size** (:obj:`int`, `optional`, defaults to 0) -- Value that will be used by default in the
        :obj:`generate` method of the model for ``no_repeat_ngram_size``. If set to int > 0, all ngrams of that size
        can only occur once.
      - **encoder_no_repeat_ngram_size** (:obj:`int`, `optional`, defaults to 0) -- Value that will be used by
        default in the :obj:`generate` method of the model for ``encoder_no_repeat_ngram_size``. If set to int > 0,
        all ngrams of that size that occur in the ``encoder_input_ids`` cannot occur in the ``decoder_input_ids``.
      - **bad_words_ids** (:obj:`List[int]`, `optional`) -- List of token ids that are not allowed to be generated
        that will be used by default in the :obj:`generate` method of the model. In order to get the tokens of the
        words that should not appear in the generated text, use :obj:`tokenizer.encode(bad_word,
        add_prefix_space=True)`.
      - **num_return_sequences** (:obj:`int`, `optional`, defaults to 1) -- Number of independently computed returned
        sequences for each element in the batch that will be used by default in the :obj:`generate` method of the
        model.
      - **output_scores** (:obj:`bool`, `optional`, defaults to :obj:`False`) -- Whether the model should return the
        logits when used for generation
      - **return_dict_in_generate** (:obj:`bool`, `optional`, defaults to :obj:`False`) -- Whether the model should
        return a :class:`~transformers.file_utils.ModelOutput` instead of a :obj:`torch.LongTensor`
      - **forced_bos_token_id** (:obj:`int`, `optional`) -- The id of the token to force as the first generated token
        after the :obj:`decoder_start_token_id`. Useful for multilingual models like :doc:`mBART
        <../model_doc/mbart>` where the first generated token needs to be the target language token.
      - **forced_eos_token_id** (:obj:`int`, `optional`) -- The id of the token to force as the last generated token
        when :obj:`max_length` is reached.
      - **remove_invalid_values** (:obj:`bool`, `optional`) -- Whether to remove possible `nan` and `inf` outputs of
        the model to prevent the generation method to crash. Note that using ``remove_invalid_values`` can slow down
        generation.
  
  
  Parameters for fine-tuning tasks
  
      - **architectures** (:obj:`List[str]`, `optional`) -- Model architectures that can be used with the model
        pretrained weights.
      - **finetuning_task** (:obj:`str`, `optional`) -- Name of the task used to fine-tune the model. This can be
        used when converting from an original (TensorFlow or PyTorch) checkpoint.
      - **id2label** (:obj:`Dict[int, str]`, `optional`) -- A map from index (for instance prediction index, or
        target index) to label.
      - **label2id** (:obj:`Dict[str, int]`, `optional`) -- A map from label to index for the model.
      - **num_labels** (:obj:`int`, `optional`) -- Number of labels to use in the last layer added to the model,
        typically for a classification task.
      - **task_specific_params** (:obj:`Dict[str, Any]`, `optional`) -- Additional keyword arguments to store for the
        current task.
      - **problem_type** (:obj:`str`, `optional`) -- Problem type for :obj:`XxxForSequenceClassification` models. Can
        be one of (:obj:`"regression"`, :obj:`"single_label_classification"`, :obj:`"multi_label_classification"`).
        Please note that this parameter is only available in the following models: `AlbertForSequenceClassification`,
        `BertForSequenceClassification`, `BigBirdForSequenceClassification`, `ConvBertForSequenceClassification`,
        `DistilBertForSequenceClassification`, `ElectraForSequenceClassification`, `FunnelForSequenceClassification`,
        `LongformerForSequenceClassification`, `MobileBertForSequenceClassification`,
        `ReformerForSequenceClassification`, `RobertaForSequenceClassification`,
        `SqueezeBertForSequenceClassification`, `XLMForSequenceClassification` and `XLNetForSequenceClassification`.
  
  Parameters linked to the tokenizer
  
      - **tokenizer_class** (:obj:`str`, `optional`) -- The name of the associated tokenizer class to use (if none is
        set, will use the tokenizer associated to the model by default).
      - **prefix** (:obj:`str`, `optional`) -- A specific prompt that should be added at the beginning of each text
        before calling the model.
      - **bos_token_id** (:obj:`int`, `optional`)) -- The id of the `beginning-of-stream` token.
      - **pad_token_id** (:obj:`int`, `optional`)) -- The id of the `padding` token.
      - **eos_token_id** (:obj:`int`, `optional`)) -- The id of the `end-of-stream` token.
      - **decoder_start_token_id** (:obj:`int`, `optional`)) -- If an encoder-decoder model starts decoding with a
        different token than `bos`, the id of that token.
      - **sep_token_id** (:obj:`int`, `optional`)) -- The id of the `separation` token.
  
  PyTorch specific parameters
  
      - **torchscript** (:obj:`bool`, `optional`, defaults to :obj:`False`) -- Whether or not the model should be
        used with Torchscript.
      - **tie_word_embeddings** (:obj:`bool`, `optional`, defaults to :obj:`True`) -- Whether the model's input and
        output word embeddings should be tied. Note that this is only relevant if the model has a output word
        embedding layer.
      - **torch_dtype** (:obj:`str`, `optional`) -- The :obj:`dtype` of the weights. This attribute can be used to
        initialize the model to a non-default ``dtype`` (which is normally ``float32``) and thus allow for optimal
        storage allocation. For example, if the saved model is ``float16``, ideally we want to load it back using the
        minimal amount of memory needed to load ``float16`` weights. Since the config object is stored in plain text,
        this attribute contains just the floating type string without the ``torch.`` prefix. For example, for
        ``torch.float16`` ``torch_dtype`` is the ``"float16"`` string.
  
        This attribute is currently not being used during model loading time, but this may change in the future
        versions. But we can already start preparing for the future by saving the dtype with save_pretrained.
  
  TensorFlow specific parameters
  
      - **use_bfloat16** (:obj:`bool`, `optional`, defaults to :obj:`False`) -- Whether or not the model should use
        BFloat16 scalars (only used by some TensorFlow models).
docstr: Save a configuration object to the directory ``save_directory``, so that it can be re-loaded using the
  :func:`~transformers.PretrainedConfig.from_pretrained` class method.
  
  Args:
      save_directory (:obj:`str` or :obj:`os.PathLike`):
          Directory where the configuration JSON file will be saved (will be created if it does not exist).
      push_to_hub (:obj:`bool`, `optional`, defaults to :obj:`False`):
          Whether or not to push your model to the Hugging Face model hub after saving it.
  
          .. warning::
  
              Using :obj:`push_to_hub=True` will synchronize the repository you are pushing to with
              :obj:`save_directory`, which requires :obj:`save_directory` to be a local clone of the repo you are
              pushing to if it's an existing folder. Pass along :obj:`temp_dir=True` to use a temporary directory
              instead.
  
      kwargs:
          Additional key word arguments passed along to the
          :meth:`~transformers.file_utils.PushToHubMixin.push_to_hub` method.
docstr_tok: ["Save","a","configuration","object","to","the","directory","``","save_directory","``",",","so","that","it","can","be","re-loaded","using","the",":","func",":","`","~transformers.PretrainedConfig.from_pretrained","`","class","method",".","Args",":","save_directory","(",":","obj",":","`","str","`","or",":","obj",":","`","os.PathLike","`",")",":","Directory","where","the","configuration","JSON","file","will","be","saved","(","will","be","created","if","it","does","not","exist",")",".","push_to_hub","(",":","obj",":","`","bool","`",",","`","optional","`",",","defaults","to",":","obj",":","`","False","`",")",":","Whether","or","not","to","push","your","model","to","the","Hugging","Face","model","hub","after","saving","it",".","..","warning",":",":","Using",":","obj",":","`","push_to_hub=True","`","will","synchronize","the","repository","you","are","pushing","to","with",":","obj",":","`","save_directory","`",",","which","requires",":","obj",":","`","save_directory","`","to","be","a","local","clone","of","the","repo","you","are","pushing","to","if","it","'s","an","existing","folder",".","Pass","along",":","obj",":","`","temp_dir=True","`","to","use","a","temporary","directory","instead",".","kwargs",":","Additional","key","word","arguments","passed","along","to","the",":","meth",":","`","~transformers.file_utils.PushToHubMixin.push_to_hub","`","method","."]
code: def save_pretrained(
      self, save_directory: Union[str, os.PathLike], **kwargs
  ):
      """
      Save a configuration object to the directory ``save_directory``, so that it can be re-loaded using the
      :func:`~transformers.PretrainedConfig.from_pretrained` class method.
  
      Args:
          save_directory (:obj:`str` or :obj:`os.PathLike`):
              Directory where the configuration JSON file will be saved (will be created if it does not exist).
          push_to_hub (:obj:`bool`, `optional`, defaults to :obj:`False`):
              Whether or not to push your model to the Hugging Face model hub after saving it.
  
              .. warning::
  
                  Using :obj:`push_to_hub=True` will synchronize the repository you are pushing to with
                  :obj:`save_directory`, which requires :obj:`save_directory` to be a local clone of the repo you are
                  pushing to if it's an existing folder. Pass along :obj:`temp_dir=True` to use a temporary directory
                  instead.
  
          kwargs:
              Additional key word arguments passed along to the
              :meth:`~transformers.file_utils.PushToHubMixin.push_to_hub` method.
      """
      if os.path.isfile(save_directory):
          raise AssertionError(
              f"Provided path ({save_directory}) should be a directory, not a file"
          )
  
      os.makedirs(save_directory, exist_ok=True)
      # If we save using the predefined names, we can load using `from_pretrained`
      output_config_file = os.path.join(save_directory, CONFIG_NAME)
  
      self.to_json_file(output_config_file, use_diff=True)
      logger.info(f"Configuration saved in {output_config_file}")
  
imports: import copy
  import json
  import os
  from typing import Any, Dict, Tuple, Union
  from .None import __version__
  from .file_utils import CONFIG_NAME, cached_path, hf_bucket_url, is_offline_mode, is_remote_url
  from fastNLP.envs.imports import _NEED_IMPORT_TORCH
  from fastNLP.core.log import logger
label_desc: Use image node_id 9 for calling the PretrainedConfig obj's underlying member method code with example usage: obj.save_pretrained(save_directory) without return types