MahmoudAshraf97 / whisper-diarization

Automatic Speech Recognition with Speaker Diarization based on OpenAI Whisper
BSD 2-Clause "Simplified" License
3.53k stars 301 forks source link

mutable default <class 'nemo.core.classes.mixins.adapter_mixin_strategies.ResidualAddAdapterStrategyConfig'> for field adapter_strategy is not allowed: use default_factory #54

Closed mirix closed 1 year ago

mirix commented 1 year ago

I receive the following error message:

[NeMo W 2023-06-14 11:08:57 nemo_logging:393] Apex was not found. Using the lamb or fused_adam optimizer will error out.
╭─────────────────────────────── Traceback (most recent call last) ────────────────────────────────╮
│ /home/emoman/Work/diarisation/whisper-diarization/diarize.py:9 in <module>                       │
│                                                                                                  │
│     6 import torch                                                                               │
│     7 import librosa                                                                             │
│     8 import soundfile                                                                           │
│ ❱   9 from nemo.collections.asr.models.msdd_models import NeuralDiarizer                         │
│    10 from deepmultilingualpunctuation import PunctuationModel                                   │
│    11 import re                                                                                  │
│    12 import logging                                                                             │
│                                                                                                  │
│ /home/emoman/.local/lib/python3.11/site-packages/nemo/collections/asr/__init__.py:15 in <module> │
│                                                                                                  │
│   12 # See the License for the specific language governing permissions and                       │
│   13 # limitations under the License.                                                            │
│   14                                                                                             │
│ ❱ 15 from nemo.collections.asr import data, losses, models, modules                              │
│   16 from nemo.package_info import __version__                                                   │
│   17                                                                                             │
│   18 # Set collection version equal to NeMo version.                                             │
│                                                                                                  │
│ /home/emoman/.local/lib/python3.11/site-packages/nemo/collections/asr/losses/__init__.py:16 in   │
│ <module>                                                                                         │
│                                                                                                  │
│   13 # limitations under the License.                                                            │
│   14                                                                                             │
│   15 from nemo.collections.asr.losses.angularloss import AngularSoftmaxLoss                      │
│ ❱ 16 from nemo.collections.asr.losses.audio_losses import SDRLoss                                │
│   17 from nemo.collections.asr.losses.ctc import CTCLoss                                         │
│   18 from nemo.collections.asr.losses.lattice_losses import LatticeLoss                          │
│   19 from nemo.collections.asr.losses.ssl_losses.contrastive import ContrastiveLoss              │
│                                                                                                  │
│ /home/emoman/.local/lib/python3.11/site-packages/nemo/collections/asr/losses/audio_losses.py:21  │
│ in <module>                                                                                      │
│                                                                                                  │
│    18 import numpy as np                                                                         │
│    19 import torch                                                                               │
│    20                                                                                            │
│ ❱  21 from nemo.collections.asr.parts.preprocessing.features import make_seq_mask_like           │
│    22 from nemo.collections.asr.parts.utils.audio_utils import toeplitz                          │
│    23 from nemo.core.classes import Loss, Typing, typecheck                                      │
│    24 from nemo.core.neural_types import AudioSignal, LengthsType, LossType, MaskType, NeuralT   │
│                                                                                                  │
│ /home/emoman/.local/lib/python3.11/site-packages/nemo/collections/asr/parts/preprocessing/__init │
│ __.py:16 in <module>                                                                             │
│                                                                                                  │
│   13 # limitations under the License.                                                            │
│   14                                                                                             │
│   15 from nemo.collections.asr.parts.preprocessing.feature_loader import ExternalFeatureLoade    │
│ ❱ 16 from nemo.collections.asr.parts.preprocessing.features import FeaturizerFactory, Filterb    │
│   17 from nemo.collections.asr.parts.preprocessing.perturb import (                              │
│   18 │   AudioAugmentor,                                                                         │
│   19 │   AugmentationDataset,                                                                    │
│                                                                                                  │
│ /home/emoman/.local/lib/python3.11/site-packages/nemo/collections/asr/parts/preprocessing/featur │
│ es.py:44 in <module>                                                                             │
│                                                                                                  │
│    41 import torch                                                                               │
│    42 import torch.nn as nn                                                                      │
│    43                                                                                            │
│ ❱  44 from nemo.collections.asr.parts.preprocessing.perturb import AudioAugmentor                │
│    45 from nemo.collections.asr.parts.preprocessing.segment import AudioSegment                  │
│    46 from nemo.utils import logging                                                             │
│    47                                                                                            │
│                                                                                                  │
│ /home/emoman/.local/lib/python3.11/site-packages/nemo/collections/asr/parts/preprocessing/pertur │
│ b.py:50 in <module>                                                                              │
│                                                                                                  │
│     47 from torch.utils.data import IterableDataset                                              │
│     48                                                                                           │
│     49 from nemo.collections.asr.parts.preprocessing.segment import AudioSegment                 │
│ ❱   50 from nemo.collections.common.parts.preprocessing import collections, parsers              │
│     51 from nemo.utils import logging                                                            │
│     52                                                                                           │
│     53 # TODO @blisc: Perhaps refactor instead of import guarding                                │
│                                                                                                  │
│ /home/emoman/.local/lib/python3.11/site-packages/nemo/collections/common/__init__.py:16 in       │
│ <module>                                                                                         │
│                                                                                                  │
│   13 # limitations under the License.                                                            │
│   14                                                                                             │
│   15 import nemo.collections.common.callbacks                                                    │
│ ❱ 16 from nemo.collections.common import data, losses, parts, tokenizers                         │
│   17 from nemo.package_info import __version__                                                   │
│   18                                                                                             │
│   19 # Set collection version equal to NeMo version.                                             │
│                                                                                                  │
│ /home/emoman/.local/lib/python3.11/site-packages/nemo/collections/common/parts/__init__.py:15 in │
│ <module>                                                                                         │
│                                                                                                  │
│   12 # See the License for the specific language governing permissions and                       │
│   13 # limitations under the License.                                                            │
│   14                                                                                             │
│ ❱ 15 from nemo.collections.common.parts.adapter_modules import LinearAdapter, LinearAdapterCo    │
│   16 from nemo.collections.common.parts.mlm_scorer import MLMScorer                              │
│   17 from nemo.collections.common.parts.multi_layer_perceptron import MultiLayerPerceptron       │
│   18 from nemo.collections.common.parts.transformer_utils import *                               │
│                                                                                                  │
│ /home/emoman/.local/lib/python3.11/site-packages/nemo/collections/common/parts/adapter_modules.p │
│ y:147 in <module>                                                                                │
│                                                                                                  │
│   144 │   │   return x                                                                           │
│   145                                                                                            │
│   146                                                                                            │
│ ❱ 147 @dataclass                                                                                 │
│   148 class LinearAdapterConfig:                                                                 │
│   149 │   in_features: int                                                                       │
│   150 │   dim: int                                                                               │
│                                                                                                  │
│ /usr/lib/python3.11/dataclasses.py:1223 in dataclass                                             │
│                                                                                                  │
│   1220 │   │   return wrap                                                                       │
│   1221 │                                                                                         │
│   1222 │   # We're called as @dataclass without parens.                                          │
│ ❱ 1223 │   return wrap(cls)                                                                      │
│   1224                                                                                           │
│   1225                                                                                           │
│   1226 def fields(class_or_instance):                                                            │
│                                                                                                  │
│ /usr/lib/python3.11/dataclasses.py:1213 in wrap                                                  │
│                                                                                                  │
│   1210 │   """                                                                                   │
│   1211 │                                                                                         │
│   1212 │   def wrap(cls):                                                                        │
│ ❱ 1213 │   │   return _process_class(cls, init, repr, eq, order, unsafe_hash,                    │
│   1214 │   │   │   │   │   │   │     frozen, match_args, kw_only, slots,                         │
│   1215 │   │   │   │   │   │   │     weakref_slot)                                               │
│   1216                                                                                           │
│                                                                                                  │
│ /usr/lib/python3.11/dataclasses.py:958 in _process_class                                         │
│                                                                                                  │
│    955 │   │   │   kw_only = True                                                                │
│    956 │   │   else:                                                                             │
│    957 │   │   │   # Otherwise it's a field of some type.                                        │
│ ❱  958 │   │   │   cls_fields.append(_get_field(cls, name, type, kw_only))                       │
│    959 │                                                                                         │
│    960 │   for f in cls_fields:                                                                  │
│    961 │   │   fields[f.name] = f                                                                │
│                                                                                                  │
│ /usr/lib/python3.11/dataclasses.py:815 in _get_field                                             │
│                                                                                                  │
│    812 │   # indicator for mutability.  Read the __hash__ attribute from the class,              │
│    813 │   # not the instance.                                                                   │
│    814 │   if f._field_type is _FIELD and f.default.__class__.__hash__ is None:                  │
│ ❱  815 │   │   raise ValueError(f'mutable default {type(f.default)} for field '                  │
│    816 │   │   │   │   │   │    f'{f.name} is not allowed: use default_factory')                 │
│    817 │                                                                                         │
│    818 │   return f                                                                              │
╰──────────────────────────────────────────────────────────────────────────────────────────────────╯
ValueError: mutable default <class 'nemo.core.classes.mixins.adapter_mixin_strategies.ResidualAddAdapterStrategyConfig'> for field adapter_strategy is not 
allowed: use default_factory
gsouf commented 1 year ago

Got a similar issue. I was using python 3.11. I switched to python 3.8 and it worked. That's the minimum version required by nemo

mirix commented 1 year ago

Got a similar issue. I was using python 3.11. I switched to python 3.8 and it worked. That's the minimum version required by nemo

Indeed, creating a fresh venv with Python 3.8 solves the issue and I am now able to run the code. Thanks a million!