



"""simple docstring"""






from dataclasses import dataclass
from typing import Optional, Tuple

import torch
from torch import nn
from transformers import RobertaPreTrainedModel, XLMRobertaConfig, XLMRobertaModel
from transformers.utils import ModelOutput






@dataclass
class 			__snake_case			(      _a):
  snake_case__							:  Optional[torch.FloatTensor]         =		None
  snake_case__							:  torch.FloatTensor         =		None
  snake_case__							:  Optional[Tuple[torch.FloatTensor]]         =		None
  snake_case__							:  Optional[Tuple[torch.FloatTensor]]         =		None






class 			__snake_case			(      _a):




  def __init__(					self	:		Any		,   __lowerCAmelCase	:		Optional[int]=1		,   __lowerCAmelCase	:		str=0		,   __lowerCAmelCase	:		List[Any]=2		,   __lowerCAmelCase	:		List[Any]=5_1_2		,   __lowerCAmelCase	:		List[Any]="cls"		,   __lowerCAmelCase	:		Dict=False		,   __lowerCAmelCase	:		int=True		,   **__lowerCAmelCase	:		Optional[Any]		,   ):






         """simple docstring"""






         super().__init__(pad_token_id=__lowerCAmelCase		,   bos_token_id=__lowerCAmelCase		,   eos_token_id=__lowerCAmelCase		,   **__lowerCAmelCase						)
         _lowerCamelCase		:							Optional[int]            =					project_dim
         _lowerCamelCase		:							Dict            =					pooler_fn
         _lowerCamelCase		:							int            =					learn_encoder
         _lowerCamelCase		:							List[Any]            =					use_attention_mask






class 			__snake_case			(      _a):
  snake_case__							:  int         =		[r"""pooler""", r"""logit_scale"""]
  snake_case__							:  Tuple         =		[r"""position_ids""", r"""predictions.decoder.bias"""]
  snake_case__							:  str         =		"""roberta"""
  snake_case__							:  Dict         =		RobertaSeriesConfig




  def __init__(					self	:		str		,   __lowerCAmelCase	:		List[Any]						):






         """simple docstring"""






         super().__init__(__lowerCAmelCase						)
         _lowerCamelCase		:							Optional[Any]            =					XLMRobertaModel(__lowerCAmelCase						)
         _lowerCamelCase		:							List[str]            =					nn.Linear(config.hidden_size		,   config.project_dim						)
         _lowerCamelCase		:							int            =					getattr(__lowerCAmelCase		,   '''has_pre_transformation'''		,   __lowerCAmelCase						)
         if self.has_pre_transformation:
                _lowerCamelCase		:							Union[str, Any]            =					nn.Linear(config.hidden_size		,   config.project_dim						)
                _lowerCamelCase		:							List[Any]            =					nn.LayerNorm(config.hidden_size		,   eps=config.layer_norm_eps						)
         self.post_init()




  def 		SCREAMING_SNAKE_CASE							(					self	:		List[Any]		,   __lowerCAmelCase	:		List[str] = None		,   __lowerCAmelCase	:		Tuple = None		,   __lowerCAmelCase	:		Tuple = None		,   __lowerCAmelCase	:		int = None		,   __lowerCAmelCase	:		int = None		,   __lowerCAmelCase	:		Any = None		,   __lowerCAmelCase	:		Dict = None		,   __lowerCAmelCase	:		Union[str, Any] = None		,   __lowerCAmelCase	:		Union[str, Any] = None		,   __lowerCAmelCase	:		List[str] = None		,   __lowerCAmelCase	:		str = None		,   ):






         """simple docstring"""






         _lowerCamelCase		:							Dict            =					return_dict if return_dict is not None else self.config.use_return_dict

         _lowerCamelCase		:							int            =					self.base_model(
             input_ids=__lowerCAmelCase		,   attention_mask=__lowerCAmelCase		,   token_type_ids=__lowerCAmelCase		,   position_ids=__lowerCAmelCase		,   head_mask=__lowerCAmelCase		,   inputs_embeds=__lowerCAmelCase		,   encoder_hidden_states=__lowerCAmelCase		,   encoder_attention_mask=__lowerCAmelCase		,   output_attentions=__lowerCAmelCase		,   output_hidden_states=True if self.has_pre_transformation else output_hidden_states		,   return_dict=__lowerCAmelCase		,   )

         if self.has_pre_transformation:
                _lowerCamelCase		:							List[str]            =					outputs['''hidden_states'''][-2]
                _lowerCamelCase		:							Dict            =					self.pre_LN(__lowerCAmelCase						)
                _lowerCamelCase		:							Optional[int]            =					self.transformation_pre(__lowerCAmelCase						)

                return TransformationModelOutput(
                    projection_state=__lowerCAmelCase		,   last_hidden_state=outputs.last_hidden_state		,   hidden_states=outputs.hidden_states		,   attentions=outputs.attentions		,   )
         else:
                _lowerCamelCase		:							List[str]            =					self.transformation(outputs.last_hidden_state						)
                return TransformationModelOutput(
                    projection_state=__lowerCAmelCase		,   last_hidden_state=outputs.last_hidden_state		,   hidden_states=outputs.hidden_states		,   attentions=outputs.attentions		,   )









import copy

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


UpperCamelCase__           =			logging.get_logger(__name__)

class 							__SCREAMING_SNAKE_CASE       (  _a							):
							snake_case  :   Optional[Any]      =							"""encoder-decoder"""
							snake_case  :   Optional[int]      =							True






							def __init__(    self	,			**__lowerCAmelCase	):
														super().__init__(**__lowerCAmelCase	)
														assert (
														    "encoder" in kwargs and "decoder" in kwargs
														), "Config has to be initialized with encoder and decoder config"
														UpperCamelCase__					  =      kwargs.pop("""encoder"""	)
														UpperCamelCase__					  =      encoder_config.pop("""model_type"""	)
														UpperCamelCase__					  =      kwargs.pop("""decoder"""	)
														UpperCamelCase__					  =      decoder_config.pop("""model_type"""	)

														from ..auto.configuration_auto import AutoConfig

														UpperCamelCase__					  =      AutoConfig.for_model(__lowerCAmelCase	,			**__lowerCAmelCase	)
														UpperCamelCase__					  =      AutoConfig.for_model(__lowerCAmelCase	,			**__lowerCAmelCase	)
														UpperCamelCase__					  =      True






							@classmethod
							def 					_lowerCamelCase		(    cls	,			__lowerCAmelCase	,			__lowerCAmelCase	,			**__lowerCAmelCase	):
														logger.info("""Set `config.is_decoder=True` and `config.add_cross_attention=True` for decoder_config"""	)
														UpperCamelCase__					  =      True
														UpperCamelCase__					  =      True

														return cls(encoder=encoder_config.to_dict()	,			decoder=decoder_config.to_dict()	,			**__lowerCAmelCase	)







							def 					_lowerCamelCase		(    self	):
														UpperCamelCase__					  =      copy.deepcopy(self.__dict__	)
														UpperCamelCase__					  =      self.encoder.to_dict()
														UpperCamelCase__					  =      self.decoder.to_dict()
														UpperCamelCase__					  =      self.__class__.model_type
														return output




