| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116 |
- # 🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨
- # This file was automatically generated from src/transformers/models/moonshine/modular_moonshine.py.
- # Do NOT edit this file manually as any edits will be overwritten by the generation of
- # the file from the modular. If any change should be done, please apply the change to the
- # modular_moonshine.py file directly. One of our CI enforces this.
- # 🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨
- # Copyright 2025 The HuggingFace Inc. team. All rights reserved.
- #
- # Licensed under the Apache License, Version 2.0 (the "License");
- # you may not use this file except in compliance with the License.
- # You may obtain a copy of the License at
- #
- # http://www.apache.org/licenses/LICENSE-2.0
- #
- # Unless required by applicable law or agreed to in writing, software
- # distributed under the License is distributed on an "AS IS" BASIS,
- # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- # See the License for the specific language governing permissions and
- # limitations under the License.
- from huggingface_hub.dataclasses import strict
- from ...configuration_utils import PreTrainedConfig
- from ...modeling_rope_utils import RopeParameters
- from ...utils import auto_docstring
- @auto_docstring(checkpoint="UsefulSensors/moonshine-tiny")
- @strict
- class MoonshineConfig(PreTrainedConfig):
- r"""
- encoder_num_key_value_heads (`int`, *optional*):
- This is the number of key_value heads that should be used to implement Grouped Query Attention. If
- `encoder_num_key_value_heads=encoder_num_attention_heads`, the model will use Multi Head Attention (MHA), if
- `encoder_num_key_value_heads=1` the model will use Multi Query Attention (MQA) otherwise GQA is used. When
- converting a multi-head checkpoint to a GQA checkpoint, each group key and value head should be constructed
- by meanpooling all the original heads within that group. For more details, check out [this
- paper](https://huggingface.co/papers/2305.13245). If it is not specified, will default to
- `num_attention_heads`.
- decoder_num_key_value_heads (`int`, *optional*):
- This is the number of key_value heads that should be used to implement Grouped Query Attention. If
- `decoder_num_key_value_heads=decoder_num_attention_heads`, the model will use Multi Head Attention (MHA), if
- `decoder_num_key_value_heads=1` the model will use Multi Query Attention (MQA) otherwise GQA is used. When
- converting a multi-head checkpoint to a GQA checkpoint, each group key and value head should be constructed
- by meanpooling all the original heads within that group. For more details, check out [this
- paper](https://huggingface.co/papers/2305.13245). If it is not specified, will default to
- `decoder_num_attention_heads`.
- pad_head_dim_to_multiple_of (`int`, *optional*):
- Pad head dimension in encoder and decoder to the next multiple of this value. Necessary for using certain
- optimized attention implementations.
- encoder_hidden_act (`str` or `function`, *optional*, defaults to `"gelu"`):
- The non-linear activation function (function or string) in the encoder.
- decoder_hidden_act (`str` or `function`, *optional*, defaults to `"silu"`):
- The non-linear activation function (function or string) in the decoder.
- Example:
- ```python
- >>> from transformers import MoonshineModel, MoonshineConfig
- >>> # Initializing a Moonshine style configuration
- >>> configuration = MoonshineConfig().from_pretrained("UsefulSensors/moonshine-tiny")
- >>> # Initializing a model from the configuration
- >>> model = MoonshineModel(configuration)
- >>> # Accessing the model configuration
- >>> configuration = model.config
- ```"""
- model_type = "moonshine"
- keys_to_ignore_at_inference = ["past_key_values"]
- attribute_map = {
- "num_key_value_heads": "decoder_num_key_value_heads",
- "num_attention_heads": "decoder_num_attention_heads",
- "num_hidden_layers": "decoder_num_hidden_layers",
- "hidden_act": "decoder_hidden_act",
- }
- vocab_size: int = 32768
- hidden_size: int = 288
- intermediate_size: int = 1152
- encoder_num_hidden_layers: int = 6
- decoder_num_hidden_layers: int = 6
- encoder_num_attention_heads: int = 8
- decoder_num_attention_heads: int = 8
- encoder_num_key_value_heads: int | None = None
- decoder_num_key_value_heads: int | None = None
- pad_head_dim_to_multiple_of: int | None = None
- encoder_hidden_act: str = "gelu"
- decoder_hidden_act: str = "silu"
- max_position_embeddings: int = 512
- initializer_range: float = 0.02
- decoder_start_token_id: int = 1
- use_cache: bool = True
- rope_parameters: RopeParameters | dict | None = None
- is_encoder_decoder: bool = True
- attention_bias: bool = False
- attention_dropout: float | int = 0.0
- bos_token_id: int | None = 1
- eos_token_id: int | list[int] | None = 2
- pad_token_id: int | None = None
- tie_word_embeddings: bool = True
- def __post_init__(self, **kwargs):
- if self.encoder_num_key_value_heads is None:
- self.encoder_num_key_value_heads = self.encoder_num_attention_heads
- if self.decoder_num_key_value_heads is None:
- self.decoder_num_key_value_heads = self.decoder_num_attention_heads
- kwargs.setdefault("partial_rotary_factor", 0.9) # assign default for BC
- super().__post_init__(**kwargs)
- __all__ = ["MoonshineConfig"]
|