





"""simple docstring"""
from collections import OrderedDict
from typing import Mapping

from packaging import version

from ...configuration_utils import PretrainedConfig
from ...onnx import OnnxConfig
from ...utils import logging


__UpperCamelCase     :						Optional[Any]						       =  logging.get_logger(__name__)

__UpperCamelCase     :						Optional[int]						       =  {
    '''microsoft/beit-base-patch16-224-pt22k''': (
        '''https://huggingface.co/microsoft/beit-base-patch16-224-pt22k/resolve/main/config.json'''
    ),
    # See all BEiT models at https://huggingface.co/models?filter=beit
}







class       a							(   a__  ):
 snake_case__             =       '''beit'''



 def __init__(     self				,       _snake_case=81_92				,       _snake_case=7_68				,       _snake_case=12				,       _snake_case=12				,       _snake_case=30_72				,       _snake_case="gelu"				,       _snake_case=0.0				,       _snake_case=0.0				,       _snake_case=0.02				,       _snake_case=1E-12				,       _snake_case=2_24				,       _snake_case=16				,       _snake_case=3				,       _snake_case=False				,       _snake_case=False				,       _snake_case=False				,       _snake_case=False				,       _snake_case=0.1				,       _snake_case=0.1				,       _snake_case=True				,       _snake_case=[3, 5, 7, 11]				,       _snake_case=[1, 2, 3, 6]				,       _snake_case=True				,       _snake_case=0.4				,       _snake_case=2_56				,       _snake_case=1				,       _snake_case=False				,       _snake_case=2_55				,       **_snake_case				,       ):







  """simple docstring"""






  super().__init__(**_snake_case     )

  lowerCAmelCase    				= vocab_size
  lowerCAmelCase    				= hidden_size
  lowerCAmelCase    				= num_hidden_layers
  lowerCAmelCase    				= num_attention_heads
  lowerCAmelCase    				= intermediate_size
  lowerCAmelCase    				= hidden_act
  lowerCAmelCase    				= hidden_dropout_prob
  lowerCAmelCase    				= attention_probs_dropout_prob
  lowerCAmelCase    				= initializer_range
  lowerCAmelCase    				= layer_norm_eps

  lowerCAmelCase    				= image_size
  lowerCAmelCase    				= patch_size
  lowerCAmelCase    				= num_channels
  lowerCAmelCase    				= use_mask_token
  lowerCAmelCase    				= use_absolute_position_embeddings
  lowerCAmelCase    				= use_relative_position_bias
  lowerCAmelCase    				= use_shared_relative_position_bias
  lowerCAmelCase    				= layer_scale_init_value
  lowerCAmelCase    				= drop_path_rate
  lowerCAmelCase    				= use_mean_pooling
  # decode head attributes (semantic segmentation)
  lowerCAmelCase    				= out_indices
  lowerCAmelCase    				= pool_scales
  # auxiliary head attributes (semantic segmentation)
  lowerCAmelCase    				= use_auxiliary_head
  lowerCAmelCase    				= auxiliary_loss_weight
  lowerCAmelCase    				= auxiliary_channels
  lowerCAmelCase    				= auxiliary_num_convs
  lowerCAmelCase    				= auxiliary_concat_input
  lowerCAmelCase    				= semantic_loss_ignore_index







class       a							(   a__  ):
 snake_case__             =       version.parse('''1.11'''  )



 @property
 def    UpperCamelCase__  (     self     ):







  """simple docstring"""






  return OrderedDict(
      [
          ('pixel_values', {0: 'batch', 1: 'num_channels', 2: 'height', 3: 'width'}),
      ]     )



 @property
 def    UpperCamelCase__  (     self     ):







  """simple docstring"""






  return 1E-4












"""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							(   a__  ):
 snake_case__             =       42







class       a							(   a__   , a__  ):



 @register_to_config
 def __init__(     self				,       _snake_case = 3				,       _snake_case = 3				,       _snake_case = ("DownEncoderBlock2D",)				,       _snake_case = ("UpDecoderBlock2D",)				,       _snake_case = (64,)				,       _snake_case = 1				,       _snake_case = "silu"				,       _snake_case = 3				,       _snake_case = 32				,       _snake_case = 2_56				,       _snake_case = 32				,       _snake_case = None				,       _snake_case = 0.18_215				,       _snake_case = "group"				,       ):







  """simple docstring"""






  super().__init__()

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

  lowerCAmelCase    				= vq_embed_dim if vq_embed_dim is not None else latent_channels

  lowerCAmelCase    				= nn.Convad(_snake_case				,       _snake_case				,       1     )
  lowerCAmelCase    				= VectorQuantizer(_snake_case				,       _snake_case				,       beta=0.25				,       remap=_snake_case				,       sane_index_shape=_snake_case     )
  lowerCAmelCase    				= nn.Convad(_snake_case				,       _snake_case				,       1     )

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



 @apply_forward_hook
 def    UpperCamelCase__  (     self				,       _snake_case				,       _snake_case = True     ):







  """simple docstring"""






  lowerCAmelCase    				= self.encoder(_snake_case     )
  lowerCAmelCase    				= self.quant_conv(_snake_case     )

  if not return_dict:
   return (h,)

  return VQEncoderOutput(latents=_snake_case     )



 @apply_forward_hook
 def    UpperCamelCase__  (     self				,       _snake_case				,       _snake_case = False				,       _snake_case = True     ):







  """simple docstring"""






  if not force_not_quantize:
   lowerCAmelCase				,lowerCAmelCase				,lowerCAmelCase    				= self.quantize(_snake_case     )
  else:
   lowerCAmelCase    				= h
  lowerCAmelCase    				= self.post_quant_conv(_snake_case     )
  lowerCAmelCase    				= self.decoder(_snake_case				,       quant if self.config.norm_type == 'spatial' else None     )

  if not return_dict:
   return (dec,)

  return DecoderOutput(sample=_snake_case     )



 def    UpperCamelCase__  (     self				,       _snake_case				,       _snake_case = True     ):







  """simple docstring"""






  lowerCAmelCase    				= sample
  lowerCAmelCase    				= self.encode(_snake_case     ).latents
  lowerCAmelCase    				= self.decode(_snake_case     ).sample

  if not return_dict:
   return (dec,)

  return DecoderOutput(sample=_snake_case     )





