configuration_cpmant.py 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. # coding=utf-8
  2. # Copyright 2022 The OpenBMB Team and 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. """CPMAnt model configuration"""
  16. from ...configuration_utils import PretrainedConfig
  17. from ...utils import logging
  18. logger = logging.get_logger(__name__)
  19. class CpmAntConfig(PretrainedConfig):
  20. r"""
  21. This is the configuration class to store the configuration of a [`CpmAntModel`]. It is used to instantiate an
  22. CPMAnt model according to the specified arguments, defining the model architecture. Instantiating a configuration
  23. with the defaults will yield a similar configuration to that of the CPMAnt
  24. [openbmb/cpm-ant-10b](https://huggingface.co/openbmb/cpm-ant-10b) 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 30720):
  29. Vocabulary size of the CPMAnt model. Defines the number of different tokens that can be represented by the
  30. `input` passed when calling [`CpmAntModel`].
  31. hidden_size (`int`, *optional*, defaults to 4096):
  32. Dimension of the encoder layers.
  33. num_attention_heads (`int`, *optional*, defaults to 32):
  34. Number of attention heads in the Transformer encoder.
  35. dim_head (`int`, *optional*, defaults to 128):
  36. Dimension of attention heads for each attention layer in the Transformer encoder.
  37. dim_ff (`int`, *optional*, defaults to 10240):
  38. Dimension of the "intermediate" (i.e., feed-forward) layer in the Transformer encoder.
  39. num_hidden_layers (`int`, *optional*, defaults to 48):
  40. Number of layers of the Transformer encoder.
  41. dropout_p (`float`, *optional*, defaults to 0.0):
  42. The dropout probability for all fully connected layers in the embeddings, encoder.
  43. position_bias_num_buckets (`int`, *optional*, defaults to 512):
  44. The number of position_bias buckets.
  45. position_bias_max_distance (`int`, *optional*, defaults to 2048):
  46. The maximum sequence length that this model might ever be used with. Typically set this to something large
  47. just in case (e.g., 512 or 1024 or 2048).
  48. eps (`float`, *optional*, defaults to 1e-06):
  49. The epsilon used by the layer normalization layers.
  50. init_std (`float`, *optional*, defaults to 1.0):
  51. Initialize parameters with std = init_std.
  52. prompt_types (`int`, *optional*, defaults to 32):
  53. The type of prompt.
  54. prompt_length (`int`, *optional*, defaults to 32):
  55. The length of prompt.
  56. segment_types (`int`, *optional*, defaults to 32):
  57. The type of segment.
  58. use_cache (`bool`, *optional*, defaults to `True`):
  59. Whether to use cache.
  60. Example:
  61. ```python
  62. >>> from transformers import CpmAntModel, CpmAntConfig
  63. >>> # Initializing a CPMAnt cpm-ant-10b style configuration
  64. >>> configuration = CpmAntConfig()
  65. >>> # Initializing a model from the cpm-ant-10b style configuration
  66. >>> model = CpmAntModel(configuration)
  67. >>> # Accessing the model configuration
  68. >>> configuration = model.config
  69. ```"""
  70. model_type = "cpmant"
  71. def __init__(
  72. self,
  73. vocab_size: int = 30720,
  74. hidden_size: int = 4096,
  75. num_attention_heads: int = 32,
  76. dim_head: int = 128,
  77. dim_ff: int = 10240,
  78. num_hidden_layers: int = 48,
  79. dropout_p: int = 0.0,
  80. position_bias_num_buckets: int = 512,
  81. position_bias_max_distance: int = 2048,
  82. eps: int = 1e-6,
  83. init_std: float = 1.0,
  84. prompt_types: int = 32,
  85. prompt_length: int = 32,
  86. segment_types: int = 32,
  87. use_cache: bool = True,
  88. **kwargs,
  89. ):
  90. super().__init__(**kwargs)
  91. self.prompt_types = prompt_types
  92. self.prompt_length = prompt_length
  93. self.segment_types = segment_types
  94. self.hidden_size = hidden_size
  95. self.num_attention_heads = num_attention_heads
  96. self.dim_head = dim_head
  97. self.dim_ff = dim_ff
  98. self.num_hidden_layers = num_hidden_layers
  99. self.position_bias_num_buckets = position_bias_num_buckets
  100. self.position_bias_max_distance = position_bias_max_distance
  101. self.dropout_p = dropout_p
  102. self.eps = eps
  103. self.use_cache = use_cache
  104. self.vocab_size = vocab_size
  105. self.init_std = init_std
  106. __all__ = ["CpmAntConfig"]