




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


lowerCamelCase__					:  Optional[int]      							=				logging.get_logger(__name__)

lowerCamelCase__					:  Tuple      							=				{
    'microsoft/swinv2-tiny-patch4-window8-256': (
        'https://huggingface.co/microsoft/swinv2-tiny-patch4-window8-256/resolve/main/config.json'
    ),
}





class 			lowerCamelCase_				( _SCREAMING_SNAKE_CASE   ):


 '''simple docstring'''







 lowercase_							       =       "swinv2"

 lowercase_							       =       {
     "num_attention_heads": "num_heads",
     "num_hidden_layers": "num_layers",
 }



 def __init__(				self    :						Dict							,							_lowerCAmelCase    :						Optional[Any]=224							,							_lowerCAmelCase    :						Optional[int]=4							,							_lowerCAmelCase    :						Tuple=3							,							_lowerCAmelCase    :						Tuple=96							,							_lowerCAmelCase    :						Dict=[2, 2, 6, 2]							,							_lowerCAmelCase    :						Optional[Any]=[3, 6, 12, 24]							,							_lowerCAmelCase    :						str=7							,							_lowerCAmelCase    :						List[Any]=4.0							,							_lowerCAmelCase    :						List[str]=True							,							_lowerCAmelCase    :						List[Any]=0.0							,							_lowerCAmelCase    :						List[Any]=0.0							,							_lowerCAmelCase    :						Any=0.1							,							_lowerCAmelCase    :						List[Any]="gelu"							,							_lowerCAmelCase    :						str=False							,							_lowerCAmelCase    :						str=0.02							,							_lowerCAmelCase    :						List[Any]=1E-5							,							_lowerCAmelCase    :						str=32							,							**_lowerCAmelCase    :						List[Any]							,							):
       super().__init__(**_lowerCAmelCase		)

       SCREAMING_SNAKE_CASE_      		=     image_size
       SCREAMING_SNAKE_CASE_      		=     patch_size
       SCREAMING_SNAKE_CASE_      		=     num_channels
       SCREAMING_SNAKE_CASE_      		=     embed_dim
       SCREAMING_SNAKE_CASE_      		=     depths
       SCREAMING_SNAKE_CASE_      		=     len(_lowerCAmelCase		)
       SCREAMING_SNAKE_CASE_      		=     num_heads
       SCREAMING_SNAKE_CASE_      		=     window_size
       SCREAMING_SNAKE_CASE_      		=     mlp_ratio
       SCREAMING_SNAKE_CASE_      		=     qkv_bias
       SCREAMING_SNAKE_CASE_      		=     hidden_dropout_prob
       SCREAMING_SNAKE_CASE_      		=     attention_probs_dropout_prob
       SCREAMING_SNAKE_CASE_      		=     drop_path_rate
       SCREAMING_SNAKE_CASE_      		=     hidden_act
       SCREAMING_SNAKE_CASE_      		=     use_absolute_embeddings
       SCREAMING_SNAKE_CASE_      		=     layer_norm_eps
       SCREAMING_SNAKE_CASE_      		=     initializer_range
       SCREAMING_SNAKE_CASE_      		=     encoder_stride
       # we set the hidden_size attribute in order to make Swinv2 work with VisionEncoderDecoderModel
       # this indicates the channel dimension after the last stage of the model
       SCREAMING_SNAKE_CASE_      		=     int(embed_dim * 2 ** (len(_lowerCAmelCase		) - 1)		)
       SCREAMING_SNAKE_CASE_      		=     (0, 0, 0, 0)

"""simple docstring"""


from dataclasses import dataclass
from typing import Optional, Tuple, Union

import torch
import torch.nn as nn

from ..configuration_utils import ConfigMixin, register_to_config
from ..utils import BaseOutput, apply_forward_hook
from .modeling_utils import ModelMixin
from .vae import Decoder, DecoderOutput, Encoder, VectorQuantizer



@dataclass
class 	__a	(   _lowerCAmelCase						):
       UpperCamelCase_		:       torch.FloatTensor





class 	__a	(   _lowerCAmelCase     ,  _lowerCAmelCase						):






       @register_to_config
       def __init__(	self			:				int							,   UpperCAmelCase_			:				int = 3							,   UpperCAmelCase_			:				int = 3							,   UpperCAmelCase_			:				Tuple[str] = ("DownEncoderBlock2D",)							,   UpperCAmelCase_			:				Tuple[str] = ("UpDecoderBlock2D",)							,   UpperCAmelCase_			:				Tuple[int] = (64,)							,   UpperCAmelCase_			:				int = 1							,   UpperCAmelCase_			:				str = "silu"							,   UpperCAmelCase_			:				int = 3							,   UpperCAmelCase_			:				int = 32							,   UpperCAmelCase_			:				int = 256							,   UpperCAmelCase_			:				int = 32							,   UpperCAmelCase_			:				Optional[int] = None							,   UpperCAmelCase_			:				float = 0.18215							,   UpperCAmelCase_			:				str = "group"							,   )->	Optional[Any]:







              """simple docstring"""
              super().__init__()

              # pass init params to Encoder
              UpperCamelCase       			=		Encoder(
                  in_channels=UpperCAmelCase_							,   out_channels=UpperCAmelCase_							,   down_block_types=UpperCAmelCase_							,   block_out_channels=UpperCAmelCase_							,   layers_per_block=UpperCAmelCase_							,   act_fn=UpperCAmelCase_							,   norm_num_groups=UpperCAmelCase_							,   double_z=UpperCAmelCase_							,   )

              UpperCamelCase       			=		vq_embed_dim if vq_embed_dim is not None else latent_channels

              UpperCamelCase       			=		nn.Convad(UpperCAmelCase_							,   UpperCAmelCase_							,   1      )
              UpperCamelCase       			=		VectorQuantizer(UpperCAmelCase_							,   UpperCAmelCase_							,   beta=0.25							,   remap=UpperCAmelCase_							,   sane_index_shape=UpperCAmelCase_      )
              UpperCamelCase       			=		nn.Convad(UpperCAmelCase_							,   UpperCAmelCase_							,   1      )

              # pass init params to Decoder
              UpperCamelCase       			=		Decoder(
                  in_channels=UpperCAmelCase_							,   out_channels=UpperCAmelCase_							,   up_block_types=UpperCAmelCase_							,   block_out_channels=UpperCAmelCase_							,   layers_per_block=UpperCAmelCase_							,   act_fn=UpperCAmelCase_							,   norm_num_groups=UpperCAmelCase_							,   norm_type=UpperCAmelCase_							,   )






       @apply_forward_hook
       def 						_SCREAMING_SNAKE_CASE							(	self			:				List[str]							,   UpperCAmelCase_			:				torch.FloatTensor							,   UpperCAmelCase_			:				bool = True      )->	VQEncoderOutput:







              """simple docstring"""
              UpperCamelCase       			=		self.encoder(UpperCAmelCase_      )
              UpperCamelCase       			=		self.quant_conv(UpperCAmelCase_      )

              if not return_dict:
                     return (h,)

              return VQEncoderOutput(latents=UpperCAmelCase_      )






       @apply_forward_hook
       def 						_SCREAMING_SNAKE_CASE							(	self			:				Optional[Any]							,   UpperCAmelCase_			:				torch.FloatTensor							,   UpperCAmelCase_			:				bool = False							,   UpperCAmelCase_			:				bool = True      )->	Union[DecoderOutput, torch.FloatTensor]:







              """simple docstring"""
              # also go through quantization layer
              if not force_not_quantize:
                     UpperCamelCase			,							UpperCamelCase			,							UpperCamelCase       			=		self.quantize(UpperCAmelCase_      )
              else:
                     UpperCamelCase       			=		h
              UpperCamelCase       			=		self.post_quant_conv(UpperCAmelCase_      )
              UpperCamelCase       			=		self.decoder(UpperCAmelCase_							,   quant if self.config.norm_type == "spatial" else None      )

              if not return_dict:
                     return (dec,)

              return DecoderOutput(sample=UpperCAmelCase_      )






       def 						_SCREAMING_SNAKE_CASE							(	self			:				Union[str, Any]							,   UpperCAmelCase_			:				torch.FloatTensor							,   UpperCAmelCase_			:				bool = True      )->	Union[DecoderOutput, torch.FloatTensor]:







              """simple docstring"""
              UpperCamelCase       			=		sample
              UpperCamelCase       			=		self.encode(UpperCAmelCase_      ).latents
              UpperCamelCase       			=		self.decode(UpperCAmelCase_      ).sample

              if not return_dict:
                     return (dec,)

              return DecoderOutput(sample=UpperCAmelCase_      )





