configuration_exaone4.py 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. # 🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨
  2. # This file was automatically generated from src/transformers/models/exaone4/modular_exaone4.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_exaone4.py file directly. One of our CI enforces this.
  6. # 🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨
  7. # Copyright 2025 The LG AI Research and HuggingFace Inc. team. 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="LGAI-EXAONE/EXAONE-4.0-32B")
  26. @strict
  27. class Exaone4Config(PreTrainedConfig):
  28. r"""
  29. sliding_window_pattern (`str`, *optional*):
  30. The pattern to use for sliding window attention. Can be one of:
  31. - `None`: No sliding window attention is used
  32. - `int`: Every `sliding_window` layers, use global attention, else use local attention.
  33. - `str`: A sequence of "L" (local attention) and "G" (global attention) characters that defines the
  34. attention pattern. The pattern starts from layer 0 and repeats every `sliding_window` layers. The
  35. final layer always uses global attention regardless of the pattern.
  36. For instance, sliding_window_pattern="LLLG" same as sliding_window=4, which means:
  37. - Layer 0, 1, 2: local attention,
  38. - Layer 3: global attention,
  39. ...(repeated)
  40. Example:
  41. ```python
  42. >>> from transformers import Exaone4Model, Exaone4Config
  43. >>> # Initializing a EXAONE configuration
  44. >>> configuration = Exaone4Config()
  45. >>> # Initializing a model from configuration
  46. >>> model = Exaone4Model(configuration)
  47. >>> # Accessing the model configuration
  48. >>> configuration = model.config
  49. ```"""
  50. model_type = "exaone4"
  51. keys_to_ignore_at_inference = ["past_key_values"]
  52. # Default tensor parallel plan for base model `LlamaModel`
  53. base_model_tp_plan = {
  54. "layers.*.self_attn.q_proj": "colwise",
  55. "layers.*.self_attn.k_proj": "colwise",
  56. "layers.*.self_attn.v_proj": "colwise",
  57. "layers.*.self_attn.q_norm": "replicated_with_grad_allreduce",
  58. "layers.*.self_attn.k_norm": "replicated_with_grad_allreduce",
  59. "layers.*.self_attn.o_proj": "rowwise",
  60. "layers.*.mlp.gate_proj": "colwise",
  61. "layers.*.mlp.up_proj": "colwise",
  62. "layers.*.mlp.down_proj": "rowwise",
  63. }
  64. base_model_pp_plan = {
  65. "embed_tokens": (["input_ids"], ["inputs_embeds"]),
  66. "layers": (["hidden_states", "attention_mask"], ["hidden_states"]),
  67. "norm": (["hidden_states"], ["hidden_states"]),
  68. }
  69. vocab_size: int = 102400
  70. hidden_size: int = 4096
  71. intermediate_size: int = 16384
  72. num_hidden_layers: int = 32
  73. num_attention_heads: int = 32
  74. num_key_value_heads: int = 32
  75. hidden_act: str = "silu"
  76. max_position_embeddings: int = 2048
  77. initializer_range: float = 0.02
  78. rms_norm_eps: float = 1e-5
  79. use_cache: bool = True
  80. bos_token_id: int | None = 0
  81. eos_token_id: int | list[int] | None = 2
  82. pad_token_id: int | None = None
  83. tie_word_embeddings: bool = False
  84. rope_parameters: RopeParameters | dict | None = None
  85. attention_dropout: float | int = 0.0
  86. sliding_window: int | None = 4096
  87. sliding_window_pattern: str | int | None = 4
  88. layer_types: list[str] | None = None
  89. def __post_init__(self, **kwargs):
  90. if self.sliding_window is None:
  91. self.sliding_window_pattern = 0
  92. if self.layer_types is None:
  93. self.layer_types = [
  94. "sliding_attention"
  95. if ((i + 1) % (self.sliding_window_pattern) != 0 and i < self.num_hidden_layers)
  96. else "full_attention"
  97. for i in range(self.num_hidden_layers)
  98. ]
  99. super().__post_init__(**kwargs)
  100. __all__ = ["Exaone4Config"]