NeMo icon indicating copy to clipboard operation
NeMo copied to clipboard

[Nemotron VoiceChat] ASR EOS loss-weight mismatch between labels and token weighting

Open petrichor20211 opened this issue 3 months ago • 1 comments

Describe the bug

In the nemotron-labs-voicechat branch, prepare_labels() replaces the user EOS token (user_eos_id, $) with text_eos_id:

source_tokens_flat[source_tokens_flat == user_eos_id] = text_eos_id

However, ASR loss weighting still checks:

asr_labels == self.user_eos_id

Therefore, when user_eos_id != text_eos_id, the actual ASR EOS label does not receive eos_weight and instead falls back to text_weight.

Steps/Code to reproduce bug

  1. Check out the nemotron-labs-voicechat branch.
  2. Set predict_user_text=True.
  3. Enable distinct token loss weights:
token_loss_weight:
  eos: 10.0
  text: 1.0
  1. Inspect an ASR EOS position after prepare_labels().

The label at that position is text_eos_id, but asr_loss_scale compares it with self.user_eos_id. The position therefore receives text_weight (1.0) rather than eos_weight (10.0).

Relevant code:

# nemo/collections/speechlm2/parts/label_prep.py
source_tokens_flat[source_tokens_flat == user_eos_id] = text_eos_id
# nemo/collections/speechlm2/models/duplex_stt_model.py
torch.where(
    asr_labels.unsqueeze(-1) == self.user_eos_id,
    eos_weight,
    text_weight,
)

Expected behavior

ASR EOS positions should receive eos_weight.

Because prepare_labels() converts ASR EOS labels to text_eos_id, the weighting condition should also use self.text_eos_id:

torch.where(
    asr_labels.unsqueeze(-1) == self.text_eos_id,
    eos_weight,
    text_weight,
)

Environment overview

  • Environment location: Linux
  • Method of NeMo install: From source
  • Branch: nemotron-labs-voicechat
  • Commit: 097dfe9e2f55baf653b83035868bdc89849f1b47

Environment details

  • OS version: Ubuntu 20.04.3 LTS
  • Kernel: Linux 5.15.0-60-generic x86_64
  • PyTorch version: 2.10.0+cu128
  • CUDA runtime reported by PyTorch: 12.8
  • Python version: 3.12.13

Additional context

The inference path already applies the user EOS boost to text_eos_id:

asr_logits[:, :, self.text_eos_id] += self.cfg.inference_user_eos_boost

Additionally, the current main branch uses text_eos_id for ASR EOS loss weighting:

torch.where(
    asr_labels.unsqueeze(-1) == self.text_eos_id,
    eos_weight,
    text_weight,
)

This suggests that the mismatch is specific to the legacy VoiceChat implementation and may already have been corrected during subsequent development on main.

petrichor20211 avatar Aug 26 '26 05:08 petrichor20211

I worked from the nemotron-labs-voicechat branch and reproduced the issue on CPU by giving the user EOS and text EOS tokens different IDs. Label preparation remapped the token correctly, but the loss calculation still looked for the original ID, so the EOS position received the regular text weight.

The patch uses the remapped text EOS ID when assigning the loss weight. I checked the original and patched behavior with distinct and shared EOS IDs, masked positions, and ASR disabled. I also added a regression test through prepare_inputs. The full VoiceChat test remains unverified locally because the environment is missing lhotse.

The patch is in #16597.

spacenets7 avatar Nov 11 '26 18:11 spacenets7