


'''simple docstring'''


import torch
import torch.nn as nn
from transformers.modeling_utils import ModuleUtilsMixin
from transformers.models.ta.modeling_ta import TaBlock, TaConfig, TaLayerNorm

from ...configuration_utils import ConfigMixin, register_to_config
from ...models import ModelMixin







class 							__magic_name__	(       lowerCAmelCase    ,		lowerCAmelCase    ,		lowerCAmelCase ):

     """simple docstring"""






     @register_to_config
     def __init__(   self			,     lowerCamelCase			,     lowerCamelCase			,     lowerCamelCase			,     lowerCamelCase			,     lowerCamelCase			,     lowerCamelCase			,     lowerCamelCase			,     lowerCamelCase			,     lowerCamelCase			,     lowerCamelCase = False			,     ):


          '''simple docstring'''





          super().__init__()

          __A	:       Dict      =							nn.Embedding(lowerCamelCase			,     lowerCamelCase		)

          __A	:       List[Any]      =							nn.Embedding(lowerCamelCase			,     lowerCamelCase		)
          __A	:       List[Any]      =							False

          __A	:       List[Any]      =							nn.Dropout(p=lowerCamelCase		)

          __A	:       List[Any]      =							TaConfig(
              vocab_size=lowerCamelCase			,     d_model=lowerCamelCase			,     num_heads=lowerCamelCase			,     d_kv=lowerCamelCase			,     d_ff=lowerCamelCase			,     dropout_rate=lowerCamelCase			,     feed_forward_proj=lowerCamelCase			,     is_decoder=lowerCamelCase			,     is_encoder_decoder=lowerCamelCase			,     )

          __A	:       Tuple      =							nn.ModuleList()
          for lyr_num in range(lowerCamelCase		):
               __A	:       str      =							TaBlock(lowerCamelCase		)
               self.encoders.append(lowerCamelCase		)

          __A	:       List[Any]      =							TaLayerNorm(lowerCamelCase		)
          __A	:       int      =							nn.Dropout(p=lowerCamelCase		)


     def lowerCAmelCase__  (   self			,     lowerCamelCase			,     lowerCamelCase		):


          '''simple docstring'''





          __A	:       List[str]      =							self.token_embedder(lowerCamelCase		)

          __A	:       str      =							encoder_input_tokens.shape[1]
          __A	:       int      =							torch.arange(lowerCamelCase			,     device=encoder_input_tokens.device		)
          x += self.position_encoding(lowerCamelCase		)

          __A	:       List[str]      =							self.dropout_pre(lowerCamelCase		)

          # inverted the attention mask
          __A	:       Union[str, Any]      =							encoder_input_tokens.size()
          __A	:       List[str]      =							self.get_extended_attention_mask(lowerCamelCase			,     lowerCamelCase		)

          for lyr in self.encoders:
               __A	:       Tuple      =							lyr(lowerCamelCase			,     lowerCamelCase		)[0]
          __A	:       Union[str, Any]      =							self.layer_norm(lowerCamelCase		)

          return self.dropout_post(lowerCamelCase		), encoder_inputs_mask





'''simple docstring'''


from typing import TYPE_CHECKING

from ...utils import OptionalDependencyNotAvailable, _LazyModule, is_torch_available


_UpperCamelCase 							=  {
    """configuration_upernet""": ["""UperNetConfig"""],
}

try:
      if not is_torch_available():
            raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
      pass
else:
      _UpperCamelCase 							=  [
          """UperNetForSemanticSegmentation""",
          """UperNetPreTrainedModel""",
      ]


if TYPE_CHECKING:
      from .configuration_upernet import UperNetConfig

      try:
            if not is_torch_available():
                  raise OptionalDependencyNotAvailable()
      except OptionalDependencyNotAvailable:
            pass
      else:
            from .modeling_upernet import UperNetForSemanticSegmentation, UperNetPreTrainedModel


else:
      import sys

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

