configuration_mra.py 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. # coding=utf-8
  2. # Copyright 2023 The HuggingFace Inc. team. All rights reserved.
  3. #
  4. # Licensed under the Apache License, Version 2.0 (the "License");
  5. # you may not use this file except in compliance with the License.
  6. # You may obtain a copy of the License at
  7. #
  8. # http://www.apache.org/licenses/LICENSE-2.0
  9. #
  10. # Unless required by applicable law or agreed to in writing, software
  11. # distributed under the License is distributed on an "AS IS" BASIS,
  12. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. # See the License for the specific language governing permissions and
  14. # limitations under the License.
  15. """MRA model configuration"""
  16. from ...configuration_utils import PretrainedConfig
  17. from ...utils import logging
  18. logger = logging.get_logger(__name__)
  19. class MraConfig(PretrainedConfig):
  20. r"""
  21. This is the configuration class to store the configuration of a [`MraModel`]. It is used to instantiate an MRA
  22. model according to the specified arguments, defining the model architecture. Instantiating a configuration with the
  23. defaults will yield a similar configuration to that of the Mra
  24. [uw-madison/mra-base-512-4](https://huggingface.co/uw-madison/mra-base-512-4) architecture.
  25. Configuration objects inherit from [`PretrainedConfig`] and can be used to control the model outputs. Read the
  26. documentation from [`PretrainedConfig`] for more information.
  27. Args:
  28. vocab_size (`int`, *optional*, defaults to 50265):
  29. Vocabulary size of the Mra model. Defines the number of different tokens that can be represented by the
  30. `inputs_ids` passed when calling [`MraModel`].
  31. hidden_size (`int`, *optional*, defaults to 768):
  32. Dimension of the encoder layers and the pooler layer.
  33. num_hidden_layers (`int`, *optional*, defaults to 12):
  34. Number of hidden layers in the Transformer encoder.
  35. num_attention_heads (`int`, *optional*, defaults to 12):
  36. Number of attention heads for each attention layer in the Transformer encoder.
  37. intermediate_size (`int`, *optional*, defaults to 3072):
  38. Dimension of the "intermediate" (i.e., feed-forward) layer in the Transformer encoder.
  39. hidden_act (`str` or `function`, *optional*, defaults to `"gelu"`):
  40. The non-linear activation function (function or string) in the encoder and pooler. If string, `"gelu"`,
  41. `"relu"`, `"selu"` and `"gelu_new"` are supported.
  42. hidden_dropout_prob (`float`, *optional*, defaults to 0.1):
  43. The dropout probability for all fully connected layers in the embeddings, encoder, and pooler.
  44. attention_probs_dropout_prob (`float`, *optional*, defaults to 0.1):
  45. The dropout ratio for the attention probabilities.
  46. max_position_embeddings (`int`, *optional*, defaults to 512):
  47. The maximum sequence length that this model might ever be used with. Typically set this to something large
  48. just in case (e.g., 512 or 1024 or 2048).
  49. type_vocab_size (`int`, *optional*, defaults to 1):
  50. The vocabulary size of the `token_type_ids` passed when calling [`MraModel`].
  51. initializer_range (`float`, *optional*, defaults to 0.02):
  52. The standard deviation of the truncated_normal_initializer for initializing all weight matrices.
  53. layer_norm_eps (`float`, *optional*, defaults to 1e-5):
  54. The epsilon used by the layer normalization layers.
  55. position_embedding_type (`str`, *optional*, defaults to `"absolute"`):
  56. Type of position embedding. Choose one of `"absolute"`, `"relative_key"`, `"relative_key_query"`.
  57. block_per_row (`int`, *optional*, defaults to 4):
  58. Used to set the budget for the high resolution scale.
  59. approx_mode (`str`, *optional*, defaults to `"full"`):
  60. Controls whether both low and high resolution approximations are used. Set to `"full"` for both low and
  61. high resolution and `"sparse"` for only low resolution.
  62. initial_prior_first_n_blocks (`int`, *optional*, defaults to 0):
  63. The initial number of blocks for which high resolution is used.
  64. initial_prior_diagonal_n_blocks (`int`, *optional*, defaults to 0):
  65. The number of diagonal blocks for which high resolution is used.
  66. Example:
  67. ```python
  68. >>> from transformers import MraConfig, MraModel
  69. >>> # Initializing a Mra uw-madison/mra-base-512-4 style configuration
  70. >>> configuration = MraConfig()
  71. >>> # Initializing a model (with random weights) from the uw-madison/mra-base-512-4 style configuration
  72. >>> model = MraModel(configuration)
  73. >>> # Accessing the model configuration
  74. >>> configuration = model.config
  75. ```"""
  76. model_type = "mra"
  77. def __init__(
  78. self,
  79. vocab_size=50265,
  80. hidden_size=768,
  81. num_hidden_layers=12,
  82. num_attention_heads=12,
  83. intermediate_size=3072,
  84. hidden_act="gelu",
  85. hidden_dropout_prob=0.1,
  86. attention_probs_dropout_prob=0.1,
  87. max_position_embeddings=512,
  88. type_vocab_size=1,
  89. initializer_range=0.02,
  90. layer_norm_eps=1e-5,
  91. position_embedding_type="absolute",
  92. block_per_row=4,
  93. approx_mode="full",
  94. initial_prior_first_n_blocks=0,
  95. initial_prior_diagonal_n_blocks=0,
  96. pad_token_id=1,
  97. bos_token_id=0,
  98. eos_token_id=2,
  99. **kwargs,
  100. ):
  101. super().__init__(pad_token_id=pad_token_id, bos_token_id=bos_token_id, eos_token_id=eos_token_id, **kwargs)
  102. self.vocab_size = vocab_size
  103. self.max_position_embeddings = max_position_embeddings
  104. self.hidden_size = hidden_size
  105. self.num_hidden_layers = num_hidden_layers
  106. self.num_attention_heads = num_attention_heads
  107. self.intermediate_size = intermediate_size
  108. self.hidden_act = hidden_act
  109. self.hidden_dropout_prob = hidden_dropout_prob
  110. self.attention_probs_dropout_prob = attention_probs_dropout_prob
  111. self.initializer_range = initializer_range
  112. self.type_vocab_size = type_vocab_size
  113. self.layer_norm_eps = layer_norm_eps
  114. self.position_embedding_type = position_embedding_type
  115. self.block_per_row = block_per_row
  116. self.approx_mode = approx_mode
  117. self.initial_prior_first_n_blocks = initial_prior_first_n_blocks
  118. self.initial_prior_diagonal_n_blocks = initial_prior_diagonal_n_blocks
  119. __all__ = ["MraConfig"]