Error(s):   ConfidenceConfig.__init__() got an unexpected keyword argument 'measure_cfg'
State: closed | Pull request: no
Labels: name: bug

name: stale

How to solve the issue of 'measure_cfg' and 'method_cfg'?

When loading the model using the text_to_speech_eval.py script the model instantiation fails:

[NeMo E 2024-06-02 11:21:20 common:529] Model instantiation failed!
    Target class:       nemo.collections.asr.models.ctc_bpe_models.EncDecCTCModelBPE
    Error(s):   ConfidenceConfig.__init__() got an unexpected keyword argument 'measure_cfg'
    Traceback (most recent call last):
      File "/home/ma-user/work/exp/nemo/core/classes/common.py", line 508, in from_config_dict
        instance = imported_cls(cfg=config, trainer=trainer)
      File "/home/ma-user/work/exp/nemo/collections/asr/models/ctc_bpe_models.py", line 75, in __init__
        super().__init__(cfg=cfg, trainer=trainer)
      File "/home/ma-user/work/exp/nemo/collections/asr/models/ctc_models.py", line 102, in __init__
        self.decoding = CTCDecoding(self.cfg.decoding, vocabulary=OmegaConf.to_container(self.decoder.vocabulary))
      File "/home/ma-user/work/exp/nemo/collections/asr/parts/submodules/ctc_decoding.py", line 1032, in __init__
        super().__init__(decoding_cfg=decoding_cfg, blank_id=blank_id)
      File "/home/ma-user/work/exp/nemo/collections/asr/parts/submodules/ctc_decoding.py", line 235, in __init__
        self._init_confidence(self.cfg.get('confidence_cfg', None))
      File "/home/ma-user/work/exp/nemo/collections/asr/parts/utils/asr_confidence_utils.py", line 352, in _init_confidence
        ConfidenceConfig() if confidence_cfg is None else ConfidenceConfig(**confidence_cfg)
    TypeError: ConfidenceConfig.__init__() got an unexpected keyword argument 'measure_cfg'
    
    Model trained with NeMo version 1.21.0


@nithinraok @titu1994 

Please update to NeMo 1.23.0. 

> Please update to NeMo 1.23.0.
@titu1994 

Traceback (most recent call last):
  File "/home/ma-user/work/exp/speech_to_text_eval.py", line 71, in <module>
    import transcribe_speech
  File "/home/ma-user/work/exp/transcribe_speech.py", line 111, in <module>
    class TranscriptionConfig:
  File "/home/ma-user/work/exp/transcribe_speech.py", line 159, in TranscriptionConfig
    fused_batch_size=-1, greedy=GreedyBatchedRNNTInferConfig(use_cuda_graph_decoder=True)
TypeError: GreedyBatchedRNNTInferConfig.__init__() got an unexpected keyword argument 'use_cuda_graph_decoder'


**model_config:**

```
target: nemo.collections.asr.models.ctc_bpe_models.EncDecCTCModelBPE
nemo_version: 1.21.0
decoding:
  strategy: greedy
  preserve_alignments: null
  compute_timestamps: null
  word_seperator: ' '
  ctc_timestamp_type: all
  batch_dim_index: 0
  greedy:
    preserve_alignments: false
    compute_timestamps: false
    preserve_frame_confidence: false
    confidence_measure_cfg:
      name: entropy
      entropy_type: tsallis
      alpha: 0.33
      entropy_norm: exp
      temperature: DEPRECATED
    confidence_method_cfg: DEPRECATED
  beam:
    beam_size: 4
    search_type: default
    preserve_alignments: false
    compute_timestamps: false
    return_best_hypothesis: true
    beam_alpha: 1.0
    beam_beta: 0.0
    kenlm_path: null
    flashlight_cfg:
      lexicon_path: null
      boost_path: null
      beam_size_token: 16
      beam_threshold: 20.0
      unk_weight: -.inf
      sil_weight: 0.0
    pyctcdecode_cfg:
      beam_prune_logp: -10.0
      token_min_logp: -5.0
      prune_history: false
      hotwords: null
      hotword_weight: 10.0
  confidence_cfg:
    preserve_frame_confidence: false
    preserve_token_confidence: false
    preserve_word_confidence: false
    exclude_blank: true
    aggregation: min
    measure_cfg:
      name: entropy
      entropy_type: tsallis
      alpha: 0.33
      entropy_norm: exp
      temperature: DEPRECATED
    method_cfg: DEPRECATED
  temperature: 1.0

```

@titu1994 @nithinraok your help kindly 

You're using the script from main, that won't work. Switch branch to r1.23 and then use that script 

> You're using the script from main, that won't work. Switch branch to r1.23 and then use that script

**Still facing this error:** TypeError: ConfidenceConfig.__init__() got an unexpected keyword argument 'measure_cfg'

What I see is that, r1.23.0 is also using 'method_cfg', but my trained model using 'measure_cfg'

@titu1994 

Delete the entire "confidence_cfg" part using following 

```pythob
cfg = ASRModel.restore_from(filepath, return_config=True)

del cfg.decoding.confidence_cfg

Model = ASRModel.restore_from(filepath, override_config_path=cfg)

Model.save_to(new_filepath)

```

> Delete the entire "confidence_cfg" part using following
> 
> ```
> cfg = ASRModel.restore_from(filepath, return_config=True)
> 
> del cfg.decoding.confidence_cfg
> 
> Model = ASRModel.restore_from(filepath, override_config_path=cfg)
> 
> Model.save_to(new_filepath)
> ```

This error occurs:

Target class:       nemo.collections.asr.models.ctc_bpe_models.EncDecCTCModelBPE
    Error(s):   nemo.collections.asr.parts.utils.asr_confidence_utils.ConfidenceMethodConfig() argument after ** must be a mapping, not str
    Traceback (most recent call last):
      File "/home/ma-user/work/exp/nemo/core/classes/common.py", line 508, in from_config_dict
        instance = imported_cls(cfg=config, trainer=trainer)
      File "/home/ma-user/work/exp/nemo/collections/asr/models/ctc_bpe_models.py", line 75, in __init__
        super().__init__(cfg=cfg, trainer=trainer)
      File "/home/ma-user/work/exp/nemo/collections/asr/models/ctc_models.py", line 102, in __init__
        self.decoding = CTCDecoding(self.cfg.decoding, vocabulary=OmegaConf.to_container(self.decoder.vocabulary))
      File "/home/ma-user/work/exp/nemo/collections/asr/parts/submodules/ctc_decoding.py", line 1032, in __init__
        super().__init__(decoding_cfg=decoding_cfg, blank_id=blank_id)
      File "/home/ma-user/work/exp/nemo/collections/asr/parts/submodules/ctc_decoding.py", line 235, in __init__
        self._init_confidence(self.cfg.get('confidence_cfg', None))
      File "/home/ma-user/work/exp/nemo/collections/asr/parts/utils/asr_confidence_utils.py", line 384, in _init_confidence
        else OmegaConf.structured(ConfidenceMethodConfig(**confidence_method_cfg))
    TypeError: nemo.collections.asr.parts.utils.asr_confidence_utils.ConfidenceMethodConfig() argument after ** must be a mapping, not str
    
Code:
```
import nemo.collections.asr as nemo_asr

filepath= "Conformer-CTC-BPE-multilang.nemo"

asr_model = nemo_asr.models.EncDecCTCModelBPE
cfg = asr_model.restore_from(filepath, return_config=True)

del cfg.decoding.confidence_cfg

Model = asr_model.restore_from(filepath, override_config_path=cfg)

Model.save_to("./modified/Conformer-CTC-BPE-multilang.nemo")
```
@titu1994 

Oh I see, also delete in a similar way the cfg.decoding.greedy.confidence_measure_cfg

Still..
Traceback (most recent call last):
  File "/home/ma-user/work/exp/del.py", line 11, in <module>
    Model = asr_model.restore_from(filepath, override_config_path=cfg)
  File "/home/ma-user/work/exp/nemo/core/classes/modelPT.py", line 449, in restore_from
    instance = cls._save_restore_connector.restore_from(
  File "/home/ma-user/work/exp/nemo/core/connectors/save_restore_connector.py", line 241, in restore_from
    loaded_params = self.load_config_and_state_dict(
  File "/home/ma-user/work/exp/nemo/core/connectors/save_restore_connector.py", line 164, in load_config_and_state_dict
    instance = calling_cls.from_config_dict(config=conf, trainer=trainer)
  File "/home/ma-user/work/exp/nemo/core/classes/common.py", line 518, in from_config_dict
    raise e
  File "/home/ma-user/work/exp/nemo/core/classes/common.py", line 510, in from_config_dict
    instance = cls(cfg=config, trainer=trainer)
  File "/home/ma-user/work/exp/nemo/collections/asr/models/ctc_bpe_models.py", line 73, in __init__
    super().__init__(cfg=cfg, trainer=trainer)
  File "/home/ma-user/work/exp/nemo/collections/asr/models/ctc_models.py", line 97, in __init__
    self.decoding = CTCDecoding(self.cfg.decoding, vocabulary=OmegaConf.to_container(self.decoder.vocabulary))
  File "/home/ma-user/work/exp/nemo/collections/asr/parts/submodules/ctc_decoding.py", line 935, in __init__
    super().__init__(decoding_cfg=decoding_cfg, blank_id=blank_id)
  File "/home/ma-user/work/exp/nemo/collections/asr/parts/submodules/ctc_decoding.py", line 193, in __init__
    self._init_confidence(self.cfg.get('confidence_cfg', None))
  File "/home/ma-user/work/exp/nemo/collections/asr/parts/utils/asr_confidence_utils.py", line 370, in _init_confidence
    else OmegaConf.structured(ConfidenceMethodConfig(**confidence_method_cfg))
TypeError: nemo.collections.asr.parts.utils.asr_confidence_utils.ConfidenceMethodConfig() argument after ** must be a mapping, not str

I think you’ve solved the issue here https://github.com/NVIDIA/NeMo/pull/6810, but in which branch?

@titu1994 

I had the same problem because I trained the model using nemo-toolkit[all]==1.21.0 and then load the models on latest version. I solved it by reinstall "nemo-toolkit[all]==1.21.0". It worked 

Can you print you full config after you delete the two items ? If that doesn't work there's not much to be done. Also share your script of how you're updating the config 

This issue is stale because it has been open for 30 days with no activity. Remove stale label or comment or this will be closed in 7 days.

This issue was closed because it has been inactive for 7 days since being marked as stale.