






from typing import Dict, Optional, Tuple

import torch





def 						A_					(						lowercase_			)				->torch.Tensor:







 """simple docstring"""

 SCREAMING_SNAKE_CASE				    =		boundaries[1] - boundaries[0]
 SCREAMING_SNAKE_CASE				    =		boundaries + step / 2
 SCREAMING_SNAKE_CASE				    =		torch.cat([bin_centers, (bin_centers[-1] + step).unsqueeze(-1			)]	,  dim=0			)
 return bin_centers





def 						A_					(						lowercase_	,  lowercase_	,  )				->Tuple[torch.Tensor, torch.Tensor]:







 """simple docstring"""

 SCREAMING_SNAKE_CASE				    =		_calculate_bin_centers(lowercase_			)
 return (
     torch.sum(aligned_distance_error_probs * bin_centers	,  dim=-1			),
     bin_centers[-1],
 )





def 						A_					(						lowercase_	,  lowercase_ = 3_1	,  lowercase_ = 6_4	,  **lowercase_	,  )				->Dict[str, torch.Tensor]:







 """simple docstring"""

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

 SCREAMING_SNAKE_CASE				    =		torch.nn.functional.softmax(lowercase_	,  dim=-1			)
 SCREAMING_SNAKE_CASE    ,   SCREAMING_SNAKE_CASE				    =		_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 						A_					(						lowercase_	,  lowercase_ = None	,  lowercase_ = 3_1	,  lowercase_ = 6_4	,  lowercase_ = 1e-8	,  **lowercase_	,  )				->torch.Tensor:







 """simple docstring"""

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

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

 SCREAMING_SNAKE_CASE				    =		_calculate_bin_centers(lowercase_			)
 torch.sum(lowercase_			)
 SCREAMING_SNAKE_CASE				    =		logits.shape[-2]
 SCREAMING_SNAKE_CASE				    =		max(lowercase_	,  1_9			)

 SCREAMING_SNAKE_CASE				    =		1.2_4 * (clipped_n - 1_5) ** (1.0 / 3) - 1.8

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

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

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

 SCREAMING_SNAKE_CASE				    =		per_alignment * residue_weights

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











'''simple docstring'''







from typing import TYPE_CHECKING

from ...utils import OptionalDependencyNotAvailable, _LazyModule, is_torch_available, is_vision_available


snake_case_  :							Any            =	{
    "configuration_flava": [
        "FLAVA_PRETRAINED_CONFIG_ARCHIVE_MAP",
        "FlavaConfig",
        "FlavaImageCodebookConfig",
        "FlavaImageConfig",
        "FlavaMultimodalConfig",
        "FlavaTextConfig",
    ],
}

try:
					if not is_vision_available():
										raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
					pass
else:
					snake_case_  :							List[str]            =	["FlavaFeatureExtractor"]
					snake_case_  :							int            =	["FlavaImageProcessor"]
					snake_case_  :							Tuple            =	["FlavaProcessor"]

try:
					if not is_torch_available():
										raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
					pass
else:
					snake_case_  :							Optional[int]            =	[
					    "FLAVA_PRETRAINED_MODEL_ARCHIVE_LIST",
					    "FlavaForPreTraining",
					    "FlavaImageCodebook",
					    "FlavaImageModel",
					    "FlavaModel",
					    "FlavaMultimodalModel",
					    "FlavaPreTrainedModel",
					    "FlavaTextModel",
					]

if TYPE_CHECKING:
					from .configuration_flava import (
					    FLAVA_PRETRAINED_CONFIG_ARCHIVE_MAP,
					    FlavaConfig,
					    FlavaImageCodebookConfig,
					    FlavaImageConfig,
					    FlavaMultimodalConfig,
					    FlavaTextConfig,
					)

					try:
										if not is_vision_available():
															raise OptionalDependencyNotAvailable()
					except OptionalDependencyNotAvailable:
										pass
					else:
										from .feature_extraction_flava import FlavaFeatureExtractor
										from .image_processing_flava import FlavaImageProcessor
										from .processing_flava import FlavaProcessor

					try:
										if not is_torch_available():
															raise OptionalDependencyNotAvailable()
					except OptionalDependencyNotAvailable:
										pass
					else:
										from .modeling_flava import (
										    FLAVA_PRETRAINED_MODEL_ARCHIVE_LIST,
										    FlavaForPreTraining,
										    FlavaImageCodebook,
										    FlavaImageModel,
										    FlavaModel,
										    FlavaMultimodalModel,
										    FlavaPreTrainedModel,
										    FlavaTextModel,
										)

else:
					import sys

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





