


"""simple docstring"""





from typing import List, Optional, Tuple, Union

from . import logging
from .import_utils import is_torch_available, is_torch_version


if is_torch_available():
 import torch

snake_case__		:  Any     					=					logging.get_logger(__name__)  # pylint: disable=invalid-name

try:
 from torch._dynamo import allow_in_graph as maybe_allow_in_graph
except (ImportError, ModuleNotFoundError):


 def   _snake_case    (    cls					:      List[Any]      ):
       return cls


def   _snake_case    (    _snake_case					:      Union[Tuple, List]			, _snake_case					:      Optional[Union[List["torch.Generator"], "torch.Generator"]] = None			, _snake_case					:      Optional["torch.device"] = None			, _snake_case					:      Optional["torch.dtype"] = None			, _snake_case					:      Optional["torch.layout"] = None			, ):
      lowerCAmelCase       :						Optional[Any]							= device
      lowerCAmelCase       :						str							= shape[0]

      lowerCAmelCase       :						List[str]							= layout or torch.strided
      lowerCAmelCase       :						Tuple							= device or torch.device('''cpu'''      )

      if generator is not None:
            lowerCAmelCase       :						Any							= generator.device.type if not isinstance(_snake_case			, _snake_case      ) else generator[0].device.type
            if gen_device_type != device.type and gen_device_type == "cpu":
                  lowerCAmelCase       :						List[Any]							= '''cpu'''
                  if device != "mps":
                        logger.info(
                            f'''The passed generator was created on \'cpu\' even though a tensor on {device} was expected.'''
                            f''' Tensors will be created on \'cpu\' and then moved to {device}. Note that one can probably'''
                            f''' slighly speed up this function by passing a generator that was created on the {device} device.'''      )
            elif gen_device_type != device.type and gen_device_type == "cuda":
                  raise ValueError(f'''Cannot generate a {device} tensor from a generator of type {gen_device_type}.'''      )

      if isinstance(_snake_case			, _snake_case      ):
            lowerCAmelCase       :						Optional[Any]							= (1,) + shape[1:]
            lowerCAmelCase       :						str							= [
                torch.randn(_snake_case			, generator=generator[i]			, device=_snake_case			, dtype=_snake_case			, layout=_snake_case      )
                for i in range(_snake_case      )
            ]
            lowerCAmelCase       :						Tuple							= torch.cat(_snake_case			, dim=0      ).to(_snake_case      )
      else:
            lowerCAmelCase       :						List[Any]							= torch.randn(_snake_case			, generator=_snake_case			, device=_snake_case			, dtype=_snake_case			, layout=_snake_case      ).to(_snake_case      )

      return latents






def   _snake_case    (    _snake_case					:      int      ):
      if is_torch_version('''<'''			, '''2.0.0'''      ) or not hasattr(_snake_case			, '''_dynamo'''      ):
            return False
      return isinstance(_snake_case			, torch._dynamo.eval_frame.OptimizedModule      )






"""simple docstring"""





from typing import Callable, Optional, Union

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


snake_case__		:  Optional[Any]     					=					logging.get_logger(__name__)

snake_case__		:  str     					=					{
    '''microsoft/prophetnet-large-uncased''': (
        '''https://huggingface.co/microsoft/prophetnet-large-uncased/resolve/main/config.json'''
    ),
}



class 		snake_case_(							a__      ):
     __UpperCamelCase	=       '''prophetnet'''
     __UpperCamelCase	=       ['''past_key_values''']
     __UpperCamelCase	=       {
         '''num_attention_heads''': '''num_encoder_attention_heads''',
     }






     def __init__(						self	:       Union[str, Any]       ,					UpperCamelCase_	:       Optional[float] = 0.1       ,					UpperCamelCase_	:       Optional[Union[str, Callable]] = "gelu"       ,					UpperCamelCase_	:       Optional[int] = 3_0_5_2_2       ,					UpperCamelCase_	:       Optional[int] = 1_0_2_4       ,					UpperCamelCase_	:       Optional[int] = 4_0_9_6       ,					UpperCamelCase_	:       Optional[int] = 1_2       ,					UpperCamelCase_	:       Optional[int] = 1_6       ,					UpperCamelCase_	:       Optional[int] = 4_0_9_6       ,					UpperCamelCase_	:       Optional[int] = 1_2       ,					UpperCamelCase_	:       Optional[int] = 1_6       ,					UpperCamelCase_	:       Optional[float] = 0.1       ,					UpperCamelCase_	:       Optional[float] = 0.1       ,					UpperCamelCase_	:       Optional[int] = 5_1_2       ,					UpperCamelCase_	:       Optional[float] = 0.02       ,					UpperCamelCase_	:       Optional[bool] = True       ,					UpperCamelCase_	:       Optional[bool] = True       ,					UpperCamelCase_	:       Optional[int] = 0       ,					UpperCamelCase_	:       Optional[int] = 2       ,					UpperCamelCase_	:       Optional[int] = 3_2       ,					UpperCamelCase_	:       Optional[int] = 1_2_8       ,					UpperCamelCase_	:       Optional[bool] = False       ,					UpperCamelCase_	:       Optional[float] = 0.0       ,					UpperCamelCase_	:       Optional[bool] = True       ,					UpperCamelCase_	:       Optional[int] = 0       ,					UpperCamelCase_	:       Optional[int] = 1       ,					UpperCamelCase_	:       Optional[int] = 2       ,					**UpperCamelCase_	:       List[Any]       ,					):
           lowerCAmelCase       :						Union[str, Any]							= vocab_size
           lowerCAmelCase       :						Any							= hidden_size
           lowerCAmelCase       :						Tuple							= encoder_ffn_dim
           lowerCAmelCase       :						str							= num_encoder_layers
           lowerCAmelCase       :						int							= num_encoder_attention_heads
           lowerCAmelCase       :						Optional[Any]							= decoder_ffn_dim
           lowerCAmelCase       :						Union[str, Any]							= num_decoder_layers
           lowerCAmelCase       :						Union[str, Any]							= num_decoder_attention_heads
           lowerCAmelCase       :						List[Any]							= max_position_embeddings
           lowerCAmelCase       :						Dict							= init_std  # Normal(0, this parameter)
           lowerCAmelCase       :						Optional[int]							= activation_function

           # parameters for prophetnet
           lowerCAmelCase       :						Tuple							= ngram
           lowerCAmelCase       :						List[Any]							= num_buckets
           lowerCAmelCase       :						Optional[Any]							= relative_max_distance
           lowerCAmelCase       :						Dict							= disable_ngram_loss
           lowerCAmelCase       :						Optional[int]							= eps

           # 3 Types of Dropout
           lowerCAmelCase       :						Any							= attention_dropout
           lowerCAmelCase       :						List[Any]							= activation_dropout
           lowerCAmelCase       :						Tuple							= dropout

           lowerCAmelCase       :						Optional[int]							= use_cache

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






     @property
     def   lowerCamelCase__  (						self	:       str					):
           return self.num_encoder_layers + self.num_decoder_layers






     @num_hidden_layers.setter
     def   lowerCamelCase__  (						self	:       Optional[Any]       ,					UpperCamelCase_	:       int					):
           raise NotImplementedError(
               '''This model does not support the setting of `num_hidden_layers`. Please set `num_encoder_layers` and'''
               ''' `num_decoder_layers`.'''					)


