Upload config
Browse files- config.json +5 -9
- configuration_meralion.py +5 -434
config.json
CHANGED
@@ -1,10 +1,7 @@
|
|
1 |
{
|
2 |
-
"
|
3 |
-
"MERaLiONForConditionalGeneration"
|
4 |
-
],
|
5 |
"auto_map": {
|
6 |
-
"AutoConfig": "configuration_meralion.MERaLiONConfig"
|
7 |
-
"AutoModelForSpeechSeq2Seq": "modeling_meralion.MERaLiONForConditionalGeneration"
|
8 |
},
|
9 |
"head_dim": 256,
|
10 |
"hidden_size": 3584,
|
@@ -51,7 +48,7 @@
|
|
51 |
],
|
52 |
"mask_time_length": 20,
|
53 |
"max_length": 448,
|
54 |
-
"model_type": "
|
55 |
"num_hidden_layers": 32,
|
56 |
"num_mel_bins": 80,
|
57 |
"pad_token_id": 50257,
|
@@ -159,13 +156,12 @@
|
|
159 |
"hidden_act": "gelu_pytorch_tanh",
|
160 |
"hidden_size": 3584,
|
161 |
"intermediate_size": 14336,
|
162 |
-
"model_type": "
|
163 |
"num_hidden_layers": 42,
|
164 |
"num_key_value_heads": 8,
|
165 |
"query_pre_attn_scalar": 256,
|
166 |
"sliding_window_size": 4096,
|
167 |
"torch_dtype": "bfloat16"
|
168 |
},
|
169 |
-
"torch_dtype": "bfloat16",
|
170 |
"transformers_version": "4.46.3"
|
171 |
-
}
|
|
|
1 |
{
|
2 |
+
"_attn_implementation_autoset": true,
|
|
|
|
|
3 |
"auto_map": {
|
4 |
+
"AutoConfig": "configuration_meralion.MERaLiONConfig"
|
|
|
5 |
},
|
6 |
"head_dim": 256,
|
7 |
"hidden_size": 3584,
|
|
|
48 |
],
|
49 |
"mask_time_length": 20,
|
50 |
"max_length": 448,
|
51 |
+
"model_type": "whisper",
|
52 |
"num_hidden_layers": 32,
|
53 |
"num_mel_bins": 80,
|
54 |
"pad_token_id": 50257,
|
|
|
156 |
"hidden_act": "gelu_pytorch_tanh",
|
157 |
"hidden_size": 3584,
|
158 |
"intermediate_size": 14336,
|
159 |
+
"model_type": "gemma2",
|
160 |
"num_hidden_layers": 42,
|
161 |
"num_key_value_heads": 8,
|
162 |
"query_pre_attn_scalar": 256,
|
163 |
"sliding_window_size": 4096,
|
164 |
"torch_dtype": "bfloat16"
|
165 |
},
|
|
|
166 |
"transformers_version": "4.46.3"
|
167 |
+
}
|
configuration_meralion.py
CHANGED
@@ -1,442 +1,13 @@
|
|
1 |
"""MERaLiON AudioLLM model configuration"""
|
2 |
|
3 |
-
from
|
4 |
-
from typing import TYPE_CHECKING, Any, Mapping, Optional, Union
|
5 |
-
|
6 |
from transformers.configuration_utils import PretrainedConfig
|
7 |
-
from transformers.onnx import OnnxConfig
|
8 |
from transformers.utils import logging
|
9 |
|
10 |
|
11 |
-
if TYPE_CHECKING:
|
12 |
-
from transformers.feature_extraction_utils import FeatureExtractionMixin
|
13 |
-
from transformers.tokenization_utils_base import PreTrainedTokenizerBase
|
14 |
-
from transformers.utils import TensorType
|
15 |
-
|
16 |
-
|
17 |
logger = logging.get_logger(__name__)
|
18 |
|
19 |
|
20 |
-
# fmt: off
|
21 |
-
NON_SPEECH_TOKENS = [
|
22 |
-
1, 2, 7, 8, 9, 10, 14, 25,
|
23 |
-
26, 27, 28, 29, 31, 58, 59, 60, 61, 62,
|
24 |
-
63, 90, 91, 92, 93, 357, 366, 438, 532, 685,
|
25 |
-
705, 796, 930, 1058, 1220, 1267, 1279, 1303, 1343, 1377,
|
26 |
-
1391, 1635, 1782, 1875, 2162, 2361, 2488, 3467, 4008, 4211,
|
27 |
-
4600, 4808, 5299, 5855, 6329, 7203, 9609, 9959, 10563, 10786,
|
28 |
-
11420, 11709, 11907, 13163, 13697, 13700, 14808, 15306, 16410, 16791,
|
29 |
-
17992, 19203, 19510, 20724, 22305, 22935, 27007, 30109, 30420, 33409,
|
30 |
-
34949, 40283, 40493, 40549, 47282, 49146, 50257, 50359, 50360, 50361
|
31 |
-
]
|
32 |
-
NON_SPEECH_TOKENS_MULTI = [
|
33 |
-
1, 2, 7, 8, 9, 10, 14, 25,
|
34 |
-
26, 27, 28, 29, 31, 58, 59, 60, 61, 62,
|
35 |
-
63, 90, 91, 92, 93, 359, 503, 522, 542, 873,
|
36 |
-
893, 902, 918, 922, 931, 1350, 1853, 1982, 2460, 2627,
|
37 |
-
3246, 3253, 3268, 3536, 3846, 3961, 4183, 4667, 6585, 6647,
|
38 |
-
7273, 9061, 9383, 10428, 10929, 11938, 12033, 12331, 12562, 13793,
|
39 |
-
14157, 14635, 15265, 15618, 16553, 16604, 18362, 18956, 20075, 21675,
|
40 |
-
22520, 26130, 26161, 26435, 28279, 29464, 31650, 32302, 32470, 36865,
|
41 |
-
42863, 47425, 49870, 50254, 50258, 50360, 50361, 50362
|
42 |
-
]
|
43 |
-
# fmt: on
|
44 |
-
|
45 |
-
# Copied from transformers.models.whisper.configuration_whisper.WhisperConfig
|
46 |
-
class MERaLiONSpeechConfig(PretrainedConfig):
|
47 |
-
r"""
|
48 |
-
This is the configuration class to store the configuration of a [`MERaLiONSpeechModel`]. It is used to instantiate a
|
49 |
-
MERaLiONSpeech model according to the specified arguments, defining the model architecture. Instantiating a configuration
|
50 |
-
with the defaults will yield a similar configuration to that of the MERaLiONSpeech
|
51 |
-
[openai/whisper-tiny](https://huggingface.co/openai/whisper-tiny) architecture.
|
52 |
-
|
53 |
-
Configuration objects inherit from [`PretrainedConfig`] and can be used to control the model outputs. Read the
|
54 |
-
documentation from [`PretrainedConfig`] for more information.
|
55 |
-
|
56 |
-
|
57 |
-
Args:
|
58 |
-
vocab_size (`int`, *optional*, defaults to 51865):
|
59 |
-
Vocabulary size of the MERaLiONSpeech model. Defines the number of different tokens that can be represented by the
|
60 |
-
`decoder_input_ids` passed when calling [`MERaLiONSpeechModel`]
|
61 |
-
num_mel_bins (`int`, *optional*, defaults to 80):
|
62 |
-
Number of mel features used per input features. Should correspond to the value used in the
|
63 |
-
`MERaLiONSpeechProcessor` class.
|
64 |
-
encoder_layers (`int`, *optional*, defaults to 4):
|
65 |
-
Number of encoder layers.
|
66 |
-
decoder_layers (`int`, *optional*, defaults to 4):
|
67 |
-
Number of decoder layers.
|
68 |
-
encoder_attention_heads (`int`, *optional*, defaults to 6):
|
69 |
-
Number of attention heads for each attention layer in the Transformer encoder.
|
70 |
-
decoder_attention_heads (`int`, *optional*, defaults to 6):
|
71 |
-
Number of attention heads for each attention layer in the Transformer decoder.
|
72 |
-
encoder_ffn_dim (`int`, *optional*, defaults to 1536):
|
73 |
-
Dimensionality of the "intermediate" (often named feed-forward) layer in encoder.
|
74 |
-
decoder_ffn_dim (`int`, *optional*, defaults to 1536):
|
75 |
-
Dimensionality of the "intermediate" (often named feed-forward) layer in decoder.
|
76 |
-
encoder_layerdrop (`float`, *optional*, defaults to 0.0):
|
77 |
-
The LayerDrop probability for the encoder. See the [LayerDrop paper](see https://arxiv.org/abs/1909.11556)
|
78 |
-
for more details.
|
79 |
-
decoder_layerdrop (`float`, *optional*, defaults to 0.0):
|
80 |
-
The LayerDrop probability for the decoder. See the [LayerDrop paper](see https://arxiv.org/abs/1909.11556)
|
81 |
-
for more details.
|
82 |
-
decoder_start_token_id (`int`, *optional*, defaults to 50257):
|
83 |
-
Corresponds to the "<|startoftranscript|>" token, which is automatically used when no `decoder_input_ids`
|
84 |
-
are provided to the `generate` function. It is used to guide the model`s generation process depending on
|
85 |
-
the task.
|
86 |
-
use_cache (`bool`, *optional*, defaults to `True`):
|
87 |
-
Whether or not the model should return the last key/values attentions (not used by all models).
|
88 |
-
is_encoder_decoder (`bool`, *optional*, defaults to `True`):
|
89 |
-
Whether the model is used as an encoder/decoder or not.
|
90 |
-
activation_function (`str`, *optional*, defaults to `"gelu"`):
|
91 |
-
The non-linear activation function (function or string) in the encoder and pooler. If string, `"gelu"`,
|
92 |
-
`"relu"`, `"silu"` and `"gelu_new"` are supported.
|
93 |
-
d_model (`int`, *optional*, defaults to 384):
|
94 |
-
Dimensionality of the layers.
|
95 |
-
dropout (`float`, *optional*, defaults to 0.1):
|
96 |
-
The dropout probability for all fully connected layers in the embeddings, encoder, and pooler.
|
97 |
-
attention_dropout (`float`, *optional*, defaults to 0.0):
|
98 |
-
The dropout ratio for the attention probabilities.
|
99 |
-
activation_dropout (`float`, *optional*, defaults to 0.0):
|
100 |
-
The dropout ratio for activations inside the fully connected layer.
|
101 |
-
init_std (`float`, *optional*, defaults to 0.02):
|
102 |
-
The standard deviation of the truncated_normal_initializer for initializing all weight matrices.
|
103 |
-
scale_embedding (`bool`, *optional*, defaults to False):
|
104 |
-
Scale embeddings by diving by sqrt(d_model).
|
105 |
-
max_source_positions (`int`, *optional*, defaults to 1500):
|
106 |
-
The maximum sequence length of log-mel filter-bank features that this model might ever be used with.
|
107 |
-
max_target_positions (`int`, *optional*, defaults to 448):
|
108 |
-
The maximum sequence length that this model might ever be used with. Typically set this to something large
|
109 |
-
just in case (e.g., 512 or 1024 or 2048).
|
110 |
-
pad_token_id (`int`, *optional*, defaults to 50256):
|
111 |
-
Padding token id.
|
112 |
-
bos_token_id (`int`, *optional*, defaults to 50256):
|
113 |
-
Begin of stream token id.
|
114 |
-
eos_token_id (`int`, *optional*, defaults to 50256):
|
115 |
-
End of stream token id.
|
116 |
-
suppress_tokens (`List[int]`, *optional*):
|
117 |
-
A list containing the non-speech tokens that will be used by the logit processor in the `generate`
|
118 |
-
function. NON_SPEECH_TOKENS and NON_SPEECH_TOKENS_MULTI each correspond to the `english-only` and the
|
119 |
-
`multilingual` model.
|
120 |
-
begin_suppress_tokens (`List[int]`, *optional*, defaults to `[220,50256]`):
|
121 |
-
A list containing tokens that will be supressed at the beginning of the sampling process. Initialized as
|
122 |
-
the token for `" "` (`blank_token_id`) and the `eos_token_id`
|
123 |
-
use_weighted_layer_sum (`bool`, *optional*, defaults to `False`):
|
124 |
-
Whether to use a weighted average of layer outputs with learned weights. Only relevant when using an
|
125 |
-
instance of [`MERaLiONSpeechForAudioClassification`].
|
126 |
-
classifier_proj_size (`int`, *optional*, defaults to 256):
|
127 |
-
Dimensionality of the projection before token mean-pooling for classification. Only relevant when using an
|
128 |
-
instance of [`MERaLiONSpeechForAudioClassification`].
|
129 |
-
apply_spec_augment (`bool`, *optional*, defaults to `False`):
|
130 |
-
Whether to apply *SpecAugment* data augmentation to the outputs of the feature encoder. For reference see
|
131 |
-
[SpecAugment: A Simple Data Augmentation Method for Automatic Speech
|
132 |
-
Recognition](https://arxiv.org/abs/1904.08779).
|
133 |
-
mask_time_prob (`float`, *optional*, defaults to 0.05):
|
134 |
-
Percentage (between 0 and 1) of all feature vectors along the time axis which will be masked. The masking
|
135 |
-
procecure generates `mask_time_prob*len(time_axis)/mask_time_length` independent masks over the axis. If
|
136 |
-
reasoning from the propability of each feature vector to be chosen as the start of the vector span to be
|
137 |
-
masked, *mask_time_prob* should be `prob_vector_start*mask_time_length`. Note that overlap may decrease the
|
138 |
-
actual percentage of masked vectors. This is only relevant if `apply_spec_augment == True`.
|
139 |
-
mask_time_length (`int`, *optional*, defaults to 10):
|
140 |
-
Length of vector span along the time axis.
|
141 |
-
mask_time_min_masks (`int`, *optional*, defaults to 2),:
|
142 |
-
The minimum number of masks of length `mask_feature_length` generated along the time axis, each time step,
|
143 |
-
irrespectively of `mask_feature_prob`. Only relevant if ''mask_time_prob*len(time_axis)/mask_time_length <
|
144 |
-
mask_time_min_masks''
|
145 |
-
mask_feature_prob (`float`, *optional*, defaults to 0.0):
|
146 |
-
Percentage (between 0 and 1) of all feature vectors along the feature axis which will be masked. The
|
147 |
-
masking procecure generates `mask_feature_prob*len(feature_axis)/mask_time_length` independent masks over
|
148 |
-
the axis. If reasoning from the propability of each feature vector to be chosen as the start of the vector
|
149 |
-
span to be masked, *mask_feature_prob* should be `prob_vector_start*mask_feature_length`. Note that overlap
|
150 |
-
may decrease the actual percentage of masked vectors. This is only relevant if `apply_spec_augment is
|
151 |
-
True`.
|
152 |
-
mask_feature_length (`int`, *optional*, defaults to 10):
|
153 |
-
Length of vector span along the feature axis.
|
154 |
-
mask_feature_min_masks (`int`, *optional*, defaults to 0),:
|
155 |
-
The minimum number of masks of length `mask_feature_length` generated along the feature axis, each time
|
156 |
-
step, irrespectively of `mask_feature_prob`. Only relevant if
|
157 |
-
`mask_feature_prob*len(feature_axis)/mask_feature_length < mask_feature_min_masks`.
|
158 |
-
median_filter_width (`int`, *optional*, defaults to 7):
|
159 |
-
Width of the median filter used to smoothen to cross-attention outputs when computing token timestamps.
|
160 |
-
Should be an odd number.
|
161 |
-
"""
|
162 |
-
|
163 |
-
model_type = "meralion_speech_encoder"
|
164 |
-
keys_to_ignore_at_inference = ["past_key_values"]
|
165 |
-
attribute_map = {
|
166 |
-
"num_key_value_heads": "encoder_attention_heads",
|
167 |
-
"num_attention_heads": "encoder_attention_heads",
|
168 |
-
"hidden_size": "d_model",
|
169 |
-
}
|
170 |
-
|
171 |
-
def __init__(
|
172 |
-
self,
|
173 |
-
vocab_size=51865,
|
174 |
-
num_mel_bins=80,
|
175 |
-
encoder_layers=4,
|
176 |
-
encoder_attention_heads=6,
|
177 |
-
decoder_layers=4,
|
178 |
-
decoder_attention_heads=6,
|
179 |
-
decoder_ffn_dim=1536,
|
180 |
-
encoder_ffn_dim=1536,
|
181 |
-
encoder_layerdrop=0.0,
|
182 |
-
decoder_layerdrop=0.0,
|
183 |
-
decoder_start_token_id=50257,
|
184 |
-
use_cache=True,
|
185 |
-
is_encoder_decoder=True,
|
186 |
-
activation_function="gelu",
|
187 |
-
d_model=384,
|
188 |
-
dropout=0.0,
|
189 |
-
attention_dropout=0.0,
|
190 |
-
activation_dropout=0.0,
|
191 |
-
init_std=0.02,
|
192 |
-
scale_embedding=False,
|
193 |
-
max_source_positions=1500,
|
194 |
-
max_target_positions=448,
|
195 |
-
pad_token_id=50256,
|
196 |
-
bos_token_id=50256,
|
197 |
-
eos_token_id=50256,
|
198 |
-
suppress_tokens=None,
|
199 |
-
begin_suppress_tokens=[220, 50256],
|
200 |
-
use_weighted_layer_sum=False,
|
201 |
-
classifier_proj_size=256,
|
202 |
-
apply_spec_augment=False,
|
203 |
-
mask_time_prob=0.05,
|
204 |
-
mask_time_length=10,
|
205 |
-
mask_time_min_masks=2,
|
206 |
-
mask_feature_prob=0.0,
|
207 |
-
mask_feature_length=10,
|
208 |
-
mask_feature_min_masks=0,
|
209 |
-
median_filter_width=7,
|
210 |
-
**kwargs,
|
211 |
-
):
|
212 |
-
self.vocab_size = vocab_size
|
213 |
-
self.num_mel_bins = num_mel_bins
|
214 |
-
self.d_model = d_model
|
215 |
-
self.encoder_layers = encoder_layers
|
216 |
-
self.encoder_attention_heads = encoder_attention_heads
|
217 |
-
self.decoder_layers = decoder_layers
|
218 |
-
self.decoder_attention_heads = decoder_attention_heads
|
219 |
-
self.decoder_ffn_dim = decoder_ffn_dim
|
220 |
-
self.encoder_ffn_dim = encoder_ffn_dim
|
221 |
-
self.dropout = dropout
|
222 |
-
self.attention_dropout = attention_dropout
|
223 |
-
self.activation_dropout = activation_dropout
|
224 |
-
self.activation_function = activation_function
|
225 |
-
self.init_std = init_std
|
226 |
-
self.encoder_layerdrop = encoder_layerdrop
|
227 |
-
self.decoder_layerdrop = decoder_layerdrop
|
228 |
-
self.use_cache = use_cache
|
229 |
-
self.num_hidden_layers = encoder_layers
|
230 |
-
self.scale_embedding = scale_embedding # scale factor will be sqrt(d_model) if True
|
231 |
-
self.max_source_positions = max_source_positions
|
232 |
-
self.max_target_positions = max_target_positions
|
233 |
-
|
234 |
-
# Audio Classification-specific parameters. Feel free to ignore for other classes.
|
235 |
-
self.classifier_proj_size = classifier_proj_size
|
236 |
-
self.use_weighted_layer_sum = use_weighted_layer_sum
|
237 |
-
|
238 |
-
# fine-tuning config parameters for SpecAugment: https://arxiv.org/abs/1904.08779
|
239 |
-
self.apply_spec_augment = apply_spec_augment
|
240 |
-
self.mask_time_prob = mask_time_prob
|
241 |
-
self.mask_time_length = mask_time_length
|
242 |
-
self.mask_time_min_masks = mask_time_min_masks
|
243 |
-
self.mask_feature_prob = mask_feature_prob
|
244 |
-
self.mask_feature_length = mask_feature_length
|
245 |
-
self.mask_feature_min_masks = mask_feature_min_masks
|
246 |
-
|
247 |
-
self.median_filter_width = median_filter_width
|
248 |
-
|
249 |
-
super().__init__(
|
250 |
-
pad_token_id=pad_token_id,
|
251 |
-
bos_token_id=bos_token_id,
|
252 |
-
eos_token_id=eos_token_id,
|
253 |
-
is_encoder_decoder=is_encoder_decoder,
|
254 |
-
decoder_start_token_id=decoder_start_token_id,
|
255 |
-
suppress_tokens=suppress_tokens,
|
256 |
-
begin_suppress_tokens=begin_suppress_tokens,
|
257 |
-
**kwargs,
|
258 |
-
)
|
259 |
-
@property
|
260 |
-
def inputs(self) -> Mapping[str, Mapping[int, str]]:
|
261 |
-
common_inputs = OrderedDict(
|
262 |
-
[
|
263 |
-
("input_features", {0: "batch", 1: "feature_size", 2: "encoder_sequence"}),
|
264 |
-
]
|
265 |
-
)
|
266 |
-
if self.use_past:
|
267 |
-
common_inputs["decoder_input_ids"] = {0: "batch"}
|
268 |
-
else:
|
269 |
-
common_inputs["decoder_input_ids"] = {0: "batch", 1: "decoder_sequence"}
|
270 |
-
|
271 |
-
if self.use_past:
|
272 |
-
self.fill_with_past_key_values_(common_inputs, direction="inputs")
|
273 |
-
|
274 |
-
return common_inputs
|
275 |
-
|
276 |
-
def generate_dummy_inputs(
|
277 |
-
self,
|
278 |
-
preprocessor: Union["PreTrainedTokenizerBase", "FeatureExtractionMixin"],
|
279 |
-
batch_size: int = -1,
|
280 |
-
seq_length: int = -1,
|
281 |
-
is_pair: bool = False,
|
282 |
-
framework: Optional["TensorType"] = None,
|
283 |
-
sampling_rate: int = 22050,
|
284 |
-
time_duration: float = 5.0,
|
285 |
-
frequency: int = 220,
|
286 |
-
) -> Mapping[str, Any]:
|
287 |
-
dummy_inputs = OrderedDict()
|
288 |
-
encoder_inputs = OnnxConfig.generate_dummy_inputs(
|
289 |
-
self,
|
290 |
-
preprocessor=preprocessor.feature_extractor,
|
291 |
-
batch_size=batch_size,
|
292 |
-
framework=framework,
|
293 |
-
sampling_rate=sampling_rate,
|
294 |
-
time_duration=time_duration,
|
295 |
-
frequency=frequency,
|
296 |
-
)
|
297 |
-
encoder_sequence_length = encoder_inputs["input_features"].shape[2]
|
298 |
-
seq_length = encoder_sequence_length // 2 if self.use_past else seq_length
|
299 |
-
|
300 |
-
decoder_inputs = super().generate_dummy_inputs(
|
301 |
-
preprocessor.tokenizer, batch_size, seq_length, is_pair, framework
|
302 |
-
)
|
303 |
-
|
304 |
-
dummy_inputs["input_features"] = encoder_inputs.pop("input_features")
|
305 |
-
dummy_inputs["decoder_input_ids"] = decoder_inputs.pop("decoder_input_ids")
|
306 |
-
|
307 |
-
if "past_key_values" in decoder_inputs:
|
308 |
-
dummy_inputs["past_key_values"] = decoder_inputs.pop("past_key_values")
|
309 |
-
|
310 |
-
return dummy_inputs
|
311 |
-
|
312 |
-
@property
|
313 |
-
def atol_for_validation(self) -> float:
|
314 |
-
return 1e-3
|
315 |
-
|
316 |
-
|
317 |
-
# Copied from transformers.models.gemma2.configuration_gemma2.Gemma2Config
|
318 |
-
class MERaLiONTextConfig(PretrainedConfig):
|
319 |
-
r"""
|
320 |
-
This is the configuration class to store the configuration of a [`MERaLiONTextModel`]. It is used to instantiate an MERaLiONText
|
321 |
-
model according to the specified arguments, defining the model architecture.
|
322 |
-
Configuration objects inherit from [`PretrainedConfig`] and can be used to control the model outputs. Read the
|
323 |
-
documentation from [`PretrainedConfig`] for more information.
|
324 |
-
Args:
|
325 |
-
vocab_size (`int`, *optional*, defaults to 256000):
|
326 |
-
Vocabulary size of the MERaLiONText model. Defines the number of different tokens that can be represented by the
|
327 |
-
`inputs_ids` passed when calling [`MERaLiONTextModel`]
|
328 |
-
hidden_size (`int`, *optional*, defaults to 3072):
|
329 |
-
Dimension of the hidden representations.
|
330 |
-
intermediate_size (`int`, *optional*, defaults to 24576):
|
331 |
-
Dimension of the MLP representations.
|
332 |
-
num_hidden_layers (`int`, *optional*, defaults to 28):
|
333 |
-
Number of hidden layers in the Transformer decoder.
|
334 |
-
num_attention_heads (`int`, *optional*, defaults to 16):
|
335 |
-
Number of attention heads for each attention layer in the Transformer decoder.
|
336 |
-
num_key_value_heads (`int`, *optional*, defaults to 16):
|
337 |
-
This is the number of key_value heads that should be used to implement Grouped Query Attention. If
|
338 |
-
`num_key_value_heads=num_attention_heads`, the model will use Multi Head Attention (MHA), if
|
339 |
-
`num_key_value_heads=1` the model will use Multi Query Attention (MQA) otherwise GQA is used. When
|
340 |
-
converting a multi-head checkpoint to a GQA checkpoint, each group key and value head should be constructed
|
341 |
-
by meanpooling all the original heads within that group. For more details checkout [this
|
342 |
-
paper](https://arxiv.org/pdf/2305.13245.pdf). If it is not specified, will default to
|
343 |
-
`num_attention_heads`.
|
344 |
-
head_dim (`int`, *optional*, defaults to 256):
|
345 |
-
The attention head dimension.
|
346 |
-
hidden_activation (`str` or `function`, *optional*, defaults to `"gelu_pytorch_tanh"`):
|
347 |
-
The non-linear activation function (function or string) in the decoder. Will default to `"gelu_pytorch_tanh"`
|
348 |
-
if not specified. `"gelu_pytorch_tanh"` uses an approximation of the `"gelu"` activation function.
|
349 |
-
max_position_embeddings (`int`, *optional*, defaults to 8192):
|
350 |
-
The maximum sequence length that this model might ever be used with.
|
351 |
-
initializer_range (`float`, *optional*, defaults to 0.02):
|
352 |
-
The standard deviation of the truncated_normal_initializer for initializing all weight matrices.
|
353 |
-
rms_norm_eps (`float`, *optional*, defaults to 1e-06):
|
354 |
-
The epsilon used by the rms normalization layers.
|
355 |
-
use_cache (`bool`, *optional*, defaults to `True`):
|
356 |
-
Whether or not the model should return the last key/values attentions (not used by all models). Only
|
357 |
-
relevant if `config.is_decoder=True`.
|
358 |
-
pad_token_id (`int`, *optional*, defaults to 0):
|
359 |
-
Padding token id.
|
360 |
-
eos_token_id (`int`, *optional*, defaults to 1):
|
361 |
-
End of stream token id.
|
362 |
-
bos_token_id (`int`, *optional*, defaults to 2):
|
363 |
-
Beginning of stream token id.
|
364 |
-
tie_word_embeddings (`bool`, *optional*, defaults to `True`):
|
365 |
-
Whether to tie weight embeddings
|
366 |
-
rope_theta (`float`, *optional*, defaults to 10000.0):
|
367 |
-
The base period of the RoPE embeddings.
|
368 |
-
attention_bias (`bool`, defaults to `False`, *optional*, defaults to `False`):
|
369 |
-
Whether to use a bias in the query, key, value and output projection layers during self-attention.
|
370 |
-
attention_dropout (`float`, *optional*, defaults to 0.0):
|
371 |
-
The dropout ratio for the attention probabilities.
|
372 |
-
query_pre_attn_scalar (`float`, *optional*, defaults to 224): scaling factor used on the attention scores
|
373 |
-
sliding_window (`int`, *optional*, defaults to 4096): in MERaLiONText, every other layer uses sliding window attention. This is the
|
374 |
-
size of the sliding window.
|
375 |
-
final_logit_softcapping (`float`, *optional*, defaults to 30.0): scaling factor when applying tanh softcapping on the logits.
|
376 |
-
attn_logit_softcapping (`float`, *optional*, defaults to 50.0): scaling factor when applying tanh softcapping on the attention scores.
|
377 |
-
cache_implementation (`str`, *optional*, defaults to `"hybrid"`): the cache type to be used with `generate`.
|
378 |
-
"""
|
379 |
-
|
380 |
-
model_type = "meralion_text_decoder"
|
381 |
-
keys_to_ignore_at_inference = ["past_key_values"]
|
382 |
-
|
383 |
-
def __init__(
|
384 |
-
self,
|
385 |
-
vocab_size=256000,
|
386 |
-
hidden_size=3072,
|
387 |
-
intermediate_size=24576,
|
388 |
-
num_hidden_layers=28,
|
389 |
-
num_attention_heads=16,
|
390 |
-
num_key_value_heads=16,
|
391 |
-
head_dim=256,
|
392 |
-
hidden_activation="gelu_pytorch_tanh",
|
393 |
-
max_position_embeddings=8192,
|
394 |
-
initializer_range=0.02,
|
395 |
-
rms_norm_eps=1e-6,
|
396 |
-
use_cache=True,
|
397 |
-
pad_token_id=0,
|
398 |
-
eos_token_id=1,
|
399 |
-
bos_token_id=2,
|
400 |
-
tie_word_embeddings=True,
|
401 |
-
rope_theta=10000.0,
|
402 |
-
attention_bias=False,
|
403 |
-
attention_dropout=0.0,
|
404 |
-
query_pre_attn_scalar=224,
|
405 |
-
sliding_window=4096,
|
406 |
-
final_logit_softcapping=30.0,
|
407 |
-
attn_logit_softcapping=50.0,
|
408 |
-
cache_implementation="hybrid",
|
409 |
-
**kwargs,
|
410 |
-
):
|
411 |
-
super().__init__(
|
412 |
-
pad_token_id=pad_token_id,
|
413 |
-
bos_token_id=bos_token_id,
|
414 |
-
eos_token_id=eos_token_id,
|
415 |
-
tie_word_embeddings=tie_word_embeddings,
|
416 |
-
**kwargs,
|
417 |
-
)
|
418 |
-
self.vocab_size = vocab_size
|
419 |
-
self.max_position_embeddings = max_position_embeddings
|
420 |
-
self.hidden_size = hidden_size
|
421 |
-
self.intermediate_size = intermediate_size
|
422 |
-
self.num_hidden_layers = num_hidden_layers
|
423 |
-
self.num_attention_heads = num_attention_heads
|
424 |
-
self.head_dim = head_dim
|
425 |
-
self.num_key_value_heads = num_key_value_heads
|
426 |
-
self.initializer_range = initializer_range
|
427 |
-
self.rms_norm_eps = rms_norm_eps
|
428 |
-
self.use_cache = use_cache
|
429 |
-
self.rope_theta = rope_theta
|
430 |
-
self.attention_bias = attention_bias
|
431 |
-
self.attention_dropout = attention_dropout
|
432 |
-
self.hidden_activation = hidden_activation
|
433 |
-
self.query_pre_attn_scalar = query_pre_attn_scalar
|
434 |
-
self.sliding_window = sliding_window
|
435 |
-
self.final_logit_softcapping = final_logit_softcapping
|
436 |
-
self.attn_logit_softcapping = attn_logit_softcapping
|
437 |
-
self.cache_implementation = cache_implementation
|
438 |
-
|
439 |
-
|
440 |
class MERaLiONConfig(PretrainedConfig):
|
441 |
r"""
|
442 |
This is the configuration class to store the configuration of a [`MERaLiONForConditionalGeneration`]. It is used to instantiate an
|
@@ -468,9 +39,9 @@ class MERaLiONConfig(PretrainedConfig):
|
|
468 |
):
|
469 |
|
470 |
if isinstance(speech_config, dict):
|
471 |
-
speech_config =
|
472 |
elif speech_config is None:
|
473 |
-
speech_config =
|
474 |
d_model=1280,
|
475 |
encoder_attention_heads=20,
|
476 |
encoder_ffn_dim=5120,
|
@@ -485,9 +56,9 @@ class MERaLiONConfig(PretrainedConfig):
|
|
485 |
self.speech_config = speech_config
|
486 |
|
487 |
if isinstance(text_config, dict):
|
488 |
-
text_config =
|
489 |
elif text_config is None:
|
490 |
-
text_config =
|
491 |
|
492 |
self.text_config = text_config
|
493 |
|
|
|
1 |
"""MERaLiON AudioLLM model configuration"""
|
2 |
|
3 |
+
from transformers import Gemma2Config, WhisperConfig
|
|
|
|
|
4 |
from transformers.configuration_utils import PretrainedConfig
|
|
|
5 |
from transformers.utils import logging
|
6 |
|
7 |
|
|
|
|
|
|
|
|
|
|
|
|
|
8 |
logger = logging.get_logger(__name__)
|
9 |
|
10 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
11 |
class MERaLiONConfig(PretrainedConfig):
|
12 |
r"""
|
13 |
This is the configuration class to store the configuration of a [`MERaLiONForConditionalGeneration`]. It is used to instantiate an
|
|
|
39 |
):
|
40 |
|
41 |
if isinstance(speech_config, dict):
|
42 |
+
speech_config = WhisperConfig(**speech_config)
|
43 |
elif speech_config is None:
|
44 |
+
speech_config = WhisperConfig(
|
45 |
d_model=1280,
|
46 |
encoder_attention_heads=20,
|
47 |
encoder_ffn_dim=5120,
|
|
|
56 |
self.speech_config = speech_config
|
57 |
|
58 |
if isinstance(text_config, dict):
|
59 |
+
text_config = Gemma2Config(**text_config)
|
60 |
elif text_config is None:
|
61 |
+
text_config = Gemma2Config()
|
62 |
|
63 |
self.text_config = text_config
|
64 |
|