




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


__A						:		Union[str, Any]          =						logging.get_logger(__name__)

__A						:		Dict          =						{
    "dandelin/vilt-b32-mlm": "https://huggingface.co/dandelin/vilt-b32-mlm/blob/main/config.json"
}

class 		lowercase_       (	lowerCAmelCase__				):
					__UpperCamelCase     	= "vilt"




					def __init__(   self:		Optional[int],     _lowercase:		Tuple=30522,     _lowercase:		Tuple=2,     _lowercase:		Optional[int]=2,     _lowercase:		Any=40,     _lowercase:		str=768,     _lowercase:		Any=12,     _lowercase:		int=12,     _lowercase:		Any=3072,     _lowercase:		str="gelu",     _lowercase:		Optional[Any]=0.0,     _lowercase:		Optional[Any]=0.0,     _lowercase:		Optional[Any]=0.02,     _lowercase:		int=1e-12,     _lowercase:		Any=384,     _lowercase:		Tuple=32,     _lowercase:		Union[str, Any]=3,     _lowercase:		Any=True,     _lowercase:		Dict=-1,     _lowercase:		Optional[int]=False,     _lowercase:		str=-1,     **_lowercase:		int,     ):


									'''simple docstring'''


									super().__init__(tie_word_embeddings=_lowercase,     **_lowercase)

									__lowerCAmelCase					=  vocab_size
									__lowerCAmelCase					=  type_vocab_size
									__lowerCAmelCase					=  modality_type_vocab_size
									__lowerCAmelCase					=  max_position_embeddings

									__lowerCAmelCase					=  hidden_size
									__lowerCAmelCase					=  num_hidden_layers
									__lowerCAmelCase					=  num_attention_heads
									__lowerCAmelCase					=  intermediate_size
									__lowerCAmelCase					=  hidden_act
									__lowerCAmelCase					=  hidden_dropout_prob
									__lowerCAmelCase					=  attention_probs_dropout_prob
									__lowerCAmelCase					=  initializer_range
									__lowerCAmelCase					=  layer_norm_eps

									__lowerCAmelCase					=  image_size
									__lowerCAmelCase					=  patch_size
									__lowerCAmelCase					=  num_channels
									__lowerCAmelCase					=  qkv_bias
									__lowerCAmelCase					=  max_image_length
									__lowerCAmelCase					=  num_images








from typing import Dict, Optional, Tuple

import torch
def   _lowerCAmelCase(						__A      ):
  UpperCAmelCase          =	boundaries[1] - boundaries[0]
  UpperCAmelCase          =	boundaries + step / 2
  UpperCAmelCase          =	torch.cat([bin_centers, (bin_centers[-1] + step).unsqueeze(-1      )] ,							dim=0      )
  return bin_centers
def   _lowerCAmelCase(						__A ,							__A ,							):
  UpperCAmelCase          =	_calculate_bin_centers(__A      )
  return (
      torch.sum(aligned_distance_error_probs * bin_centers ,							dim=-1      ),
      bin_centers[-1],
  )
def   _lowerCAmelCase(						__A ,							__A = 31 ,							__A = 64 ,							**__A ,							):
  UpperCAmelCase          =	torch.linspace(0 ,							__A ,							steps=(no_bins - 1) ,							device=logits.device      )

  UpperCAmelCase          =	torch.nn.functional.softmax(__A ,							dim=-1      )
  UpperCAmelCase   ,						UpperCAmelCase          =	_calculate_expected_aligned_error(
      alignment_confidence_breaks=__A ,							aligned_distance_error_probs=__A ,							)

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





def   _lowerCAmelCase(						__A ,							__A = None ,							__A = 31 ,							__A = 64 ,							__A = 1E-8 ,							**__A ,							):
  if residue_weights is None:
    UpperCAmelCase          =	logits.new_ones(logits.shape[-2]      )

  UpperCAmelCase          =	torch.linspace(0 ,							__A ,							steps=(no_bins - 1) ,							device=logits.device      )

  UpperCAmelCase          =	_calculate_bin_centers(__A      )
  torch.sum(__A      )
  UpperCAmelCase          =	logits.shape[-2]
  UpperCAmelCase          =	max(__A ,							19      )

  UpperCAmelCase          =	1.24 * (clipped_n - 15) ** (1.0 / 3) - 1.8

  UpperCAmelCase          =	torch.nn.functional.softmax(__A ,							dim=-1      )

  UpperCAmelCase          =	1.0 / (1 + (bin_centers**2) / (da**2))
  UpperCAmelCase          =	torch.sum(probs * tm_per_bin ,							dim=-1      )

  UpperCAmelCase          =	residue_weights / (eps + residue_weights.sum())
  UpperCAmelCase          =	torch.sum(predicted_tm_term * normed_residue_mask ,							dim=-1      )

  UpperCAmelCase          =	per_alignment * residue_weights

  UpperCAmelCase          =	(weighted == torch.max(__A      )).nonzero()[0]
  return per_alignment[tuple(__A      )]



