configuration_olmo2.py 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. # 🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨
  2. # This file was automatically generated from src/transformers/models/olmo2/modular_olmo2.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_olmo2.py file directly. One of our CI enforces this.
  6. # 🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨
  7. # Copyright 2024 HuggingFace Inc. team. All rights reserved.
  8. #
  9. # This code is based on EleutherAI's GPT-NeoX library and the GPT-NeoX
  10. # and OPT implementations in this library. It has been modified from its
  11. # original forms to accommodate minor architectural differences compared
  12. # to GPT-NeoX and OPT used by the Meta AI team that trained the model.
  13. #
  14. # Licensed under the Apache License, Version 2.0 (the "License");
  15. # you may not use this file except in compliance with the License.
  16. # You may obtain a copy of the License at
  17. #
  18. # http://www.apache.org/licenses/LICENSE-2.0
  19. #
  20. # Unless required by applicable law or agreed to in writing, software
  21. # distributed under the License is distributed on an "AS IS" BASIS,
  22. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  23. # See the License for the specific language governing permissions and
  24. # limitations under the License.
  25. from huggingface_hub.dataclasses import strict
  26. from ...configuration_utils import PreTrainedConfig
  27. from ...modeling_rope_utils import RopeParameters
  28. from ...utils import auto_docstring
  29. @auto_docstring(checkpoint="allenai/Olmo2-7B-1124-hf")
  30. @strict
  31. class Olmo2Config(PreTrainedConfig):
  32. r"""
  33. Example:
  34. ```python
  35. >>> from transformers import Olmo2Model, Olmo2Config
  36. >>> # Initializing a Olmo2 7B style configuration
  37. >>> configuration = Olmo2Config()
  38. >>> # Initializing a model from the Olmo2 7B style configuration
  39. >>> model = Olmo2Model(configuration)
  40. >>> # Accessing the model configuration
  41. >>> configuration = model.config
  42. ```
  43. """
  44. model_type = "olmo2"
  45. keys_to_ignore_at_inference = ["past_key_values"]
  46. base_model_tp_plan = {
  47. "layers.*.self_attn.q_proj": "colwise_gather_output", # we need to replicate here due to the added norm on q and k
  48. "layers.*.self_attn.k_proj": "colwise_gather_output", # we need to replicate here due to the added norm on q and k
  49. "layers.*.self_attn.v_proj": "colwise_gather_output", # we need to replicate here due to the added norm on q and k
  50. "layers.*.self_attn.o_proj": "rowwise_split_input", # input is replicated due to the added norm on q and k
  51. "layers.*.mlp.gate_proj": "colwise",
  52. "layers.*.mlp.up_proj": "colwise",
  53. "layers.*.mlp.down_proj": "rowwise",
  54. }
  55. base_model_pp_plan = {
  56. "embed_tokens": (["input_ids"], ["inputs_embeds"]),
  57. "layers": (["hidden_states", "attention_mask"], ["hidden_states"]),
  58. "norm": (["hidden_states"], ["hidden_states"]),
  59. }
  60. vocab_size: int = 50304
  61. hidden_size: int = 4096
  62. intermediate_size: int = 11008
  63. num_hidden_layers: int = 32
  64. num_attention_heads: int = 32
  65. num_key_value_heads: int | None = None
  66. hidden_act: str = "silu"
  67. max_position_embeddings: int = 2048
  68. initializer_range: float = 0.02
  69. use_cache: bool = True
  70. pad_token_id: int | None = 1
  71. bos_token_id: int | None = None
  72. eos_token_id: int | list[int] | None = 50279
  73. tie_word_embeddings: bool = False
  74. rope_parameters: RopeParameters | dict | None = None
  75. attention_bias: bool = False
  76. attention_dropout: float | int = 0.0
  77. rms_norm_eps: float = 1e-5
  78. def __post_init__(self, **kwargs):
  79. if self.num_key_value_heads is None:
  80. self.num_key_value_heads = self.num_attention_heads
  81. super().__post_init__(**kwargs)
  82. __all__ = ["Olmo2Config"]