kamahori commited on
Commit
7d96429
·
verified ·
1 Parent(s): 1a1b2d9

Upload LiteWhisperForConditionalGeneration

Browse files
README.md ADDED
@@ -0,0 +1,199 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ library_name: transformers
3
+ tags: []
4
+ ---
5
+
6
+ # Model Card for Model ID
7
+
8
+ <!-- Provide a quick summary of what the model is/does. -->
9
+
10
+
11
+
12
+ ## Model Details
13
+
14
+ ### Model Description
15
+
16
+ <!-- Provide a longer summary of what this model is. -->
17
+
18
+ This is the model card of a 🤗 transformers model that has been pushed on the Hub. This model card has been automatically generated.
19
+
20
+ - **Developed by:** [More Information Needed]
21
+ - **Funded by [optional]:** [More Information Needed]
22
+ - **Shared by [optional]:** [More Information Needed]
23
+ - **Model type:** [More Information Needed]
24
+ - **Language(s) (NLP):** [More Information Needed]
25
+ - **License:** [More Information Needed]
26
+ - **Finetuned from model [optional]:** [More Information Needed]
27
+
28
+ ### Model Sources [optional]
29
+
30
+ <!-- Provide the basic links for the model. -->
31
+
32
+ - **Repository:** [More Information Needed]
33
+ - **Paper [optional]:** [More Information Needed]
34
+ - **Demo [optional]:** [More Information Needed]
35
+
36
+ ## Uses
37
+
38
+ <!-- Address questions around how the model is intended to be used, including the foreseeable users of the model and those affected by the model. -->
39
+
40
+ ### Direct Use
41
+
42
+ <!-- This section is for the model use without fine-tuning or plugging into a larger ecosystem/app. -->
43
+
44
+ [More Information Needed]
45
+
46
+ ### Downstream Use [optional]
47
+
48
+ <!-- This section is for the model use when fine-tuned for a task, or when plugged into a larger ecosystem/app -->
49
+
50
+ [More Information Needed]
51
+
52
+ ### Out-of-Scope Use
53
+
54
+ <!-- This section addresses misuse, malicious use, and uses that the model will not work well for. -->
55
+
56
+ [More Information Needed]
57
+
58
+ ## Bias, Risks, and Limitations
59
+
60
+ <!-- This section is meant to convey both technical and sociotechnical limitations. -->
61
+
62
+ [More Information Needed]
63
+
64
+ ### Recommendations
65
+
66
+ <!-- This section is meant to convey recommendations with respect to the bias, risk, and technical limitations. -->
67
+
68
+ Users (both direct and downstream) should be made aware of the risks, biases and limitations of the model. More information needed for further recommendations.
69
+
70
+ ## How to Get Started with the Model
71
+
72
+ Use the code below to get started with the model.
73
+
74
+ [More Information Needed]
75
+
76
+ ## Training Details
77
+
78
+ ### Training Data
79
+
80
+ <!-- This should link to a Dataset Card, perhaps with a short stub of information on what the training data is all about as well as documentation related to data pre-processing or additional filtering. -->
81
+
82
+ [More Information Needed]
83
+
84
+ ### Training Procedure
85
+
86
+ <!-- This relates heavily to the Technical Specifications. Content here should link to that section when it is relevant to the training procedure. -->
87
+
88
+ #### Preprocessing [optional]
89
+
90
+ [More Information Needed]
91
+
92
+
93
+ #### Training Hyperparameters
94
+
95
+ - **Training regime:** [More Information Needed] <!--fp32, fp16 mixed precision, bf16 mixed precision, bf16 non-mixed precision, fp16 non-mixed precision, fp8 mixed precision -->
96
+
97
+ #### Speeds, Sizes, Times [optional]
98
+
99
+ <!-- This section provides information about throughput, start/end time, checkpoint size if relevant, etc. -->
100
+
101
+ [More Information Needed]
102
+
103
+ ## Evaluation
104
+
105
+ <!-- This section describes the evaluation protocols and provides the results. -->
106
+
107
+ ### Testing Data, Factors & Metrics
108
+
109
+ #### Testing Data
110
+
111
+ <!-- This should link to a Dataset Card if possible. -->
112
+
113
+ [More Information Needed]
114
+
115
+ #### Factors
116
+
117
+ <!-- These are the things the evaluation is disaggregating by, e.g., subpopulations or domains. -->
118
+
119
+ [More Information Needed]
120
+
121
+ #### Metrics
122
+
123
+ <!-- These are the evaluation metrics being used, ideally with a description of why. -->
124
+
125
+ [More Information Needed]
126
+
127
+ ### Results
128
+
129
+ [More Information Needed]
130
+
131
+ #### Summary
132
+
133
+
134
+
135
+ ## Model Examination [optional]
136
+
137
+ <!-- Relevant interpretability work for the model goes here -->
138
+
139
+ [More Information Needed]
140
+
141
+ ## Environmental Impact
142
+
143
+ <!-- Total emissions (in grams of CO2eq) and additional considerations, such as electricity usage, go here. Edit the suggested text below accordingly -->
144
+
145
+ Carbon emissions can be estimated using the [Machine Learning Impact calculator](https://mlco2.github.io/impact#compute) presented in [Lacoste et al. (2019)](https://arxiv.org/abs/1910.09700).
146
+
147
+ - **Hardware Type:** [More Information Needed]
148
+ - **Hours used:** [More Information Needed]
149
+ - **Cloud Provider:** [More Information Needed]
150
+ - **Compute Region:** [More Information Needed]
151
+ - **Carbon Emitted:** [More Information Needed]
152
+
153
+ ## Technical Specifications [optional]
154
+
155
+ ### Model Architecture and Objective
156
+
157
+ [More Information Needed]
158
+
159
+ ### Compute Infrastructure
160
+
161
+ [More Information Needed]
162
+
163
+ #### Hardware
164
+
165
+ [More Information Needed]
166
+
167
+ #### Software
168
+
169
+ [More Information Needed]
170
+
171
+ ## Citation [optional]
172
+
173
+ <!-- If there is a paper or blog post introducing the model, the APA and Bibtex information for that should go in this section. -->
174
+
175
+ **BibTeX:**
176
+
177
+ [More Information Needed]
178
+
179
+ **APA:**
180
+
181
+ [More Information Needed]
182
+
183
+ ## Glossary [optional]
184
+
185
+ <!-- If relevant, include terms and calculations in this section that can help readers understand the model or model card. -->
186
+
187
+ [More Information Needed]
188
+
189
+ ## More Information [optional]
190
+
191
+ [More Information Needed]
192
+
193
+ ## Model Card Authors [optional]
194
+
195
+ [More Information Needed]
196
+
197
+ ## Model Card Contact
198
+
199
+ [More Information Needed]
config.json ADDED
@@ -0,0 +1,305 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "_name_or_path": "efficient-speech/lite-whisper-large-v3-fast",
3
+ "activation_dropout": 0.0,
4
+ "activation_function": "gelu",
5
+ "apply_spec_augment": false,
6
+ "architectures": [
7
+ "LiteWhisperForConditionalGeneration"
8
+ ],
9
+ "attention_dropout": 0.0,
10
+ "auto_map": {
11
+ "AutoConfig": "configuration_lite_whisper.LiteWhisperConfig",
12
+ "AutoModel": "modeling_lite_whisper.LiteWhisperForConditionalGeneration"
13
+ },
14
+ "begin_suppress_tokens": null,
15
+ "bos_token_id": 50257,
16
+ "classifier_proj_size": 256,
17
+ "d_model": 1280,
18
+ "decoder_attention_heads": 20,
19
+ "decoder_ffn_dim": 5120,
20
+ "decoder_layerdrop": 0.0,
21
+ "decoder_layers": 32,
22
+ "decoder_start_token_id": 50258,
23
+ "dropout": 0.0,
24
+ "encoder_attention_heads": 20,
25
+ "encoder_ffn_dim": 5120,
26
+ "encoder_layerdrop": 0.0,
27
+ "encoder_layers": 32,
28
+ "eos_token_id": 50257,
29
+ "init_std": 0.02,
30
+ "is_encoder_decoder": true,
31
+ "low_rank_config": [
32
+ {
33
+ "fc1": 320,
34
+ "fc2": 272,
35
+ "k_proj": 32,
36
+ "out_proj": 32,
37
+ "q_proj": 32,
38
+ "v_proj": 48
39
+ },
40
+ {
41
+ "fc1": 192,
42
+ "fc2": 224,
43
+ "k_proj": 64,
44
+ "out_proj": 112,
45
+ "q_proj": 64,
46
+ "v_proj": 128
47
+ },
48
+ {
49
+ "fc1": 128,
50
+ "fc2": 112,
51
+ "k_proj": 48,
52
+ "out_proj": 160,
53
+ "q_proj": 48,
54
+ "v_proj": 160
55
+ },
56
+ {
57
+ "fc1": 192,
58
+ "fc2": 96,
59
+ "k_proj": 48,
60
+ "out_proj": 160,
61
+ "q_proj": 48,
62
+ "v_proj": 192
63
+ },
64
+ {
65
+ "fc1": 192,
66
+ "fc2": 160,
67
+ "k_proj": 48,
68
+ "out_proj": 144,
69
+ "q_proj": 64,
70
+ "v_proj": 208
71
+ },
72
+ {
73
+ "fc1": 192,
74
+ "fc2": 160,
75
+ "k_proj": 48,
76
+ "out_proj": 144,
77
+ "q_proj": 48,
78
+ "v_proj": 192
79
+ },
80
+ {
81
+ "fc1": 224,
82
+ "fc2": 224,
83
+ "k_proj": 64,
84
+ "out_proj": 208,
85
+ "q_proj": 80,
86
+ "v_proj": 304
87
+ },
88
+ {
89
+ "fc1": 240,
90
+ "fc2": 432,
91
+ "k_proj": 80,
92
+ "out_proj": 208,
93
+ "q_proj": 96,
94
+ "v_proj": 256
95
+ },
96
+ {
97
+ "fc1": 288,
98
+ "fc2": 512,
99
+ "k_proj": 80,
100
+ "out_proj": 224,
101
+ "q_proj": 96,
102
+ "v_proj": 288
103
+ },
104
+ {
105
+ "fc1": 288,
106
+ "fc2": 512,
107
+ "k_proj": 80,
108
+ "out_proj": 224,
109
+ "q_proj": 96,
110
+ "v_proj": 288
111
+ },
112
+ {
113
+ "fc1": 320,
114
+ "fc2": 528,
115
+ "k_proj": 48,
116
+ "out_proj": 240,
117
+ "q_proj": 64,
118
+ "v_proj": 288
119
+ },
120
+ {
121
+ "fc1": 320,
122
+ "fc2": 528,
123
+ "k_proj": 64,
124
+ "out_proj": 224,
125
+ "q_proj": 80,
126
+ "v_proj": 320
127
+ },
128
+ {
129
+ "fc1": 352,
130
+ "fc2": 592,
131
+ "k_proj": 64,
132
+ "out_proj": 224,
133
+ "q_proj": 64,
134
+ "v_proj": 352
135
+ },
136
+ {
137
+ "fc1": 400,
138
+ "fc2": 688,
139
+ "k_proj": 48,
140
+ "out_proj": 240,
141
+ "q_proj": 64,
142
+ "v_proj": 288
143
+ },
144
+ {
145
+ "fc1": 480,
146
+ "fc2": 656,
147
+ "k_proj": 64,
148
+ "out_proj": 256,
149
+ "q_proj": 80,
150
+ "v_proj": 448
151
+ },
152
+ {
153
+ "fc1": 384,
154
+ "fc2": 768,
155
+ "k_proj": 48,
156
+ "out_proj": 256,
157
+ "q_proj": 48,
158
+ "v_proj": 432
159
+ },
160
+ {
161
+ "fc1": 400,
162
+ "fc2": 800,
163
+ "k_proj": 48,
164
+ "out_proj": 224,
165
+ "q_proj": 64,
166
+ "v_proj": 272
167
+ },
168
+ {
169
+ "fc1": 464,
170
+ "fc2": 784,
171
+ "k_proj": 80,
172
+ "out_proj": 288,
173
+ "q_proj": 96,
174
+ "v_proj": 368
175
+ },
176
+ {
177
+ "fc1": 512,
178
+ "fc2": 848,
179
+ "k_proj": 64,
180
+ "out_proj": 256,
181
+ "q_proj": 80,
182
+ "v_proj": 304
183
+ },
184
+ {
185
+ "fc1": 528,
186
+ "fc2": 752,
187
+ "k_proj": 80,
188
+ "out_proj": 272,
189
+ "q_proj": 80,
190
+ "v_proj": 416
191
+ },
192
+ {
193
+ "fc1": 400,
194
+ "fc2": 16,
195
+ "k_proj": 80,
196
+ "out_proj": 352,
197
+ "q_proj": 96,
198
+ "v_proj": 432
199
+ },
200
+ {
201
+ "fc1": 672,
202
+ "fc2": 960,
203
+ "k_proj": 96,
204
+ "out_proj": 336,
205
+ "q_proj": 112,
206
+ "v_proj": 448
207
+ },
208
+ {
209
+ "fc1": 640,
210
+ "fc2": 976,
211
+ "k_proj": 112,
212
+ "out_proj": 448,
213
+ "q_proj": 144,
214
+ "v_proj": 544
215
+ },
216
+ {
217
+ "fc1": 720,
218
+ "k_proj": 96,
219
+ "out_proj": 416,
220
+ "q_proj": 128,
221
+ "v_proj": 464
222
+ },
223
+ {
224
+ "fc1": 752,
225
+ "k_proj": 128,
226
+ "out_proj": 448,
227
+ "q_proj": 176,
228
+ "v_proj": 560
229
+ },
230
+ {
231
+ "fc1": 752,
232
+ "k_proj": 128,
233
+ "out_proj": 416,
234
+ "q_proj": 176,
235
+ "v_proj": 592
236
+ },
237
+ {
238
+ "fc1": 848,
239
+ "k_proj": 144,
240
+ "out_proj": 496,
241
+ "q_proj": 192,
242
+ "v_proj": 624
243
+ },
244
+ {
245
+ "fc1": 912,
246
+ "fc2": 1024,
247
+ "k_proj": 128,
248
+ "out_proj": 400,
249
+ "q_proj": 192,
250
+ "v_proj": 608
251
+ },
252
+ {
253
+ "fc1": 944,
254
+ "fc2": 944,
255
+ "k_proj": 144,
256
+ "out_proj": 448,
257
+ "q_proj": 208,
258
+ "v_proj": 592
259
+ },
260
+ {
261
+ "fc1": 960,
262
+ "fc2": 976,
263
+ "k_proj": 176,
264
+ "out_proj": 496,
265
+ "q_proj": 272,
266
+ "v_proj": 560
267
+ },
268
+ {
269
+ "fc1": 896,
270
+ "fc2": 992,
271
+ "k_proj": 192,
272
+ "out_proj": 464,
273
+ "q_proj": 272,
274
+ "v_proj": 560
275
+ },
276
+ {
277
+ "fc1": 800,
278
+ "fc2": 736,
279
+ "k_proj": 176,
280
+ "out_proj": 464,
281
+ "q_proj": 272,
282
+ "v_proj": 432
283
+ }
284
+ ],
285
+ "mask_feature_length": 10,
286
+ "mask_feature_min_masks": 0,
287
+ "mask_feature_prob": 0.0,
288
+ "mask_time_length": 10,
289
+ "mask_time_min_masks": 2,
290
+ "mask_time_prob": 0.05,
291
+ "max_length": null,
292
+ "max_source_positions": 1500,
293
+ "max_target_positions": 448,
294
+ "median_filter_width": 7,
295
+ "model_type": "lite-whisper",
296
+ "num_hidden_layers": 32,
297
+ "num_mel_bins": 128,
298
+ "pad_token_id": 50256,
299
+ "scale_embedding": false,
300
+ "torch_dtype": "float32",
301
+ "transformers_version": "4.46.3",
302
+ "use_cache": true,
303
+ "use_weighted_layer_sum": false,
304
+ "vocab_size": 51866
305
+ }
configuration_lite_whisper.py ADDED
@@ -0,0 +1,12 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from transformers import WhisperConfig
2
+
3
+ class LiteWhisperConfig(WhisperConfig):
4
+ model_type = "lite-whisper"
5
+
6
+ def __init__(
7
+ self,
8
+ low_rank_config: list[dict[str, int]] = None,
9
+ **kwargs,
10
+ ):
11
+ super().__init__(**kwargs)
12
+ self.low_rank_config = low_rank_config
generation_config.json ADDED
@@ -0,0 +1,13 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "_from_model_config": true,
3
+ "begin_suppress_tokens": [
4
+ 220,
5
+ 50257
6
+ ],
7
+ "bos_token_id": 50257,
8
+ "decoder_start_token_id": 50258,
9
+ "eos_token_id": 50257,
10
+ "max_length": 448,
11
+ "pad_token_id": 50256,
12
+ "transformers_version": "4.46.3"
13
+ }
model-00001-of-00002.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:8f8cc9ce658ae80282bbfaa955b39638d5702883f24951e2e630bf7fba97183c
3
+ size 4864811592
model-00002-of-00002.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:30152e675fb2a99e1a7a5af859fadc21f8546a0fd04c6536a31959898869ef43
3
+ size 265554048
model.safetensors.index.json ADDED
The diff for this file is too large to render. See raw diff
 
modeling_lite_whisper.py ADDED
@@ -0,0 +1,79 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import torch
2
+ import torch.utils.checkpoint
3
+ from torch import nn
4
+ from transformers.models.whisper.configuration_whisper import WhisperConfig
5
+ from transformers.models.whisper.modeling_whisper import (
6
+ WhisperEncoderLayer,
7
+ WhisperEncoder,
8
+ WhisperModel,
9
+ WhisperForConditionalGeneration,
10
+ )
11
+
12
+ from .configuration_lite_whisper import LiteWhisperConfig
13
+
14
+
15
+ class LinearLowRank(nn.Module):
16
+ def __init__(
17
+ self,
18
+ in_features: int,
19
+ out_features: int,
20
+ low_rank_features: int,
21
+ ):
22
+ super().__init__()
23
+
24
+ self.weight1 = nn.Parameter(torch.randn(in_features, low_rank_features))
25
+ self.weight2 = nn.Parameter(torch.randn(low_rank_features, out_features))
26
+ self.bias = nn.Parameter(torch.zeros(out_features))
27
+
28
+ def forward(self, x: torch.Tensor) -> torch.Tensor:
29
+ return (x @ self.weight1) @ self.weight2 + self.bias
30
+
31
+
32
+ class LiteWhisperEncoderLayer(WhisperEncoderLayer):
33
+ def __init__(self, config: WhisperConfig, low_rank_config: dict[str, int]):
34
+ super().__init__(config)
35
+
36
+ if "k_proj" in low_rank_config:
37
+ self.self_attn.k_proj = LinearLowRank(self.embed_dim, self.embed_dim, low_rank_config["k_proj"])
38
+
39
+ if "v_proj" in low_rank_config:
40
+ self.self_attn.v_proj = LinearLowRank(self.embed_dim, self.embed_dim, low_rank_config["v_proj"])
41
+
42
+ if "q_proj" in low_rank_config:
43
+ self.self_attn.q_proj = LinearLowRank(self.embed_dim, self.embed_dim, low_rank_config["q_proj"])
44
+
45
+ if "out_proj" in low_rank_config:
46
+ self.self_attn.out_proj = LinearLowRank(self.embed_dim, self.embed_dim, low_rank_config["out_proj"])
47
+
48
+ if "fc1" in low_rank_config:
49
+ self.fc1 = LinearLowRank(self.embed_dim, config.encoder_ffn_dim, low_rank_config["fc1"])
50
+
51
+ if "fc2" in low_rank_config:
52
+ self.fc2 = LinearLowRank(config.encoder_ffn_dim, self.embed_dim, low_rank_config["fc2"])
53
+
54
+
55
+ class LiteWhisperEncoder(WhisperEncoder):
56
+ def __init__(self, config: WhisperConfig, low_rank_config: list[dict[str, int]]):
57
+ super().__init__(config)
58
+
59
+ self.layers = nn.ModuleList([
60
+ LiteWhisperEncoderLayer(config, low_rank_config[i])
61
+ for i in range(config.encoder_layers)
62
+ ])
63
+
64
+
65
+ class LiteWhisperModel(WhisperModel):
66
+ def __init__(self, config: WhisperConfig, low_rank_config: list[dict[str, int]]):
67
+ super().__init__(config)
68
+
69
+ self.encoder = LiteWhisperEncoder(config, low_rank_config)
70
+
71
+
72
+ class LiteWhisperForConditionalGeneration(WhisperForConditionalGeneration):
73
+ config_class = LiteWhisperConfig
74
+
75
+ def __init__(self, config: LiteWhisperConfig):
76
+ low_rank_config = getattr(config, "low_rank_config", None)
77
+
78
+ super().__init__(config)
79
+ self.model = LiteWhisperModel(config, low_rank_config)