



import copy

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


_lowerCamelCase         =	logging.get_logger(__name__)

_lowerCamelCase         =	{}

class    _SCREAMING_SNAKE_CASE						(_UpperCAmelCase			):
     lowerCAmelCase       =      "fsmt_decoder"





     def __init__(							self			:				Union[str, Any]  ,	UpperCamelCase			:				str=0  ,	UpperCamelCase			:				Dict=0					)->List[str]:
      super().__init__()
      __SCREAMING_SNAKE_CASE							:     Dict							=						vocab_size
      __SCREAMING_SNAKE_CASE							:     Optional[int]							=						bos_token_id






class    _SCREAMING_SNAKE_CASE						(_UpperCAmelCase			):
     lowerCAmelCase       =      "fsmt"
     lowerCAmelCase       =      {"num_attention_heads": "encoder_attention_heads", "hidden_size": "d_model"}





     def __init__(							self			:				List[str]  ,	UpperCamelCase			:				Optional[int]=["en", "de"]  ,	UpperCamelCase			:				List[str]=4_2_0_2_4  ,	UpperCamelCase			:				Union[str, Any]=4_2_0_2_4  ,	UpperCamelCase			:				List[Any]="relu"  ,	UpperCamelCase			:				Optional[int]=1_0_2_4  ,	UpperCamelCase			:				List[Any]=2_0_0  ,	UpperCamelCase			:				int=1_0_2_4  ,	UpperCamelCase			:				Optional[Any]=4_0_9_6  ,	UpperCamelCase			:				Optional[int]=1_2  ,	UpperCamelCase			:				List[Any]=1_6  ,	UpperCamelCase			:				Optional[Any]=0.0  ,	UpperCamelCase			:				Dict=4_0_9_6  ,	UpperCamelCase			:				int=1_2  ,	UpperCamelCase			:				Dict=1_6  ,	UpperCamelCase			:				Dict=0.0  ,	UpperCamelCase			:				Union[str, Any]=0.0  ,	UpperCamelCase			:				Dict=0.1  ,	UpperCamelCase			:				Optional[int]=0.0  ,	UpperCamelCase			:				Optional[int]=0.0_2  ,	UpperCamelCase			:				Tuple=2  ,	UpperCamelCase			:				str=True  ,	UpperCamelCase			:				Optional[Any]=True  ,	UpperCamelCase			:				int=False  ,	UpperCamelCase			:				str=5  ,	UpperCamelCase			:				Tuple=1.0  ,	UpperCamelCase			:				Tuple=False  ,	UpperCamelCase			:				List[Any]=True  ,	UpperCamelCase			:				str=1  ,	UpperCamelCase			:				str=0  ,	UpperCamelCase			:				str=2  ,	UpperCamelCase			:				int=2  ,	**UpperCamelCase			:				Dict  ,	)->Tuple:
      __SCREAMING_SNAKE_CASE							:     Optional[Any]							=						langs
      __SCREAMING_SNAKE_CASE							:     str							=						src_vocab_size
      __SCREAMING_SNAKE_CASE							:     List[str]							=						tgt_vocab_size
      __SCREAMING_SNAKE_CASE							:     Any							=						d_model  # encoder_embed_dim and decoder_embed_dim

      __SCREAMING_SNAKE_CASE							:     List[str]							=						encoder_ffn_dim
      __SCREAMING_SNAKE_CASE							:     Union[str, Any]							=						encoder_layers
      __SCREAMING_SNAKE_CASE							:     List[Any]							=						encoder_attention_heads
      __SCREAMING_SNAKE_CASE							:     Optional[int]							=						encoder_layerdrop
      __SCREAMING_SNAKE_CASE							:     Union[str, Any]							=						decoder_layerdrop
      __SCREAMING_SNAKE_CASE							:     List[Any]							=						decoder_ffn_dim
      __SCREAMING_SNAKE_CASE							:     Optional[Any]							=						decoder_layers
      __SCREAMING_SNAKE_CASE							:     Union[str, Any]							=						decoder_attention_heads
      __SCREAMING_SNAKE_CASE							:     int							=						max_position_embeddings
      __SCREAMING_SNAKE_CASE							:     Optional[Any]							=						init_std  # Normal(0, this parameter)
      __SCREAMING_SNAKE_CASE							:     Any							=						activation_function

      __SCREAMING_SNAKE_CASE							:     Any							=						DecoderConfig(vocab_size=_lowerCAmelCase  ,	bos_token_id=_lowerCAmelCase					)
      if "decoder" in common_kwargs:
       del common_kwargs["decoder"]

      __SCREAMING_SNAKE_CASE							:     Optional[int]							=						scale_embedding  # scale factor will be sqrt(d_model) if True

      # 3 Types of Dropout
      __SCREAMING_SNAKE_CASE							:     int							=						attention_dropout
      __SCREAMING_SNAKE_CASE							:     Any							=						activation_dropout
      __SCREAMING_SNAKE_CASE							:     str							=						dropout

      __SCREAMING_SNAKE_CASE							:     int							=						use_cache
      super().__init__(
          pad_token_id=_lowerCAmelCase  ,	bos_token_id=_lowerCAmelCase  ,	eos_token_id=_lowerCAmelCase  ,	decoder_start_token_id=_lowerCAmelCase  ,	is_encoder_decoder=_lowerCAmelCase  ,	tie_word_embeddings=_lowerCAmelCase  ,	forced_eos_token_id=_lowerCAmelCase  ,	max_length=_lowerCAmelCase  ,	num_beams=_lowerCAmelCase  ,	length_penalty=_lowerCAmelCase  ,	early_stopping=_lowerCAmelCase  ,	**_lowerCAmelCase  ,	)






     def 						__snake_case     (							self			:				Dict					)->Optional[int]:
      __SCREAMING_SNAKE_CASE							:     List[str]							=						copy.deepcopy(self.__dict__					)
      __SCREAMING_SNAKE_CASE							:     Any							=						self.decoder.to_dict()
      __SCREAMING_SNAKE_CASE							:     Dict							=						self.__class__.model_type
      return output










from collections import OrderedDict
from dataclasses import fields
from typing import Any, Tuple

import numpy as np

from .import_utils import is_torch_available
def 				UpperCamelCase_	(					__snake_case      :    Dict  )->   str:




						'''simple docstring'''
						if is_torch_available():
												import torch

												if isinstance(__snake_case						,      torch.Tensor  ):
																		return True

						return isinstance(__snake_case						,      np.ndarray  )




class      __snake_case				(   _UpperCAmelCase):
					def 	a			(						self       :						Optional[Any]  )							->					Optional[Any]:



											'''simple docstring'''





											__magic_name__					=      fields(self  )

											# Safety and consistency checks
											if not len(_lowerCAmelCase  ):
																	raise ValueError(F'''{self.__class__.__name__} has no fields.'''  )

											__magic_name__					=      getattr(self	,      class_fields[0].name  )
											__magic_name__					=      all(getattr(self	,      field.name  ) is None for field in class_fields[1:]  )

											if other_fields_are_none and isinstance(_lowerCAmelCase	,      _lowerCAmelCase  ):
																	for key, value in first_field.items():
																							__magic_name__					=      value
											else:
																	for field in class_fields:
																							__magic_name__					=      getattr(self	,      field.name  )
																							if v is not None:
																													__magic_name__					=      v
					def __delitem__(						self       :						Dict	,      *_lowerCAmelCase       :						List[str]	,      **_lowerCAmelCase       :						List[str]  )							->					List[str]:



											'''simple docstring'''





											raise Exception(F'''You cannot use ``__delitem__`` on a {self.__class__.__name__} instance.'''  )
					def 	a			(						self       :						Optional[int]	,      *_lowerCAmelCase       :						Optional[Any]	,      **_lowerCAmelCase       :						Optional[Any]  )							->					str:



											'''simple docstring'''





											raise Exception(F'''You cannot use ``setdefault`` on a {self.__class__.__name__} instance.'''  )
					def 	a			(						self       :						Union[str, Any]	,      *_lowerCAmelCase       :						List[str]	,      **_lowerCAmelCase       :						Any  )							->					str:



											'''simple docstring'''





											raise Exception(F'''You cannot use ``pop`` on a {self.__class__.__name__} instance.'''  )
					def 	a			(						self       :						Any	,      *_lowerCAmelCase       :						str	,      **_lowerCAmelCase       :						Optional[int]  )							->					List[Any]:



											'''simple docstring'''





											raise Exception(F'''You cannot use ``update`` on a {self.__class__.__name__} instance.'''  )
					def __getitem__(						self       :						Optional[Any]	,      _lowerCAmelCase       :						Any  )							->					Tuple:



											'''simple docstring'''





											if isinstance(_lowerCAmelCase	,      _lowerCAmelCase  ):
																	__magic_name__					=      dict(self.items()  )
																	return inner_dict[k]
											else:
																	return self.to_tuple()[k]
					def __setattr__(						self       :						str	,      _lowerCAmelCase       :						Optional[Any]	,      _lowerCAmelCase       :						Optional[int]  )							->					int:



											'''simple docstring'''





											if name in self.keys() and value is not None:
																	# Don't call self.__setitem__ to avoid recursion errors
																	super().__setitem__(_lowerCAmelCase	,      _lowerCAmelCase  )
											super().__setattr__(_lowerCAmelCase	,      _lowerCAmelCase  )
					def __setitem__(						self       :						Optional[Any]	,      _lowerCAmelCase       :						Optional[Any]	,      _lowerCAmelCase       :						List[str]  )							->					Optional[int]:



											'''simple docstring'''





											super().__setitem__(_lowerCAmelCase	,      _lowerCAmelCase  )
											# Don't call self.__setattr__ to avoid recursion errors
											super().__setattr__(_lowerCAmelCase	,      _lowerCAmelCase  )







					def 	a			(						self       :						str  )							->					Tuple[Any]:



											'''simple docstring'''





											return tuple(self[k] for k in self.keys()  )

