configuration_stablelm.py 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. # Copyright 2024 Stability AI 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. """StableLM 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="stabilityai/stablelm-3b-4e1t")
  20. @strict
  21. class StableLmConfig(PreTrainedConfig):
  22. r"""
  23. use_parallel_residual (`bool`, *optional*, defaults to `False`):
  24. Whether to use a "parallel" formulation in each Transformer layer, which can provide a slight training
  25. speedup at large scales.
  26. hidden_dropout (`float`, *optional*, defaults to 0.0):
  27. The dropout ratio after applying the MLP to the hidden states.
  28. Example:
  29. ```python
  30. >>> from transformers import StableLmModel, StableLmConfig
  31. >>> # Initializing a StableLM stablelm-3b style configuration
  32. >>> configuration = StableLmConfig()
  33. ```"""
  34. model_type = "stablelm"
  35. keys_to_ignore_at_inference = ["past_key_values"]
  36. vocab_size: int = 50304
  37. intermediate_size: int = 6912
  38. hidden_size: int = 2560
  39. num_hidden_layers: int = 32
  40. num_attention_heads: int = 32
  41. num_key_value_heads: int = 32
  42. hidden_act: str = "silu"
  43. max_position_embeddings: int = 4096
  44. initializer_range: float = 0.02
  45. layer_norm_eps: float = 1.0e-5
  46. use_cache: bool = True
  47. tie_word_embeddings: bool = False
  48. rope_parameters: RopeParameters | dict | None = None
  49. use_qkv_bias: bool = False
  50. qk_layernorm: bool = False
  51. use_parallel_residual: bool = False
  52. hidden_dropout: float | int = 0.0
  53. attention_dropout: float | int = 0.0
  54. bos_token_id: int | None = 0
  55. eos_token_id: int | list[int] | None = 0
  56. pad_token_id: int | None = None
  57. def __post_init__(self, **kwargs):
  58. kwargs.setdefault("partial_rotary_factor", 0.25) # assign default for BC
  59. super().__post_init__(**kwargs)
  60. __all__ = ["StableLmConfig"]