configuration_granitemoe.py 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. # Copyright 2024 EleutherAI and the HuggingFace Inc. team. All rights reserved.
  2. #
  3. # This code is based on EleutherAI's GPT-NeoX library and the GPT-NeoX
  4. # and OPT implementations in this library. It has been modified from its
  5. # original forms to accommodate minor architectural differences compared
  6. # to GPT-NeoX and OPT used by the Meta AI team that trained the model.
  7. #
  8. # Licensed under the Apache License, Version 2.0 (the "License");
  9. # you may not use this file except in compliance with the License.
  10. # You may obtain a copy of the License at
  11. #
  12. # http://www.apache.org/licenses/LICENSE-2.0
  13. #
  14. # Unless required by applicable law or agreed to in writing, software
  15. # distributed under the License is distributed on an "AS IS" BASIS,
  16. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  17. # See the License for the specific language governing permissions and
  18. # limitations under the License.
  19. """GraniteMoe model configuration"""
  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="ibm-granite/granite-speech-3.2-8b")
  25. @strict
  26. class GraniteMoeConfig(PreTrainedConfig):
  27. r"""
  28. ```python
  29. >>> from transformers import GraniteMoeModel, GraniteMoeConfig
  30. >>> # Initializing a GraniteMoe granitemoe-3b style configuration
  31. >>> configuration = GraniteMoeConfig()
  32. >>> # Initializing a model from the granitemoe-7b style configuration
  33. >>> model = GraniteMoeModel(configuration)
  34. >>> # Accessing the model configuration
  35. >>> configuration = model.config
  36. ```
  37. """
  38. model_type = "granitemoe"
  39. keys_to_ignore_at_inference = ["past_key_values"]
  40. vocab_size: int = 32000
  41. hidden_size: int = 4096
  42. intermediate_size: int = 11008
  43. num_hidden_layers: int = 32
  44. num_attention_heads: int = 32
  45. num_key_value_heads: int | None = None
  46. hidden_act: str = "silu"
  47. max_position_embeddings: int = 2048
  48. initializer_range: float = 0.02
  49. rms_norm_eps: float = 1e-6
  50. use_cache: bool = True
  51. pad_token_id: int | None = None
  52. bos_token_id: int | None = 1
  53. eos_token_id: int | list[int] | None = 2
  54. tie_word_embeddings: bool = False
  55. rope_parameters: RopeParameters | dict | None = None
  56. attention_bias: bool = False
  57. attention_dropout: float | int | None = 0.0
  58. embedding_multiplier: float | int | None = 1.0
  59. logits_scaling: float | int | None = 1.0
  60. residual_multiplier: float | int | None = 1.0
  61. attention_multiplier: float | int | None = 1.0
  62. num_local_experts: int | None = 8
  63. num_experts_per_tok: int | None = 2
  64. output_router_logits: bool | None = False
  65. router_aux_loss_coef: float | None = 0.001
  66. def __post_init__(self, **kwargs):
  67. # for backward compatibility
  68. if self.num_key_value_heads is None:
  69. self.num_key_value_heads = self.num_attention_heads
  70. super().__post_init__(**kwargs)
  71. __all__ = ["GraniteMoeConfig"]