




from typing import Dict, Optional, Tuple

import torch

def       SCREAMING_SNAKE_CASE							(     __UpperCamelCase)    ->  torch.Tensor:
     a											=   boundaries[1] - boundaries[0]
     a											=   boundaries + step / 2
     a											=   torch.cat([bin_centers, (bin_centers[-1] + step).unsqueeze(-1)]	,      dim=0)
     return bin_centers

def       SCREAMING_SNAKE_CASE							(     __UpperCamelCase	,      __UpperCamelCase	,      )    ->  Tuple[torch.Tensor, torch.Tensor]:
     a											=   _calculate_bin_centers(lowercase_)
     return (
         torch.sum(aligned_distance_error_probs * bin_centers	,      dim=-1),
         bin_centers[-1],
     )

def       SCREAMING_SNAKE_CASE							(     __UpperCamelCase	,      __UpperCamelCase = 31	,      __UpperCamelCase = 64	,      **__UpperCamelCase	,      )    ->  Dict[str, torch.Tensor]:
     a											=   torch.linspace(0	,      lowercase_	,      steps=(no_bins - 1)	,      device=logits.device)

     a											=   torch.nn.functional.softmax(lowercase_	,      dim=-1)
     a											=   _calculate_expected_aligned_error(
         alignment_confidence_breaks=lowercase_	,      aligned_distance_error_probs=lowercase_	,      )

     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	,      __UpperCamelCase = None	,      __UpperCamelCase = 31	,      __UpperCamelCase = 64	,      __UpperCamelCase = 1e-8	,      **__UpperCamelCase	,      )    ->  torch.Tensor:
     if residue_weights is None:
          a											=   logits.new_ones(logits.shape[-2])

     a											=   torch.linspace(0	,      lowercase_	,      steps=(no_bins - 1)	,      device=logits.device)

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

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

     a											=   torch.nn.functional.softmax(lowercase_	,      dim=-1)

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

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

     a											=   per_alignment * residue_weights

     a											=   (weighted == torch.max(lowercase_)).nonzero()[0]
     return per_alignment[tuple(lowercase_)]







from typing import TYPE_CHECKING

from ...utils import OptionalDependencyNotAvailable, _LazyModule, is_torch_available


lowercase__   :    Union[str, Any] 					=      {"configuration_visual_bert": ["VISUAL_BERT_PRETRAINED_CONFIG_ARCHIVE_MAP", "VisualBertConfig"]}

try:
   if not is_torch_available():
      raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
   pass
else:
   lowercase__   :    List[Any] 					=      [
       "VISUAL_BERT_PRETRAINED_MODEL_ARCHIVE_LIST",
       "VisualBertForMultipleChoice",
       "VisualBertForPreTraining",
       "VisualBertForQuestionAnswering",
       "VisualBertForRegionToPhraseAlignment",
       "VisualBertForVisualReasoning",
       "VisualBertLayer",
       "VisualBertModel",
       "VisualBertPreTrainedModel",
   ]


if TYPE_CHECKING:
   from .configuration_visual_bert import VISUAL_BERT_PRETRAINED_CONFIG_ARCHIVE_MAP, VisualBertConfig

   try:
      if not is_torch_available():
         raise OptionalDependencyNotAvailable()
   except OptionalDependencyNotAvailable:
      pass
   else:
      from .modeling_visual_bert import (
          VISUAL_BERT_PRETRAINED_MODEL_ARCHIVE_LIST,
          VisualBertForMultipleChoice,
          VisualBertForPreTraining,
          VisualBertForQuestionAnswering,
          VisualBertForRegionToPhraseAlignment,
          VisualBertForVisualReasoning,
          VisualBertLayer,
          VisualBertModel,
          VisualBertPreTrainedModel,
      )


else:
   import sys

   lowercase__   :    Union[str, Any] 					=      _LazyModule(__name__, globals()["__file__"], _import_structure, module_spec=__spec__)

