configuration_apertus.py 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. # 🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨
  2. # This file was automatically generated from src/transformers/models/apertus/modular_apertus.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_apertus.py file directly. One of our CI enforces this.
  6. # 🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨
  7. # Copyright 2025 the HuggingFace Inc. team and the Swiss AI Initiative. 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="swiss-ai/Apertus-8B-Instruct-2509")
  26. @strict
  27. class ApertusConfig(PreTrainedConfig):
  28. r"""
  29. ```python
  30. >>> from transformers import ApertusModel, ApertusConfig
  31. >>> # Initializing a Apertus-8B style configuration
  32. >>> configuration = ApertusConfig()
  33. >>> # Initializing a model from the Apertus-8B style configuration
  34. >>> model = ApertusModel(configuration)
  35. >>> # Accessing the model configuration
  36. >>> configuration = model.config
  37. ```"""
  38. model_type = "apertus"
  39. keys_to_ignore_at_inference = ["past_key_values"]
  40. default_theta = 12000000.0
  41. base_model_tp_plan = {
  42. "layers.*.self_attn.q_proj": "colwise",
  43. "layers.*.self_attn.k_proj": "colwise",
  44. "layers.*.self_attn.v_proj": "colwise",
  45. "layers.*.self_attn.q_norm": "replicated_with_grad_allreduce",
  46. "layers.*.self_attn.k_norm": "replicated_with_grad_allreduce",
  47. "layers.*.self_attn.o_proj": "rowwise",
  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. vocab_size: int = 131072
  57. hidden_size: int = 4096
  58. intermediate_size: int = 14336
  59. num_hidden_layers: int = 32
  60. num_attention_heads: int = 32
  61. num_key_value_heads: int | None = None
  62. hidden_act: str = "xielu"
  63. max_position_embeddings: int = 65536
  64. initializer_range: float = 0.02
  65. rms_norm_eps: float = 1e-5
  66. use_cache: bool = True
  67. pad_token_id: int | None = 3
  68. bos_token_id: int | None = 1
  69. eos_token_id: int | list[int] | None = 2
  70. tie_word_embeddings: bool = False
  71. rope_parameters: RopeParameters | dict | None = None
  72. attention_bias: bool = False
  73. attention_dropout: float | int = 0.0
  74. def __post_init__(self, **kwargs):
  75. if self.num_key_value_heads is None:
  76. self.num_key_value_heads = self.num_attention_heads
  77. if self.rope_parameters is None:
  78. self.rope_parameters = {
  79. "rope_type": "llama3",
  80. "rope_theta": 12000000.0,
  81. "factor": 8.0,
  82. "original_max_position_embeddings": 8192,
  83. "low_freq_factor": 1.0,
  84. "high_freq_factor": 4.0,
  85. }
  86. super().__post_init__(**kwargs)
  87. __all__ = ["ApertusConfig"]