Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fast N-Gram LM on GPU + greedy decoding (RNN-T, TDT, CTC) #10989

Draft
wants to merge 56 commits into
base: main
Choose a base branch
from

Conversation

artbataev
Copy link
Collaborator

@artbataev artbataev commented Oct 22, 2024

What does this PR do ?

Add a one line overview of what this PR aims to accomplish.

Collection: [Note which collection this PR will affect]

Changelog

  • Add specific line by line info of high level changes in this PR.

Usage

Step 1: Build LM for ASR Model (model-dependent) on domain texts

python nemo/scripts/asr_language_modeling/ngram_lm/train_kenlm.py \
      nemo_model_file="nvidia/parakeet-rnnt-1.1b" \
      train_paths=["<train_manifest>"] \
      kenlm_bin_path=$KENLM_BIN_PATH \
      kenlm_model_file=parakeet-rnnt-1.1b_lm-o6.arpa \
      ngram_length=6 \
      preserve_arpa=true

Step 2: Run Decoding with LM (arpa)

python examples/asr/speech_to_text_eval.py \
   pretrained_name="nvidia/parakeet-rnnt-1.1b" \
   dataset_manifest=<dataset_manifest>  \
   batch_size=32 \
   output_filename=decoded.jsonl \
   rnnt_decoding.strategy="greedy_batch" \
   rnnt_decoding.greedy.ngram_lm_model="parakeet-rnnt-1.1b_lm-o6.arpa.tmp.arpa" \
   rnnt_decoding.greedy.ngram_lm_alpha=0.5

GitHub Actions CI

The Jenkins CI system has been replaced by GitHub Actions self-hosted runners.

The GitHub Actions CI will run automatically when the "Run CICD" label is added to the PR.
To re-run CI remove and add the label again.
To run CI on an untrusted fork, a NeMo user with write access must first click "Approve and run".

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?
  • Does the PR affect components that are optional to install? (Ex: Numba, Pynini, Apex etc)
    • Reviewer: Does the PR have correct import guards for all optional libraries?

PR Type:

  • New Feature
  • Bugfix
  • Documentation

If you haven't finished some of the above items you can still open "Draft" PR.

Who can review?

Anyone in the community is free to review the PR once the checks have passed.
Contributor guidelines contains specific people who can review PRs to various areas.

Additional Information

  • Related to # (issue)

@github-actions github-actions bot added the ASR label Oct 22, 2024
nemo/collections/asr/parts/ngram_lm.py Fixed Show fixed Hide fixed
nemo/collections/asr/parts/ngram_lm.py Fixed Show fixed Hide fixed
nemo/collections/asr/parts/ngram_lm.py Fixed Show fixed Hide fixed
nemo/collections/asr/parts/ngram_lm.py Fixed Show fixed Hide fixed
nemo/collections/asr/parts/ngram_lm.py Fixed Show fixed Hide fixed
Comment on lines +521 to +523
# for i, label in enumerate(labels.tolist()):
# if label != self._blank_index:
# batch_lm_states[i] = batch_lm_states_candidates[i][label]

Check notice

Code scanning / CodeQL

Commented-out code Note

This comment appears to contain commented-out code.
Comment on lines +586 to +588
# for i, label in enumerate(labels.tolist()):
# if label != self._blank_index:
# batch_lm_states[i] = batch_lm_states_candidates[i][label]

Check notice

Code scanning / CodeQL

Commented-out code Note

This comment appears to contain commented-out code.
Copy link

@github-advanced-security github-advanced-security bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CodeQL found more than 20 potential problems in the proposed changes. Check the Files changed tab for more details.

@github-actions github-actions bot added the stale label Nov 6, 2024
@artbataev artbataev removed the stale label Nov 6, 2024
@github-actions github-actions bot added the stale label Nov 29, 2024
@github-actions github-actions bot closed this Dec 6, 2024
@artbataev artbataev removed the stale label Dec 13, 2024
@artbataev artbataev reopened this Dec 13, 2024
@github-actions github-actions bot added the stale label Jan 28, 2025
@artbataev artbataev removed the stale label Jan 28, 2025
@NVIDIA NVIDIA deleted a comment from github-actions bot Jan 28, 2025
Copy link
Contributor

beep boop 🤖: 🙏 The following files have warnings. In case you are familiar with these, please try helping us to improve the code base.


Your code was analyzed with PyLint. The following annotations have been identified:

************* Module nemo.collections.asr.parts.submodules.ctc_decoding
nemo/collections/asr/parts/submodules/ctc_decoding.py:370:0: C0301: Line too long (136/119) (line-too-long)
nemo/collections/asr/parts/submodules/ctc_decoding.py:764:0: C0301: Line too long (151/119) (line-too-long)
nemo/collections/asr/parts/submodules/ctc_decoding.py:921:0: C0301: Line too long (125/119) (line-too-long)
nemo/collections/asr/parts/submodules/ctc_decoding.py:33:0: C0116: Missing function or method docstring (missing-function-docstring)
nemo/collections/asr/parts/submodules/ctc_decoding.py:995:4: C0116: Missing function or method docstring (missing-function-docstring)
nemo/collections/asr/parts/submodules/ctc_decoding.py:1006:4: C0116: Missing function or method docstring (missing-function-docstring)
nemo/collections/asr/parts/submodules/ctc_decoding.py:1017:4: C0116: Missing function or method docstring (missing-function-docstring)
nemo/collections/asr/parts/submodules/ctc_decoding.py:1477:0: C0115: Missing class docstring (missing-class-docstring)
nemo/collections/asr/parts/submodules/ctc_decoding.py:1524:0: C0115: Missing class docstring (missing-class-docstring)
************* Module nemo.collections.asr.parts.submodules.ctc_greedy_decoding
nemo/collections/asr/parts/submodules/ctc_greedy_decoding.py:63:0: C0301: Line too long (247/119) (line-too-long)
nemo/collections/asr/parts/submodules/ctc_greedy_decoding.py:162:0: C0301: Line too long (123/119) (line-too-long)
nemo/collections/asr/parts/submodules/ctc_greedy_decoding.py:171:0: C0301: Line too long (205/119) (line-too-long)
nemo/collections/asr/parts/submodules/ctc_greedy_decoding.py:399:0: C0301: Line too long (123/119) (line-too-long)
nemo/collections/asr/parts/submodules/ctc_greedy_decoding.py:30:0: C0116: Missing function or method docstring (missing-function-docstring)
nemo/collections/asr/parts/submodules/ctc_greedy_decoding.py:643:0: C0115: Missing class docstring (missing-class-docstring)
************* Module nemo.collections.asr.parts.submodules.rnnt_loop_labels_computer
nemo/collections/asr/parts/submodules/rnnt_loop_labels_computer.py:198:4: C0115: Missing class docstring (missing-class-docstring)
************* Module nemo.collections.asr.parts.submodules.tdt_loop_labels_computer
nemo/collections/asr/parts/submodules/tdt_loop_labels_computer.py:204:4: C0115: Missing class docstring (missing-class-docstring)
************* Module scripts.asr_language_modeling.ngram_lm.kenlm_utils
scripts/asr_language_modeling/ngram_lm/kenlm_utils.py:20:0: C0301: Line too long (129/119) (line-too-long)
scripts/asr_language_modeling/ngram_lm/kenlm_utils.py:21:0: C0301: Line too long (124/119) (line-too-long)
scripts/asr_language_modeling/ngram_lm/kenlm_utils.py:80:0: C0301: Line too long (129/119) (line-too-long)
scripts/asr_language_modeling/ngram_lm/kenlm_utils.py:53:0: C0116: Missing function or method docstring (missing-function-docstring)
scripts/asr_language_modeling/ngram_lm/kenlm_utils.py:58:0: C0116: Missing function or method docstring (missing-function-docstring)
scripts/asr_language_modeling/ngram_lm/kenlm_utils.py:104:0: C0116: Missing function or method docstring (missing-function-docstring)
scripts/asr_language_modeling/ngram_lm/kenlm_utils.py:130:0: C0116: Missing function or method docstring (missing-function-docstring)
scripts/asr_language_modeling/ngram_lm/kenlm_utils.py:180:0: C0116: Missing function or method docstring (missing-function-docstring)
scripts/asr_language_modeling/ngram_lm/kenlm_utils.py:189:0: C0116: Missing function or method docstring (missing-function-docstring)
scripts/asr_language_modeling/ngram_lm/kenlm_utils.py:216:0: C0116: Missing function or method docstring (missing-function-docstring)
************* Module scripts.asr_language_modeling.ngram_lm.train_kenlm
scripts/asr_language_modeling/ngram_lm/train_kenlm.py:66:0: C0301: Line too long (169/119) (line-too-long)
scripts/asr_language_modeling/ngram_lm/train_kenlm.py:77:0: C0301: Line too long (128/119) (line-too-long)
scripts/asr_language_modeling/ngram_lm/train_kenlm.py:83:0: C0116: Missing function or method docstring (missing-function-docstring)

-----------------------------------
Your code has been rated at 9.90/10

Mitigation guide:

  • Add sensible and useful docstrings to functions and methods
  • For trivial methods like getter/setters, consider adding # pylint: disable=C0116 inside the function itself
  • To disable multiple functions/methods at once, put a # pylint: disable=C0116 before the first and a # pylint: enable=C0116 after the last.

By applying these rules, we reduce the occurance of this message in future.

Thank you for improving NeMo's documentation!

Copy link
Contributor

beep boop 🤖: 🚨 The following files must be fixed before merge!


Your code was analyzed with PyLint. The following annotations have been identified:

************* Module nemo.collections.asr.parts.submodules.ngram_lm
nemo/collections/asr/parts/submodules/ngram_lm.py:86:4: C0116: Missing function or method docstring (missing-function-docstring)
nemo/collections/asr/parts/submodules/ngram_lm.py:95:4: C0116: Missing function or method docstring (missing-function-docstring)
nemo/collections/asr/parts/submodules/ngram_lm.py:98:4: C0116: Missing function or method docstring (missing-function-docstring)
nemo/collections/asr/parts/submodules/ngram_lm.py:148:4: C0116: Missing function or method docstring (missing-function-docstring)
nemo/collections/asr/parts/submodules/ngram_lm.py:172:0: C0115: Missing class docstring (missing-class-docstring)
nemo/collections/asr/parts/submodules/ngram_lm.py:279:4: C0116: Missing function or method docstring (missing-function-docstring)
nemo/collections/asr/parts/submodules/ngram_lm.py:385:4: C0116: Missing function or method docstring (missing-function-docstring)
nemo/collections/asr/parts/submodules/ngram_lm.py:518:4: C0116: Missing function or method docstring (missing-function-docstring)
nemo/collections/asr/parts/submodules/ngram_lm.py:716:4: C0116: Missing function or method docstring (missing-function-docstring)
nemo/collections/asr/parts/submodules/ngram_lm.py:805:4: C0116: Missing function or method docstring (missing-function-docstring)

-----------------------------------
Your code has been rated at 9.82/10

Mitigation guide:

  • Add sensible and useful docstrings to functions and methods
  • For trivial methods like getter/setters, consider adding # pylint: disable=C0116 inside the function itself
  • To disable multiple functions/methods at once, put a # pylint: disable=C0116 before the first and a # pylint: enable=C0116 after the last.

By applying these rules, we reduce the occurance of this message in future.

Thank you for improving NeMo's documentation!

assert ilabel == -2
self.states[from_state]["final"] = ngram["weight"]
continue
assert 0 <= ilabel < self.vocab_size

Check warning

Code scanning / CodeQL

Redundant comparison Warning

Test is always true, because of
this condition
.
Copy link
Contributor

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

@github-actions github-actions bot added the stale label Feb 13, 2025
@artbataev artbataev removed the stale label Feb 13, 2025
Signed-off-by: Vladimir Bataev <[email protected]>
from collections.abc import Iterator
from dataclasses import InitVar, dataclass, field
from pathlib import Path
from typing import List, NamedTuple, Optional, cast

Check notice

Code scanning / CodeQL

Unused import Note

Import of 'Optional' is not used.
Import of 'List' is not used.
from tqdm.auto import tqdm

from nemo.collections.common.parts import NEG_INF
from nemo.core import ModelPT, PretrainedModelInfo

Check notice

Code scanning / CodeQL

Unused import Note

Import of 'PretrainedModelInfo' is not used.

self._final_resolved = False

def list_available_models(cls):

Check notice

Code scanning / CodeQL

First parameter of a method is not named 'self' Note

Normal methods should have 'self', rather than 'cls', as their first parameter.
artbataev and others added 9 commits February 13, 2025 18:15
Signed-off-by: Vladimir Bataev <[email protected]>
Signed-off-by: Vladimir Bataev <[email protected]>
Signed-off-by: Vladimir Bataev <[email protected]>
Signed-off-by: Vladimir Bataev <[email protected]>
Signed-off-by: Vladimir Bataev <[email protected]>
Signed-off-by: Vladimir Bataev <[email protected]>
Comment on lines +40 to +43
from nemo.collections.asr.parts.submodules.ngram_lm_triton import (
_ngram_advance_triton_kernel,
_ngram_advance_triton_kernel_v2,
)

Check notice

Code scanning / CodeQL

Unused import Note

Import of '_ngram_advance_triton_kernel' is not used.
Signed-off-by: Vladimir Bataev <[email protected]>
Signed-off-by: Vladimir Bataev <[email protected]>
Signed-off-by: Vladimir Bataev <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ASR core Changes to NeMo Core
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant