configuration_youtu.py 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. # 🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨
  2. # This file was automatically generated from src/transformers/models/youtu/modular_youtu.py.
  3. # Do NOT edit this file manually as any edits will be overwritten by the generation of
  4. # the file from the modular. If any change should be done, please apply the change to the
  5. # modular_youtu.py file directly. One of our CI enforces this.
  6. # 🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨
  7. # Copyright 2026 the Tencent and HuggingFace Inc. team. All rights reserved.
  8. #
  9. # This code is based on EleutherAI's GPT-NeoX library and the GPT-NeoX
  10. # and OPT implementations in this library. It has been modified from its
  11. # original forms to accommodate minor architectural differences compared
  12. # to GPT-NeoX and OPT used by the Meta AI team that trained the model.
  13. #
  14. # Licensed under the Apache License, Version 2.0 (the "License");
  15. # you may not use this file except in compliance with the License.
  16. # You may obtain a copy of the License at
  17. #
  18. # http://www.apache.org/licenses/LICENSE-2.0
  19. #
  20. # Unless required by applicable law or agreed to in writing, software
  21. # distributed under the License is distributed on an "AS IS" BASIS,
  22. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  23. # See the License for the specific language governing permissions and
  24. # limitations under the License.
  25. from huggingface_hub.dataclasses import strict
  26. from ...configuration_utils import PreTrainedConfig
  27. from ...modeling_rope_utils import RopeParameters
  28. from ...utils import auto_docstring
  29. @auto_docstring(checkpoint="tencent/Youtu-LLM-2B")
  30. @strict
  31. class YoutuConfig(PreTrainedConfig):
  32. r"""
  33. rope_interleave (`bool`, *optional*, defaults to `True`):
  34. Whether to interleave the rotary position embeddings.
  35. embedding_initializer_range (`float`, *optional*):
  36. The standard deviation of the truncated_normal_initializer for initializing all embedding matrices.
  37. ```python
  38. >>> from transformers import YoutuModel, YoutuConfig
  39. >>> # Initializing a Youtu-LLM-2B style configuration
  40. >>> configuration = YoutuConfig()
  41. >>> # Accessing the model configuration
  42. >>> configuration = model.config
  43. ```"""
  44. model_type = "youtu"
  45. keys_to_ignore_at_inference = ["past_key_values"]
  46. base_model_tp_plan = {
  47. "layers.*.mlp.gate_proj": "colwise",
  48. "layers.*.mlp.up_proj": "colwise",
  49. "layers.*.mlp.down_proj": "rowwise",
  50. }
  51. base_model_pp_plan = {
  52. "embed_tokens": (["input_ids"], ["inputs_embeds"]),
  53. "layers": (["hidden_states", "attention_mask"], ["hidden_states"]),
  54. "norm": (["hidden_states"], ["hidden_states"]),
  55. }
  56. attribute_map = {}
  57. vocab_size: int = 128256
  58. hidden_size: int = 2048
  59. intermediate_size: int = 6144
  60. num_hidden_layers: int = 32
  61. num_attention_heads: int = 16
  62. num_key_value_heads: int = 16
  63. kv_lora_rank: int = 512
  64. q_lora_rank: int | None = 1536
  65. qk_rope_head_dim: int = 64
  66. v_head_dim: int | None = 128
  67. qk_nope_head_dim: int = 128
  68. hidden_act: str = "silu"
  69. max_position_embeddings: int = 131072
  70. initializer_range: float | None = None
  71. rms_norm_eps: float = 1e-6
  72. use_cache: bool = True
  73. pad_token_id: int | None = None
  74. bos_token_id: int | None = 128000
  75. eos_token_id: int | list[int] | None = 128001
  76. tie_word_embeddings: bool = True
  77. rope_parameters: RopeParameters | dict | None = None
  78. rope_interleave: bool | None = True
  79. attention_bias: bool = False
  80. attention_dropout: float | int | None = 0.0
  81. embedding_initializer_range: float | None = None
  82. def __post_init__(self, **kwargs):
  83. if self.initializer_range is None:
  84. if self.hidden_size != 0:
  85. self.initializer_range = 2.0 / (5.0 * self.hidden_size) ** 0.5
  86. else:
  87. self.initializer_range = 0.02
  88. self.embedding_initializer_range = self.embedding_initializer_range or 2.0 * self.initializer_range
  89. if self.num_key_value_heads is None:
  90. self.num_key_value_heads = self.num_attention_heads
  91. self.qk_head_dim = self.qk_nope_head_dim + self.qk_rope_head_dim
  92. self.head_dim = self.qk_rope_head_dim
  93. super().__post_init__(**kwargs)
  94. __all__ = ["YoutuConfig"]