+
    QV-j²  ã                   ó~   € ^ RI t ^RIHtHt ]P                  ! ]4      t]! 4       '       d   ^ RItRR R lltRR lt	R# )é    N)Úis_torchaudio_availableÚloggingc                óÐ   € V ^8„  d   QhR\         P                  R\         P                  R\         P                  R\         P                  R\        R\        R\         P                  /# )é   ÚlogitsÚtargetsÚlogit_lengthsÚtarget_lengthsÚblank_token_idÚ	reductionÚreturn)ÚtorchÚTensorÚintÚstr)Úformats   "Úl/Volumes/fast/ai/experiments/ui-tars-smoke/.venv/lib/python3.14/site-packages/transformers/loss/loss_rnnt.pyÚ__annotate__r      sb   € ÷ ?ñ ?Ü�L‰Lð?ä�\‰\ð?ô —<‘<ð?ô —L‘Lð	?ô
 ð?ô ð?ô ‡\�\ñ?ó    c           	     ó2  € \        4       '       g   \        R4      hRpWV9  d)   \        RV RR	P                  R
 V 4       4       R24      hVP	                  V P
                  4      p\        P                  P                  V P                  4       P                  4       VP	                  V P
                  4      P                  4       VP	                  V P
                  4      P                  4       VP                  4       VRR7      pVR8X  d4   VP                  4       VP                  4       P                  4       ,          # VR8X  d   VP                  4       # VR8X  d%   WsP                  4       ,          P                  4       # VR8X  d   VP                  4       # V# )a¯  
Compute standard RNN-T (RNN Transducer) loss (https://huggingface.co/papers/1211.3711).

Thin wrapper around [`torchaudio.functional.rnnt_loss`]. torchaudio is queried with `reduction="none"` to get
the per-sample negative log-likelihoods, and the requested reduction is applied here. The reduction names and
formulas mirror NeMo's `RNNTLoss` (the reference implementation used to train/finetune Parakeet), so that loss
magnitudes and gradient scaling match when finetuning other RNNT models like Parakeet:

- `"mean_volume"`: sum of per-sample losses divided by the sum of target lengths (per-token average over the
  whole batch). This is what `nvidia/parakeet-rnnt-0.6b` is trained with (`rnnt_reduction: mean_volume`).
- `"mean_batch"`: plain average of per-sample losses over the batch (NeMo's default).
- `"mean"`: per-sample loss divided by its own target length, then averaged over the batch.
- `"sum"`: sum of per-sample losses.
- `"none"`: per-sample losses, unreduced.

Args:
    logits: Joint token logits of shape `(batch, T, U+1, vocab_size)`.
    targets: Target labels of shape `(batch, U)`.
    logit_lengths: Encoder output lengths of shape `(batch,)`.
    target_lengths: Target lengths of shape `(batch,)`.
    blank_token_id: Blank token id.
    reduction: Loss reduction method. One of `"mean_volume"`, `"mean_batch"`, `"mean"`, `"sum"`, or `"none"`.

Returns:
    Scalar loss tensor (or per-example losses if `reduction="none"`).

zWComputing the RNN-T loss requires torchaudio. Install it with `pip install torchaudio`.Úmean_volumeÚ
mean_batchÚmeanÚsumÚnonezInvalid reduction mode "z". Expected one of z, c              3   ó8   "  € T F  p\        V4      x € K  	  R # 5i)N)Úrepr)Ú.0Úrs   & r   Ú	<genexpr>Úrnnt_loss.<locals>.<genexpr>D   s   é € ÐNqÑ`pÐ[\ÌtÐTUÏwÈwÓ`pùs   ‚Ú.)r   r   r	   r
   Úblankr   )r   r   r   r   r   )r   ÚImportErrorÚ
ValueErrorÚjoinÚtoÚdeviceÚ
torchaudioÚ
functionalÚ	rnnt_lossÚfloatÚ
contiguousr   r   r   )r   r   r	   r
   r   r   Úvalid_reductionsÚlossess   &&&&&&  r   r+   r+      s^  € ôH #×$Ò$ÜÐsÓtÐtàKÐØÔ(ÜØ& y kÐ1DÀTÇYÁYÑNqÑ`pÓNqÓEqÐDrÐrsÐtó
ð 	
ð $×&Ñ& v§}¡}Ó5€NÜ×"Ñ"×,Ñ,Ø�|‰|‹~×(Ñ(Ó*Ø—
‘
˜6Ÿ=™=Ó)×-Ñ-Ó/Ø#×&Ñ& v§}¡}Ó5×9Ñ9Ó;Ø%×)Ñ)Ó+ØØð -ó €Fð �MÔ!Ø�z‰z‹|˜n×2Ñ2Ó4×8Ñ8Ó:Õ:Ð:Ø	�lÔ	"Ø�{‰{‹}ÐØ	�fÔ	Ø×-Ñ-Ó/Õ/×5Ñ5Ó7Ð7Ø	�eÔ	Ø�z‰z‹|ÐØ€Mr   c           	      ó$   € \        V VVVVVR 7      # ))r   r   r	   r
   r   r   )r+   )r   Úlabelsr	   Úlabel_lengthsr   r   Úkwargss   &&&&&&,r   ÚParakeetForRNNTLossr4   \   s#   € ô ØØØ#Ø$Ø%Øôð r   )r   )
r   Úutilsr   r   Ú
get_loggerÚ__name__Úloggerr)   r+   r4   © r   r   Ú<module>r:      s6   ðó ç 4ð 
×	Ò	˜HÓ	%€á×ÒÛ÷?öDr   