configuration_vaultgemma.py 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. # 🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨
  2. # This file was automatically generated from src/transformers/models/vaultgemma/modular_vaultgemma.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_vaultgemma.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. @auto_docstring(checkpoint="google/vaultgemma-1b")
  25. @strict
  26. class VaultGemmaConfig(PreTrainedConfig):
  27. r"""
  28. query_pre_attn_scalar (`float`, *optional*, defaults to 256):
  29. scaling factor used on the attention scores
  30. final_logit_softcapping (`float`, *optional*, defaults to 30.0):
  31. scaling factor when applying tanh softcapping on the logits.
  32. attn_logit_softcapping (`float`, *optional*, defaults to 50.0):
  33. scaling factor when applying tanh softcapping on the attention scores.
  34. ```python
  35. >>> from transformers import VaultGemmaModel, VaultGemmaConfig
  36. >>> # Initializing a VaultGemma vaultgemma-7b style configuration
  37. >>> configuration = VaultGemmaConfig()
  38. >>> # Initializing a model from the vaultgemma-7b style configuration
  39. >>> model = VaultGemmaModel(configuration)
  40. >>> # Accessing the model configuration
  41. >>> configuration = model.config
  42. ```"""
  43. model_type = "vaultgemma"
  44. keys_to_ignore_at_inference = ["past_key_values"]
  45. base_model_tp_plan = {
  46. "layers.*.self_attn.q_proj": "colwise",
  47. "layers.*.self_attn.k_proj": "colwise",
  48. "layers.*.self_attn.v_proj": "colwise",
  49. "layers.*.self_attn.o_proj": "rowwise",
  50. "layers.*.mlp.gate_proj": "colwise",
  51. "layers.*.mlp.up_proj": "colwise",
  52. "layers.*.mlp.down_proj": "rowwise",
  53. }
  54. base_model_pp_plan = {
  55. "embed_tokens": (["input_ids"], ["inputs_embeds"]),
  56. "layers": (["hidden_states", "attention_mask"], ["hidden_states"]),
  57. "norm": (["hidden_states"], ["hidden_states"]),
  58. }
  59. vocab_size: int = 256000
  60. hidden_size: int = 2304
  61. intermediate_size: int = 9216
  62. num_hidden_layers: int = 26
  63. num_attention_heads: int = 8
  64. num_key_value_heads: int = 4
  65. head_dim: int = 256
  66. hidden_activation: str = "gelu_pytorch_tanh"
  67. max_position_embeddings: int = 8192
  68. initializer_range: float = 0.02
  69. rms_norm_eps: float = 1e-6
  70. use_cache: bool = True
  71. pad_token_id: int | None = 0
  72. eos_token_id: int | list[int] | None = 1
  73. bos_token_id: int | None = 2
  74. tie_word_embeddings: bool = True
  75. rope_parameters: RopeParameters | dict | None = None
  76. attention_bias: bool = False
  77. attention_dropout: int | float | None = 0.0
  78. query_pre_attn_scalar: int = 256
  79. sliding_window: int | None = 4096
  80. layer_types: list[str] | None = None
  81. final_logit_softcapping: float | None = 30.0
  82. attn_logit_softcapping: float | None = 50.0
  83. def __post_init__(self, **kwargs):
  84. if self.layer_types is None:
  85. self.layer_types = [
  86. "sliding_attention" if bool((i + 1) % 2) else "full_attention" for i in range(self.num_hidden_layers)
  87. ]
  88. super().__post_init__(**kwargs)
  89. def validate_architecture(self):
  90. """Part of `@strict`-powered validation. Validates the architecture of the config."""
  91. if self.hidden_size % self.num_attention_heads != 0:
  92. raise ValueError(
  93. f"The hidden size ({self.hidden_size}) is not a multiple of the number of attention "
  94. f"heads ({self.num_attention_heads})."
  95. )
  96. __all__ = ["VaultGemmaConfig"]