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

Use Label-Looping algorithm for RNN-T decoding by default #8831

Merged
merged 7 commits into from
Apr 10, 2024

Conversation

artbataev
Copy link
Collaborator

@artbataev artbataev commented Apr 5, 2024

What does this PR do ?

Enable Label-Looping algorithm introduced in #8286 and #7926 (loop_labels=True) by default for RNN-T greedy decoding.

Collection: [ASR]

Changelog

  • Enable Label-Looping algorithm by default (loop_labels=true)
  • fix Label Looping algorithm for RNN-T/TDT + Stateless network
  • fix tests with custom RNNT Decoder
  • parametrize tests for batched greedy decoding to test both algorithms (Frame-/Label-Looping)

Usage

Label-Looping algorithm is used by default now for batched greedy decoding.

For Frame-Looping algorithm one can use:

python examples/asr/speech_to_text_eval.py  <...> \
 rnnt_decoding.greedy.loop_labels=false

Jenkins CI

To run Jenkins, a NeMo User with write access must comment jenkins on the PR.

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)

Signed-off-by: Vladimir Bataev <vbataev@nvidia.com>
@artbataev artbataev requested review from titu1994 and galv April 5, 2024 13:57
@github-actions github-actions bot added the ASR label Apr 5, 2024
@artbataev artbataev marked this pull request as draft April 5, 2024 18:12
Signed-off-by: Vladimir Bataev <vbataev@nvidia.com>
@artbataev
Copy link
Collaborator Author

Not ready yet

Signed-off-by: Vladimir Bataev <vbataev@nvidia.com>
Signed-off-by: Vladimir Bataev <vbataev@nvidia.com>
Signed-off-by: Vladimir Bataev <vbataev@nvidia.com>
Signed-off-by: Vladimir Bataev <vbataev@nvidia.com>
@artbataev
Copy link
Collaborator Author

jenkins

@artbataev artbataev marked this pull request as ready for review April 9, 2024 07:06
@artbataev artbataev requested a review from hainan-xv April 9, 2024 07:06
state = [torch.ones([batch, self.context_size], dtype=torch.long, device=y.device) * self.blank_idx]
# state contains context_size - 1 elements for each utterance in batch,
# consistent with the state returned from StatelessNet.forward
state = [torch.ones([batch, self.context_size - 1], dtype=torch.long, device=y.device) * self.blank_idx]
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@hainan-xv, please, confirm that I broke nothing when fixing state for the Stateless decoder.
We need the state with the constant size (to allow replacements when we found the end of utterance), and forward returns the state of size [batch_size, context_size - 1]

Copy link
Collaborator

Choose a reason for hiding this comment

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

LGTM.

Copy link
Collaborator

Choose a reason for hiding this comment

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

FYI, you can also use torch.full instead of torch.ones followed by multiplication. No need to change it though.

Copy link
Collaborator

@titu1994 titu1994 left a comment

Choose a reason for hiding this comment

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

Overall looks great, nice work !

@@ -73,7 +73,7 @@ def predict(
return (
output,
[
torch.tensor([0] * self.vocab_size + [1], dtype=torch.float32)[None, None, :].exand(
torch.tensor([0] * self.vocab_size + [1], dtype=torch.float32)[None, None, :].expand(
Copy link
Collaborator

Choose a reason for hiding this comment

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

How how did this test pass with this error ?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I think this case is redundant and never executed in decoding, but we need to implement this to conform the interface where y is optional (see AbstractRNNTDecoder.predict)

@artbataev artbataev merged commit b33af25 into main Apr 10, 2024
127 checks passed
@artbataev artbataev deleted the rnnt_decoding_loop_labels_default branch April 10, 2024 17:03
Copy link
Collaborator

@galv galv left a comment

Choose a reason for hiding this comment

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

Late review with a few FYI comments. Do we test the cuda graphs implementation with stateless transducers yet?

state = [torch.ones([batch, self.context_size], dtype=torch.long, device=y.device) * self.blank_idx]
# state contains context_size - 1 elements for each utterance in batch,
# consistent with the state returned from StatelessNet.forward
state = [torch.ones([batch, self.context_size - 1], dtype=torch.long, device=y.device) * self.blank_idx]
Copy link
Collaborator

Choose a reason for hiding this comment

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

FYI, you can also use torch.full instead of torch.ones followed by multiplication. No need to change it though.

return [
torch.tensor([0] * self.vocab_size + [1], dtype=torch.float32)[None, None, :]
.expand([1, batch_size, -1])
.clone()
Copy link
Collaborator

Choose a reason for hiding this comment

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

torch.repeat or torch.repeat_interleave is probably the better way to do it than expand followed by clone.

@artbataev
Copy link
Collaborator Author

artbataev commented Apr 11, 2024

Late review with a few FYI comments. Do we test the cuda graphs implementation with stateless transducers yet?

Thanks for the comments, @galv! I will make fixes in next PRs.
Cuda graphs implementation with stateless prediction network is not tested on CI for now (no production model), but I tested loop labels + cuda graphs locally with a custom model, and it works.

anmolgupt pushed a commit to anmolgupt/NeMo that referenced this pull request Apr 11, 2024
* Use Label-Looping algorithm for RNN-T decoding by default
* Fix loop labels + stateless decoding

---------

Signed-off-by: Vladimir Bataev <vbataev@nvidia.com>
ftxj pushed a commit to ftxj/NeMo that referenced this pull request Apr 12, 2024
* Use Label-Looping algorithm for RNN-T decoding by default
* Fix loop labels + stateless decoding

---------

Signed-off-by: Vladimir Bataev <vbataev@nvidia.com>
Signed-off-by: jxin <jxin@nvidia.com>
suiyoubi pushed a commit that referenced this pull request May 2, 2024
* Use Label-Looping algorithm for RNN-T decoding by default
* Fix loop labels + stateless decoding

---------

Signed-off-by: Vladimir Bataev <vbataev@nvidia.com>
Signed-off-by: Ao Tang <aot@nvidia.com>
rohitrango pushed a commit to rohitrango/NeMo that referenced this pull request Jun 25, 2024
* Use Label-Looping algorithm for RNN-T decoding by default
* Fix loop labels + stateless decoding

---------

Signed-off-by: Vladimir Bataev <vbataev@nvidia.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants