'''simple docstring'''


from typing import Dict, Optional, Tuple

import torch


def    _lowerCamelCase       ( lowerCamelCase_   :				torch.Tensor  ):



     """simple docstring"""





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


def    _lowerCamelCase       ( lowerCamelCase_   :				torch.Tensor      ,	lowerCamelCase_   :				torch.Tensor      ,	):



     """simple docstring"""





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


def    _lowerCamelCase       ( lowerCamelCase_   :				torch.Tensor      ,	lowerCamelCase_   :				int = 31      ,	lowerCamelCase_   :				int = 64      ,	**lowerCamelCase_   :				Tuple      ,	):



     """simple docstring"""





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

     UpperCAmelCase_				:  List[Any]  = torch.nn.functional.softmax(_SCREAMING_SNAKE_CASE      ,	dim=-1  )
     UpperCAmelCase_  ,     UpperCAmelCase_				:  str  = _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    _lowerCamelCase       ( lowerCamelCase_   :				torch.Tensor      ,	lowerCamelCase_   :				Optional[torch.Tensor] = None      ,	lowerCamelCase_   :				int = 31      ,	lowerCamelCase_   :				int = 64      ,	lowerCamelCase_   :				float = 1e-8      ,	**lowerCamelCase_   :				str      ,	):



     """simple docstring"""





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

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

     UpperCAmelCase_				:  Any  = _calculate_bin_centers(_SCREAMING_SNAKE_CASE  )
     torch.sum(_SCREAMING_SNAKE_CASE  )
     UpperCAmelCase_				:  int  = logits.shape[-2]
     UpperCAmelCase_				:  Optional[Any]  = max(_SCREAMING_SNAKE_CASE      ,	19  )

     UpperCAmelCase_				:  Optional[Any]  = 1.24 * (clipped_n - 15) ** (1.0 / 3) - 1.8

     UpperCAmelCase_				:  Optional[int]  = torch.nn.functional.softmax(_SCREAMING_SNAKE_CASE      ,	dim=-1  )

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

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

     UpperCAmelCase_				:  Any  = per_alignment * residue_weights

     UpperCAmelCase_				:  Union[str, Any]  = (weighted == torch.max(_SCREAMING_SNAKE_CASE  )).nonzero()[0]
     return per_alignment[tuple(_SCREAMING_SNAKE_CASE  )]











from typing import List, Union

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


UpperCAmelCase_          =				logging.get_logger(__name__)

UpperCAmelCase_          =				{
    "allenai/led-base-16384": "https://huggingface.co/allenai/led-base-16384/resolve/main/config.json",
    # See all LED models at https://huggingface.co/models?filter=led
}





class 		UpperCAmelCase    (    snake_case_					):
   SCREAMING_SNAKE_CASE__					      =  '''led'''
   SCREAMING_SNAKE_CASE__					      =  {
       '''num_attention_heads''': '''encoder_attention_heads''',
       '''hidden_size''': '''d_model''',
       '''attention_probs_dropout_prob''': '''attention_dropout''',
       '''initializer_range''': '''init_std''',
   }





   def __init__(						self							,  _lowerCAmelCase=50_265							,  _lowerCAmelCase=16_384							,  _lowerCAmelCase=1_024							,  _lowerCAmelCase=12							,  _lowerCAmelCase=4_096							,  _lowerCAmelCase=16							,  _lowerCAmelCase=12							,  _lowerCAmelCase=4_096							,  _lowerCAmelCase=16							,  _lowerCAmelCase=0.0							,  _lowerCAmelCase=0.0							,  _lowerCAmelCase=True							,  _lowerCAmelCase=True							,  _lowerCAmelCase="gelu"							,  _lowerCAmelCase=1_024							,  _lowerCAmelCase=0.1							,  _lowerCAmelCase=0.0							,  _lowerCAmelCase=0.0							,  _lowerCAmelCase=0.02							,  _lowerCAmelCase=2							,  _lowerCAmelCase=0.0							,  _lowerCAmelCase=1							,  _lowerCAmelCase=0							,  _lowerCAmelCase=2							,  _lowerCAmelCase = 512							,  **_lowerCAmelCase							,  ):
         _lowerCAmelCase			      =	vocab_size
         _lowerCAmelCase			      =	max_encoder_position_embeddings
         _lowerCAmelCase			      =	max_decoder_position_embeddings
         _lowerCAmelCase			      =	d_model
         _lowerCAmelCase			      =	encoder_ffn_dim
         _lowerCAmelCase			      =	encoder_layers
         _lowerCAmelCase			      =	encoder_attention_heads
         _lowerCAmelCase			      =	decoder_ffn_dim
         _lowerCAmelCase			      =	decoder_layers
         _lowerCAmelCase			      =	decoder_attention_heads
         _lowerCAmelCase			      =	dropout
         _lowerCAmelCase			      =	attention_dropout
         _lowerCAmelCase			      =	activation_dropout
         _lowerCAmelCase			      =	activation_function
         _lowerCAmelCase			      =	init_std
         _lowerCAmelCase			      =	encoder_layerdrop
         _lowerCAmelCase			      =	decoder_layerdrop
         _lowerCAmelCase			      =	classifier_dropout
         _lowerCAmelCase			      =	use_cache
         _lowerCAmelCase			      =	encoder_layers
         _lowerCAmelCase			      =	attention_window

         super().__init__(
             pad_token_id=_lowerCAmelCase							,  bos_token_id=_lowerCAmelCase							,  eos_token_id=_lowerCAmelCase							,  is_encoder_decoder=_lowerCAmelCase							,  decoder_start_token_id=_lowerCAmelCase							,  **_lowerCAmelCase							,  )