

"""simple docstring"""




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


__A	:       Tuple        =						logging.get_logger(__name__)

__A	:       Union[str, Any]        =						{
    'ZinengTang/tvlt-base': 'https://huggingface.co/ZinengTang/tvlt-base/blob/main/config.json',
}





class      __UpperCamelCase					(  _A		):
		SCREAMING_SNAKE_CASE														=       "tvlt"


		def __init__(self					:						str	,	__SCREAMING_SNAKE_CASE					:						Dict=2_2_4	,	__SCREAMING_SNAKE_CASE					:						Union[str, Any]=2_0_4_8	,	__SCREAMING_SNAKE_CASE					:						Any=1_2_8	,	__SCREAMING_SNAKE_CASE					:						Tuple=[1_6, 1_6]	,	__SCREAMING_SNAKE_CASE					:						List[str]=[1_6, 1_6]	,	__SCREAMING_SNAKE_CASE					:						Optional[int]=3	,	__SCREAMING_SNAKE_CASE					:						Union[str, Any]=1	,	__SCREAMING_SNAKE_CASE					:						Tuple=8	,	__SCREAMING_SNAKE_CASE					:						Optional[Any]=7_6_8	,	__SCREAMING_SNAKE_CASE					:						Optional[Any]=1_2	,	__SCREAMING_SNAKE_CASE					:						str=1_2	,	__SCREAMING_SNAKE_CASE					:						Optional[Any]=3_0_7_2	,	__SCREAMING_SNAKE_CASE					:						Union[str, Any]="gelu"	,	__SCREAMING_SNAKE_CASE					:						Optional[int]=0.0	,	__SCREAMING_SNAKE_CASE					:						int=0.0	,	__SCREAMING_SNAKE_CASE					:						Tuple=0.0_2	,	__SCREAMING_SNAKE_CASE					:						Any=1E-6	,	__SCREAMING_SNAKE_CASE					:						Optional[Any]=True	,	__SCREAMING_SNAKE_CASE					:						Optional[Any]=False	,	__SCREAMING_SNAKE_CASE					:						Dict=1_6	,	__SCREAMING_SNAKE_CASE					:						Dict=5_1_2	,	__SCREAMING_SNAKE_CASE					:						List[Any]=8	,	__SCREAMING_SNAKE_CASE					:						List[Any]=2_0_4_8	,	__SCREAMING_SNAKE_CASE					:						Any=0.7_5	,	__SCREAMING_SNAKE_CASE					:						List[str]=0.1_5	,	__SCREAMING_SNAKE_CASE					:						Union[str, Any]="frame-level"	,	__SCREAMING_SNAKE_CASE					:						Union[str, Any]=True	,	__SCREAMING_SNAKE_CASE					:						Dict=True	,	__SCREAMING_SNAKE_CASE					:						Union[str, Any]="classification"	,	**__SCREAMING_SNAKE_CASE					:						Tuple	,	):
							super().__init__(**__SCREAMING_SNAKE_CASE)

							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     =   image_size
							A     =   spectrogram_length
							A     =   frequency_length
							A     =   image_patch_size
							A     =   audio_patch_size
							A     =   num_image_channels
							A     =   num_audio_channels
							A     =   num_frames

							A     =   hidden_size
							A     =   num_hidden_layers
							A     =   num_attention_heads
							A     =   intermediate_size
							A     =   hidden_act
							A     =   hidden_dropout_prob
							A     =   attention_probs_dropout_prob
							A     =   initializer_range
							A     =   layer_norm_eps
							A     =   qkv_bias
							A     =   use_mean_pooling

							A     =   decoder_num_attention_heads
							A     =   decoder_hidden_size
							A     =   decoder_num_hidden_layers
							A     =   decoder_intermediate_size
							A     =   pixel_mask_ratio
							A     =   audio_mask_ratio
							A     =   audio_mask_type

							A     =   task_matching
							A     =   task_mae
							A     =   loss_type






"""simple docstring"""







from typing import Dict, Optional, Tuple

import torch




def 						_lowercase				(  _SCREAMING_SNAKE_CASE				:				torch.Tensor						)    ->     torch.Tensor:







     '''simple docstring'''


     __A					:					List[str]								=		boundaries[1] - boundaries[0]
     __A					:					int								=		boundaries + step / 2
     __A					:					Union[str, Any]								=		torch.cat([bin_centers, (bin_centers[-1] + step).unsqueeze(-1						)]  ,       dim=0						)
     return bin_centers




def 						_lowercase				(  _SCREAMING_SNAKE_CASE				:				torch.Tensor  ,       _SCREAMING_SNAKE_CASE				:				torch.Tensor  ,       )    ->     Tuple[torch.Tensor, torch.Tensor]:







     '''simple docstring'''


     __A					:					str								=		_calculate_bin_centers(_SCREAMING_SNAKE_CASE						)
     return (
         torch.sum(aligned_distance_error_probs * bin_centers  ,       dim=-1						),
         bin_centers[-1],
     )




def 						_lowercase				(  _SCREAMING_SNAKE_CASE				:				torch.Tensor  ,       _SCREAMING_SNAKE_CASE				:				int = 31  ,       _SCREAMING_SNAKE_CASE				:				int = 64  ,       **_SCREAMING_SNAKE_CASE				:				Optional[Any]  ,       )    ->     Dict[str, torch.Tensor]:







     '''simple docstring'''


     __A					:					int								=		torch.linspace(0  ,       _SCREAMING_SNAKE_CASE  ,       steps=(no_bins - 1)  ,       device=logits.device						)

     __A					:					Any								=		torch.nn.functional.softmax(_SCREAMING_SNAKE_CASE  ,       dim=-1						)
     __A						,		__A					:					Tuple								=		_calculate_expected_aligned_error(
         alignment_confidence_breaks=_SCREAMING_SNAKE_CASE  ,       aligned_distance_error_probs=_SCREAMING_SNAKE_CASE  ,       )

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




def 						_lowercase				(  _SCREAMING_SNAKE_CASE				:				torch.Tensor  ,       _SCREAMING_SNAKE_CASE				:				Optional[torch.Tensor] = None  ,       _SCREAMING_SNAKE_CASE				:				int = 31  ,       _SCREAMING_SNAKE_CASE				:				int = 64  ,       _SCREAMING_SNAKE_CASE				:				float = 1E-8  ,       **_SCREAMING_SNAKE_CASE				:				Union[str, Any]  ,       )    ->     torch.Tensor:







     '''simple docstring'''


     if residue_weights is None:
          __A					:					Optional[int]								=		logits.new_ones(logits.shape[-2]						)

     __A					:					List[str]								=		torch.linspace(0  ,       _SCREAMING_SNAKE_CASE  ,       steps=(no_bins - 1)  ,       device=logits.device						)

     __A					:					Tuple								=		_calculate_bin_centers(_SCREAMING_SNAKE_CASE						)
     torch.sum(_SCREAMING_SNAKE_CASE						)
     __A					:					int								=		logits.shape[-2]
     __A					:					str								=		max(_SCREAMING_SNAKE_CASE  ,       19						)

     __A					:					Tuple								=		1.24 * (clipped_n - 15) ** (1.0 / 3) - 1.8

     __A					:					Tuple								=		torch.nn.functional.softmax(_SCREAMING_SNAKE_CASE  ,       dim=-1						)

     __A					:					List[str]								=		1.0 / (1 + (bin_centers**2) / (da**2))
     __A					:					int								=		torch.sum(probs * tm_per_bin  ,       dim=-1						)

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

     __A					:					int								=		per_alignment * residue_weights

     __A					:					Optional[int]								=		(weighted == torch.max(_SCREAMING_SNAKE_CASE						)).nonzero()[0]
     return per_alignment[tuple(_SCREAMING_SNAKE_CASE						)]



