Skip to content

[ASR][CTC] Beam decoding ignores beam.search_type (search_type hardcoded to "default") #15400

@nedalaltiti

Description

@nedalaltiti

Describe the bug

In AbstractCTCDecoding.__init__ (nemo/collections/asr/parts/submodules/ctc_decoding.py, around line 321), when cfg.strategy == "beam", the search_type argument passed to BeamCTCInfer is hardcoded to "default" instead of being read from cfg.beam.search_type.

All other beam parameters in the same block (beam_size, beam_alpha, beam_beta, kenlm_path) are read from config via self.cfg.beam.get(...). search_type is the only one skipped.

As a result, setting beam.search_type = "pyctcdecode" (e.g., to use a KenLM LM for beam scoring) has no effect: the LM file may load (because kenlm_path is read), but decoding still uses the default beam search algorithm, and no warning/error is raised.

Steps/Code to reproduce bug

from nemo.collections.asr.models import EncDecHybridRNNTCTCBPEModel
from omegaconf import OmegaConf

model = EncDecHybridRNNTCTCBPEModel.from_pretrained(
    "nvidia/stt_ar_fastconformer_hybrid_large_pc"
)

ctc_cfg = OmegaConf.create({
    "strategy": "beam",
    "beam": {
        "beam_size": 32,
        "search_type": "pyctcdecode",
        "kenlm_path": "/path/to/lm.arpa",
        "beam_alpha": 0.5,
        "beam_beta": 0.1,
    },
})

model.change_decoding_strategy(decoding_cfg=ctc_cfg, decoder_type="ctc")
print(model.ctc_decoding.decoding.search_type)

Expected behavior

model.ctc_decoding.decoding.search_type should equal "pyctcdecode" (the value from config), not "default". When kenlm_path is provided and search_type selects an LM-aware beam search (e.g., pyctcdecode), the KenLM language model should participate in scoring.

Environment overview (please complete the following information)

  • Environment location: Docker
  • Method of NeMo install: pip install "nemo_toolkit[asr]==1.23.0"
  • Docker base image: python:3.10-slim (not using an NVIDIA NeMo docker image)

Environment details

  • OS: Debian 12 (Docker) / macOS 15 (host)
  • PyTorch: 2.2.0
  • Python: 3.10
  • NeMo: 1.23.0 (also reproducible on current main)

Additional context

Workaround (monkey-patch after change_decoding_strategy):

beam_infer = model.ctc_decoding.decoding
beam_infer.search_type = "pyctcdecode"
beam_infer.search_algorithm = beam_infer._pyctcdecode_beam_search

Proposed fix: change the hardcoded value to read from config with a backward-compatible fallback:

search_type=self.cfg.beam.get("search_type", "default"),

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions