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

Making TDT models support all-positive durations (previously duration must contain 0) #9656

Open
wants to merge 7 commits into
base: main
Choose a base branch
from

Conversation

hainan-xv
Copy link
Collaborator

@hainan-xv hainan-xv commented Jul 9, 2024

What does this PR do ?

This PR makes TDT models support all-positive durations (previously duration must contain 0).

Collection: [ASR]

Changelog

  • the kernal code for computing TDT loss is changed.
  • tests are added to test the correctness of new code and also ensures it's back-compatible.

Usage

N/A

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)

…ions for TDT

Signed-off-by: Hainan Xu <hainanx@nvidia.com>
@hainan-xv hainan-xv self-assigned this Jul 9, 2024
@github-actions github-actions bot added the ASR label Jul 9, 2024
Hainan Xu and others added 5 commits July 9, 2024 12:54
Signed-off-by: hainan-xv <hainan-xv@users.noreply.github.com>
Signed-off-by: Hainan Xu <hainanx@nvidia.com>
Signed-off-by: Hainan Xu <hainanx@nvidia.com>
Copy link
Collaborator

@artbataev artbataev left a comment

Choose a reason for hiding this comment

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

LGTM, thanks!
Minor suggestions in comments.

@pytest.mark.unit
@pytest.mark.parametrize('device', DEVICES)
def test_case_randomized_act_label_no_0_duration(self, device):
if device == 'cuda':
Copy link
Collaborator

Choose a reason for hiding this comment

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

I would suggest explicitly skipping the test for "cpu" here and in other tests for TDT.
I see that TDT is not implemented for CPU, but pytest logs show TestTDTLoss::test_case_randomized_act_label_no_0_duration[cpu] PASSED which is confusing.

- sigma
+ logp_duration(duration_acts, maxT, maxU, num_durations, b, T - 1, U - 1, 1)
)
if durations[0] == 1:
Copy link
Collaborator

Choose a reason for hiding this comment

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

Just a suggestion (at your discretion):

duration_1_idx = ... # find index or -1
if duration_1_idx != -1:
    betas[offset + (T - 1) * maxU + U - 1] = ... # set betas

Motivation: avoid duplicating complex expression.

@artbataev
Copy link
Collaborator

@hainan-xv Something is wrong with tests in this branch (not related to TDT). Please, update to main and toggle Run CICD label

@@ -961,7 +961,9 @@ def compute_tdt_alphas_kernel(
if t > 0 and t < T:
Copy link
Collaborator

Choose a reason for hiding this comment

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

Git not letting me comment but remove the comment from 945. I don't know why we left that lying around if it's not in use.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Also, let's just remove num_durations as a variable since it's redundant with also specifying which duration lengths.

Please also update the doc args

) # t = 0, so it must be duration = 0. Therefore the last argument passed to logp_duration() is 0.
)
else:
alphas[offset + u] = -INF

# now we have t != 0 and u != 0, and we need to consider both non-blank and blank emissions.
elif t > 0 and t < T:
Copy link
Collaborator

Choose a reason for hiding this comment

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

Dumb question: what do we do in cases t<0 are those just skipped passes on the kernel call?

@@ -961,7 +961,9 @@ def compute_tdt_alphas_kernel(
if t > 0 and t < T:
alphas[offset + t * maxU + u] = -INF

for i in range(1, num_durations): # skip 0 since blank emission has to advance by at least one
for i in range(0, num_durations):
Copy link
Collaborator

Choose a reason for hiding this comment

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

just make it single variable range. No need to make it overt


# then we add the scores for duration > 1, if such durations are possible given the audio lengths.
for i in range(2, num_durations):
for i in range(0, num_durations):
Copy link
Collaborator

Choose a reason for hiding this comment

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

just use single variable range

@@ -1140,11 +1159,12 @@ def compute_tdt_betas_kernel(
# u == U - 1, we only consider blank emissions.
if t >= 0 and t + 1 < T:
betas[offset + t * maxU + U - 1] = -INF
for i in range(1, num_durations):
for i in range(0, num_durations):
Copy link
Collaborator

Choose a reason for hiding this comment

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

use single variable range

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants