Skip to content

Commit 068a41b

Browse files
Move files with optional dependencies to integrations folder (speechbrain#2782)
Co-authored-by: Adel Moumen <[email protected]>
1 parent e2696d9 commit 068a41b

142 files changed

Lines changed: 3278 additions & 2843 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/workflows/pythonapp.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,7 @@ jobs:
3030
- name: Full dependencies
3131
run: |
3232
pip install uv
33-
uv pip install --system ctc-segmentation sacrebleu # ctc-segmentation is funky with uv due to their oldest-supported-numpy dependency
34-
uv pip install --system -r requirements.txt torch==2.6.0+cpu torchaudio==2.6.0+cpu --extra-index-url https://download.pytorch.org/whl/cpu k2==1.24.4.dev20250307+cpu.torch2.6.0 --find-links https://k2-fsa.github.io/k2/cpu.html gensim==4.3.2 bitsandbytes==0.45.3 scikit-learn==1.6.1 accelerate
33+
uv pip install --system -r requirements.txt torch==2.6.0+cpu torchaudio==2.6.0+cpu --extra-index-url https://download.pytorch.org/whl/cpu
3534
uv pip install --system --editable . --no-deps # already installed pinned deps from requirements.txt, we're good
3635
- name: Install sox
3736
run: |

conftest.py

Lines changed: 8 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -12,60 +12,17 @@ def pytest_generate_tests(metafunc):
1212

1313
collect_ignore = [
1414
"setup.py",
15-
"speechbrain/lobes/models/huggingface_transformers/mert.py",
16-
"speechbrain/lobes/models/flair",
17-
"speechbrain/lobes/models/spacy",
15+
"speechbrain/integrations/",
16+
# These can be removed once the modules are fully deprecated
17+
"speechbrain/utils/bleu.py",
18+
"speechbrain/utils/kmeans.py",
19+
"speechbrain/processing/diarization.py",
20+
"speechbrain/decoders/language_model.py",
1821
"speechbrain/alignment/ctc_segmentation.py",
19-
"speechbrain/lm/arpa.py",
22+
"speechbrain/lobes/models/fairseq_wav2vec.py",
23+
"speechbrain/lobes/models/kmeans.py",
2024
]
2125
try:
2226
import numba # noqa: F401
2327
except ModuleNotFoundError:
2428
collect_ignore.append("speechbrain/nnet/loss/transducer_loss.py")
25-
try:
26-
import kenlm # noqa: F401
27-
except ModuleNotFoundError:
28-
collect_ignore.append("speechbrain/decoders/language_model.py")
29-
try:
30-
import fairseq # noqa: F401
31-
except ModuleNotFoundError:
32-
collect_ignore.append("speechbrain/lobes/models/fairseq_wav2vec.py")
33-
try:
34-
from transformers import Wav2Vec2Model # noqa: F401
35-
except ModuleNotFoundError:
36-
collect_ignore.append(
37-
"speechbrain/lobes/models/huggingface_transformers/wav2vec2.py"
38-
)
39-
try:
40-
from transformers import WhisperModel # noqa: F401
41-
except ModuleNotFoundError:
42-
collect_ignore.append(
43-
"speechbrain/lobes/models/huggingface_transformers/whisper.py"
44-
)
45-
try:
46-
import sklearn # noqa: F401
47-
except ModuleNotFoundError:
48-
collect_ignore.append("speechbrain/utils/kmeans.py")
49-
collect_ignore.append(
50-
"speechbrain/lobes/models/huggingface_transformers/discrete_ssl.py"
51-
)
52-
try:
53-
import sacrebleu # noqa: F401
54-
except ModuleNotFoundError:
55-
collect_ignore.append("speechbrain/utils/bleu.py")
56-
try:
57-
import vocos # noqa: F401
58-
except ModuleNotFoundError:
59-
collect_ignore.append(
60-
"speechbrain/lobes/models/huggingface_transformers/vocos.py"
61-
)
62-
try:
63-
from speechtokenizer import SpeechTokenizer # noqa: F401
64-
except ModuleNotFoundError:
65-
collect_ignore.append(
66-
"speechbrain/lobes/models/discrete/speechtokenizer.py"
67-
)
68-
try:
69-
import wavtokenizer # noqa: F401
70-
except ModuleNotFoundError:
71-
collect_ignore.append("speechbrain/lobes/models/discrete/wavtokenizer.py")

docs/contributing.md

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -72,14 +72,20 @@ These checks are run and enforced on the CI.
7272
### Adding dependencies
7373

7474
In general, we strive to have as few dependencies as possible. However, we will
75-
debate dependencies on a case-by-case basis. We value easy installability via
76-
pip.
75+
debate new dependencies on a case-by-case basis. We value keeping the toolkit
76+
lightweight to preserve easy installability via pip and to reduce the work
77+
needed to maintain the tool in the face of conflicting dependencies.
7778

78-
In case the dependency is only needed for a specific recipe or specific niche
79-
module, we suggest the extra tools pattern: don't add the dependency to general
79+
In case the dependency is only needed for a specific recipe, we suggest using
80+
the extra tools pattern: don't add the dependency to general
8081
requirements, but add it in the `extra-requirements.txt` file of that specific
8182
recipe.
8283

84+
Finally, if you want to add to the speechbrain core tools but a dependency
85+
cannot be added to the full toolkit dependency list, you can add the tool to
86+
the `speechbrain/integrations` folder, which requires more tests and will
87+
only be verified to work before each release, not on every CI run.
88+
8389
## Important documentation guidelines
8490

8591
In SpeechBrain, we plan to provide documentation at different levels:
@@ -103,4 +109,4 @@ and where the implemented algorithm needs clarification.
103109
### Internal contributors
104110

105111
- [Releasing a new version](newversion.md)
106-
- [Reviewing code](codereview.md)
112+
- [Reviewing code](codereview.md)

docs/index.rst

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,13 +98,12 @@ API
9898
speechbrain.dataio
9999
speechbrain.decoders
100100
speechbrain.inference
101-
speechbrain.k2_integration
101+
speechbrain.integrations
102102
speechbrain.lm
103103
speechbrain.lobes
104104
speechbrain.nnet
105105
speechbrain.processing
106106
speechbrain.tokenizers
107107
speechbrain.utils
108-
speechbrain.wordemb
109108

110109
hyperpyyaml.core

docs/tutorials/nn/using-wav2vec-2.0-hubert-wavlm-and-whisper-from-huggingface-with-speechbrain.ipynb

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -180,8 +180,8 @@
180180
"source": [
181181
"# BE CAREFUL, IF YOU ARE NOT CONNECTED TO A GPU RUNTIME, THIS WILL CRASH\n",
182182
"# THis only happens on Colab, you can of course load models on\n",
183-
"from speechbrain.lobes.models.huggingface_transformers.wav2vec2 import Wav2Vec2\n",
184-
"from speechbrain.lobes.models.huggingface_transformers.whisper import Whisper\n",
183+
"from speechbrain.integrations.huggingface.wav2vec2 import Wav2Vec2\n",
184+
"from speechbrain.integrations.huggingface.whisper import Whisper\n",
185185
"\n",
186186
"# HuggingFace model hub\n",
187187
"model_hub_w2v2 = \"facebook/wav2vec2-base-960h\"\n",
@@ -258,15 +258,15 @@
258258
"\n",
259259
"For Wav2vec 2.0:\n",
260260
"```yaml\n",
261-
"wav2vec2: !new:speechbrain.lobes.models.huggingface_transformers.wav2vec2.Wav2Vec2\n",
261+
"wav2vec2: !new:speechbrain.integrations.huggingface.wav2vec2.Wav2Vec2\n",
262262
" source: !ref <wav2vec2_hub>\n",
263263
" freeze: True\n",
264264
" save_path: !ref <save_folder>/wav2vec2_checkpoint\n",
265265
"```\n",
266266
"\n",
267267
"For Whisper:\n",
268268
"```yaml\n",
269-
"whisper: !new:speechbrain.lobes.models.huggingface_transformers.whisper.Whisper\n",
269+
"whisper: !new:speechbrain.integrations.huggingface.whisper.Whisper\n",
270270
" pretrained_path: !ref <wav2vec2_url>\n",
271271
" freeze: True\n",
272272
" encoder_only: True\n",
@@ -305,13 +305,13 @@
305305
" [...]\n",
306306
"\n",
307307
" # The instianciation of the SpeechBrain lobe\n",
308-
" wav2vec2: !new:speechbrain.lobes.models.huggingface_transformers.wav2vec2.Wav2Vec2\n",
308+
" wav2vec2: !new:speechbrain.integrations.huggingface.wav2vec2.Wav2Vec2\n",
309309
" source: !ref <wav2vec2_hub>\n",
310310
" freeze: !ref <freeze_pretrained>\n",
311311
" save_path: !ref <save_folder>/wav2vec2_checkpoint\n",
312312
"\n",
313313
" # The instianciation of the SpeechBrain lobe\n",
314-
" whisper: !new:speechbrain.lobes.models.huggingface_transformers.whisper.Whisper\n",
314+
" whisper: !new:speechbrain.integrations.huggingface.whisper.Whisper\n",
315315
" source: !ref <whisper_hub>\n",
316316
" freeze: !ref <freeze_pretrained>\n",
317317
" encoder_only: True\n",
@@ -481,7 +481,7 @@
481481
" [...]\n",
482482
"\n",
483483
" # The instanciation of the SpeechBrain lobe\n",
484-
" whisper: !new:speechbrain.lobes.models.huggingface_transformers.whisper.Whisper\n",
484+
" whisper: !new:speechbrain.integrations.huggingface.whisper.Whisper\n",
485485
" source: !ref <whisper_hub>\n",
486486
" freeze: !ref <freeze_pretrained>\n",
487487
" encoder_only: False # :)\n",

docs/tutorials/tasks/asr-metrics.ipynb

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -315,7 +315,7 @@
315315
"wer_stats_uposer: !new:speechbrain.utils.metric_stats.ErrorRateStats\n",
316316
" equality_comparator: !ref <uposer_dict>\n",
317317
"\n",
318-
"pos_tagger: !apply:speechbrain.lobes.models.flair.FlairSequenceTagger.from_hf\n",
318+
"pos_tagger: !apply:speechbrain.integrations.nlp.FlairSequenceTagger.from_hf\n",
319319
" source: \"qanastek/pos-french\"\n",
320320
" save_path: ./pretrained_models/\n",
321321
"\"\"\")"
@@ -469,7 +469,7 @@
469469
"outputs": [],
470470
"source": [
471471
"ler_hparams = load_hyperpyyaml(\"\"\"\n",
472-
"ler_model: !apply:speechbrain.lobes.models.spacy.SpacyPipeline.from_name\n",
472+
"ler_model: !apply:speechbrain.integrations.nlp.SpacyPipeline.from_name\n",
473473
" name: fr_core_news_md\n",
474474
" exclude: [\"tagger\", \"parser\", \"ner\", \"textcat\"]\n",
475475
"\n",
@@ -567,13 +567,13 @@
567567
"ember_hparams = load_hyperpyyaml(\"\"\"\n",
568568
"wer_stats: !new:speechbrain.utils.metric_stats.ErrorRateStats\n",
569569
"\n",
570-
"ember_embeddings: !apply:speechbrain.lobes.models.flair.embeddings.FlairEmbeddings.from_hf\n",
570+
"ember_embeddings: !apply:speechbrain.integrations.nlp.FlairEmbeddings.from_hf\n",
571571
" embeddings_class: !name:flair.embeddings.FastTextEmbeddings\n",
572572
" source: facebook/fasttext-fr-vectors\n",
573573
" save_path: ./pretrained_models/\n",
574574
"\n",
575575
"ember_metric: !new:speechbrain.utils.metric_stats.EmbeddingErrorRateSimilarity\n",
576-
" embedding_function: !name:speechbrain.lobes.models.flair.embeddings.FlairEmbeddings.embed_word\n",
576+
" embedding_function: !name:speechbrain.integrations.nlp.FlairEmbeddings.embed_word\n",
577577
" - !ref <ember_embeddings>\n",
578578
" low_similarity_weight: 1.0\n",
579579
" high_similarity_weight: 0.1\n",
@@ -646,7 +646,7 @@
646646
"bertscore_model_device: cuda\n",
647647
"\n",
648648
"bertscore_stats: !new:speechbrain.utils.bertscore.BERTScoreStats\n",
649-
" lm: !new:speechbrain.lobes.models.huggingface_transformers.TextEncoder\n",
649+
" lm: !new:speechbrain.integrations.huggingface.TextEncoder\n",
650650
" source: !ref <bertscore_model_name>\n",
651651
" save_path: pretrained_models/\n",
652652
" device: !ref <bertscore_model_device>\n",
@@ -704,7 +704,7 @@
704704
"semdist_model_device: cuda\n",
705705
"\n",
706706
"semdist_stats: !new:speechbrain.utils.semdist.SemDistStats\n",
707-
" lm: !new:speechbrain.lobes.models.huggingface_transformers.TextEncoder\n",
707+
" lm: !new:speechbrain.integrations.huggingface.TextEncoder\n",
708708
" source: !ref <semdist_model_name>\n",
709709
" save_path: pretrained_models/\n",
710710
" device: !ref <semdist_model_device>\n",

recipes/AISHELL-1/ASR/CTC/hparams/train_with_wav2vec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ enc: !new:speechbrain.nnet.containers.Sequential
163163
bn3: !name:speechbrain.nnet.normalization.BatchNorm1d
164164
activation3: !new:torch.nn.LeakyReLU
165165

166-
wav2vec2: !new:speechbrain.lobes.models.huggingface_transformers.wav2vec2.Wav2Vec2
166+
wav2vec2: !new:speechbrain.integrations.huggingface.wav2vec2.Wav2Vec2
167167
source: !ref <wav2vec2_hub>
168168
output_norm: True
169169
freeze: !ref <freeze_wav2vec>

recipes/AISHELL-1/ASR/transformer/hparams/train_ASR_transformer_with_wav2vect.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ ctc_weight_decode: 0.40
101101

102102
############################## Models ##########################################
103103

104-
wav2vec2: !new:speechbrain.lobes.models.huggingface_transformers.wav2vec2.Wav2Vec2
104+
wav2vec2: !new:speechbrain.integrations.huggingface.wav2vec2.Wav2Vec2
105105
source: !ref <wav2vec2_hub>
106106
output_norm: True
107107
freeze: !ref <freeze_wav2vec>

recipes/AMI/Diarization/experiment.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232

3333
import speechbrain as sb
3434
from speechbrain.dataio.dataio import read_audio, read_audio_multichannel
35-
from speechbrain.processing import diarization as diar
35+
from speechbrain.integrations.alignment import diarization as diar
3636
from speechbrain.processing.PLDA_LDA import StatObject_SB
3737
from speechbrain.utils.DER import DER
3838
from speechbrain.utils.distributed import run_on_main

recipes/CVSS/S2ST/extract_code.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818

1919
import speechbrain as sb
2020
from speechbrain.dataio.dataio import load_pkl, save_pkl
21-
from speechbrain.lobes.models.huggingface_transformers.wav2vec2 import Wav2Vec2
21+
from speechbrain.integrations.huggingface.wav2vec2 import Wav2Vec2
2222
from speechbrain.utils.logger import get_logger
2323

2424
OPT_FILE = "opt_cvss_extract.pkl"

0 commit comments

Comments
 (0)