eyoel-gebre commited on
Commit
ee30d36
·
verified ·
1 Parent(s): bc44c07

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,241 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "_name_or_path": "efficient-speech/lite-whisper-medium-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": 1024,
18
+ "decoder_attention_heads": 16,
19
+ "decoder_ffn_dim": 4096,
20
+ "decoder_layerdrop": 0.0,
21
+ "decoder_layers": 24,
22
+ "decoder_start_token_id": 50258,
23
+ "dropout": 0.0,
24
+ "encoder_attention_heads": 16,
25
+ "encoder_ffn_dim": 4096,
26
+ "encoder_layerdrop": 0.0,
27
+ "encoder_layers": 24,
28
+ "eos_token_id": 50257,
29
+ "forced_decoder_ids": [
30
+ [
31
+ 1,
32
+ 50259
33
+ ],
34
+ [
35
+ 2,
36
+ 50359
37
+ ],
38
+ [
39
+ 3,
40
+ 50363
41
+ ]
42
+ ],
43
+ "init_std": 0.02,
44
+ "is_encoder_decoder": true,
45
+ "low_rank_config": [
46
+ {
47
+ "fc1": 208,
48
+ "fc2": 240,
49
+ "k_proj": 48,
50
+ "out_proj": 80,
51
+ "q_proj": 48,
52
+ "v_proj": 128
53
+ },
54
+ {
55
+ "fc1": 256,
56
+ "fc2": 288,
57
+ "k_proj": 80,
58
+ "out_proj": 176,
59
+ "q_proj": 96,
60
+ "v_proj": 240
61
+ },
62
+ {
63
+ "fc1": 272,
64
+ "fc2": 560,
65
+ "k_proj": 80,
66
+ "out_proj": 224,
67
+ "q_proj": 96,
68
+ "v_proj": 208
69
+ },
70
+ {
71
+ "fc1": 288,
72
+ "fc2": 544,
73
+ "k_proj": 80,
74
+ "out_proj": 240,
75
+ "q_proj": 96,
76
+ "v_proj": 256
77
+ },
78
+ {
79
+ "fc1": 336,
80
+ "fc2": 624,
81
+ "k_proj": 112,
82
+ "out_proj": 224,
83
+ "q_proj": 144,
84
+ "v_proj": 288
85
+ },
86
+ {
87
+ "fc1": 448,
88
+ "fc2": 688,
89
+ "k_proj": 128,
90
+ "out_proj": 304,
91
+ "q_proj": 160,
92
+ "v_proj": 368
93
+ },
94
+ {
95
+ "fc1": 528,
96
+ "fc2": 480,
97
+ "k_proj": 176,
98
+ "out_proj": 320,
99
+ "q_proj": 240,
100
+ "v_proj": 416
101
+ },
102
+ {
103
+ "fc1": 272,
104
+ "fc2": 16,
105
+ "k_proj": 160,
106
+ "out_proj": 320,
107
+ "q_proj": 224,
108
+ "v_proj": 400
109
+ },
110
+ {
111
+ "fc1": 544,
112
+ "fc2": 608,
113
+ "k_proj": 144,
114
+ "out_proj": 336,
115
+ "q_proj": 208,
116
+ "v_proj": 416
117
+ },
118
+ {
119
+ "fc1": 576,
120
+ "fc2": 592,
121
+ "k_proj": 176,
122
+ "out_proj": 304,
123
+ "q_proj": 240,
124
+ "v_proj": 400
125
+ },
126
+ {
127
+ "fc1": 640,
128
+ "fc2": 464,
129
+ "k_proj": 144,
130
+ "out_proj": 240,
131
+ "q_proj": 208,
132
+ "v_proj": 368
133
+ },
134
+ {
135
+ "fc1": 688,
136
+ "fc2": 768,
137
+ "k_proj": 208,
138
+ "out_proj": 288,
139
+ "q_proj": 272,
140
+ "v_proj": 416
141
+ },
142
+ {
143
+ "fc1": 736,
144
+ "fc2": 768,
145
+ "k_proj": 240,
146
+ "out_proj": 336,
147
+ "q_proj": 288,
148
+ "v_proj": 464
149
+ },
150
+ {
151
+ "fc1": 736,
152
+ "k_proj": 224,
153
+ "out_proj": 320,
154
+ "q_proj": 288,
155
+ "v_proj": 448
156
+ },
157
+ {
158
+ "fc1": 720,
159
+ "k_proj": 256,
160
+ "out_proj": 336,
161
+ "q_proj": 320,
162
+ "v_proj": 480
163
+ },
164
+ {
165
+ "fc1": 768,
166
+ "k_proj": 272,
167
+ "out_proj": 352,
168
+ "q_proj": 336,
169
+ "v_proj": 480
170
+ },
171
+ {
172
+ "fc1": 816,
173
+ "k_proj": 272,
174
+ "out_proj": 320,
175
+ "q_proj": 320,
176
+ "v_proj": 496
177
+ },
178
+ {
179
+ "k_proj": 368,
180
+ "out_proj": 400,
181
+ "q_proj": 432
182
+ },
183
+ {
184
+ "k_proj": 224,
185
+ "out_proj": 384,
186
+ "q_proj": 320
187
+ },
188
+ {
189
+ "k_proj": 272,
190
+ "out_proj": 432,
191
+ "q_proj": 352
192
+ },
193
+ {
194
+ "k_proj": 368,
195
+ "out_proj": 368,
196
+ "q_proj": 432,
197
+ "v_proj": 512
198
+ },
199
+ {
200
+ "k_proj": 336,
201
+ "out_proj": 368,
202
+ "q_proj": 416,
203
+ "v_proj": 480
204
+ },
205
+ {
206
+ "fc2": 816,
207
+ "k_proj": 208,
208
+ "out_proj": 288,
209
+ "q_proj": 304,
210
+ "v_proj": 352
211
+ },
212
+ {
213
+ "fc1": 800,
214
+ "fc2": 784,
215
+ "k_proj": 288,
216
+ "out_proj": 320,
217
+ "q_proj": 384,
218
+ "v_proj": 400
219
+ }
220
+ ],
221
+ "mask_feature_length": 10,
222
+ "mask_feature_min_masks": 0,
223
+ "mask_feature_prob": 0.0,
224
+ "mask_time_length": 10,
225
+ "mask_time_min_masks": 2,
226
+ "mask_time_prob": 0.05,
227
+ "max_length": null,
228
+ "max_source_positions": 1500,
229
+ "max_target_positions": 448,
230
+ "median_filter_width": 7,
231
+ "model_type": "lite-whisper",
232
+ "num_hidden_layers": 24,
233
+ "num_mel_bins": 80,
234
+ "pad_token_id": 50257,
235
+ "scale_embedding": false,
236
+ "torch_dtype": "float32",
237
+ "transformers_version": "4.49.0",
238
+ "use_cache": true,
239
+ "use_weighted_layer_sum": false,
240
+ "vocab_size": 51865
241
+ }
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,117 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ "forced_decoder_ids": [
11
+ [
12
+ 1,
13
+ 50259
14
+ ],
15
+ [
16
+ 2,
17
+ 50359
18
+ ],
19
+ [
20
+ 3,
21
+ 50363
22
+ ]
23
+ ],
24
+ "max_length": 448,
25
+ "pad_token_id": 50257,
26
+ "suppress_tokens": [
27
+ 1,
28
+ 2,
29
+ 7,
30
+ 8,
31
+ 9,
32
+ 10,
33
+ 14,
34
+ 25,
35
+ 26,
36
+ 27,
37
+ 28,
38
+ 29,
39
+ 31,
40
+ 58,
41
+ 59,
42
+ 60,
43
+ 61,
44
+ 62,
45
+ 63,
46
+ 90,
47
+ 91,
48
+ 92,
49
+ 93,
50
+ 359,
51
+ 503,
52
+ 522,
53
+ 542,
54
+ 873,
55
+ 893,
56
+ 902,
57
+ 918,
58
+ 922,
59
+ 931,
60
+ 1350,
61
+ 1853,
62
+ 1982,
63
+ 2460,
64
+ 2627,
65
+ 3246,
66
+ 3253,
67
+ 3268,
68
+ 3536,
69
+ 3846,
70
+ 3961,
71
+ 4183,
72
+ 4667,
73
+ 6585,
74
+ 6647,
75
+ 7273,
76
+ 9061,
77
+ 9383,
78
+ 10428,
79
+ 10929,
80
+ 11938,
81
+ 12033,
82
+ 12331,
83
+ 12562,
84
+ 13793,
85
+ 14157,
86
+ 14635,
87
+ 15265,
88
+ 15618,
89
+ 16553,
90
+ 16604,
91
+ 18362,
92
+ 18956,
93
+ 20075,
94
+ 21675,
95
+ 22520,
96
+ 26130,
97
+ 26161,
98
+ 26435,
99
+ 28279,
100
+ 29464,
101
+ 31650,
102
+ 32302,
103
+ 32470,
104
+ 36865,
105
+ 42863,
106
+ 47425,
107
+ 49870,
108
+ 50254,
109
+ 50258,
110
+ 50358,
111
+ 50359,
112
+ 50360,
113
+ 50361,
114
+ 50362
115
+ ],
116
+ "transformers_version": "4.49.0"
117
+ }
model.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:6805078c424d2ebed8d162f2978c63be8bae9a64a9cce77e60fa033f0b465b1c
3
+ size 2906537744
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)