fix(rnnt): guard the export decoder_type path on the actual signature, not hasattr - #16166
Open
Anai-Guo wants to merge 1 commit into
Open
fix(rnnt): guard the export decoder_type path on the actual signature, not hasattr#16166Anai-Guo wants to merge 1 commit into
Anai-Guo wants to merge 1 commit into
Conversation
EncDecRNNTModel.set_export_config() gates the decoder_type call on hasattr(self, 'change_decoding_strategy'), but EncDecRNNTModel defines change_decoding_strategy() itself, so that check is always True and the else branch is unreachable. On a non-hybrid RNNT model the call then raises TypeError instead of the intended error message. Check for the decoder_type parameter itself, which is what the branch actually needs. Hybrid models are unaffected. Signed-off-by: Anai-Guo <antai12232931@outlook.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What does this PR do ?
EncDecRNNTModel.set_export_config()gates thedecoder_typeexport option onhasattr(self, 'change_decoding_strategy'), butEncDecRNNTModeldefineschange_decoding_strategy()itself, so the check is alwaysTrue. Theelsebranch is therefore unreachable, and a non-hybrid RNNT model exported with
decoder_typeraises a confusingTypeErrorfrom deep inside the call instead ofthe intended message.
https://github.com/NVIDIA-NeMo/Speech/blob/main/nemo/collections/asr/models/rnnt_models.py#L1103-L1111
Only the hybrid models actually accept the keyword:
change_decoding_strategysignaturedecoder_type?EncDecRNNTModel(rnnt_models.py:425)(self, decoding_cfg: DictConfig, verbose=True)EncDecRNNTBPEModel(rnnt_bpe_models.py:387)(self, decoding_cfg: DictConfig, verbose: bool = True)EncDecHybridRNNTCTCModel(hybrid_rnnt_ctc_models.py:324)(self, decoding_cfg=None, decoder_type=None, verbose=True)EncDecHybridRNNTCTCBPEModel(hybrid_rnnt_ctc_bpe_models.py:424)(self, decoding_cfg=None, decoder_type=None, verbose=True)Collection: [ASR]
Changelog
decoder_typebranch on the parameter the branch actually needs(
'decoder_type' in inspect.signature(...).parameters) instead of onhasattr, which cannot discriminate.intended
Model does not have decoder type optionerror.Usage
Before this change, on any non-hybrid RNNT model:
After:
Verification
I don't have a GPU here, so rather than importing NeMo I lifted each
change_decoding_strategysignature verbatim from the sources withast, rebuiltthem, and replayed the exact call the guarded branch makes — under both the current
and the patched guard:
main)EncDecRNNTModelTypeError: ... unexpected keyword argument 'decoder_type'Exception: Model does not have decoder type optionEncDecRNNTBPEModelTypeError: ... unexpected keyword argument 'decoder_type'Exception: Model does not have decoder type optionEncDecHybridRNNTCTCModelreturns 'applied'returns 'applied'(unchanged)EncDecHybridRNNTCTCBPEModelreturns 'applied'returns 'applied'(unchanged)Before your PR is "Ready for review"
Pre checks:
PR Type:
🤖 Generated with Claude Code