kamahori commited on
Commit
f51396d
·
verified ·
1 Parent(s): 2feec39

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,285 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "_name_or_path": "efficient-speech/lite-whisper-large-v3",
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": 368,
34
+ "fc2": 368,
35
+ "k_proj": 32,
36
+ "out_proj": 32,
37
+ "q_proj": 32,
38
+ "v_proj": 48
39
+ },
40
+ {
41
+ "fc1": 272,
42
+ "fc2": 352,
43
+ "k_proj": 64,
44
+ "out_proj": 112,
45
+ "q_proj": 64,
46
+ "v_proj": 128
47
+ },
48
+ {
49
+ "fc1": 224,
50
+ "fc2": 224,
51
+ "k_proj": 48,
52
+ "out_proj": 160,
53
+ "q_proj": 48,
54
+ "v_proj": 160
55
+ },
56
+ {
57
+ "fc1": 288,
58
+ "fc2": 208,
59
+ "k_proj": 48,
60
+ "out_proj": 160,
61
+ "q_proj": 48,
62
+ "v_proj": 192
63
+ },
64
+ {
65
+ "fc1": 304,
66
+ "fc2": 320,
67
+ "k_proj": 48,
68
+ "out_proj": 144,
69
+ "q_proj": 64,
70
+ "v_proj": 208
71
+ },
72
+ {
73
+ "fc1": 304,
74
+ "fc2": 304,
75
+ "k_proj": 48,
76
+ "out_proj": 144,
77
+ "q_proj": 48,
78
+ "v_proj": 192
79
+ },
80
+ {
81
+ "fc1": 352,
82
+ "fc2": 400,
83
+ "k_proj": 64,
84
+ "out_proj": 208,
85
+ "q_proj": 80,
86
+ "v_proj": 304
87
+ },
88
+ {
89
+ "fc1": 384,
90
+ "fc2": 656,
91
+ "k_proj": 80,
92
+ "out_proj": 208,
93
+ "q_proj": 96,
94
+ "v_proj": 256
95
+ },
96
+ {
97
+ "fc1": 464,
98
+ "fc2": 752,
99
+ "k_proj": 80,
100
+ "out_proj": 224,
101
+ "q_proj": 96,
102
+ "v_proj": 288
103
+ },
104
+ {
105
+ "fc1": 464,
106
+ "fc2": 752,
107
+ "k_proj": 80,
108
+ "out_proj": 224,
109
+ "q_proj": 96,
110
+ "v_proj": 288
111
+ },
112
+ {
113
+ "fc1": 528,
114
+ "fc2": 768,
115
+ "k_proj": 48,
116
+ "out_proj": 240,
117
+ "q_proj": 64,
118
+ "v_proj": 288
119
+ },
120
+ {
121
+ "fc1": 528,
122
+ "fc2": 768,
123
+ "k_proj": 64,
124
+ "out_proj": 224,
125
+ "q_proj": 80,
126
+ "v_proj": 320
127
+ },
128
+ {
129
+ "fc1": 560,
130
+ "fc2": 864,
131
+ "k_proj": 64,
132
+ "out_proj": 224,
133
+ "q_proj": 64,
134
+ "v_proj": 352
135
+ },
136
+ {
137
+ "fc1": 624,
138
+ "fc2": 960,
139
+ "k_proj": 48,
140
+ "out_proj": 240,
141
+ "q_proj": 64,
142
+ "v_proj": 288
143
+ },
144
+ {
145
+ "fc1": 720,
146
+ "fc2": 944,
147
+ "k_proj": 64,
148
+ "out_proj": 256,
149
+ "q_proj": 80,
150
+ "v_proj": 448
151
+ },
152
+ {
153
+ "fc1": 624,
154
+ "k_proj": 48,
155
+ "out_proj": 256,
156
+ "q_proj": 48,
157
+ "v_proj": 432
158
+ },
159
+ {
160
+ "fc1": 656,
161
+ "k_proj": 48,
162
+ "out_proj": 224,
163
+ "q_proj": 64,
164
+ "v_proj": 272
165
+ },
166
+ {
167
+ "fc1": 736,
168
+ "k_proj": 80,
169
+ "out_proj": 288,
170
+ "q_proj": 96,
171
+ "v_proj": 368
172
+ },
173
+ {
174
+ "fc1": 784,
175
+ "k_proj": 64,
176
+ "out_proj": 256,
177
+ "q_proj": 80,
178
+ "v_proj": 304
179
+ },
180
+ {
181
+ "fc1": 832,
182
+ "k_proj": 80,
183
+ "out_proj": 272,
184
+ "q_proj": 80,
185
+ "v_proj": 416
186
+ },
187
+ {
188
+ "fc1": 720,
189
+ "fc2": 16,
190
+ "k_proj": 80,
191
+ "out_proj": 352,
192
+ "q_proj": 96,
193
+ "v_proj": 432
194
+ },
195
+ {
196
+ "fc1": 960,
197
+ "k_proj": 96,
198
+ "out_proj": 336,
199
+ "q_proj": 112,
200
+ "v_proj": 448
201
+ },
202
+ {
203
+ "fc1": 960,
204
+ "k_proj": 112,
205
+ "out_proj": 448,
206
+ "q_proj": 144,
207
+ "v_proj": 544
208
+ },
209
+ {
210
+ "fc1": 1008,
211
+ "k_proj": 96,
212
+ "out_proj": 416,
213
+ "q_proj": 128,
214
+ "v_proj": 464
215
+ },
216
+ {
217
+ "k_proj": 128,
218
+ "out_proj": 448,
219
+ "q_proj": 176,
220
+ "v_proj": 560
221
+ },
222
+ {
223
+ "k_proj": 128,
224
+ "out_proj": 416,
225
+ "q_proj": 176,
226
+ "v_proj": 592
227
+ },
228
+ {
229
+ "k_proj": 144,
230
+ "out_proj": 496,
231
+ "q_proj": 192,
232
+ "v_proj": 624
233
+ },
234
+ {
235
+ "k_proj": 128,
236
+ "out_proj": 400,
237
+ "q_proj": 192,
238
+ "v_proj": 608
239
+ },
240
+ {
241
+ "k_proj": 144,
242
+ "out_proj": 448,
243
+ "q_proj": 208,
244
+ "v_proj": 592
245
+ },
246
+ {
247
+ "k_proj": 176,
248
+ "out_proj": 496,
249
+ "q_proj": 272,
250
+ "v_proj": 560
251
+ },
252
+ {
253
+ "k_proj": 192,
254
+ "out_proj": 464,
255
+ "q_proj": 272,
256
+ "v_proj": 560
257
+ },
258
+ {
259
+ "k_proj": 176,
260
+ "out_proj": 464,
261
+ "q_proj": 272,
262
+ "v_proj": 432
263
+ }
264
+ ],
265
+ "mask_feature_length": 10,
266
+ "mask_feature_min_masks": 0,
267
+ "mask_feature_prob": 0.0,
268
+ "mask_time_length": 10,
269
+ "mask_time_min_masks": 2,
270
+ "mask_time_prob": 0.05,
271
+ "max_length": null,
272
+ "max_source_positions": 1500,
273
+ "max_target_positions": 448,
274
+ "median_filter_width": 7,
275
+ "model_type": "lite-whisper",
276
+ "num_hidden_layers": 32,
277
+ "num_mel_bins": 128,
278
+ "pad_token_id": 50256,
279
+ "scale_embedding": false,
280
+ "torch_dtype": "float32",
281
+ "transformers_version": "4.46.3",
282
+ "use_cache": true,
283
+ "use_weighted_layer_sum": false,
284
+ "vocab_size": 51866
285
+ }
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:3d547bb5c3f8321c3fdc0854d69d3fc3cf1ab74a11ea0849c57ee92576e740fd
3
+ size 4984275648
model-00002-of-00002.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:e5668cd5111b01f540959d42b8214e1a62df8f51f05f662a9da4b6ddcfe5f3d8
3
+ size 422977232
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)