configuration_jais2.py 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. # 🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨
  2. # This file was automatically generated from src/transformers/models/jais2/modular_jais2.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_jais2.py file directly. One of our CI enforces this.
  6. # 🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨
  7. # Copyright 2025 the HuggingFace Team. All rights reserved.
  8. #
  9. # Licensed under the Apache License, Version 2.0 (the "License");
  10. # you may not use this file except in compliance with the License.
  11. # You may obtain a copy of the License at
  12. #
  13. # http://www.apache.org/licenses/LICENSE-2.0
  14. #
  15. # Unless required by applicable law or agreed to in writing, software
  16. # distributed under the License is distributed on an "AS IS" BASIS,
  17. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  18. # See the License for the specific language governing permissions and
  19. # limitations under the License.
  20. from huggingface_hub.dataclasses import strict
  21. from ...configuration_utils import PreTrainedConfig
  22. from ...modeling_rope_utils import RopeParameters
  23. from ...utils import auto_docstring
  24. from ...utils.type_validators import interval
  25. @auto_docstring(checkpoint="inceptionai/Jais-2-8B-Chat")
  26. @strict
  27. class Jais2Config(PreTrainedConfig):
  28. r"""
  29. ```python
  30. >>> from transformers import Jais2Model, Jais2Config
  31. >>> # Initializing a Jais2 jais2-7b style configuration
  32. >>> configuration = Jais2Config()
  33. >>> # Initializing a model from the jais2-7b style configuration
  34. >>> model = Jais2Model(configuration)
  35. >>> # Accessing the model configuration
  36. >>> configuration = model.config
  37. ```"""
  38. model_type = "jais2"
  39. keys_to_ignore_at_inference = ["past_key_values"]
  40. base_model_tp_plan = {
  41. "layers.*.self_attn.q_proj": "colwise",
  42. "layers.*.self_attn.k_proj": "colwise",
  43. "layers.*.self_attn.v_proj": "colwise",
  44. "layers.*.self_attn.o_proj": "rowwise",
  45. "layers.*.mlp.up_proj": "colwise",
  46. "layers.*.mlp.down_proj": "rowwise",
  47. }
  48. base_model_pp_plan = {
  49. "embed_tokens": (["input_ids"], ["inputs_embeds"]),
  50. "layers": (["hidden_states", "attention_mask"], ["hidden_states"]),
  51. "norm": (["hidden_states"], ["hidden_states"]),
  52. }
  53. vocab_size: int = 150272
  54. hidden_size: int = 3328
  55. intermediate_size: int = 26624
  56. num_hidden_layers: int = 32
  57. num_attention_heads: int = 26
  58. num_key_value_heads: int | None = None
  59. hidden_act: str = "relu2"
  60. max_position_embeddings: int = 8192
  61. initializer_range: float = interval(min=0.0, max=1.0)(default=0.02)
  62. use_cache: bool = True
  63. pad_token_id: int | None = None
  64. bos_token_id: int | None = 0
  65. eos_token_id: int | list[int] | None = 150024
  66. tie_word_embeddings: bool = False
  67. rope_parameters: RopeParameters | dict | None = None
  68. attention_bias: bool = True
  69. attention_dropout: int | float | None = 0.0
  70. mlp_bias: bool = True
  71. head_dim: int | None = None
  72. layer_norm_eps: float = 1e-5
  73. def __post_init__(self, **kwargs):
  74. if self.head_dim is None:
  75. self.head_dim = self.hidden_size // self.num_attention_heads
  76. if self.num_key_value_heads is None:
  77. self.num_key_value_heads = self.num_attention_heads
  78. super().__post_init__(**kwargs)
  79. def validate_architecture(self):
  80. """Part of `@strict`-powered validation. Validates the architecture of the config."""
  81. if self.hidden_size % self.num_attention_heads != 0:
  82. raise ValueError(
  83. f"The hidden size ({self.hidden_size}) is not a multiple of the number of attention "
  84. f"heads ({self.num_attention_heads})."
  85. )
  86. __all__ = ["Jais2Config"]