configuration_moonshine.py 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. # 🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨
  2. # This file was automatically generated from src/transformers/models/moonshine/modular_moonshine.py.
  3. # Do NOT edit this file manually as any edits will be overwritten by the generation of
  4. # the file from the modular. If any change should be done, please apply the change to the
  5. # modular_moonshine.py file directly. One of our CI enforces this.
  6. # 🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨
  7. # Copyright 2025 The HuggingFace Inc. team. All rights reserved.
  8. #
  9. # Licensed under the Apache License, Version 2.0 (the "License");
  10. # you may not use this file except in compliance with the License.
  11. # You may obtain a copy of the License at
  12. #
  13. # http://www.apache.org/licenses/LICENSE-2.0
  14. #
  15. # Unless required by applicable law or agreed to in writing, software
  16. # distributed under the License is distributed on an "AS IS" BASIS,
  17. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  18. # See the License for the specific language governing permissions and
  19. # limitations under the License.
  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="UsefulSensors/moonshine-tiny")
  25. @strict
  26. class MoonshineConfig(PreTrainedConfig):
  27. r"""
  28. encoder_num_key_value_heads (`int`, *optional*):
  29. This is the number of key_value heads that should be used to implement Grouped Query Attention. If
  30. `encoder_num_key_value_heads=encoder_num_attention_heads`, the model will use Multi Head Attention (MHA), if
  31. `encoder_num_key_value_heads=1` the model will use Multi Query Attention (MQA) otherwise GQA is used. When
  32. converting a multi-head checkpoint to a GQA checkpoint, each group key and value head should be constructed
  33. by meanpooling all the original heads within that group. For more details, check out [this
  34. paper](https://huggingface.co/papers/2305.13245). If it is not specified, will default to
  35. `num_attention_heads`.
  36. decoder_num_key_value_heads (`int`, *optional*):
  37. This is the number of key_value heads that should be used to implement Grouped Query Attention. If
  38. `decoder_num_key_value_heads=decoder_num_attention_heads`, the model will use Multi Head Attention (MHA), if
  39. `decoder_num_key_value_heads=1` the model will use Multi Query Attention (MQA) otherwise GQA is used. When
  40. converting a multi-head checkpoint to a GQA checkpoint, each group key and value head should be constructed
  41. by meanpooling all the original heads within that group. For more details, check out [this
  42. paper](https://huggingface.co/papers/2305.13245). If it is not specified, will default to
  43. `decoder_num_attention_heads`.
  44. pad_head_dim_to_multiple_of (`int`, *optional*):
  45. Pad head dimension in encoder and decoder to the next multiple of this value. Necessary for using certain
  46. optimized attention implementations.
  47. encoder_hidden_act (`str` or `function`, *optional*, defaults to `"gelu"`):
  48. The non-linear activation function (function or string) in the encoder.
  49. decoder_hidden_act (`str` or `function`, *optional*, defaults to `"silu"`):
  50. The non-linear activation function (function or string) in the decoder.
  51. Example:
  52. ```python
  53. >>> from transformers import MoonshineModel, MoonshineConfig
  54. >>> # Initializing a Moonshine style configuration
  55. >>> configuration = MoonshineConfig().from_pretrained("UsefulSensors/moonshine-tiny")
  56. >>> # Initializing a model from the configuration
  57. >>> model = MoonshineModel(configuration)
  58. >>> # Accessing the model configuration
  59. >>> configuration = model.config
  60. ```"""
  61. model_type = "moonshine"
  62. keys_to_ignore_at_inference = ["past_key_values"]
  63. attribute_map = {
  64. "num_key_value_heads": "decoder_num_key_value_heads",
  65. "num_attention_heads": "decoder_num_attention_heads",
  66. "num_hidden_layers": "decoder_num_hidden_layers",
  67. "hidden_act": "decoder_hidden_act",
  68. }
  69. vocab_size: int = 32768
  70. hidden_size: int = 288
  71. intermediate_size: int = 1152
  72. encoder_num_hidden_layers: int = 6
  73. decoder_num_hidden_layers: int = 6
  74. encoder_num_attention_heads: int = 8
  75. decoder_num_attention_heads: int = 8
  76. encoder_num_key_value_heads: int | None = None
  77. decoder_num_key_value_heads: int | None = None
  78. pad_head_dim_to_multiple_of: int | None = None
  79. encoder_hidden_act: str = "gelu"
  80. decoder_hidden_act: str = "silu"
  81. max_position_embeddings: int = 512
  82. initializer_range: float = 0.02
  83. decoder_start_token_id: int = 1
  84. use_cache: bool = True
  85. rope_parameters: RopeParameters | dict | None = None
  86. is_encoder_decoder: bool = True
  87. attention_bias: bool = False
  88. attention_dropout: float | int = 0.0
  89. bos_token_id: int | None = 1
  90. eos_token_id: int | list[int] | None = 2
  91. pad_token_id: int | None = None
  92. tie_word_embeddings: bool = True
  93. def __post_init__(self, **kwargs):
  94. if self.encoder_num_key_value_heads is None:
  95. self.encoder_num_key_value_heads = self.encoder_num_attention_heads
  96. if self.decoder_num_key_value_heads is None:
  97. self.decoder_num_key_value_heads = self.decoder_num_attention_heads
  98. kwargs.setdefault("partial_rotary_factor", 0.9) # assign default for BC
  99. super().__post_init__(**kwargs)
  100. __all__ = ["MoonshineConfig"]