Adel-Moumen commited on
Commit
8b5f2fa
·
verified ·
1 Parent(s): 052162f

Add files using upload-large-folder tool

Browse files
Files changed (45) hide show
  1. .gitattributes +3 -0
  2. dev-clean.csv +0 -0
  3. env.log +247 -0
  4. hyperparams.yaml +249 -0
  5. log.txt +0 -0
  6. opt_librispeech_prepare.pkl +3 -0
  7. save/CKPT+2025-08-09+18-52-20+00/CKPT.yaml +5 -0
  8. save/CKPT+2025-08-09+18-52-20+00/brain.ckpt +3 -0
  9. save/CKPT+2025-08-09+18-52-20+00/counter.ckpt +3 -0
  10. save/CKPT+2025-08-09+18-52-20+00/dataloader-TRAIN.ckpt +3 -0
  11. save/CKPT+2025-08-09+18-52-20+00/llm.ckpt +3 -0
  12. save/CKPT+2025-08-09+18-52-20+00/lr_annealing_wav2vec.ckpt +3 -0
  13. save/CKPT+2025-08-09+18-52-20+00/noam_scheduler.ckpt +3 -0
  14. save/CKPT+2025-08-09+18-52-20+00/optimizer.ckpt +3 -0
  15. save/CKPT+2025-08-09+18-52-20+00/proj.ckpt +3 -0
  16. save/CKPT+2025-08-09+18-52-20+00/ssl.ckpt +3 -0
  17. save/CKPT+2025-08-10+03-13-34+00/CKPT.yaml +5 -0
  18. save/CKPT+2025-08-10+03-13-34+00/brain.ckpt +3 -0
  19. save/CKPT+2025-08-10+03-13-34+00/counter.ckpt +3 -0
  20. save/CKPT+2025-08-10+03-13-34+00/dataloader-TRAIN.ckpt +3 -0
  21. save/CKPT+2025-08-10+03-13-34+00/llm.ckpt +3 -0
  22. save/CKPT+2025-08-10+03-13-34+00/lr_annealing_wav2vec.ckpt +3 -0
  23. save/CKPT+2025-08-10+03-13-34+00/noam_scheduler.ckpt +3 -0
  24. save/CKPT+2025-08-10+03-13-34+00/optimizer.ckpt +3 -0
  25. save/CKPT+2025-08-10+03-13-34+00/proj.ckpt +3 -0
  26. save/CKPT+2025-08-10+03-13-34+00/ssl.ckpt +3 -0
  27. save/CKPT+2025-08-10+04-00-44+00/CKPT.yaml +4 -0
  28. save/CKPT+2025-08-10+04-00-44+00/brain.ckpt +3 -0
  29. save/CKPT+2025-08-10+04-00-44+00/counter.ckpt +3 -0
  30. save/CKPT+2025-08-10+04-00-44+00/dataloader-TRAIN.ckpt +3 -0
  31. save/CKPT+2025-08-10+04-00-44+00/llm.ckpt +3 -0
  32. save/CKPT+2025-08-10+04-00-44+00/lr_annealing_wav2vec.ckpt +3 -0
  33. save/CKPT+2025-08-10+04-00-44+00/noam_scheduler.ckpt +3 -0
  34. save/CKPT+2025-08-10+04-00-44+00/optimizer.ckpt +3 -0
  35. save/CKPT+2025-08-10+04-00-44+00/proj.ckpt +3 -0
  36. save/CKPT+2025-08-10+04-00-44+00/ssl.ckpt +3 -0
  37. test-clean.csv +0 -0
  38. test-other.csv +0 -0
  39. train-clean-100.csv +0 -0
  40. train-clean-360.csv +3 -0
  41. train-other-500.csv +3 -0
  42. train.csv +3 -0
  43. train_log.txt +5 -0
  44. train_speechllm.py +423 -0
  45. wer_results/wer_test-clean.txt +0 -0
.gitattributes CHANGED
@@ -33,3 +33,6 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
33
  *.zip filter=lfs diff=lfs merge=lfs -text
34
  *.zst filter=lfs diff=lfs merge=lfs -text
35
  *tfevents* filter=lfs diff=lfs merge=lfs -text
 
 
 
 
33
  *.zip filter=lfs diff=lfs merge=lfs -text
34
  *.zst filter=lfs diff=lfs merge=lfs -text
35
  *tfevents* filter=lfs diff=lfs merge=lfs -text
36
+ train-clean-360.csv filter=lfs diff=lfs merge=lfs -text
37
+ train.csv filter=lfs diff=lfs merge=lfs -text
38
+ train-other-500.csv filter=lfs diff=lfs merge=lfs -text
dev-clean.csv ADDED
The diff for this file is too large to render. See raw diff
 
env.log ADDED
@@ -0,0 +1,247 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ SpeechBrain system description
2
+ ==============================
3
+ Python version:
4
+ 3.12.4 (main, Jun 7 2024, 23:47:47) [GCC 13.3.0]
5
+ ==============================
6
+ Installed Python packages:
7
+ accelerate==1.9.0
8
+ aiohappyeyeballs==2.4.4+computecanada
9
+ aiohttp==3.10.9+computecanada
10
+ aiosignal==1.3.2+computecanada
11
+ annotated_types==0.7.0+computecanada
12
+ anyio==4.9.0+computecanada
13
+ argon2_cffi==23.1.0+computecanada
14
+ argon2_cffi_bindings==21.2.0+computecanada
15
+ arrow==1.3.0+computecanada
16
+ asttokens==3.0.0+computecanada
17
+ async_lru==2.0.4+computecanada
18
+ attrs==25.1.0+computecanada
19
+ babel==2.17.0+computecanada
20
+ beautifulsoup4==4.13.4+computecanada
21
+ bioc==2.1+computecanada
22
+ bleach==6.2.0+computecanada
23
+ blis==1.0.1+computecanada
24
+ boto3==1.40.1
25
+ botocore==1.40.1
26
+ catalogue==2.0.10+computecanada
27
+ certifi==2024.12.14+computecanada
28
+ cffi==1.17.1+computecanada
29
+ cfgv==3.4.0+computecanada
30
+ charset-normalizer==3.4.1
31
+ click==8.2.1+computecanada
32
+ cloudpathlib==0.21.1
33
+ colorama==0.4.6+computecanada
34
+ comm==0.2.2+computecanada
35
+ confection==0.1.5+computecanada
36
+ conllu==4.5.3+computecanada
37
+ contourpy==1.3.1+computecanada
38
+ cycler==0.12.1+computecanada
39
+ cymem==2.0.8+computecanada
40
+ datasets==4.0.0
41
+ debugpy==1.8.12+computecanada
42
+ decorator==5.2.1+computecanada
43
+ defusedxml==0.7.1+computecanada
44
+ Deprecated==1.2.18+computecanada
45
+ dill==0.3.8+computecanada
46
+ distlib==0.3.9+computecanada
47
+ docopt==0.6.2+computecanada
48
+ einops==0.8.0+computecanada
49
+ executing==2.2.0+computecanada
50
+ fastjsonschema==2.21.1+computecanada
51
+ filelock==3.16.1+computecanada
52
+ flair==0.15.1
53
+ flash_attn==2.5.7+computecanada
54
+ fonttools==4.59.0+computecanada
55
+ fqdn==1.5.1+computecanada
56
+ frozenlist==1.5.0+computecanada
57
+ fsspec==2024.9.0+computecanada
58
+ ftfy==6.3.1+computecanada
59
+ Gammatone @ https://github.com/detly/gammatone/archive/master.zip#sha256=a33b739c787152035646cf5c1910ae3ff5da556b6d1f8c9d27191a2495ad6612
60
+ gdown==5.2.0+computecanada
61
+ gitdb==4.0.12+computecanada
62
+ GitPython==3.1.37+computecanada
63
+ h11==0.16.0+computecanada
64
+ h5py==3.12.0+computecanada
65
+ httpcore==1.0.9+computecanada
66
+ httpx==0.28.1+computecanada
67
+ huggingface-hub==0.27.0
68
+ HyperPyYAML==1.2.2+computecanada
69
+ identify==2.6.6
70
+ idna==3.10+computecanada
71
+ inflect==7.5.0+computecanada
72
+ iniconfig==2.1.0+computecanada
73
+ intervaltree==3.1.0+computecanada
74
+ ipykernel==6.29.5+computecanada
75
+ ipython==9.3.0+computecanada
76
+ ipython_genutils==0.2.0+computecanada
77
+ ipython_pygments_lexers==1.1.1+computecanada
78
+ ipywidgets==8.1.5+computecanada
79
+ isoduration==20.11.0+computecanada
80
+ jedi==0.19.2+computecanada
81
+ Jinja2==3.1.5
82
+ jmespath==1.0.1+computecanada
83
+ joblib==1.4.2+computecanada
84
+ json5==0.10.0+computecanada
85
+ jsonlines==4.0.0+computecanada
86
+ jsonpointer==3.0.0+computecanada
87
+ jsonschema==4.24.0+computecanada
88
+ jsonschema_specifications==2025.4.1+computecanada
89
+ jupyter==1.0.0+computecanada
90
+ jupyter-console==6.4.0+computecanada
91
+ jupyter_client==8.6.3+computecanada
92
+ jupyter_core==5.8.1+computecanada
93
+ jupyter_events==0.12.0+computecanada
94
+ jupyter_lsp==2.2.5+computecanada
95
+ jupyter_server==2.15.0+computecanada
96
+ jupyter_server_terminals==0.5.3+computecanada
97
+ jupyterlab==4.3.5+computecanada
98
+ jupyterlab_pygments==0.3.0+computecanada
99
+ jupyterlab_server==2.27.3+computecanada
100
+ jupyterlab_widgets==3.0.13+computecanada
101
+ kaldilm==1.15.1
102
+ kenlm @ https://github.com/kpu/kenlm/archive/master.zip#sha256=f935c2ac0be6dd1bf96a5852973dad6103c48e866cf33532459fb1336bea4bfe
103
+ kiwisolver==1.4.8+computecanada
104
+ langcodes==3.5.0+computecanada
105
+ langdetect==1.0.9+computecanada
106
+ language_data==1.3.0+computecanada
107
+ lilcom==1.8.1
108
+ llvmlite==0.44.0+computecanada
109
+ lxml==5.3.1+computecanada
110
+ marisa_trie==1.2.1+computecanada
111
+ markdown_it_py==3.0.0+computecanada
112
+ MarkupSafe==2.1.5+computecanada
113
+ matplotlib==3.10.0+computecanada
114
+ matplotlib_inline==0.1.7+computecanada
115
+ mdurl==0.1.2+computecanada
116
+ mistune==3.1.1+computecanada
117
+ mock==5.2.0
118
+ more_itertools==10.7.0+computecanada
119
+ mpld3==0.5.11
120
+ mpmath==1.3.0+computecanada
121
+ multidict==6.1.0+computecanada
122
+ multiprocess==0.70.16+computecanada
123
+ murmurhash==1.0.10+computecanada
124
+ nbclient==0.10.2+computecanada
125
+ nbconvert==7.16.6+computecanada
126
+ nbformat==5.10.4+computecanada
127
+ nest_asyncio==1.6.0+computecanada
128
+ networkx==3.4.2+computecanada
129
+ ninja==1.11.1+computecanada
130
+ nodeenv==1.9.1
131
+ nose==1.3.7+computecanada
132
+ notebook==7.3.2+computecanada
133
+ notebook_shim==0.2.4+computecanada
134
+ numba==0.61.0+computecanada
135
+ numpy==2.1.1+computecanada
136
+ overrides==7.7.0+computecanada
137
+ packaging==24.2+computecanada
138
+ pandas==2.2.3+computecanada
139
+ pandocfilters==1.5.1+computecanada
140
+ parso==0.8.4+computecanada
141
+ pexpect==4.9.0+computecanada
142
+ pillow==11.1.0+computecanada
143
+ platformdirs==4.3.6+computecanada
144
+ pluggy==1.6.0+computecanada
145
+ portalocker==3.2.0+computecanada
146
+ pptree==3.1+computecanada
147
+ pre_commit==4.2.0+computecanada
148
+ preshed==3.0.9+computecanada
149
+ prometheus_client==0.22.1+computecanada
150
+ prompt_toolkit==3.0.51+computecanada
151
+ propcache==0.2.1+computecanada
152
+ protobuf==6.31.1+computecanada
153
+ psutil==6.1.1+computecanada
154
+ ptyprocess==0.7.0+computecanada
155
+ pure_eval==0.2.3+computecanada
156
+ pyarrow @ file:///tmp/ebuser/avx2/Arrow/19.0.1/GCCcore-12.3-gentoo/arrow/python
157
+ pycparser==2.22+computecanada
158
+ pydantic==2.11.7+computecanada
159
+ pydantic_core==2.33.2+computecanada
160
+ pygments==2.19.2+computecanada
161
+ pyparsing==3.2.3+computecanada
162
+ PySocks==1.7.1+computecanada
163
+ pytest==8.4.1+computecanada
164
+ python_dateutil==2.9.0.post0+computecanada
165
+ python_json_logger==3.3.0+computecanada
166
+ pytorch_revgrad==0.2.0+computecanada
167
+ pytz==2025.1+computecanada
168
+ PyYAML==6.0.2+computecanada
169
+ pyzmq==26.2.1+computecanada
170
+ qtconsole==5.3.2+computecanada
171
+ QtPy==2.2.0+computecanada
172
+ referencing==0.36.2+computecanada
173
+ regex==2024.9.11+computecanada
174
+ requests==2.32.3+computecanada
175
+ rfc3339_validator==0.1.4+computecanada
176
+ rfc3986_validator==0.1.1+computecanada
177
+ rich==14.1.0+computecanada
178
+ rpds_py==0.21.0+computecanada
179
+ ruamel.yaml==0.18.8
180
+ ruamel.yaml.clib==0.2.8+computecanada
181
+ s3transfer==0.13.1
182
+ sacrebleu==2.5.1+computecanada
183
+ sacremoses==0.1.1
184
+ safetensors==0.4.5+computecanada
185
+ scikit_learn==1.6.1+computecanada
186
+ scipy==1.14.1+computecanada
187
+ segtok==1.5.11+computecanada
188
+ Send2Trash==1.8.3+computecanada
189
+ sentencepiece==0.2.0+computecanada
190
+ setuptools==75.6.0+computecanada
191
+ shellingham==1.5.4+computecanada
192
+ six==1.17.0+computecanada
193
+ smart_open==7.3.0.post1
194
+ smmap==5.0.2+computecanada
195
+ sniffio==1.3.1+computecanada
196
+ sortedcontainers==2.4.0+computecanada
197
+ soundfile==0.12.1+computecanada
198
+ soupsieve==2.7+computecanada
199
+ spacy==3.8.2+computecanada
200
+ spacy_legacy==3.0.12+computecanada
201
+ spacy_loggers==1.0.5+computecanada
202
+ -e git+https://github.com/speechbrain/speechbrain.git@a024f32dc92b6cecf7342d5e7f0483e78b5a381a#egg=speechbrain
203
+ sqlitedict==2.0.0+computecanada
204
+ SRMRpy @ git+https://github.com/jfsantos/SRMRpy@fee009779cef96bed34db3a7e31d10f3ad1ea133
205
+ srsly==2.4.8+computecanada
206
+ stack_data==0.6.3+computecanada
207
+ sympy==1.13.1+computecanada
208
+ tabulate==0.9.0+computecanada
209
+ terminado==0.18.1+computecanada
210
+ thinc==8.3.2+computecanada
211
+ threadpoolctl==3.6.0+computecanada
212
+ tinycss2==1.4.0+computecanada
213
+ tokenizers==0.21.0+computecanada
214
+ torch==2.4.1+computecanada
215
+ torchaudio==2.4.1+computecanada
216
+ tornado==6.4.2+computecanada
217
+ tqdm==4.67.1+computecanada
218
+ traitlets==5.14.3+computecanada
219
+ transformer-smaller-training-vocab==0.4.2
220
+ transformers==4.47.1
221
+ triton==3.1.0+computecanada
222
+ typeguard==4.4.4+computecanada
223
+ typer==0.16.0+computecanada
224
+ types_python_dateutil==2.9.0.20241206+computecanada
225
+ typing_extensions==4.14.1+computecanada
226
+ typing_inspection==0.4.1+computecanada
227
+ tzdata==2025.1+computecanada
228
+ uri_template==1.3.0+computecanada
229
+ urllib3==2.3.0
230
+ virtualenv==20.29.1+computecanada
231
+ wasabi==1.1.3+computecanada
232
+ wcwidth==0.2.13+computecanada
233
+ weasel==0.4.1+computecanada
234
+ webcolors==24.11.1+computecanada
235
+ webencodings==0.5.1+computecanada
236
+ websocket_client==1.8.0+computecanada
237
+ widgetsnbextension==4.0.13+computecanada
238
+ Wikipedia_API==0.6.0+computecanada
239
+ wrapt==1.17.2+computecanada
240
+ xxhash==3.5.0+computecanada
241
+ yarl==1.18.3+computecanada
242
+ ==============================
243
+ Git revision:
244
+ a024f32dc
245
+ ==============================
246
+ CUDA version:
247
+ 12.2
hyperparams.yaml ADDED
@@ -0,0 +1,249 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Generated 2025-08-10 from:
2
+ # /home/adelmou/proj/speechbrain/speechllm_librispeech/speechbrain/recipes/LibriSpeech/ASR/transformer/hparams/llama.yaml
3
+ # yamllint disable
4
+ # ############################################################################
5
+ # Authors: Adel Moumen
6
+ # ############################################################################
7
+ # Seed needs to be set at top of yaml, before objects with parameters are made
8
+ seed: 3407
9
+ __set_seed: !apply:speechbrain.utils.seed_everything [3407]
10
+ experiment_name: llama_3.2_1b_ASR
11
+ output_folder: /scratch/adelmou/speechllm_results_ls/wavlm_large+smol1.7B_mlp_lora/
12
+ output_wer_folder: /scratch/adelmou/speechllm_results_ls/wavlm_large+smol1.7B_mlp_lora//wer_results
13
+ save_folder: /scratch/adelmou/speechllm_results_ls/wavlm_large+smol1.7B_mlp_lora//save
14
+ train_log:
15
+ /scratch/adelmou/speechllm_results_ls/wavlm_large+smol1.7B_mlp_lora//train_log.txt
16
+
17
+
18
+ # Data files
19
+ data_folder: /localscratch/adelmou.47747915.0/LibriSpeech/
20
+ # e.g., /path/to/LibriSpeech
21
+ # If RIRS_NOISES dir exists in /localscratch/xxx_corpus/RIRS_NOISES
22
+ # then data_folder_rirs should be /localscratch/xxx_corpus
23
+ # otherwise the dataset will automatically be downloaded
24
+ # data_folder_rirs: !ref <data_folder>
25
+ train_splits: [train-clean-100, train-clean-360, train-other-500] # , "train-clean-360", "train-other-500"
26
+ dev_splits: [dev-clean]
27
+ test_splits: [test-clean, test-other]
28
+ skip_prep: false
29
+ train_csv: /scratch/adelmou/speechllm_results_ls/wavlm_large+smol1.7B_mlp_lora//train.csv
30
+ valid_csv:
31
+ /scratch/adelmou/speechllm_results_ls/wavlm_large+smol1.7B_mlp_lora//dev-clean.csv
32
+ test_csv:
33
+ - /scratch/adelmou/speechllm_results_ls/wavlm_large+smol1.7B_mlp_lora//test-clean.csv
34
+ - /scratch/adelmou/speechllm_results_ls/wavlm_large+smol1.7B_mlp_lora//test-other.csv
35
+
36
+ ckpt_interval_minutes: 15 # save checkpoint every N min
37
+
38
+ ####################### Training Parameters ####################################
39
+
40
+ # URL for the HuggingFace model we want to load (BASE here)
41
+ ssl_hub: /localscratch/adelmou.47747915.0/wavlm-large/
42
+ ssl_folder:
43
+ /scratch/adelmou/speechllm_results_ls/wavlm_large+smol1.7B_mlp_lora//save/ssl_checkpoint
44
+ ssl_frozen: true
45
+
46
+ # LLM options
47
+ llm_path: /localscratch/adelmou.47747915.0/SmolLM-1.7B/
48
+ llm_emb_size: 2048
49
+
50
+ number_of_epochs: 20
51
+ batch_size: 32 # Only used if dynamic batching is off.
52
+ # 400s * 10 => 1h / opt step
53
+ grad_accumulation_factor: 5
54
+ loss_reduction: batchmean
55
+ sorting: random
56
+ num_workers: 4
57
+ precision: bf16 # bf16, fp16 or fp32
58
+ eval_precision: bf16
59
+ max_grad_norm: 1.0
60
+
61
+ # stages related parameters
62
+ lr_adam: 0.0005
63
+ lr_wav2vec: 0.00002
64
+
65
+ weight_decay: 0.0
66
+ warmup_steps: 5000
67
+ augment_warmup: 7500
68
+
69
+ # BPE parameters
70
+ token_type: unigram # ["unigram", "bpe", "char"]
71
+ character_coverage: 1.0
72
+
73
+ # Feature parameters
74
+ sample_rate: 16000
75
+ downsampling_factor: 5 # Used to downsample frames before llm projection.
76
+
77
+ # This setup works well for A100 80GB GPU, adapts it to your needs.
78
+ # Or turn it off (but training speed will decrease)
79
+ dynamic_batching: true
80
+ max_batch_length_train: 300
81
+ max_batch_length_val: 100 # we reduce it as the beam is much wider (VRAM)
82
+ num_bucket: 200
83
+ shuffle: true # if true re-creates batches at each epoch shuffling examples.
84
+ batch_ordering: random
85
+ max_batch_ex: 256
86
+
87
+ dynamic_batch_sampler_train:
88
+ max_batch_length: 300
89
+ num_buckets: 200
90
+ shuffle: true
91
+ batch_ordering: random
92
+ max_batch_ex: 256
93
+
94
+ dynamic_batch_sampler_valid:
95
+ max_batch_length: 100
96
+ num_buckets: 200
97
+ shuffle: true
98
+ batch_ordering: random
99
+ max_batch_ex: 256
100
+
101
+ # Dataloader options
102
+ train_dataloader_opts:
103
+ batch_size: 32
104
+ shuffle: true
105
+ num_workers: 4
106
+ collate_fn: !name:speechbrain.dataio.batch.PaddedBatch
107
+ padding_kwargs:
108
+ value: 49152
109
+ per_key_padding_kwargs:
110
+ sig:
111
+ value: 0
112
+ tokens_eos:
113
+ value: -100
114
+
115
+ valid_dataloader_opts:
116
+ batch_size: 8
117
+ collate_fn: !name:speechbrain.dataio.batch.PaddedBatch
118
+ padding_kwargs:
119
+ value: 49152
120
+ per_key_padding_kwargs:
121
+ sig:
122
+ value: 0
123
+ tokens_eos:
124
+ value: -100
125
+
126
+ test_dataloader_opts:
127
+ batch_size: 8
128
+ collate_fn: !name:speechbrain.dataio.batch.PaddedBatch
129
+ padding_kwargs:
130
+ value: 49152
131
+ per_key_padding_kwargs:
132
+ sig:
133
+ value: 0
134
+ tokens_eos:
135
+ value: -100
136
+
137
+
138
+ ####################### Model Parameters ###########################
139
+ activation: &id001 !name:torch.nn.GELU
140
+ # todo: try swish instead
141
+ asr_output_neurons: 1024
142
+ lora_rank: 16
143
+
144
+ # Frames - LLM projector params
145
+ dnn_layers: 4
146
+ dnn_neurons: 2048
147
+ downsampling_output_dim: 5120
148
+
149
+ # Outputs
150
+ blank_index: 0
151
+ pad_token: 49152 #Llama 3 pad index after adding: BEURK.
152
+
153
+ # Decoding parameters
154
+ valid_search_interval: 4
155
+ valid_beam_size: 1 # We do greedy here so it's faster to decode ...
156
+ test_beam_size: 5
157
+
158
+ ############################## models ################################
159
+
160
+ normalize: &id007 !new:speechbrain.processing.features.InputNormalization
161
+
162
+ # We define two optimizers as we have two stages (training + finetuning)
163
+ norm_type: sentence
164
+
165
+ #wav2vec model
166
+ ssl: &id003 !new:speechbrain.integrations.huggingface.wav2vec2.Wav2Vec2
167
+ source: /localscratch/adelmou.47747915.0/wavlm-large/
168
+ output_norm: true
169
+ freeze: true
170
+ save_path:
171
+ /scratch/adelmou/speechllm_results_ls/wavlm_large+smol1.7B_mlp_lora//save/ssl_checkpoint
172
+ device_map: cuda
173
+ # attn_implementation: sdpa
174
+ # normalize_wav: False
175
+
176
+ proj: &id006 !new:speechbrain.lobes.models.VanillaNN.VanillaNN
177
+ input_shape: [null, null, 5120] # 5 x 1024
178
+ activation: *id001
179
+ dnn_blocks: 4
180
+ dnn_neurons: 2048
181
+
182
+ backbone_llm: &id002 !new:speechbrain.integrations.huggingface.llama.LLaMA
183
+ source: /localscratch/adelmou.47747915.0/SmolLM-1.7B/
184
+ save_path: /scratch/adelmou/speechllm_results_ls/wavlm_large+smol1.7B_mlp_lora//save
185
+ freeze: true
186
+ attn_implementation: flash_attention_2
187
+ device: cuda
188
+ torch_dtype: !name:torch.bfloat16
189
+ # add_tokens:
190
+ # audio_bos_token: "<|start_of_audio|>"
191
+ # audio_eos_token: "<|end_of_audio|>"
192
+
193
+ # Simply uncomment if you want to use LoRA adaptation.
194
+ llm: &id005 !new:speechbrain.nnet.adapters.AdaptedModel
195
+
196
+ model_to_adapt: *id002
197
+ adapter_class: !name:speechbrain.nnet.adapters.LoRA
198
+ all_linear: true
199
+ adapter_kwargs:
200
+ rank: 16
201
+
202
+ feat_downsampler: &id004 !new:speechbrain.lobes.downsampling.ConcatDownsampler
203
+ downsampling_factor: 5
204
+
205
+ modules:
206
+ ssl: *id003
207
+ feat_downsampler: *id004
208
+ llm: *id005
209
+ proj: *id006
210
+ normalize: *id007
211
+ Adam: !name:torch.optim.AdamW
212
+ lr: 0.0005
213
+ weight_decay: 0.0
214
+
215
+ Adam_wav2vec2: !name:torch.optim.AdamW
216
+ lr: 0.00002
217
+ weight_decay: 0.0
218
+
219
+
220
+ noam_annealing: &id008 !new:speechbrain.nnet.schedulers.NoamScheduler
221
+ lr_initial: 0.0005
222
+ n_warmup_steps: 5000
223
+
224
+ lr_annealing_wav2vec: &id009 !new:speechbrain.nnet.schedulers.NewBobScheduler
225
+ initial_value: 0.00002
226
+ improvement_threshold: 0.0025
227
+ annealing_factor: 0.8
228
+ patient: 1
229
+
230
+
231
+ checkpointer: !new:speechbrain.utils.checkpoints.Checkpointer
232
+ checkpoints_dir: /scratch/adelmou/speechllm_results_ls/wavlm_large+smol1.7B_mlp_lora//save
233
+ recoverables:
234
+ proj: *id006
235
+ noam_scheduler: *id008
236
+ lr_annealing_wav2vec: *id009
237
+ counter: &id010 !new:speechbrain.utils.epoch_loop.EpochCounter
238
+ limit: 20
239
+
240
+ ssl: *id003
241
+ llm: *id005
242
+ epoch_counter: *id010
243
+ train_logger: !new:speechbrain.utils.train_logger.FileTrainLogger
244
+ save_file:
245
+ /scratch/adelmou/speechllm_results_ls/wavlm_large+smol1.7B_mlp_lora//train_log.txt
246
+
247
+ cer_computer: !name:speechbrain.utils.metric_stats.ErrorRateStats
248
+ split_tokens: true
249
+ error_rate_computer: !name:speechbrain.utils.metric_stats.ErrorRateStats
log.txt ADDED
The diff for this file is too large to render. See raw diff
 
opt_librispeech_prepare.pkl ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:591d7c55caa4f47bcf3caf1019535cacd582a268dea0a4aa3cad2be0d4cd0539
3
+ size 37
save/CKPT+2025-08-09+18-52-20+00/CKPT.yaml ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
 
1
+ # yamllint disable
2
+ WER: 57.485018933127456
3
+ end-of-epoch: true
4
+ epoch: 1
5
+ unixtime: 1754779940.0693338
save/CKPT+2025-08-09+18-52-20+00/brain.ckpt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:3e9e37095ed0a9ede3cdfa3a9f2ac8b1997ec37e5d9d914aace085542e6a77b8
3
+ size 49
save/CKPT+2025-08-09+18-52-20+00/counter.ckpt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:6b86b273ff34fce19d6b804eff5a3f5747ada4eaa22f1d49c01e52ddb7875b4b
3
+ size 1
save/CKPT+2025-08-09+18-52-20+00/dataloader-TRAIN.ckpt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:3354f1239660e58f56dd5d3e011818ad1f46aa866e9ad99ef27eb8c079ad7a58
3
+ size 5
save/CKPT+2025-08-09+18-52-20+00/llm.ckpt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:765d1ae759b83ce5e283bca3cbb780669446b26b04431f4571251e6accf389b4
3
+ size 75729974
save/CKPT+2025-08-09+18-52-20+00/lr_annealing_wav2vec.ckpt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:9e247c7a78bc010d7afbf49347c31ff3ca6fa619179ddde19766f44748c3a66d
3
+ size 980
save/CKPT+2025-08-09+18-52-20+00/noam_scheduler.ckpt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:667ce05145a77d4cc2969db16e2df76882e3eda7d42a504f194fb40240bdab18
3
+ size 892
save/CKPT+2025-08-09+18-52-20+00/optimizer.ckpt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:eabfc58e98451f721a34158d7babf7ca2883ca7e1cdd8cdaed5b050e89d8c79f
3
+ size 336165856
save/CKPT+2025-08-09+18-52-20+00/proj.ckpt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:319a56c6772ef2fc1ecee61e0cd33c75dbdd47b69a245602036f5f0adf10e4dc
3
+ size 92310364
save/CKPT+2025-08-09+18-52-20+00/ssl.ckpt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:d62d5122a6f6c73993a2a9114b63faf4bf1e2ad1a65cb19208793d1ab53320da
3
+ size 1261974514
save/CKPT+2025-08-10+03-13-34+00/CKPT.yaml ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
 
1
+ # yamllint disable
2
+ WER: 55.8784603507224
3
+ end-of-epoch: true
4
+ epoch: 4
5
+ unixtime: 1754810014.1578317
save/CKPT+2025-08-10+03-13-34+00/brain.ckpt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:829cf20f85e53a35380ccee38e997d53cbd55fe39c4eb58af9600c2f34a56ddc
3
+ size 49
save/CKPT+2025-08-10+03-13-34+00/counter.ckpt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:4b227777d4dd1fc61c6f884f48641d02b4d121d3fd328cb08b5531fcacdabf8a
3
+ size 1
save/CKPT+2025-08-10+03-13-34+00/dataloader-TRAIN.ckpt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:3354f1239660e58f56dd5d3e011818ad1f46aa866e9ad99ef27eb8c079ad7a58
3
+ size 5
save/CKPT+2025-08-10+03-13-34+00/llm.ckpt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:ed74e93d1a69782b26e91c7cfe39a5908c4a7184bb8f310d64a6bd9b569ab0ec
3
+ size 75729974
save/CKPT+2025-08-10+03-13-34+00/lr_annealing_wav2vec.ckpt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:9e247c7a78bc010d7afbf49347c31ff3ca6fa619179ddde19766f44748c3a66d
3
+ size 980
save/CKPT+2025-08-10+03-13-34+00/noam_scheduler.ckpt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:667ce05145a77d4cc2969db16e2df76882e3eda7d42a504f194fb40240bdab18
3
+ size 892
save/CKPT+2025-08-10+03-13-34+00/optimizer.ckpt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:f4c1274c37f916b131e764a03899993a0a9ebcc36c9f34aba147cff09d5c6af2
3
+ size 336165856
save/CKPT+2025-08-10+03-13-34+00/proj.ckpt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:d3086caa4a2071491b576375726d88a729bf298194bf8b4c1711ac59c28fa961
3
+ size 92310364
save/CKPT+2025-08-10+03-13-34+00/ssl.ckpt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:d62d5122a6f6c73993a2a9114b63faf4bf1e2ad1a65cb19208793d1ab53320da
3
+ size 1261974514
save/CKPT+2025-08-10+04-00-44+00/CKPT.yaml ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+ # yamllint disable
2
+ brain_intra_epoch_ckpt: true
3
+ end-of-epoch: false
4
+ unixtime: 1754812844.3274941
save/CKPT+2025-08-10+04-00-44+00/brain.ckpt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:41a2d0b966a5ab68c3a2613fb00d4b23eb86eb83eeb48e736a42cc4d82277923
3
+ size 68
save/CKPT+2025-08-10+04-00-44+00/counter.ckpt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:ef2d127de37b942baad06145e54b0c619a1f22327b2ebbcfbec78f5564afe39d
3
+ size 1
save/CKPT+2025-08-10+04-00-44+00/dataloader-TRAIN.ckpt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:3b9b21ac4770d6a10a27b9bfbab70888491187668f3eaa475abec6ea04c82eec
3
+ size 4
save/CKPT+2025-08-10+04-00-44+00/llm.ckpt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:6e4cbf1e9fca51cbed249ee70fd930fb0997a306e533a198f3f42a11beaee017
3
+ size 75729974
save/CKPT+2025-08-10+04-00-44+00/lr_annealing_wav2vec.ckpt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:9e247c7a78bc010d7afbf49347c31ff3ca6fa619179ddde19766f44748c3a66d
3
+ size 980
save/CKPT+2025-08-10+04-00-44+00/noam_scheduler.ckpt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:667ce05145a77d4cc2969db16e2df76882e3eda7d42a504f194fb40240bdab18
3
+ size 892
save/CKPT+2025-08-10+04-00-44+00/optimizer.ckpt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:58c4f215e290c3d7868d2dff364981daf58fcaed31d37ba4b07db2e79c860c8d
3
+ size 336165856
save/CKPT+2025-08-10+04-00-44+00/proj.ckpt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:1a4cd73d90b48deb2c1975f12abffb8c1536c34dc59ce5d3bebe5207e90f3775
3
+ size 92310364
save/CKPT+2025-08-10+04-00-44+00/ssl.ckpt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:d62d5122a6f6c73993a2a9114b63faf4bf1e2ad1a65cb19208793d1ab53320da
3
+ size 1261974514
test-clean.csv ADDED
The diff for this file is too large to render. See raw diff
 
test-other.csv ADDED
The diff for this file is too large to render. See raw diff
 
train-clean-100.csv ADDED
The diff for this file is too large to render. See raw diff
 
train-clean-360.csv ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:dea1dcef6ee76e846cf50945ea7dde94813524d7615a51feef8fc64eef2f430b
3
+ size 29076679
train-other-500.csv ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:a21b1729500f97836d004d250b78ee885acbcaa2ce4176ecf3866162303632d9
3
+ size 39565769
train.csv ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:c67797a7b5c794b27d54d9db4073af36f3c8eb078465041713e340006a44850c
3
+ size 76628881
train_log.txt ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
 
1
+ epoch: 1, lr: 5.00e-04, steps: 1498, optimizer: AdamW - train loss: 1.73 - valid loss: 1.49e-01, valid CER: 56.29, valid WER: 57.49
2
+ epoch: 2, lr: 5.00e-04, steps: 2996, optimizer: AdamW - train loss: 1.43e-01 - valid loss: 7.63e-02, valid CER: 55.70, valid WER: 56.26
3
+ epoch: 3, lr: 5.00e-04, steps: 4494, optimizer: AdamW - train loss: 1.06e-01 - valid loss: 6.71e-02, valid CER: 55.54, valid WER: 55.92
4
+ epoch: 4, lr: 5.00e-04, steps: 5992, optimizer: AdamW - train loss: 8.78e-02 - valid loss: 6.29e-02, valid CER: 55.54, valid WER: 55.88
5
+ Epoch loaded: 4 - test loss: 6.42e-02, test CER: 1.97, test WER: 3.67
train_speechllm.py ADDED
@@ -0,0 +1,423 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env python3
2
+ """
3
+ # TODO:
4
+ 1) add max length (i.e. context length of the fine tune model)
5
+ 2) torch.compile the LLM with the fixed length
6
+
7
+ Authors
8
+ * Adel Moumen 2025
9
+ """
10
+
11
+ import os
12
+ import sys
13
+ from pathlib import Path
14
+
15
+ import torch
16
+ from hyperpyyaml import load_hyperpyyaml
17
+
18
+ import speechbrain as sb
19
+ from speechbrain.utils.distributed import if_main_process, run_on_main
20
+ from speechbrain.utils.logger import get_logger
21
+
22
+ logger = get_logger(__name__)
23
+
24
+
25
+ def get_multimodal_attention_mask(wav, wav_lens, txt, txt_lens, device):
26
+ batch_size = wav.size(0)
27
+ wav_len = wav.size(1)
28
+ txt_len = txt.size(1)
29
+ # Max total length for padding
30
+ max_total_len = wav_len + txt_len
31
+ attention_mask = torch.zeros(batch_size, max_total_len, dtype=torch.bool, device=device)
32
+ for i in range(batch_size):
33
+ actual_wav_len = int(wav_lens[i].item() * wav_len)
34
+ actual_txt_len = int(txt_lens[i].item() * txt_len)
35
+ # Fill mask: audio part
36
+ attention_mask[i, :actual_wav_len] = True
37
+ # Fill mask: text part (after audio)
38
+ attention_mask[i, wav_len:wav_len + actual_txt_len] = True
39
+ return attention_mask
40
+
41
+
42
+ # Define training procedure
43
+ class ASR(sb.core.Brain):
44
+ def compute_forward(self, batch, stage):
45
+ """Forward computations from the waveform batches to the output probabilities."""
46
+ batch = batch.to(self.device)
47
+ wavs, wav_lens = batch.sig
48
+ tokens_bos, tokens_bos_lens = batch.tokens_bos
49
+ prompt_len = batch.prompt_len
50
+ wavs = self.hparams.normalize(wavs, wav_lens)
51
+ audio_feats = self.modules.ssl(wavs, wav_lens)
52
+ audio_down_feats = self.modules.feat_downsampler(audio_feats)
53
+ projected_audio_feats = self.modules.proj(audio_down_feats)
54
+ txt_embds = self.txt_embedding(tokens_bos)
55
+ multimodal_embds = torch.cat([projected_audio_feats, txt_embds], dim=1)
56
+ # attention_mask should be all the true audio features + all the true text features
57
+ attention_mask = get_multimodal_attention_mask(
58
+ projected_audio_feats, wav_lens, txt_embds, tokens_bos_lens, self.device
59
+ )
60
+ logits = self.modules.llm(
61
+ inputs_embeds=multimodal_embds,
62
+ attention_mask=attention_mask
63
+ ).logits
64
+
65
+ if hasattr(self.modules.llm, "module"):
66
+ gen_func = self.modules.llm.module.model.generate
67
+ else:
68
+ gen_func = self.modules.llm.model.generate
69
+
70
+ hyps = None
71
+ if stage != sb.Stage.TRAIN:
72
+ audio_and_prompt_len = projected_audio_feats.shape[1] + prompt_len[0]
73
+ hyps = gen_func(
74
+ inputs_embeds=multimodal_embds[
75
+ :, :audio_and_prompt_len
76
+ ], # give model audio features and prompt for inference
77
+ attention_mask=attention_mask[:, :audio_and_prompt_len],
78
+ generation_config=self.val_decoding_config,
79
+ )
80
+ return logits, hyps, projected_audio_feats.shape[1]
81
+
82
+ def compute_objectives(self, predictions, batch, stage):
83
+ """Computes the loss (CTC+NLL) given predictions and targets."""
84
+ logits, hyps, _ = predictions
85
+ tokens_eos, _ = batch.tokens_eos
86
+ ids = batch.id
87
+
88
+ num_audio_feats = logits.shape[1] - tokens_eos.shape[1]
89
+ # We prepend `-100` to the tokens_eos to ignore them in the loss.
90
+ # This corresponds to the audio features.
91
+ target_tokens = torch.cat([
92
+ torch.full((tokens_eos.shape[0], num_audio_feats), -100, device=self.device),
93
+ tokens_eos,
94
+ ], dim=1).long()
95
+ # compute the cross entropy loss
96
+ loss = torch.nn.functional.cross_entropy(
97
+ logits.view(-1, logits.shape[-1]),
98
+ target_tokens.view(-1),
99
+ ignore_index=-100
100
+ )
101
+ if stage != sb.Stage.TRAIN:
102
+ # replace -100 with pad token
103
+ target_tokens = target_tokens.masked_fill(target_tokens == -100, self.tokenizer.pad_token_id)
104
+ preds = self.tokenizer.batch_decode(hyps, skip_special_tokens=True)
105
+ preds_words = [pred.split(" ") for pred in preds]
106
+ targets = self.tokenizer.batch_decode(target_tokens, skip_special_tokens=True)
107
+ targets_words = [target.split(" ") for target in targets]
108
+ # print(preds_words)
109
+ # print(targets_words)
110
+ # import time
111
+ # time.sleep(5)
112
+ # print('--------------------------------')
113
+ self.cer_metric.append(ids, preds_words, targets_words)
114
+ self.wer_metric.append(ids, preds_words, targets_words)
115
+ return loss
116
+
117
+ def on_stage_start(self, stage, epoch):
118
+ """Gets called at the beginning of each epoch"""
119
+ # check if txt_embedding is already set
120
+ import transformers
121
+ self.val_decoding_config = transformers.GenerationConfig(
122
+ pad_token_id=self.tokenizer.pad_token_id,
123
+ eos_token_id=self.tokenizer.eos_token_id,
124
+ max_new_tokens=400,
125
+ do_sample=False, # disables sampling
126
+ num_beams=1, # no beam search
127
+ temperature=1.0, # irrelevant when do_sample=False, but keep default
128
+ top_k=0, # not used when do_sample=False
129
+ top_p=1.0, # not used when do_sample=False
130
+ repetition_penalty=1.0 # no repetition penalty
131
+ )
132
+
133
+ if not hasattr(self, "txt_embedding"):
134
+ # we save the txt embedding for easy access
135
+ self.txt_embedding = (
136
+ self.modules.llm.model.get_input_embeddings()
137
+ if not hasattr(self.modules.llm, "module")
138
+ else self.modules.llm.module.model.get_input_embeddings()
139
+ )
140
+
141
+ if stage != sb.Stage.TRAIN:
142
+ self.cer_metric = self.hparams.cer_computer()
143
+ self.wer_metric = self.hparams.error_rate_computer()
144
+
145
+ def on_stage_end(self, stage, stage_loss, epoch):
146
+ """Gets called at the end of a epoch."""
147
+ # Compute/store important stats
148
+ stage_stats = {"loss": stage_loss}
149
+ if stage == sb.Stage.TRAIN:
150
+ self.train_stats = stage_stats
151
+ else:
152
+ stage_stats["CER"] = self.cer_metric.summarize("error_rate")
153
+ stage_stats["WER"] = self.wer_metric.summarize("error_rate")
154
+
155
+ # log stats and save checkpoint at end-of-epoch
156
+ if stage == sb.Stage.VALID:
157
+ lr = self.hparams.noam_annealing.current_lr
158
+ steps = self.optimizer_step
159
+ optimizer = self.optimizer.__class__.__name__
160
+
161
+ epoch_stats = {
162
+ "epoch": epoch,
163
+ "lr": lr,
164
+ "steps": steps,
165
+ "optimizer": optimizer,
166
+ }
167
+ self.hparams.train_logger.log_stats(
168
+ stats_meta=epoch_stats,
169
+ train_stats=self.train_stats,
170
+ valid_stats=stage_stats,
171
+ )
172
+ self.checkpointer.save_and_keep_only(
173
+ meta={"WER": stage_stats["WER"], "epoch": epoch},
174
+ max_keys=["WER"],
175
+ # num_to_keep=self.hparams.avg_checkpoints,
176
+ )
177
+
178
+ elif stage == sb.Stage.TEST:
179
+ self.hparams.train_logger.log_stats(
180
+ stats_meta={"Epoch loaded": self.hparams.epoch_counter.current},
181
+ test_stats=stage_stats,
182
+ )
183
+ if if_main_process():
184
+ with open(
185
+ self.hparams.test_wer_file, "w", encoding="utf-8"
186
+ ) as w:
187
+ self.wer_metric.write_stats(w)
188
+
189
+ def on_fit_batch_end(self, batch, outputs, loss, should_step):
190
+ """At the end of the optimizer step, apply noam annealing."""
191
+ # if should_step:
192
+ # self.hparams.noam_annealing(self.optimizer)
193
+
194
+
195
+ def dataio_prepare(hparams, tokenizer):
196
+ """This function prepares the datasets to be used in the brain class.
197
+ It also defines the data processing pipeline through user-defined functions.
198
+ """
199
+ data_folder = hparams["data_folder"]
200
+
201
+ train_data = sb.dataio.dataset.DynamicItemDataset.from_csv(
202
+ csv_path=hparams["train_csv"],
203
+ replacements={"data_root": data_folder},
204
+ )
205
+
206
+ if hparams["sorting"] == "ascending":
207
+ # we sort training data to speed up training and get better results.
208
+ train_data = train_data.filtered_sorted(sort_key="duration")
209
+ # when sorting do not shuffle in dataloader ! otherwise is pointless
210
+ hparams["train_dataloader_opts"]["shuffle"] = False
211
+
212
+ elif hparams["sorting"] == "descending":
213
+ train_data = train_data.filtered_sorted(
214
+ sort_key="duration", reverse=True
215
+ )
216
+ # when sorting do not shuffle in dataloader ! otherwise is pointless
217
+ hparams["train_dataloader_opts"]["shuffle"] = False
218
+
219
+ elif hparams["sorting"] == "random":
220
+ pass
221
+
222
+ else:
223
+ raise NotImplementedError(
224
+ "sorting must be random, ascending or descending"
225
+ )
226
+ valid_data = sb.dataio.dataset.DynamicItemDataset.from_csv(
227
+ csv_path=hparams["valid_csv"],
228
+ replacements={"data_root": data_folder},
229
+ )
230
+ valid_data = valid_data.filtered_sorted(sort_key="duration")
231
+
232
+ # test is separate
233
+ test_datasets = {}
234
+ for csv_file in hparams["test_csv"]:
235
+ name = Path(csv_file).stem
236
+ test_datasets[name] = sb.dataio.dataset.DynamicItemDataset.from_csv(
237
+ csv_path=csv_file, replacements={"data_root": data_folder}
238
+ )
239
+ test_datasets[name] = test_datasets[name].filtered_sorted(
240
+ sort_key="duration"
241
+ )
242
+
243
+ datasets = [train_data, valid_data] + [i for k, i in test_datasets.items()]
244
+
245
+ # 2. Define audio pipeline:
246
+ @sb.utils.data_pipeline.takes("wav")
247
+ @sb.utils.data_pipeline.provides("sig")
248
+ def audio_pipeline(wav):
249
+ sig = sb.dataio.dataio.read_audio(wav)
250
+ return sig
251
+
252
+ sb.dataio.dataset.add_dynamic_item(datasets, audio_pipeline)
253
+
254
+ bos_index = tokenizer.bos_token_id
255
+ eos_index = tokenizer.eos_token_id
256
+ pad_index = tokenizer.pad_token_id
257
+ prompt = "Transcribe speech to text."
258
+ print(bos_index, eos_index, pad_index, prompt)
259
+
260
+ prompt_ids = tokenizer(
261
+ prompt, return_tensors="pt", add_special_tokens=False
262
+ ).input_ids.view(-1).tolist()
263
+
264
+ # 3. Define text pipeline:
265
+ @sb.utils.data_pipeline.takes("wrd")
266
+ @sb.utils.data_pipeline.provides(
267
+ "wrd", "tokens_list", "tokens_bos", "tokens_eos", "tokens", "prompt_len"
268
+ )
269
+ def text_pipeline(wrd):
270
+ # wrd = wrd[0] + wrd[1:].lower()
271
+ yield wrd
272
+ tokens_list = tokenizer(wrd, add_special_tokens=False).input_ids
273
+ yield tokens_list
274
+ tokens_bos = torch.LongTensor(prompt_ids + [bos_index] + tokens_list )
275
+ yield tokens_bos
276
+ tokens_eos = torch.LongTensor(tokens_list + [eos_index])
277
+ yield tokens_eos
278
+ tokens = torch.LongTensor(tokens_list)
279
+ yield tokens
280
+ prompt_len = len(prompt_ids + [bos_index])
281
+ yield prompt_len
282
+
283
+ sb.dataio.dataset.add_dynamic_item(datasets, text_pipeline)
284
+
285
+ # 4. Set output:
286
+ sb.dataio.dataset.set_output_keys(
287
+ datasets,
288
+ ["id", "sig", "wrd", "tokens_bos", "tokens_eos", "tokens", "prompt_len"],
289
+ )
290
+
291
+ # 5. If Dynamic Batching is used, we instantiate the needed samplers.
292
+ train_batch_sampler = None
293
+ valid_batch_sampler = None
294
+ if hparams["dynamic_batching"]:
295
+ from speechbrain.dataio.sampler import DynamicBatchSampler # noqa
296
+
297
+ dynamic_hparams_train = hparams["dynamic_batch_sampler_train"]
298
+ dynamic_hparams_valid = hparams["dynamic_batch_sampler_valid"]
299
+
300
+ train_batch_sampler = DynamicBatchSampler(
301
+ train_data,
302
+ length_func=lambda x: x["duration"],
303
+ **dynamic_hparams_train,
304
+ )
305
+ valid_batch_sampler = DynamicBatchSampler(
306
+ valid_data,
307
+ length_func=lambda x: x["duration"],
308
+ **dynamic_hparams_valid,
309
+ )
310
+
311
+ return (
312
+ train_data,
313
+ valid_data,
314
+ test_datasets,
315
+ tokenizer,
316
+ train_batch_sampler,
317
+ valid_batch_sampler,
318
+ )
319
+
320
+
321
+ if __name__ == "__main__":
322
+ # CLI:
323
+ hparams_file, run_opts, overrides = sb.parse_arguments(sys.argv[1:])
324
+ with open(hparams_file, encoding="utf-8") as fin:
325
+ hparams = load_hyperpyyaml(fin, overrides)
326
+
327
+ # create ddp_group with the right communication protocol
328
+ sb.utils.distributed.ddp_init_group(run_opts)
329
+
330
+ # 1. # Dataset prep (parsing Librispeech)
331
+ from librispeech_prepare import prepare_librispeech # noqa
332
+
333
+ # Create experiment directory
334
+ sb.create_experiment_directory(
335
+ experiment_directory=hparams["output_folder"],
336
+ hyperparams_to_save=hparams_file,
337
+ overrides=overrides,
338
+ )
339
+
340
+ # multi-gpu (ddp) save data preparation
341
+ run_on_main(
342
+ prepare_librispeech,
343
+ kwargs={
344
+ "data_folder": hparams["data_folder"],
345
+ "tr_splits": hparams["train_splits"],
346
+ "dev_splits": hparams["dev_splits"],
347
+ "te_splits": hparams["test_splits"],
348
+ "save_folder": hparams["output_folder"],
349
+ "merge_lst": hparams["train_splits"],
350
+ "merge_name": "train.csv",
351
+ "skip_prep": hparams["skip_prep"],
352
+ },
353
+ )
354
+
355
+ # here we create the datasets objects as well as tokenization and encoding
356
+ tokenizer = hparams["llm"].tokenizer
357
+
358
+ (
359
+ train_data,
360
+ valid_data,
361
+ test_datasets,
362
+ tokenizer,
363
+ train_bsampler,
364
+ valid_bsampler,
365
+ ) = dataio_prepare(hparams, tokenizer)
366
+
367
+ # Trainer initialization
368
+ asr_brain = ASR(
369
+ modules=hparams["modules"],
370
+ opt_class=hparams["Adam"],
371
+ hparams=hparams,
372
+ run_opts=run_opts,
373
+ checkpointer=hparams["checkpointer"],
374
+ )
375
+ # asr_brain.modules.llm = torch.compile(asr_brain.modules.llm)
376
+ asr_brain.tokenizer = tokenizer
377
+ # adding objects to trainer:
378
+ train_dataloader_opts = hparams["train_dataloader_opts"]
379
+ valid_dataloader_opts = hparams["valid_dataloader_opts"]
380
+
381
+ if train_bsampler is not None:
382
+ collate_fn = None
383
+ if "collate_fn" in train_dataloader_opts:
384
+ collate_fn = train_dataloader_opts["collate_fn"]
385
+
386
+ train_dataloader_opts = {
387
+ "batch_sampler": train_bsampler,
388
+ "num_workers": hparams["num_workers"],
389
+ }
390
+
391
+ if collate_fn is not None:
392
+ train_dataloader_opts["collate_fn"] = collate_fn
393
+
394
+ if valid_bsampler is not None:
395
+ collate_fn = None
396
+ if "collate_fn" in valid_dataloader_opts:
397
+ collate_fn = valid_dataloader_opts["collate_fn"]
398
+
399
+ valid_dataloader_opts = {"batch_sampler": valid_bsampler}
400
+
401
+ if collate_fn is not None:
402
+ valid_dataloader_opts["collate_fn"] = collate_fn
403
+ # Training
404
+ asr_brain.fit(
405
+ asr_brain.hparams.epoch_counter,
406
+ train_data,
407
+ valid_data,
408
+ train_loader_kwargs=train_dataloader_opts,
409
+ valid_loader_kwargs=valid_dataloader_opts,
410
+ )
411
+
412
+ # Testing
413
+ os.makedirs(hparams["output_wer_folder"], exist_ok=True)
414
+
415
+ for k in test_datasets.keys(): # keys are test_clean, test_other etc
416
+ asr_brain.hparams.test_wer_file = os.path.join(
417
+ hparams["output_wer_folder"], f"wer_{k}.txt"
418
+ )
419
+ asr_brain.evaluate(
420
+ test_datasets[k],
421
+ min_key="WER",
422
+ test_loader_kwargs=hparams["test_dataloader_opts"],
423
+ )
wer_results/wer_test-clean.txt ADDED
The diff for this file is too large to render. See raw diff