


'''simple docstring'''



from typing import TYPE_CHECKING

from ...utils import (
    OptionalDependencyNotAvailable,
    _LazyModule,
    is_flax_available,
    is_tf_available,
    is_tokenizers_available,
    is_torch_available,
)


__lowercase     :						Tuple	=     {
    'configuration_distilbert': [
        'DISTILBERT_PRETRAINED_CONFIG_ARCHIVE_MAP',
        'DistilBertConfig',
        'DistilBertOnnxConfig',
    ],
    'tokenization_distilbert': ['DistilBertTokenizer'],
}

try:
	if not is_tokenizers_available():
		raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
	pass
else:
	__lowercase     :						str	=     ['DistilBertTokenizerFast']

try:
	if not is_torch_available():
		raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
	pass
else:
	__lowercase     :						Any	=     [
	    'DISTILBERT_PRETRAINED_MODEL_ARCHIVE_LIST',
	    'DistilBertForMaskedLM',
	    'DistilBertForMultipleChoice',
	    'DistilBertForQuestionAnswering',
	    'DistilBertForSequenceClassification',
	    'DistilBertForTokenClassification',
	    'DistilBertModel',
	    'DistilBertPreTrainedModel',
	]

try:
	if not is_tf_available():
		raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
	pass
else:
	__lowercase     :						List[str]	=     [
	    'TF_DISTILBERT_PRETRAINED_MODEL_ARCHIVE_LIST',
	    'TFDistilBertForMaskedLM',
	    'TFDistilBertForMultipleChoice',
	    'TFDistilBertForQuestionAnswering',
	    'TFDistilBertForSequenceClassification',
	    'TFDistilBertForTokenClassification',
	    'TFDistilBertMainLayer',
	    'TFDistilBertModel',
	    'TFDistilBertPreTrainedModel',
	]

try:
	if not is_flax_available():
		raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
	pass
else:
	__lowercase     :						List[str]	=     [
	    'FlaxDistilBertForMaskedLM',
	    'FlaxDistilBertForMultipleChoice',
	    'FlaxDistilBertForQuestionAnswering',
	    'FlaxDistilBertForSequenceClassification',
	    'FlaxDistilBertForTokenClassification',
	    'FlaxDistilBertModel',
	    'FlaxDistilBertPreTrainedModel',
	]


if TYPE_CHECKING:
	from .configuration_distilbert import (
	    DISTILBERT_PRETRAINED_CONFIG_ARCHIVE_MAP,
	    DistilBertConfig,
	    DistilBertOnnxConfig,
	)
	from .tokenization_distilbert import DistilBertTokenizer

	try:
		if not is_tokenizers_available():
			raise OptionalDependencyNotAvailable()
	except OptionalDependencyNotAvailable:
		pass
	else:
		from .tokenization_distilbert_fast import DistilBertTokenizerFast

	try:
		if not is_torch_available():
			raise OptionalDependencyNotAvailable()
	except OptionalDependencyNotAvailable:
		pass
	else:
		from .modeling_distilbert import (
		    DISTILBERT_PRETRAINED_MODEL_ARCHIVE_LIST,
		    DistilBertForMaskedLM,
		    DistilBertForMultipleChoice,
		    DistilBertForQuestionAnswering,
		    DistilBertForSequenceClassification,
		    DistilBertForTokenClassification,
		    DistilBertModel,
		    DistilBertPreTrainedModel,
		)

	try:
		if not is_tf_available():
			raise OptionalDependencyNotAvailable()
	except OptionalDependencyNotAvailable:
		pass
	else:
		from .modeling_tf_distilbert import (
		    TF_DISTILBERT_PRETRAINED_MODEL_ARCHIVE_LIST,
		    TFDistilBertForMaskedLM,
		    TFDistilBertForMultipleChoice,
		    TFDistilBertForQuestionAnswering,
		    TFDistilBertForSequenceClassification,
		    TFDistilBertForTokenClassification,
		    TFDistilBertMainLayer,
		    TFDistilBertModel,
		    TFDistilBertPreTrainedModel,
		)

	try:
		if not is_flax_available():
			raise OptionalDependencyNotAvailable()
	except OptionalDependencyNotAvailable:
		pass
	else:
		from .modeling_flax_distilbert import (
		    FlaxDistilBertForMaskedLM,
		    FlaxDistilBertForMultipleChoice,
		    FlaxDistilBertForQuestionAnswering,
		    FlaxDistilBertForSequenceClassification,
		    FlaxDistilBertForTokenClassification,
		    FlaxDistilBertModel,
		    FlaxDistilBertPreTrainedModel,
		)

else:
	import sys

	__lowercase     :						int	=     _LazyModule(__name__, globals()['__file__'], _import_structure, module_spec=__spec__)







'''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 							__UpperCamelCase    (		lowerCAmelCase_ ):
	A_           =   None
	A_           =   None
	A_           =   None
	A_           =   None





class 							__UpperCamelCase    (		lowerCAmelCase_ ):




	def __init__(       self						,    __a=1						,    __a=0						,    __a=2						,    __a=512						,    __a="cls"						,    __a=False						,    __a=True						,    **__a						,    ):

						'''simple docstring'''





						super().__init__(pad_token_id=__a						,    bos_token_id=__a						,    eos_token_id=__a						,    **__a							)
						__a      :	Any    =  project_dim
						__a      :	Optional[Any]    =  pooler_fn
						__a      :	int    =  learn_encoder
						__a      :	str    =  use_attention_mask





class 							__UpperCamelCase    (		lowerCAmelCase_ ):
	A_           =   [r"pooler", r"logit_scale"]
	A_           =   [r"position_ids", r"predictions.decoder.bias"]
	A_           =   "roberta"
	A_           =   RobertaSeriesConfig




	def __init__(       self						,    __a							):

						'''simple docstring'''





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





	def 				__UpperCAmelCase							(       self						,    __a = None						,    __a = None						,    __a = None						,    __a = None						,    __a = None						,    __a = None						,    __a = None						,    __a = None						,    __a = None						,    __a = None						,    __a = None						,    ):

						'''simple docstring'''





						__a      :	Optional[Any]    =  return_dict if return_dict is not None else self.config.use_return_dict

						__a      :	Tuple    =  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:
											__a      :	Optional[Any]    =  outputs['hidden_states'][-2]
											__a      :	Optional[int]    =  self.pre_LN(__a							)
											__a      :	Union[str, Any]    =  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:
											__a      :	Optional[Any]    =  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						,    )



