
    Pi                     2    d dl Z de j        de j        fdZdS )    Nmaskreturnc                     |                       d                              d                              t          j                  }|                    d| j        d         dz
            S )az  
    Returns the sequence lengths (0-indexed) for each batch element, excluding masked tokens.

    Args:
        mask (torch.Tensor): Boolean mask with shape [b x s], where True indicates a value to be masked out
            This is usually a mask for padding tokens, where True indicates a padding token.

    Returns:
        Tensor: Sequence indices logits with shape [b]

    Shape notation:
        - b = batch size
        - s = sequence length

    Example:
        >>> input_ids = torch.tensor([
        ...        [2, 4, 0, 0],
        ...        [2, 4, 6, 0],
        ...        [2, 4, 6, 9]
        ...    ])
        >>> mask = input_ids == 0
        >>> mask
        tensor([[False, False,  True,  True],
                [False, False, False,  True],
                [False, False, False, False]])
        >>> get_unmasked_sequence_lengths(mask)
        tensor([1, 2, 3])

    )dim)dtyper      )cumsumargmaxtotorchlongclipshape)r   sequence_lengthss     n/home/jaya/work/projects/VOICE-AGENT/VIET/agent-env/lib/python3.11/site-packages/torchtune/training/pooling.pyget_unmasked_sequence_lengthsr   	   s_    > ~~"~--444<<??ej?QQ  DJqMA$5666    )r   Tensorr    r   r   <module>r      s@    !7 !7 !7 !7 !7 !7 !7 !7r   