configuration_starcoder2.py 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. # Copyright 2024 BigCode and the HuggingFace Inc. team. All rights reserved.
  2. #
  3. # Licensed under the Apache License, Version 2.0 (the "License");
  4. # you may not use this file except in compliance with the License.
  5. # You may obtain a copy of the License at
  6. #
  7. # http://www.apache.org/licenses/LICENSE-2.0
  8. #
  9. # Unless required by applicable law or agreed to in writing, software
  10. # distributed under the License is distributed on an "AS IS" BASIS,
  11. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. # See the License for the specific language governing permissions and
  13. # limitations under the License.
  14. """Starcoder2 model configuration"""
  15. from huggingface_hub.dataclasses import strict
  16. from ...configuration_utils import PreTrainedConfig
  17. from ...modeling_rope_utils import RopeParameters
  18. from ...utils import auto_docstring
  19. @auto_docstring(checkpoint="bigcode/starcoder2-7b")
  20. @strict
  21. class Starcoder2Config(PreTrainedConfig):
  22. r"""
  23. use_bias (`bool`, *optional*, defaults to `True`):
  24. Whether to use bias term on linear layers of the model.
  25. ```python
  26. >>> from transformers import Starcoder2Model, Starcoder2Config
  27. >>> # Initializing a Starcoder2 7B style configuration
  28. >>> configuration = Starcoder2Config()
  29. >>> # Initializing a model from the Starcoder2 7B style configuration
  30. >>> model = Starcoder2Model(configuration)
  31. >>> # Accessing the model configuration
  32. >>> configuration = model.config
  33. ```
  34. """
  35. model_type = "starcoder2"
  36. keys_to_ignore_at_inference = ["past_key_values"]
  37. # Default tensor parallel plan for base model `Starcoder2`
  38. base_model_tp_plan = {
  39. "layers.*.self_attn.q_proj": "colwise",
  40. "layers.*.self_attn.k_proj": "colwise",
  41. "layers.*.self_attn.v_proj": "colwise",
  42. "layers.*.self_attn.o_proj": "rowwise",
  43. "layers.*.mlp.c_fc": "colwise",
  44. "layers.*.mlp.c_proj": "rowwise",
  45. }
  46. base_model_pp_plan = {
  47. "embed_tokens": (["input_ids"], ["inputs_embeds"]),
  48. "layers": (["hidden_states", "attention_mask"], ["hidden_states"]),
  49. "norm": (["hidden_states"], ["hidden_states"]),
  50. }
  51. vocab_size: int = 49152
  52. hidden_size: int = 3072
  53. intermediate_size: int = 12288
  54. num_hidden_layers: int = 30
  55. num_attention_heads: int = 24
  56. num_key_value_heads: int = 2
  57. hidden_act: str = "gelu_pytorch_tanh"
  58. max_position_embeddings: int = 4096
  59. initializer_range: float = 0.018042
  60. norm_epsilon: float = 1e-5
  61. use_cache: bool = True
  62. bos_token_id: int | None = 50256
  63. eos_token_id: int | list[int] | None = 50256
  64. pad_token_id: int | None = None
  65. rope_parameters: RopeParameters | dict | None = None
  66. sliding_window: int | None = None
  67. attention_dropout: float | int = 0.0
  68. residual_dropout: float | int = 0.0
  69. embedding_dropout: float | int = 0.0
  70. use_bias: bool = True
  71. tie_word_embeddings: bool = True
  72. __all__ = ["Starcoder2Config"]