



from typing import TYPE_CHECKING

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


a_								=       {
    '''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_								=       ['''DistilBertTokenizerFast''']

try:
  if not is_torch_available():
    raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
  pass
else:
  a_								=       [
      '''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_								=       [
      '''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_								=       [
      '''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_								=       _LazyModule(__name__, globals()["""__file__"""], _import_structure, module_spec=__spec__)










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    ( _snake_case				):
 SCREAMING_SNAKE_CASE__ =			None
 SCREAMING_SNAKE_CASE__ =			None
 SCREAMING_SNAKE_CASE__ =			None
 SCREAMING_SNAKE_CASE__ =			None







class 						_snake_case    ( _snake_case				):




 def __init__(						self   ,    _lowerCamelCase=1   ,    _lowerCamelCase=0   ,    _lowerCamelCase=2   ,    _lowerCamelCase=512   ,    _lowerCamelCase="cls"   ,    _lowerCamelCase=False   ,    _lowerCamelCase=True   ,    **_lowerCamelCase   ,    ):
       super().__init__(pad_token_id=_lowerCamelCase   ,    bos_token_id=_lowerCamelCase   ,    eos_token_id=_lowerCamelCase   ,    **_lowerCamelCase       )
       a		:Tuple									=			project_dim
       a		:Optional[int]									=			pooler_fn
       a		:int									=			learn_encoder
       a		:int									=			use_attention_mask







class 						_snake_case    ( _snake_case				):
 SCREAMING_SNAKE_CASE__ =			[r'pooler', r'logit_scale']
 SCREAMING_SNAKE_CASE__ =			[r'position_ids', r'predictions.decoder.bias']
 SCREAMING_SNAKE_CASE__ =			'roberta'
 SCREAMING_SNAKE_CASE__ =			RobertaSeriesConfig




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




 def 			SCREAMING_SNAKE_CASE__							(						self   ,    _lowerCamelCase = None   ,    _lowerCamelCase = None   ,    _lowerCamelCase = None   ,    _lowerCamelCase = None   ,    _lowerCamelCase = None   ,    _lowerCamelCase = None   ,    _lowerCamelCase = None   ,    _lowerCamelCase = None   ,    _lowerCamelCase = None   ,    _lowerCamelCase = None   ,    _lowerCamelCase = None   ,    ):
       a		:Optional[int]									=			return_dict if return_dict is not None else self.config.use_return_dict

       a		: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:
             a		:Optional[int]									=			outputs['''hidden_states'''][-2]
             a		:List[Any]									=			self.pre_LN(_lowerCamelCase       )
             a		:Optional[Any]									=			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:
             a		: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   ,    )





