configuration_olmoe.py 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. # Licensed under the Apache License, Version 2.0 (the "License");
  2. # you may not use this file except in compliance with the License.
  3. # You may obtain a copy of the License at
  4. #
  5. # http://www.apache.org/licenses/LICENSE-2.0
  6. #
  7. # Unless required by applicable law or agreed to in writing, software
  8. # distributed under the License is distributed on an "AS IS" BASIS,
  9. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  10. # See the License for the specific language governing permissions and
  11. # limitations under the License.
  12. """OLMoE model configuration"""
  13. from huggingface_hub.dataclasses import strict
  14. from ...configuration_utils import PreTrainedConfig
  15. from ...modeling_rope_utils import RopeParameters
  16. from ...utils import auto_docstring
  17. @auto_docstring(checkpoint="allenai/OLMoE-1B-7B-0924")
  18. @strict
  19. class OlmoeConfig(PreTrainedConfig):
  20. r"""
  21. clip_qkv (`float`, *optional*):
  22. If not `None`, elements of query, key and value attention states are clipped so that their
  23. absolute value does not exceed this value.
  24. ```python
  25. >>> from transformers import OlmoeModel, OlmoeConfig
  26. >>> # Initializing a OLMoE 7B A1B style configuration
  27. >>> configuration = OlmoeConfig()
  28. >>> # Initializing a model from the OLMoE 7B A1B style configuration
  29. >>> model = OlmoeModel(configuration)
  30. >>> # Accessing the model configuration
  31. >>> configuration = model.config
  32. ```
  33. """
  34. model_type = "olmoe"
  35. keys_to_ignore_at_inference = ["past_key_values"]
  36. attribute_map = {"num_local_experts": "num_experts"}
  37. # Default tensor parallel plan for base model `Olmoe`
  38. base_model_tp_plan = {
  39. "layers.*.self_attn.q_proj": "colwise_gather_output", # due to the norm, we have to gather
  40. "layers.*.self_attn.k_proj": "colwise_gather_output", # due to the norm, we have to gather
  41. "layers.*.self_attn.v_proj": "colwise_gather_output", # due to the norm, we have to gather
  42. "layers.*.self_attn.o_proj": "rowwise_split_input", # due to the norm, we have to gather
  43. "layers.*.mlp.experts.gate_up_proj": "packed_colwise",
  44. "layers.*.mlp.experts.down_proj": "rowwise",
  45. "layers.*.mlp.experts": "moe_tp_experts",
  46. }
  47. vocab_size: int = 50304
  48. hidden_size: int = 2048
  49. intermediate_size: int = 2048
  50. num_hidden_layers: int = 16
  51. num_attention_heads: int = 16
  52. num_key_value_heads: int | None = None
  53. hidden_act: str = "silu"
  54. max_position_embeddings: int = 4096
  55. initializer_range: float = 0.02
  56. rms_norm_eps: float = 1e-05
  57. use_cache: bool = True
  58. pad_token_id: int | None = 1
  59. bos_token_id: int | None = None
  60. eos_token_id: int | list[int] | None = 50279
  61. tie_word_embeddings: bool = False
  62. rope_parameters: RopeParameters | dict | None = None
  63. attention_bias: bool = False
  64. attention_dropout: float | int = 0.0
  65. clip_qkv: float | None = None
  66. num_experts_per_tok: int = 8
  67. num_experts: int = 64
  68. output_router_logits: bool = False
  69. router_aux_loss_coef: float = 0.01
  70. norm_topk_prob: bool = False
  71. def __post_init__(self, **kwargs):
  72. if self.num_key_value_heads is None:
  73. self.num_key_value_heads = self.num_attention_heads
  74. super().__post_init__(**kwargs)
  75. __all__ = ["OlmoeConfig"]