configuration_gemma.py 3.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. # 🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨
  2. # This file was automatically generated from src/transformers/models/gemma/modular_gemma.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_gemma.py file directly. One of our CI enforces this.
  6. # 🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨
  7. # Copyright 2024 Google Inc. 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="google/gemma-7b")
  26. @strict
  27. class GemmaConfig(PreTrainedConfig):
  28. r"""
  29. use_bidirectional_attention (`bool`, *optional*):
  30. If True, the model will attend to all text tokens instead of using a causal mask.
  31. ```python
  32. >>> from transformers import GemmaModel, GemmaConfig
  33. >>> # Initializing a Gemma gemma-7b style configuration
  34. >>> configuration = GemmaConfig()
  35. >>> # Initializing a model from the gemma-7b style configuration
  36. >>> model = GemmaModel(configuration)
  37. >>> # Accessing the model configuration
  38. >>> configuration = model.config
  39. ```"""
  40. model_type = "gemma"
  41. keys_to_ignore_at_inference = ["past_key_values"]
  42. base_model_tp_plan = {
  43. "layers.*.self_attn.q_proj": "colwise",
  44. "layers.*.self_attn.k_proj": "colwise",
  45. "layers.*.self_attn.v_proj": "colwise",
  46. "layers.*.self_attn.o_proj": "rowwise",
  47. "layers.*.mlp.gate_proj": "colwise",
  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 = 256000
  57. hidden_size: int = 3072
  58. intermediate_size: int = 24576
  59. num_hidden_layers: int = 28
  60. num_attention_heads: int = 16
  61. num_key_value_heads: int = 16
  62. head_dim: int = 256
  63. hidden_act: str = "gelu_pytorch_tanh"
  64. max_position_embeddings: int = 8192
  65. initializer_range: float = 0.02
  66. rms_norm_eps: float = 1e-6
  67. use_cache: bool = True
  68. pad_token_id: int | None = 0
  69. eos_token_id: int | list[int] | None = 1
  70. bos_token_id: int | None = 2
  71. tie_word_embeddings: bool = True
  72. rope_parameters: RopeParameters | dict | None = None
  73. attention_bias: bool = False
  74. attention_dropout: float | int = 0.0
  75. use_bidirectional_attention: bool | None = None
  76. __all__ = ["GemmaConfig"]