Skip to content

fix(rnnt): guard the export decoder_type path on the actual signature, not hasattr - #16166

Open
Anai-Guo wants to merge 1 commit into
NVIDIA-NeMo:mainfrom
Anai-Guo:fix/rnnt-export-decoder-type-guard
Open

fix(rnnt): guard the export decoder_type path on the actual signature, not hasattr#16166
Anai-Guo wants to merge 1 commit into
NVIDIA-NeMo:mainfrom
Anai-Guo:fix/rnnt-export-decoder-type-guard

Conversation

@Anai-Guo

Copy link
Copy Markdown

What does this PR do ?

EncDecRNNTModel.set_export_config() gates the decoder_type export option on
hasattr(self, 'change_decoding_strategy'), but EncDecRNNTModel defines
change_decoding_strategy() itself
, so the check is always True. The else
branch is therefore unreachable, and a non-hybrid RNNT model exported with
decoder_type raises a confusing TypeError from deep inside the call instead of
the 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:

class change_decoding_strategy signature accepts decoder_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

  • Guard the decoder_type branch on the parameter the branch actually needs
    ('decoder_type' in inspect.signature(...).parameters) instead of on
    hasattr, which cannot discriminate.
  • Hybrid models keep their existing behaviour; non-hybrid models now get the
    intended Model does not have decoder type option error.

Usage

Before this change, on any non-hybrid RNNT model:

model.set_export_config({'decoder_type': 'ctc'})
# TypeError: change_decoding_strategy() got an unexpected keyword argument 'decoder_type'

After:

model.set_export_config({'decoder_type': 'ctc'})
# Exception: Model does not have decoder type option

Verification

I don't have a GPU here, so rather than importing NeMo I lifted each
change_decoding_strategy signature verbatim from the sources with ast, rebuilt
them, and replayed the exact call the guarded branch makes — under both the current
and the patched guard:

model current (main) with this PR
EncDecRNNTModel TypeError: ... unexpected keyword argument 'decoder_type' Exception: Model does not have decoder type option
EncDecRNNTBPEModel TypeError: ... unexpected keyword argument 'decoder_type' Exception: Model does not have decoder type option
EncDecHybridRNNTCTCModel returns 'applied' returns 'applied' (unchanged)
EncDecHybridRNNTCTCBPEModel returns 'applied' returns 'applied' (unchanged)

Before your PR is "Ready for review"

Pre checks:

  • Make sure you read and followed Contributor guidelines
  • Did you write any new necessary tests?
  • Did you add or update any necessary documentation? (no user-facing docs change; the documented behaviour is what now actually happens)
  • Does the PR affect components that are optional to install? (No)

PR Type:

  • Bugfix
  • New Feature
  • Documentation
  • Test

🤖 Generated with Claude Code

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>
@copy-pr-bot

copy-pr-bot Bot commented Aug 29, 2026

Copy link
Copy Markdown

This pull request requires additional validation before any workflows can run on NVIDIA's runners.

Pull request vetters can view their responsibilities here.

Contributors can view more details about this message here.

@github-actions github-actions Bot added the ASR label Aug 29, 2026
@svcnvidia-nemo-ci svcnvidia-nemo-ci added the waiting-on-maintainers Waiting on maintainers to respond label Aug 31, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ASR community-request waiting-on-maintainers Waiting on maintainers to respond

2 participants