configuration_granitemoeshared.py 3.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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. """GraniteMoeShared 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 GraniteMoeSharedConfig(PreTrainedConfig):
  27. r"""
  28. embedding_multiplier (`float`, *optional*, defaults to 1.0):
  29. embedding multiplier
  30. logits_scaling (`float`, *optional*, defaults to 1.0):
  31. divisor for output logits
  32. residual_multiplier (`float`, *optional*, defaults to 1.0):
  33. residual multiplier
  34. attention_multiplier (`float`, *optional*, defaults to 1.0):
  35. attention multiplier
  36. shared_intermediate_size (`int`, *optional*, defaults to 1024):
  37. intermediate size for shared experts.
  38. ```python
  39. >>> from transformers import GraniteMoeSharedModel, GraniteMoeSharedConfig
  40. >>> # Initializing a GraniteMoeShared granitemoe-3b style configuration
  41. >>> configuration = GraniteMoeSharedConfig()
  42. >>> # Initializing a model from the granitemoe-7b style configuration
  43. >>> model = GraniteMoeSharedModel(configuration)
  44. >>> # Accessing the model configuration
  45. >>> configuration = model.config
  46. ```
  47. """
  48. model_type = "granitemoeshared"
  49. keys_to_ignore_at_inference = ["past_key_values"]
  50. vocab_size: int = 32000
  51. hidden_size: int = 4096
  52. intermediate_size: int = 11008
  53. num_hidden_layers: int = 32
  54. num_attention_heads: int = 32
  55. num_key_value_heads: int | None = None
  56. hidden_act: str = "silu"
  57. max_position_embeddings: int = 2048
  58. initializer_range: float = 0.02
  59. rms_norm_eps: float = 1e-6
  60. use_cache: bool = True
  61. pad_token_id: int | None = None
  62. bos_token_id: int | None = 1
  63. eos_token_id: int | list[int] | None = 2
  64. tie_word_embeddings: bool = False
  65. rope_parameters: RopeParameters | dict | None = None
  66. attention_bias: bool = False
  67. attention_dropout: float | int | None = 0.0
  68. embedding_multiplier: float | int | None = 1.0
  69. logits_scaling: float | int | None = 1.0
  70. residual_multiplier: float | int | None = 1.0
  71. attention_multiplier: float | int | None = 1.0
  72. num_local_experts: int | None = 8
  73. num_experts_per_tok: int | None = 2
  74. output_router_logits: bool | None = False
  75. router_aux_loss_coef: float | None = 0.001
  76. shared_intermediate_size: int = 0
  77. def __post_init__(self, **kwargs):
  78. if self.num_key_value_heads is None:
  79. self.num_key_value_heads = self.num_attention_heads
  80. super().__post_init__(**kwargs)
  81. __all__ = ["GraniteMoeSharedConfig"]