configuration_granite.py 3.4 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. """Granite 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-3.0-8b-base")
  25. @strict
  26. class GraniteConfig(PreTrainedConfig):
  27. r"""
  28. ```python
  29. >>> from transformers import GraniteModel, GraniteConfig
  30. >>> # Initializing a Granite granite-3b style configuration
  31. >>> configuration = GraniteConfig()
  32. >>> # Initializing a model from the granite-7b style configuration
  33. >>> model = GraniteModel(configuration)
  34. >>> # Accessing the model configuration
  35. >>> configuration = model.config
  36. ```
  37. """
  38. model_type = "granite"
  39. keys_to_ignore_at_inference = ["past_key_values"]
  40. # Default tensor parallel plan for base model `GraniteModel`
  41. base_model_tp_plan = {
  42. "layers.*.self_attn.q_proj": "colwise",
  43. "layers.*.self_attn.k_proj": "colwise",
  44. "layers.*.self_attn.v_proj": "colwise",
  45. "layers.*.self_attn.o_proj": "rowwise",
  46. "layers.*.mlp.gate_proj": "colwise",
  47. "layers.*.mlp.up_proj": "colwise",
  48. "layers.*.mlp.down_proj": "rowwise",
  49. }
  50. base_model_pp_plan = {
  51. "embed_tokens": (["input_ids"], ["inputs_embeds"]),
  52. "layers": (["hidden_states", "attention_mask"], ["hidden_states"]),
  53. "norm": (["hidden_states"], ["hidden_states"]),
  54. }
  55. vocab_size: int = 32000
  56. hidden_size: int = 4096
  57. intermediate_size: int = 11008
  58. num_hidden_layers: int = 32
  59. num_attention_heads: int = 32
  60. num_key_value_heads: int | None = None
  61. hidden_act: str = "silu"
  62. max_position_embeddings: int = 2048
  63. initializer_range: float = 0.02
  64. rms_norm_eps: float = 1e-6
  65. use_cache: bool = True
  66. pad_token_id: int | None = None
  67. bos_token_id: int | None = 1
  68. eos_token_id: int | list[int] | None = 2
  69. tie_word_embeddings: bool = False
  70. rope_parameters: RopeParameters | dict | None = None
  71. attention_bias: bool = False
  72. attention_dropout: float | int = 0.0
  73. mlp_bias: bool = False
  74. embedding_multiplier: float | int = 1.0
  75. logits_scaling: float | int = 1.0
  76. residual_multiplier: float | int = 1.0
  77. attention_multiplier: float | int = 1.0
  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__ = ["GraniteConfig"]