



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     __lowerCAmelCase					(    A		):
			UpperCamelCase           =  None
			UpperCamelCase           =  None
			UpperCamelCase           =  None
			UpperCamelCase           =  None







class     __lowerCAmelCase					(    A		):



			def __init__(		self     :						Optional[Any]				,	A     :						List[Any]=1				,	A     :						List[Any]=0				,	A     :						Optional[int]=2				,	A     :						str=5_12				,	A     :						List[Any]="cls"				,	A     :						int=False				,	A     :						Tuple=True				,	**A     :						List[str]				,	)     ->					int:



						"""simple docstring"""






						super().__init__(pad_token_id=A				,	bos_token_id=A				,	eos_token_id=A				,	**A)
						_UpperCAmelCase	 =     project_dim
						_UpperCAmelCase	 =     pooler_fn
						_UpperCAmelCase	 =     learn_encoder
						_UpperCAmelCase	 =     use_attention_mask







class     __lowerCAmelCase					(    A		):
			UpperCamelCase           =  [R'''pooler''', R'''logit_scale''']
			UpperCamelCase           =  [R'''position_ids''', R'''predictions.decoder.bias''']
			UpperCamelCase           =  '''roberta'''
			UpperCamelCase           =  RobertaSeriesConfig



			def __init__(		self     :						Any				,	A     :						Dict)     ->					Any:



						"""simple docstring"""






						super().__init__(A)
						_UpperCAmelCase	 =     XLMRobertaModel(A)
						_UpperCAmelCase	 =     nn.Linear(config.hidden_size				,	config.project_dim)
						_UpperCAmelCase	 =     getattr(A				,	'has_pre_transformation'				,	A)
						if self.has_pre_transformation:
									_UpperCAmelCase	 =     nn.Linear(config.hidden_size				,	config.project_dim)
									_UpperCAmelCase	 =     nn.LayerNorm(config.hidden_size				,	eps=config.layer_norm_eps)
						self.post_init()



			def 					_lowerCamelCase (		self     :						List[Any]				,	A     :						Optional[torch.Tensor] = None				,	A     :						Optional[torch.Tensor] = None				,	A     :						Optional[torch.Tensor] = None				,	A     :						Optional[torch.Tensor] = None				,	A     :						Optional[torch.Tensor] = None				,	A     :						Optional[torch.Tensor] = None				,	A     :						Optional[torch.Tensor] = None				,	A     :						Optional[torch.Tensor] = None				,	A     :						Optional[bool] = None				,	A     :						Optional[bool] = None				,	A     :						Optional[bool] = None				,	)     ->					Tuple:



						"""simple docstring"""






						_UpperCAmelCase	 =     return_dict if return_dict is not None else self.config.use_return_dict

						_UpperCAmelCase	 =     self.base_model(
						    input_ids=A				,	attention_mask=A				,	token_type_ids=A				,	position_ids=A				,	head_mask=A				,	inputs_embeds=A				,	encoder_hidden_states=A				,	encoder_attention_mask=A				,	output_attentions=A				,	output_hidden_states=True if self.has_pre_transformation else output_hidden_states				,	return_dict=A				,	)

						if self.has_pre_transformation:
									_UpperCAmelCase	 =     outputs['hidden_states'][-2]
									_UpperCAmelCase	 =     self.pre_LN(A)
									_UpperCAmelCase	 =     self.transformation_pre(A)

									return TransformationModelOutput(
									    projection_state=A				,	last_hidden_state=outputs.last_hidden_state				,	hidden_states=outputs.hidden_states				,	attentions=outputs.attentions				,	)
						else:
									_UpperCAmelCase	 =     self.transformation(outputs.last_hidden_state)
									return TransformationModelOutput(
									    projection_state=A				,	last_hidden_state=outputs.last_hidden_state				,	hidden_states=outputs.hidden_states				,	attentions=outputs.attentions				,	)





from typing import TYPE_CHECKING

from ...utils import OptionalDependencyNotAvailable, _LazyModule, is_tf_available, is_torch_available


UpperCAmelCase__     = {
    "configuration_ctrl": ["CTRL_PRETRAINED_CONFIG_ARCHIVE_MAP", "CTRLConfig"],
    "tokenization_ctrl": ["CTRLTokenizer"],
}

try:
							if not is_torch_available():
														raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
							pass
else:
							UpperCAmelCase__     = [
							    "CTRL_PRETRAINED_MODEL_ARCHIVE_LIST",
							    "CTRLForSequenceClassification",
							    "CTRLLMHeadModel",
							    "CTRLModel",
							    "CTRLPreTrainedModel",
							]

try:
							if not is_tf_available():
														raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
							pass
else:
							UpperCAmelCase__     = [
							    "TF_CTRL_PRETRAINED_MODEL_ARCHIVE_LIST",
							    "TFCTRLForSequenceClassification",
							    "TFCTRLLMHeadModel",
							    "TFCTRLModel",
							    "TFCTRLPreTrainedModel",
							]


if TYPE_CHECKING:
							from .configuration_ctrl import CTRL_PRETRAINED_CONFIG_ARCHIVE_MAP, CTRLConfig
							from .tokenization_ctrl import CTRLTokenizer

							try:
														if not is_torch_available():
																					raise OptionalDependencyNotAvailable()
							except OptionalDependencyNotAvailable:
														pass
							else:
														from .modeling_ctrl import (
														    CTRL_PRETRAINED_MODEL_ARCHIVE_LIST,
														    CTRLForSequenceClassification,
														    CTRLLMHeadModel,
														    CTRLModel,
														    CTRLPreTrainedModel,
														)

							try:
														if not is_tf_available():
																					raise OptionalDependencyNotAvailable()
							except OptionalDependencyNotAvailable:
														pass
							else:
														from .modeling_tf_ctrl import (
														    TF_CTRL_PRETRAINED_MODEL_ARCHIVE_LIST,
														    TFCTRLForSequenceClassification,
														    TFCTRLLMHeadModel,
														    TFCTRLModel,
														    TFCTRLPreTrainedModel,
														)

else:
							import sys

							UpperCAmelCase__     = _LazyModule(__name__, globals()["__file__"], _import_structure, module_spec=__spec__)
