






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


_A      :     Tuple       	={
    '''configuration_imagegpt''': ['''IMAGEGPT_PRETRAINED_CONFIG_ARCHIVE_MAP''', '''ImageGPTConfig''', '''ImageGPTOnnxConfig''']
}

try:
			if not is_vision_available():
						raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
			pass
else:
			_A      :     Dict       	=['''ImageGPTFeatureExtractor''']
			_A      :     Union[str, Any]       	=['''ImageGPTImageProcessor''']

try:
			if not is_torch_available():
						raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
			pass
else:
			_A      :     str       	=[
			    '''IMAGEGPT_PRETRAINED_MODEL_ARCHIVE_LIST''',
			    '''ImageGPTForCausalImageModeling''',
			    '''ImageGPTForImageClassification''',
			    '''ImageGPTModel''',
			    '''ImageGPTPreTrainedModel''',
			    '''load_tf_weights_in_imagegpt''',
			]


if TYPE_CHECKING:
			from .configuration_imagegpt import IMAGEGPT_PRETRAINED_CONFIG_ARCHIVE_MAP, ImageGPTConfig, ImageGPTOnnxConfig

			try:
						if not is_vision_available():
									raise OptionalDependencyNotAvailable()
			except OptionalDependencyNotAvailable:
						pass
			else:
						from .feature_extraction_imagegpt import ImageGPTFeatureExtractor
						from .image_processing_imagegpt import ImageGPTImageProcessor

			try:
						if not is_torch_available():
									raise OptionalDependencyNotAvailable()
			except OptionalDependencyNotAvailable:
						pass
			else:
						from .modeling_imagegpt import (
						    IMAGEGPT_PRETRAINED_MODEL_ARCHIVE_LIST,
						    ImageGPTForCausalImageModeling,
						    ImageGPTForImageClassification,
						    ImageGPTModel,
						    ImageGPTPreTrainedModel,
						    load_tf_weights_in_imagegpt,
						)

else:
			import sys

			_A      :     str       	=_LazyModule(__name__, globals()['''__file__'''], _import_structure, module_spec=__spec__)

