configuration_minimax.py 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. # 🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨
  2. # This file was automatically generated from src/transformers/models/minimax/modular_minimax.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_minimax.py file directly. One of our CI enforces this.
  6. # 🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨
  7. # Copyright 2025 MiniMaxAI and HuggingFace Inc. teams. All rights reserved.
  8. #
  9. #
  10. # Licensed under the Apache License, Version 2.0 (the "License");
  11. # you may not use this file except in compliance with the License.
  12. # You may obtain a copy of the License at
  13. #
  14. # http://www.apache.org/licenses/LICENSE-2.0
  15. #
  16. # Unless required by applicable law or agreed to in writing, software
  17. # distributed under the License is distributed on an "AS IS" BASIS,
  18. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  19. # See the License for the specific language governing permissions and
  20. # limitations under the License.
  21. from huggingface_hub.dataclasses import strict
  22. from ...configuration_utils import PreTrainedConfig
  23. from ...modeling_rope_utils import RopeParameters
  24. from ...utils import auto_docstring
  25. @auto_docstring(checkpoint="MiniMaxAI/MiniMax-Text-01-hf")
  26. @strict
  27. class MiniMaxConfig(PreTrainedConfig):
  28. r"""
  29. block_size (`int`, *optional*, defaults to 256):
  30. The length of each attention block, determining how queries, keys, and values
  31. are grouped and processed for intra- and inter-block attention.
  32. full_attn_alpha_factor (`float`, *optional*, defaults to 1):
  33. Weight for residual value in residual connection after normal attention.
  34. full_attn_beta_factor (`float`, *optional*, defaults to 1):
  35. Weight for hidden state value in residual connection after normal attention.
  36. linear_attn_alpha_factor (`float`, *optional*, defaults to 1):
  37. Weight for residual value in residual connection after lightning attention.
  38. linear_attn_beta_factor (`float`, *optional*, defaults to 1):
  39. Weight for hidden state value in residual connection after lightning attention.
  40. mlp_alpha_factor (`float`, *optional*, defaults to 1):
  41. Weight for residual value in residual connection after MLP.
  42. mlp_beta_factor (`float`, *optional*, defaults to 1):
  43. Weight for hidden state value in residual connection after MLP.
  44. ```python
  45. >>> from transformers import MiniMaxModel, MiniMaxConfig
  46. >>> # Initializing a MiniMax style configuration
  47. >>> configuration = MiniMaxConfig()
  48. >>> # Initializing a model from the MiniMax style configuration
  49. >>> model = MiniMaxModel(configuration)
  50. >>> # Accessing the model configuration
  51. >>> configuration = model.config
  52. ```"""
  53. model_type = "minimax"
  54. keys_to_ignore_at_inference = ["past_key_values"]
  55. default_theta = 1000000.0
  56. base_model_tp_plan = {
  57. "layers.*.self_attn.q_proj": "colwise",
  58. "layers.*.self_attn.k_proj": "colwise",
  59. "layers.*.self_attn.v_proj": "colwise",
  60. "layers.*.self_attn.o_proj": "rowwise",
  61. "layers.*.mlp.experts.gate_up_proj": "packed_colwise",
  62. "layers.*.mlp.experts.down_proj": "rowwise",
  63. "layers.*.mlp.experts": "moe_tp_experts",
  64. }
  65. base_model_pp_plan = {
  66. "embed_tokens": (["input_ids"], ["inputs_embeds"]),
  67. "layers": (["hidden_states", "attention_mask"], ["hidden_states"]),
  68. "norm": (["hidden_states"], ["hidden_states"]),
  69. }
  70. attribute_map = {"num_experts": "num_local_experts"}
  71. vocab_size: int = 32000
  72. hidden_size: int = 4096
  73. intermediate_size: int = 14336
  74. num_hidden_layers: int = 32
  75. num_attention_heads: int = 32
  76. num_key_value_heads: int = 8
  77. head_dim: int | None = None
  78. hidden_act: str = "silu"
  79. max_position_embeddings: int = 4096 * 32
  80. initializer_range: float = 0.02
  81. rms_norm_eps: float = 1e-5
  82. use_cache: bool = True
  83. pad_token_id: int | None = None
  84. bos_token_id: int | None = 1
  85. eos_token_id: int | list[int] | None = 2
  86. tie_word_embeddings: bool = False
  87. sliding_window: int | None = None
  88. attention_dropout: float | int = 0.0
  89. num_experts_per_tok: int = 2
  90. num_local_experts: int = 8
  91. output_router_logits: bool = False
  92. router_aux_loss_coef: float = 0.001
  93. router_jitter_noise: float = 0.0
  94. rope_parameters: RopeParameters | dict | None = None
  95. layer_types: list[str] | None = None
  96. block_size: int = 256
  97. full_attn_alpha_factor: int | float = 1
  98. full_attn_beta_factor: int | float = 1
  99. linear_attn_alpha_factor: int | float = 1
  100. linear_attn_beta_factor: int | float = 1
  101. mlp_alpha_factor: int | float = 1
  102. mlp_beta_factor: int | float = 1
  103. def __post_init__(self, **kwargs):
  104. if self.num_key_value_heads is None:
  105. self.num_key_value_heads = self.num_attention_heads
  106. if self.layer_types is None:
  107. self.layer_types = [
  108. "full_attention" if bool((i + 1) % 2) else "linear_attention" for i in range(self.num_hidden_layers)
  109. ]
  110. super().__post_init__(**kwargs)
  111. __all__ = ["MiniMaxConfig"]