NVIDIA-NeMo/Speech · #15454

fix: replace assert statements with explicit raise in ASR models

stanley1208 · merged Sep 14, 20262 files · 9 + / 2
nemo/collections/asr/models/hybrid_rnnt_ctc_models.py5 + / 1
@@ -340,7 +340,11 @@ def change_decoding_strategy(             self.cur_decoder = "rnnt"             return super().change_decoding_strategy(decoding_cfg=decoding_cfg, verbose=verbose) -        assert decoder_type == 'ctc' and hasattr(self, 'ctc_decoder')+        if decoder_type != 'ctc' or not hasattr(self, 'ctc_decoder'):+            raise ValueError(+                f"Unsupported decoder_type '{decoder_type}'. "+                f"Expected 'ctc' with a 'ctc_decoder' attribute on the model."+            )         if decoding_cfg is None:             # Assume same decoding config as before             logging.info("No `decoding_cfg` passed when changing decoding strategy, using internal config")
nemo/collections/asr/parts/utils/manifest_utils.py4 + / 1
@@ -336,7 +336,10 @@ def get_path_dict(data_path: str, uniqids: List[str], len_wavs: int = None) -> D     if data_path is not None:         data_pathlist = read_file(data_path)         if len_wavs is not None:-            assert len(data_pathlist) == len_wavs+            if len(data_pathlist) != len_wavs:+                raise ValueError(+                    f"Number of data paths ({len(data_pathlist)}) does not match expected count ({len_wavs})."+                )             data_pathdict = get_dict_from_list(data_pathlist, uniqids)     elif len_wavs is not None:         data_pathdict = {uniq_id: None for uniq_id in uniqids}