






"""simple docstring"""







import torch
from torch import nn
from transformers import CLIPPreTrainedModel, CLIPVisionModel

from ...models.attention import BasicTransformerBlock
from ...utils import logging


__a       :	str             = logging.get_logger(__name__)  # pylint: disable=invalid-name







class        _SCREAMING_SNAKE_CASE						(  __snake_case							):





							"""simple docstring"""





							def __init__(   self:     Union[str, Any]				,		__A:     Union[str, Any]				,		__A:     Optional[int]=768    ):

												'''simple docstring'''

												super().__init__(__A    )
												a__          =  proj_size

												a__          =  CLIPVisionModel(__A    )
												a__          =  PaintByExampleMapper(__A    )
												a__          =  nn.LayerNorm(config.hidden_size    )
												a__          =  nn.Linear(config.hidden_size				,		self.proj_size    )

												# uncondition for scaling
												a__          =  nn.Parameter(torch.randn((1, 1, self.proj_size)    )    )





							def  lowercase		(   self:     Union[str, Any]				,		__A:     Tuple				,		__A:     int=False    ):

												'''simple docstring'''

												a__          =  self.model(pixel_values=__A    )
												a__          =  clip_output.pooler_output
												a__          =  self.mapper(latent_states[:, None]    )
												a__          =  self.final_layer_norm(__A    )
												a__          =  self.proj_out(__A    )
												if return_uncond_vector:
																	return latent_states, self.uncond_vector

												return latent_states







class        _SCREAMING_SNAKE_CASE						(  nn.Module							):





							"""simple docstring"""





							def __init__(   self:     int				,		__A:     Union[str, Any]    ):

												'''simple docstring'''

												super().__init__()
												a__          =  (config.num_hidden_layers + 1) // 5
												a__          =  config.hidden_size
												a__          =  1
												a__          =  nn.ModuleList(
												    [
												        BasicTransformerBlock(__A				,		__A				,		__A				,		activation_fn='''gelu'''				,		attention_bias=__A    )
												        for _ in range(__A    )
												    ]    )





							def  lowercase		(   self:     Any				,		__A:     str    ):

												'''simple docstring'''

												for block in self.blocks:
																	a__          =  block(__A    )

												return hidden_states










"""simple docstring"""







from ...configuration_utils import PretrainedConfig
from ...utils import logging


__a       :	Any             = logging.get_logger(__name__)

__a       :	Union[str, Any]             = {
    'caidas/swin2sr-classicalsr-x2-64': (
        'https://huggingface.co/caidas/swin2sr-classicalsr-x2-64/resolve/main/config.json'
    ),
}







class        _SCREAMING_SNAKE_CASE						(  __snake_case							):





							"""simple docstring"""





							_SCREAMING_SNAKE_CASE    ='swin2sr'

							_SCREAMING_SNAKE_CASE    ={
							    'hidden_size': 'embed_dim',
							    'num_attention_heads': 'num_heads',
							    'num_hidden_layers': 'num_layers',
							}




							def __init__(   self:     Union[str, Any]				,		__A:     List[Any]=64				,		__A:     int=1				,		__A:     Dict=3				,		__A:     List[Any]=180				,		__A:     int=[6, 6, 6, 6, 6, 6]				,		__A:     Tuple=[6, 6, 6, 6, 6, 6]				,		__A:     int=8				,		__A:     Optional[int]=2.0				,		__A:     Optional[int]=True				,		__A:     int=0.0				,		__A:     Any=0.0				,		__A:     Optional[Any]=0.1				,		__A:     Optional[Any]="gelu"				,		__A:     Dict=False				,		__A:     List[Any]=0.0_2				,		__A:     List[Any]=1e-5				,		__A:     List[str]=2				,		__A:     int=1.0				,		__A:     Dict="1conv"				,		__A:     Optional[Any]="pixelshuffle"				,		**__A:     Dict				,		):

												'''simple docstring'''

												super().__init__(**__A    )

												a__          =  image_size
												a__          =  patch_size
												a__          =  num_channels
												a__          =  embed_dim
												a__          =  depths
												a__          =  len(__A    )
												a__          =  num_heads
												a__          =  window_size
												a__          =  mlp_ratio
												a__          =  qkv_bias
												a__          =  hidden_dropout_prob
												a__          =  attention_probs_dropout_prob
												a__          =  drop_path_rate
												a__          =  hidden_act
												a__          =  use_absolute_embeddings
												a__          =  layer_norm_eps
												a__          =  initializer_range
												a__          =  upscale
												a__          =  img_range
												a__          =  resi_connection
												a__          =  upsampler


