




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 		lowercase_       (	lowerCAmelCase__						,							lowerCAmelCase__						,							lowerCAmelCase__				):




					@register_to_config
					def __init__(   self:		List[str],     _lowercase:		int,     _lowercase:		int,     _lowercase:		int,     _lowercase:		float,     _lowercase:		int,     _lowercase:		int,     _lowercase:		int,     _lowercase:		int,     _lowercase:		str,     _lowercase:		bool = False,     ):


									'''simple docstring'''


									super().__init__()

									__lowerCAmelCase					=  nn.Linear(_lowercase,     _lowercase,     bias=_lowercase)

									__lowerCAmelCase					=  nn.Embedding(_lowercase,     _lowercase)
									__lowerCAmelCase					=  False

									__lowerCAmelCase					=  nn.Dropout(p=_lowercase)

									__lowerCAmelCase					=  TaConfig(
									    d_model=_lowercase,     num_heads=_lowercase,     d_kv=_lowercase,     d_ff=_lowercase,     feed_forward_proj=_lowercase,     dropout_rate=_lowercase,     is_decoder=_lowercase,     is_encoder_decoder=_lowercase,     )
									__lowerCAmelCase					=  nn.ModuleList()
									for lyr_num in range(_lowercase):
													__lowerCAmelCase					=  TaBlock(_lowercase)
													self.encoders.append(_lowercase)

									__lowerCAmelCase					=  TaLayerNorm(_lowercase)
									__lowerCAmelCase					=  nn.Dropout(p=_lowercase)







					def     _lowercase						(   self:		Dict,     _lowercase:		int,     _lowercase:		Any):


									'''simple docstring'''


									__lowerCAmelCase					=  self.input_proj(_lowercase)

									# terminal relative positional encodings
									__lowerCAmelCase					=  encoder_inputs.shape[1]
									__lowerCAmelCase					=  torch.arange(_lowercase,     device=encoder_inputs.device)

									__lowerCAmelCase					=  encoder_inputs_mask.sum(-1)
									__lowerCAmelCase					=  torch.roll(input_positions.unsqueeze(0),     tuple(seq_lens.tolist()),     dims=0)
									x += self.position_encoding(_lowercase)

									__lowerCAmelCase					=  self.dropout_pre(_lowercase)

									# inverted the attention mask
									__lowerCAmelCase					=  encoder_inputs.size()
									__lowerCAmelCase					=  self.get_extended_attention_mask(_lowercase,     _lowercase)

									for lyr in self.encoders:
													__lowerCAmelCase					=  lyr(_lowercase,     _lowercase)[0]
									__lowerCAmelCase					=  self.layer_norm(_lowercase)

									return self.dropout_post(_lowercase), encoder_inputs_mask









'''simple docstring'''

from typing import TYPE_CHECKING

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


lowercase__					  =		{
    "configuration_swin2sr": ["SWIN2SR_PRETRAINED_CONFIG_ARCHIVE_MAP", "Swin2SRConfig"],
}


try:
   if not is_torch_available():
      raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
   pass
else:
   lowercase__					  =		[
       "SWIN2SR_PRETRAINED_MODEL_ARCHIVE_LIST",
       "Swin2SRForImageSuperResolution",
       "Swin2SRModel",
       "Swin2SRPreTrainedModel",
   ]


try:
   if not is_vision_available():
      raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
   pass
else:
   lowercase__					  =		["Swin2SRImageProcessor"]


if TYPE_CHECKING:
   from .configuration_swinasr import SWIN2SR_PRETRAINED_CONFIG_ARCHIVE_MAP, SwinaSRConfig

   try:
      if not is_torch_available():
         raise OptionalDependencyNotAvailable()
   except OptionalDependencyNotAvailable:
      pass
   else:
      from .modeling_swinasr import (
          SWIN2SR_PRETRAINED_MODEL_ARCHIVE_LIST,
          SwinaSRForImageSuperResolution,
          SwinaSRModel,
          SwinaSRPreTrainedModel,
      )

   try:
      if not is_vision_available():
         raise OptionalDependencyNotAvailable()
   except OptionalDependencyNotAvailable:
      pass
   else:
      from .image_processing_swinasr import SwinaSRImageProcessor


else:
   import sys

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

