configuration_doge.py 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. # 🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨
  2. # This file was automatically generated from src/transformers/models/doge/modular_doge.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_doge.py file directly. One of our CI enforces this.
  6. # 🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨
  7. # Copyright 2025 Jingze Shi and the HuggingFace Inc. team. All rights reserved.
  8. #
  9. # The Doge family of small language models is trained by SmallDoge Team.
  10. #
  11. # Licensed under the Apache License, Version 2.0 (the "License");
  12. # you may not use this file except in compliance with the License.
  13. # You may obtain a copy of the License at
  14. #
  15. # http://www.apache.org/licenses/LICENSE-2.0
  16. #
  17. # Unless required by applicable law or agreed to in writing, software
  18. # distributed under the License is distributed on an "AS IS" BASIS,
  19. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  20. # See the License for the specific language governing permissions and
  21. # limitations under the License.
  22. from huggingface_hub.dataclasses import strict
  23. from ...configuration_utils import PreTrainedConfig
  24. from ...modeling_rope_utils import RopeParameters
  25. from ...utils import auto_docstring
  26. @auto_docstring(checkpoint="SmallDoge/Doge-320M")
  27. @strict
  28. class DogeConfig(PreTrainedConfig):
  29. r"""
  30. keep_window_size (`int`, *optional*, defaults to 2048):
  31. The window size of tokens that are not dynamically masked, and dynamic masking is only performed when the sequence length exceeds this value.
  32. is_moe (`bool`, *optional*, defaults to `False`):
  33. Whether to use the Cross Domain Mixture of Experts, if `True`, the MoE will inherit the MLP to initialize.
  34. ```python
  35. >>> from transformers import DogeConfig, DogeModel
  36. >>> # Initializing a Doge-320M style configuration
  37. >>> configuration = DogeConfig()
  38. >>> # Initializing a model from the Doge-320M style configuration
  39. >>> model = DogeModel(configuration)
  40. >>> # Accessing the model configuration
  41. >>> configuration = model.config
  42. ```"""
  43. model_type = "doge"
  44. keys_to_ignore_at_inference = ["past_key_values"]
  45. # Default tensor parallel plan for base model `DogeModel`
  46. base_model_tp_plan = {
  47. "layers.*.self_attn.q_proj": "colwise",
  48. "layers.*.self_attn.k_proj": "colwise",
  49. "layers.*.self_attn.v_proj": "colwise",
  50. "layers.*.self_attn.dt_proj": "rowwise",
  51. "layers.*.self_attn.o_proj": "rowwise",
  52. "layers.*.mlp.gate_proj": "colwise",
  53. "layers.*.mlp.up_proj": "colwise",
  54. "layers.*.mlp.down_proj": "rowwise",
  55. "layers.*.mlp.router_gate": "colwise_gather_output",
  56. "layers.*.mlp.down_embed": "rowwise_split_input",
  57. "layers.*.mlp.up_embed": "rowwise_split_input",
  58. }
  59. base_model_pp_plan = {
  60. "embed_tokens": (["input_ids"], ["inputs_embeds"]),
  61. "layers": (["hidden_states", "attention_mask"], ["hidden_states"]),
  62. "norm": (["hidden_states"], ["hidden_states"]),
  63. }
  64. vocab_size: int = 32768
  65. hidden_size: int = 1024
  66. intermediate_size: int = 2048
  67. num_hidden_layers: int = 32
  68. hidden_dropout: float | int = 0.0
  69. hidden_act: str = "silu"
  70. initializer_range: float = 0.02
  71. rms_norm_eps: float = 1e-06
  72. use_cache: bool = True
  73. tie_word_embeddings: bool = False
  74. max_position_embeddings: int = 2048
  75. rope_parameters: RopeParameters | dict | None = None
  76. num_attention_heads: int = 8
  77. num_key_value_heads: int | None = None
  78. attention_bias: bool = False
  79. attention_dropout: float | None = 0.0
  80. mlp_bias: bool = False
  81. sliding_window: int | None = None
  82. keep_window_size: int = 2048
  83. is_moe: bool = False
  84. num_experts: int = 16384
  85. num_experts_per_tok: int = 64
  86. norm_topk_prob: bool = False
  87. output_router_logits: bool = False
  88. router_aux_loss_coef: float = 0.001
  89. pad_token_id: int | None = None
  90. bos_token_id: int | None = None
  91. eos_token_id: int | list[int] | None = None
  92. def __post_init__(self, **kwargs):
  93. # for backward compatibility
  94. if self.num_key_value_heads is None:
  95. self.num_key_value_heads = self.num_attention_heads
  96. super().__post_init__(**kwargs)
  97. __all__ = ["DogeConfig"]