


'''simple docstring'''

from typing import TYPE_CHECKING

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


a_						:       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:
       a_						:       List[str]      			=				["""DistilBertTokenizerFast"""]

try:
       if not is_torch_available():
              raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
       pass
else:
       a_						:       Union[str, 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:
       a_						:       Optional[int]      			=				[
           """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:
       a_						:       List[Any]      			=				[
           """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

       a_						:       List[Any]      			=				_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   snake_case					(					lowercase    ):





  """simple docstring"""




  _lowerCamelCase						=						None
  _lowerCamelCase						=						None
  _lowerCamelCase						=						None
  _lowerCamelCase						=						None





class   snake_case					(					lowercase    ):





  """simple docstring"""




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







   """simple docstring"""
   super().__init__(pad_token_id=UpperCamelCase    ,						bos_token_id=UpperCamelCase    ,						eos_token_id=UpperCamelCase    ,						**UpperCamelCase  )
   lowerCamelCase_  				=						project_dim
   lowerCamelCase_  				=						pooler_fn
   lowerCamelCase_  				=						learn_encoder
   lowerCamelCase_  				=						use_attention_mask





class   snake_case					(					lowercase    ):





  """simple docstring"""




  _lowerCamelCase						=						[r"pooler", r"logit_scale"]
  _lowerCamelCase						=						[r"position_ids", r"predictions.decoder.bias"]
  _lowerCamelCase						=						"roberta"
  _lowerCamelCase						=						RobertaSeriesConfig






  def __init__(					self    ,						UpperCamelCase  ):







   """simple docstring"""
   super().__init__(UpperCamelCase  )
   lowerCamelCase_  				=						XLMRobertaModel(UpperCamelCase  )
   lowerCamelCase_  				=						nn.Linear(config.hidden_size    ,						config.project_dim  )
   lowerCamelCase_  				=						getattr(UpperCamelCase    ,						"has_pre_transformation"    ,						UpperCamelCase  )
   if self.has_pre_transformation:
    lowerCamelCase_  				=						nn.Linear(config.hidden_size    ,						config.project_dim  )
    lowerCamelCase_  				=						nn.LayerNorm(config.hidden_size    ,						eps=config.layer_norm_eps  )
   self.post_init()







  def 						snake_case	(					self    ,						UpperCamelCase = None    ,						UpperCamelCase = None    ,						UpperCamelCase = None    ,						UpperCamelCase = None    ,						UpperCamelCase = None    ,						UpperCamelCase = None    ,						UpperCamelCase = None    ,						UpperCamelCase = None    ,						UpperCamelCase = None    ,						UpperCamelCase = None    ,						UpperCamelCase = None    ,						):







   """simple docstring"""
   lowerCamelCase_  				=						return_dict if return_dict is not None else self.config.use_return_dict

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

   if self.has_pre_transformation:
    lowerCamelCase_  				=						outputs["hidden_states"][-2]
    lowerCamelCase_  				=						self.pre_LN(UpperCamelCase  )
    lowerCamelCase_  				=						self.transformation_pre(UpperCamelCase  )

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



