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

Fix bug in RNNT Joint WER calculation for fused batch #8587

Merged
merged 1 commit into from
Mar 5, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 23 additions & 6 deletions nemo/collections/asr/modules/rnnt.py
Original file line number Diff line number Diff line change
Expand Up @@ -1394,6 +1394,7 @@ def forward(
)

losses = []
wers, wer_nums, wer_denoms = [], [], []
target_lengths = []
batch_size = int(encoder_outputs.size(0)) # actual batch size

Expand Down Expand Up @@ -1476,6 +1477,13 @@ def forward(
targets=sub_transcripts,
targets_lengths=sub_transcript_lens,
)
# Sync and all_reduce on all processes, compute global WER
wer, wer_num, wer_denom = self.wer.compute()
self.wer.reset()

wers.append(wer)
wer_nums.append(wer_num)
wer_denoms.append(wer_denom)

del sub_enc, sub_transcripts, sub_enc_lens, sub_transcript_lens

Expand All @@ -1485,9 +1493,9 @@ def forward(

# Collect sub batch wer results
if compute_wer:
# Sync and all_reduce on all processes, compute global WER
wer, wer_num, wer_denom = self.wer.compute()
self.wer.reset()
wer = sum(wers) / len(wers)
wer_num = sum(wer_nums)
wer_denom = sum(wer_denoms)
else:
wer = None
wer_num = None
Expand Down Expand Up @@ -1899,6 +1907,7 @@ def forward(
)

losses = []
wers, wer_nums, wer_denoms = [], [], []
target_lengths = []
batch_size = int(encoder_outputs.size(0)) # actual batch size

Expand Down Expand Up @@ -1992,6 +2001,14 @@ def forward(
targets_lengths=sub_transcript_lens,
)

# Sync and all_reduce on all processes, compute global WER
wer, wer_num, wer_denom = self.wer.compute()
self.wer.reset()

wers.append(wer)
wer_nums.append(wer_num)
wer_denoms.append(wer_denom)

del sub_enc, sub_transcripts, sub_enc_lens, sub_transcript_lens

# Reduce over sub batches
Expand All @@ -2000,9 +2017,9 @@ def forward(

# Collect sub batch wer results
if compute_wer:
# Sync and all_reduce on all processes, compute global WER
wer, wer_num, wer_denom = self.wer.compute()
self.wer.reset()
wer = sum(wers) / len(wers)
wer_num = sum(wer_nums)
wer_denom = sum(wer_denoms)
else:
wer = None
wer_num = None
Expand Down
Loading