


'''simple docstring'''







from ...configuration_utils import PretrainedConfig
from ...utils import logging


A__:   Optional[Any]    =	logging.get_logger(__name__)

A__:   Dict    =	{
    'ZinengTang/tvlt-base': 'https://huggingface.co/ZinengTang/tvlt-base/blob/main/config.json',
}







class A__	(						lowerCAmelCase__				):
      __UpperCamelCase	:  Any     	=							"""tvlt"""






      def __init__(			self      :Any					,						SCREAMING_SNAKE_CASE      :str=2_2_4					,						SCREAMING_SNAKE_CASE      :List[str]=2_0_4_8					,						SCREAMING_SNAKE_CASE      :Any=1_2_8					,						SCREAMING_SNAKE_CASE      :Tuple=[1_6, 1_6]					,						SCREAMING_SNAKE_CASE      :Optional[int]=[1_6, 1_6]					,						SCREAMING_SNAKE_CASE      :Optional[int]=3					,						SCREAMING_SNAKE_CASE      :Optional[Any]=1					,						SCREAMING_SNAKE_CASE      :Any=8					,						SCREAMING_SNAKE_CASE      :Optional[Any]=7_6_8					,						SCREAMING_SNAKE_CASE      :Union[str, Any]=1_2					,						SCREAMING_SNAKE_CASE      :int=1_2					,						SCREAMING_SNAKE_CASE      :List[str]=3_0_7_2					,						SCREAMING_SNAKE_CASE      :Dict="gelu"					,						SCREAMING_SNAKE_CASE      :Optional[Any]=0.0					,						SCREAMING_SNAKE_CASE      :Dict=0.0					,						SCREAMING_SNAKE_CASE      :Dict=0.02					,						SCREAMING_SNAKE_CASE      :Optional[int]=1e-6					,						SCREAMING_SNAKE_CASE      :List[str]=True					,						SCREAMING_SNAKE_CASE      :Any=False					,						SCREAMING_SNAKE_CASE      :Optional[Any]=1_6					,						SCREAMING_SNAKE_CASE      :Any=5_1_2					,						SCREAMING_SNAKE_CASE      :int=8					,						SCREAMING_SNAKE_CASE      :Dict=2_0_4_8					,						SCREAMING_SNAKE_CASE      :Any=0.75					,						SCREAMING_SNAKE_CASE      :Optional[Any]=0.15					,						SCREAMING_SNAKE_CASE      :List[Any]="frame-level"					,						SCREAMING_SNAKE_CASE      :Dict=True					,						SCREAMING_SNAKE_CASE      :Optional[int]=True					,						SCREAMING_SNAKE_CASE      :Dict="classification"					,						**SCREAMING_SNAKE_CASE      :Optional[int]					,						)	-> str:




             '''simple docstring'''
             super().__init__(**UpperCamelCase__     )

             if audio_mask_type not in ("frame-level", "patch_level"):
                    raise ValueError(
                        """audio_mask_type must be one of two acceptable strategies - {'frame_level', 'patch-level') """
                        f"got {audio_mask_type}"     )

             _a   :			str					 =image_size
             _a   :			List[str]					 =spectrogram_length
             _a   :			List[Any]					 =frequency_length
             _a   :			Any					 =image_patch_size
             _a   :			Dict					 =audio_patch_size
             _a   :			List[Any]					 =num_image_channels
             _a   :			Union[str, Any]					 =num_audio_channels
             _a   :			List[Any]					 =num_frames

             _a   :			Tuple					 =hidden_size
             _a   :			Any					 =num_hidden_layers
             _a   :			Tuple					 =num_attention_heads
             _a   :			Optional[int]					 =intermediate_size
             _a   :			Any					 =hidden_act
             _a   :			int					 =hidden_dropout_prob
             _a   :			Optional[int]					 =attention_probs_dropout_prob
             _a   :			str					 =initializer_range
             _a   :			List[str]					 =layer_norm_eps
             _a   :			Tuple					 =qkv_bias
             _a   :			int					 =use_mean_pooling

             _a   :			Dict					 =decoder_num_attention_heads
             _a   :			Optional[Any]					 =decoder_hidden_size
             _a   :			Any					 =decoder_num_hidden_layers
             _a   :			Tuple					 =decoder_intermediate_size
             _a   :			Optional[Any]					 =pixel_mask_ratio
             _a   :			Union[str, Any]					 =audio_mask_ratio
             _a   :			Any					 =audio_mask_type

             _a   :			Optional[int]					 =task_matching
             _a   :			Union[str, Any]					 =task_mae
             _a   :			int					 =loss_type






'''simple docstring'''







from typing import Dict, Optional, Tuple

import torch


def      SCREAMING_SNAKE_CASE_ (  _UpperCAmelCase     :     torch.Tensor  )  ->      torch.Tensor:
       _a   :			Tuple					 =boundaries[1] - boundaries[0]
       _a   :			Dict					 =boundaries + step / 2
       _a   :			List[Any]					 =torch.cat([bin_centers, (bin_centers[-1] + step).unsqueeze(-1  )]   ,dim=0  )
       return bin_centers


def      SCREAMING_SNAKE_CASE_ (  _UpperCAmelCase     :     torch.Tensor   ,_UpperCAmelCase     :     torch.Tensor   ,)  ->      Tuple[torch.Tensor, torch.Tensor]:
       _a   :			Any					 =_calculate_bin_centers(_UpperCAmelCase  )
       return (
           torch.sum(aligned_distance_error_probs * bin_centers   ,dim=-1  ),
           bin_centers[-1],
       )


def      SCREAMING_SNAKE_CASE_ (  _UpperCAmelCase     :     torch.Tensor   ,_UpperCAmelCase     :     int = 31   ,_UpperCAmelCase     :     int = 64   ,**_UpperCAmelCase     :     Dict   ,)  ->      Dict[str, torch.Tensor]:
       _a   :			Dict					 =torch.linspace(0   ,_UpperCAmelCase   ,steps=(no_bins - 1)   ,device=logits.device  )

       _a   :			int					 =torch.nn.functional.softmax(_UpperCAmelCase   ,dim=-1  )
       _a ,   _a   :			List[Any]					 =_calculate_expected_aligned_error(
           alignment_confidence_breaks=_UpperCAmelCase   ,aligned_distance_error_probs=_UpperCAmelCase   ,)

       return {
           "aligned_confidence_probs": aligned_confidence_probs,
           "predicted_aligned_error": predicted_aligned_error,
           "max_predicted_aligned_error": max_predicted_aligned_error,
       }


def      SCREAMING_SNAKE_CASE_ (  _UpperCAmelCase     :     torch.Tensor   ,_UpperCAmelCase     :     Optional[torch.Tensor] = None   ,_UpperCAmelCase     :     int = 31   ,_UpperCAmelCase     :     int = 64   ,_UpperCAmelCase     :     float = 1e-8   ,**_UpperCAmelCase     :     Optional[Any]   ,)  ->      torch.Tensor:
       if residue_weights is None:
              _a   :			Dict					 =logits.new_ones(logits.shape[-2]  )

       _a   :			str					 =torch.linspace(0   ,_UpperCAmelCase   ,steps=(no_bins - 1)   ,device=logits.device  )

       _a   :			Optional[int]					 =_calculate_bin_centers(_UpperCAmelCase  )
       torch.sum(_UpperCAmelCase  )
       _a   :			List[str]					 =logits.shape[-2]
       _a   :			List[Any]					 =max(_UpperCAmelCase   ,19  )

       _a   :			Union[str, Any]					 =1.2_4 * (clipped_n - 15) ** (1.0 / 3) - 1.8

       _a   :			Tuple					 =torch.nn.functional.softmax(_UpperCAmelCase   ,dim=-1  )

       _a   :			Dict					 =1.0 / (1 + (bin_centers**2) / (da**2))
       _a   :			int					 =torch.sum(probs * tm_per_bin   ,dim=-1  )

       _a   :			List[Any]					 =residue_weights / (eps + residue_weights.sum())
       _a   :			List[str]					 =torch.sum(predicted_tm_term * normed_residue_mask   ,dim=-1  )

       _a   :			int					 =per_alignment * residue_weights

       _a   :			List[Any]					 =(weighted == torch.max(_UpperCAmelCase  )).nonzero()[0]
       return per_alignment[tuple(_UpperCAmelCase  )]


