

'''simple docstring'''

import collections.abc
from typing import Optional, Tuple, Union

import torch
import torch.utils.checkpoint
from torch import nn
from torch.nn import BCEWithLogitsLoss, CrossEntropyLoss, MSELoss

from ...activations import ACTaFN
from ...modeling_outputs import BaseModelOutputWithNoAttention, ImageClassifierOutputWithNoAttention
from ...modeling_utils import PreTrainedModel
from ...utils import add_code_sample_docstrings, add_start_docstrings, add_start_docstrings_to_model_forward, logging
from .configuration_poolformer import PoolFormerConfig


A_       						=							logging.get_logger(__name__)

# General docstring
A_       						=							"PoolFormerConfig"

# Base docstring
A_       						=							"sail/poolformer_s12"
A_       						=							[1, 5_12, 7, 7]

# Image classification docstring
A_       						=							"sail/poolformer_s12"
A_       						=							"tabby, tabby cat"

A_       						=							[
    "sail/poolformer_s12",
    # See all PoolFormer models at https://huggingface.co/models?filter=poolformer
]





def    A_  ( snake_case      ,       snake_case = 0.0      ,       snake_case = False ):
  if drop_prob == 0.0 or not training:
    return input
  SCREAMING_SNAKE_CASE:Optional[Any]						      =					1 - drop_prob
  SCREAMING_SNAKE_CASE:List[str]						      =					(input.shape[0],) + (1,) * (input.ndim - 1)  # work with diff dim tensors, not just 2D ConvNets
  SCREAMING_SNAKE_CASE:Any						      =					keep_prob + torch.rand(snake_case      ,       dtype=input.dtype      ,       device=input.device )
  random_tensor.floor_()  # binarize
  SCREAMING_SNAKE_CASE:List[str]						      =					input.div(snake_case ) * random_tensor
  return output





class 							_snake_case (       nn.Module						):
   def __init__( self			:      List[Any]     ,SCREAMING_SNAKE_CASE__			:      Optional[float] = None							):
     super().__init__()
     SCREAMING_SNAKE_CASE:Any						      =					drop_prob
   def     __UpperCamelCase						( self			:      Tuple     ,SCREAMING_SNAKE_CASE__			:      torch.Tensor							):
     return drop_path(SCREAMING_SNAKE_CASE__     ,self.drop_prob     ,self.training							)







   def     __UpperCamelCase						( self			:      Optional[int]							):
     return "p={}".format(self.drop_prob							)





class 							_snake_case (       nn.Module						):
   def __init__( self			:      Any     ,SCREAMING_SNAKE_CASE__			:      str     ,SCREAMING_SNAKE_CASE__			:      List[Any]     ,SCREAMING_SNAKE_CASE__			:      int     ,SCREAMING_SNAKE_CASE__			:      Any     ,SCREAMING_SNAKE_CASE__			:      List[str]     ,SCREAMING_SNAKE_CASE__			:      List[str]=None							):
     super().__init__()
     SCREAMING_SNAKE_CASE:List[Any]						      =					patch_size if isinstance(SCREAMING_SNAKE_CASE__     ,collections.abc.Iterable							) else (patch_size, patch_size)
     SCREAMING_SNAKE_CASE:Dict						      =					stride if isinstance(SCREAMING_SNAKE_CASE__     ,collections.abc.Iterable							) else (stride, stride)
     SCREAMING_SNAKE_CASE:Union[str, Any]						      =					padding if isinstance(SCREAMING_SNAKE_CASE__     ,collections.abc.Iterable							) else (padding, padding)

     SCREAMING_SNAKE_CASE:Union[str, Any]						      =					nn.Convad(SCREAMING_SNAKE_CASE__     ,SCREAMING_SNAKE_CASE__     ,kernel_size=SCREAMING_SNAKE_CASE__     ,stride=SCREAMING_SNAKE_CASE__     ,padding=SCREAMING_SNAKE_CASE__							)
     SCREAMING_SNAKE_CASE:int						      =					norm_layer(SCREAMING_SNAKE_CASE__							) if norm_layer else nn.Identity()







   def     __UpperCamelCase						( self			:      Any     ,SCREAMING_SNAKE_CASE__			:      Union[str, Any]							):
     SCREAMING_SNAKE_CASE:List[str]						      =					self.projection(SCREAMING_SNAKE_CASE__							)
     SCREAMING_SNAKE_CASE:Tuple						      =					self.norm(SCREAMING_SNAKE_CASE__							)
     return embeddings





class 							_snake_case (       nn.GroupNorm						):
   def __init__( self			:      str     ,SCREAMING_SNAKE_CASE__			:      List[Any]     ,**SCREAMING_SNAKE_CASE__			:      int							):
     super().__init__(1     ,SCREAMING_SNAKE_CASE__     ,**SCREAMING_SNAKE_CASE__							)





class 							_snake_case (       nn.Module						):
   def __init__( self			:      Union[str, Any]     ,SCREAMING_SNAKE_CASE__			:      Optional[Any]							):
     super().__init__()
     SCREAMING_SNAKE_CASE:List[Any]						      =					nn.AvgPoolad(SCREAMING_SNAKE_CASE__     ,stride=1     ,padding=pool_size // 2     ,count_include_pad=SCREAMING_SNAKE_CASE__							)







   def     __UpperCamelCase						( self			:      Optional[int]     ,SCREAMING_SNAKE_CASE__			:      Optional[int]							):
     return self.pool(SCREAMING_SNAKE_CASE__							) - hidden_states





class 							_snake_case (       nn.Module						):
   def __init__( self			:      str     ,SCREAMING_SNAKE_CASE__			:      Optional[int]     ,SCREAMING_SNAKE_CASE__			:      Any     ,SCREAMING_SNAKE_CASE__			:      List[str]     ,SCREAMING_SNAKE_CASE__			:      List[str]							):
     super().__init__()
     SCREAMING_SNAKE_CASE:Any						      =					nn.Convad(SCREAMING_SNAKE_CASE__     ,SCREAMING_SNAKE_CASE__     ,1							)
     SCREAMING_SNAKE_CASE:Union[str, Any]						      =					nn.Convad(SCREAMING_SNAKE_CASE__     ,SCREAMING_SNAKE_CASE__     ,1							)
     SCREAMING_SNAKE_CASE:int						      =					PoolFormerDropPath(SCREAMING_SNAKE_CASE__							)
     if isinstance(config.hidden_act     ,SCREAMING_SNAKE_CASE__							):
       SCREAMING_SNAKE_CASE:List[str]						      =					ACTaFN[config.hidden_act]
     else:
       SCREAMING_SNAKE_CASE:Tuple						      =					config.hidden_act







   def     __UpperCamelCase						( self			:      str     ,SCREAMING_SNAKE_CASE__			:      int							):
     SCREAMING_SNAKE_CASE:Optional[int]						      =					self.conva(SCREAMING_SNAKE_CASE__							)
     SCREAMING_SNAKE_CASE:List[Any]						      =					self.act_fn(SCREAMING_SNAKE_CASE__							)
     SCREAMING_SNAKE_CASE:Optional[Any]						      =					self.drop(SCREAMING_SNAKE_CASE__							)
     SCREAMING_SNAKE_CASE:Union[str, Any]						      =					self.conva(SCREAMING_SNAKE_CASE__							)
     SCREAMING_SNAKE_CASE:Optional[Any]						      =					self.drop(SCREAMING_SNAKE_CASE__							)

     return hidden_states





class 							_snake_case (       nn.Module						):
   def __init__( self			:      Dict     ,SCREAMING_SNAKE_CASE__			:      Dict     ,SCREAMING_SNAKE_CASE__			:      List[Any]     ,SCREAMING_SNAKE_CASE__			:      Union[str, Any]     ,SCREAMING_SNAKE_CASE__			:      int     ,SCREAMING_SNAKE_CASE__			:      str     ,SCREAMING_SNAKE_CASE__			:      Tuple							):
     super().__init__()
     SCREAMING_SNAKE_CASE:int						      =					PoolFormerPooling(SCREAMING_SNAKE_CASE__							)
     SCREAMING_SNAKE_CASE:int						      =					PoolFormerOutput(SCREAMING_SNAKE_CASE__     ,SCREAMING_SNAKE_CASE__     ,SCREAMING_SNAKE_CASE__     ,SCREAMING_SNAKE_CASE__							)
     SCREAMING_SNAKE_CASE:Optional[Any]						      =					PoolFormerGroupNorm(SCREAMING_SNAKE_CASE__							)
     SCREAMING_SNAKE_CASE:Any						      =					PoolFormerGroupNorm(SCREAMING_SNAKE_CASE__							)

     # Useful for training neural nets
     SCREAMING_SNAKE_CASE:Any						      =					PoolFormerDropPath(SCREAMING_SNAKE_CASE__							) if drop_path > 0.0 else nn.Identity()
     SCREAMING_SNAKE_CASE:Optional[Any]						      =					config.use_layer_scale
     if config.use_layer_scale:
       SCREAMING_SNAKE_CASE:Optional[Any]						      =					nn.Parameter(
           config.layer_scale_init_value * torch.ones((SCREAMING_SNAKE_CASE__)							)     ,requires_grad=SCREAMING_SNAKE_CASE__							)
       SCREAMING_SNAKE_CASE:Dict						      =					nn.Parameter(
           config.layer_scale_init_value * torch.ones((SCREAMING_SNAKE_CASE__)							)     ,requires_grad=SCREAMING_SNAKE_CASE__							)







   def     __UpperCamelCase						( self			:      Any     ,SCREAMING_SNAKE_CASE__			:      str							):
     if self.use_layer_scale:
       SCREAMING_SNAKE_CASE:Optional[int]						      =					self.pooling(self.before_norm(SCREAMING_SNAKE_CASE__							)							)
       SCREAMING_SNAKE_CASE:Union[str, Any]						      =					self.layer_scale_a.unsqueeze(-1							).unsqueeze(-1							) * pooling_output
       # First residual connection
       SCREAMING_SNAKE_CASE:str						      =					hidden_states + self.drop_path(SCREAMING_SNAKE_CASE__							)
       SCREAMING_SNAKE_CASE:Union[str, Any]						      =					()

       SCREAMING_SNAKE_CASE:List[Any]						      =					self.output(self.after_norm(SCREAMING_SNAKE_CASE__							)							)
       SCREAMING_SNAKE_CASE:List[Any]						      =					self.layer_scale_a.unsqueeze(-1							).unsqueeze(-1							) * layer_output
       # Second residual connection
       SCREAMING_SNAKE_CASE:Dict						      =					hidden_states + self.drop_path(SCREAMING_SNAKE_CASE__							)

       SCREAMING_SNAKE_CASE:Optional[Any]						      =					(output,) + outputs
       return outputs

     else:
       SCREAMING_SNAKE_CASE:Optional[int]						      =					self.drop_path(self.pooling(self.before_norm(SCREAMING_SNAKE_CASE__							)							)							)
       # First residual connection
       SCREAMING_SNAKE_CASE:str						      =					pooling_output + hidden_states
       SCREAMING_SNAKE_CASE:int						      =					()

       # Second residual connection inside the PoolFormerOutput block
       SCREAMING_SNAKE_CASE:Dict						      =					self.drop_path(self.output(self.after_norm(SCREAMING_SNAKE_CASE__							)							)							)
       SCREAMING_SNAKE_CASE:List[Any]						      =					hidden_states + layer_output

       SCREAMING_SNAKE_CASE:List[Any]						      =					(output,) + outputs
       return outputs





class 							_snake_case (       nn.Module						):
   def __init__( self			:      List[Any]     ,SCREAMING_SNAKE_CASE__			:      Tuple							):
     super().__init__()
     SCREAMING_SNAKE_CASE:int						      =					config
     # stochastic depth decay rule
     SCREAMING_SNAKE_CASE:List[str]						      =					[x.item() for x in torch.linspace(0     ,config.drop_path_rate     ,sum(config.depths							)							)]

     # patch embeddings
     SCREAMING_SNAKE_CASE:List[Any]						      =					[]
     for i in range(config.num_encoder_blocks							):
       embeddings.append(
           PoolFormerEmbeddings(
               patch_size=config.patch_sizes[i]     ,stride=config.strides[i]     ,padding=config.padding[i]     ,num_channels=config.num_channels if i == 0 else config.hidden_sizes[i - 1]     ,hidden_size=config.hidden_sizes[i]     ,)							)
     SCREAMING_SNAKE_CASE:Optional[int]						      =					nn.ModuleList(SCREAMING_SNAKE_CASE__							)

     # Transformer blocks
     SCREAMING_SNAKE_CASE:Tuple						      =					[]
     SCREAMING_SNAKE_CASE:Optional[int]						      =					0
     for i in range(config.num_encoder_blocks							):
       # each block consists of layers
       SCREAMING_SNAKE_CASE:Dict						      =					[]
       if i != 0:
         cur += config.depths[i - 1]
       for j in range(config.depths[i]							):
         layers.append(
             PoolFormerLayer(
                 SCREAMING_SNAKE_CASE__     ,num_channels=config.hidden_sizes[i]     ,pool_size=config.pool_size     ,hidden_size=config.hidden_sizes[i]     ,intermediate_size=int(config.hidden_sizes[i] * config.mlp_ratio							)     ,drop_path=dpr[cur + j]     ,)							)
       blocks.append(nn.ModuleList(SCREAMING_SNAKE_CASE__							)							)

     SCREAMING_SNAKE_CASE:Dict						      =					nn.ModuleList(SCREAMING_SNAKE_CASE__							)







   def     __UpperCamelCase						( self			:      List[Any]     ,SCREAMING_SNAKE_CASE__			:      Tuple     ,SCREAMING_SNAKE_CASE__			:      Any=False     ,SCREAMING_SNAKE_CASE__			:      Union[str, Any]=True							):
     SCREAMING_SNAKE_CASE:List[str]						      =					() if output_hidden_states else None

     SCREAMING_SNAKE_CASE:Optional[int]						      =					pixel_values
     for idx, layers in enumerate(zip(self.patch_embeddings     ,self.block							)							):
       SCREAMING_SNAKE_CASE      ,    SCREAMING_SNAKE_CASE:Union[str, Any]						      =					layers
       # Get patch embeddings from hidden_states
       SCREAMING_SNAKE_CASE:Dict						      =					embedding_layer(SCREAMING_SNAKE_CASE__							)
       # Send the embeddings through the blocks
       for _, blk in enumerate(SCREAMING_SNAKE_CASE__							):
         SCREAMING_SNAKE_CASE:Dict						      =					blk(SCREAMING_SNAKE_CASE__							)
         SCREAMING_SNAKE_CASE:Optional[int]						      =					layer_outputs[0]

       if output_hidden_states:
         SCREAMING_SNAKE_CASE:Optional[int]						      =					all_hidden_states + (hidden_states,)

     if not return_dict:
       return tuple(v for v in [hidden_states, all_hidden_states] if v is not None							)

     return BaseModelOutputWithNoAttention(last_hidden_state=SCREAMING_SNAKE_CASE__     ,hidden_states=SCREAMING_SNAKE_CASE__							)





class 							_snake_case (       _a						):
   _A       :     List[str]       =					PoolFormerConfig
   _A       :     Any       =					'''poolformer'''
   _A       :     Optional[int]       =					'''pixel_values'''
   _A       :     Dict       =					True
   def     __UpperCamelCase						( self			:      Optional[int]     ,SCREAMING_SNAKE_CASE__			:      List[str]							):
     if isinstance(SCREAMING_SNAKE_CASE__     ,(nn.Linear, nn.Convad)							):
       module.weight.data.normal_(mean=0.0     ,std=self.config.initializer_range							)
       if module.bias is not None:
         module.bias.data.zero_()
     elif isinstance(SCREAMING_SNAKE_CASE__     ,nn.LayerNorm							):
       module.bias.data.zero_()
       module.weight.data.fill_(1.0							)







   def     __UpperCamelCase						( self			:      Optional[int]     ,SCREAMING_SNAKE_CASE__			:      Dict     ,SCREAMING_SNAKE_CASE__			:      List[str]=False							):
     if isinstance(SCREAMING_SNAKE_CASE__     ,SCREAMING_SNAKE_CASE__							):
       SCREAMING_SNAKE_CASE:Optional[int]						      =					value



A_       						=							R"\n    This model is a PyTorch [torch.nn.Module](https://pytorch.org/docs/stable/nn.html#torch.nn.Module) sub-class. Use\n    it as a regular PyTorch Module and refer to the PyTorch documentation for all matter related to general usage and\n    behavior.\n\n    Parameters:\n        config ([`PoolFormerConfig`]): Model configuration class with all the parameters of the model.\n            Initializing with a config file does not load the weights associated with the model, only the\n            configuration. Check out the [`~PreTrainedModel.from_pretrained`] method to load the model weights.\n"

A_       						=							R"\n    Args:\n        pixel_values (`torch.FloatTensor` of shape `(batch_size, num_channels, height, width)`):\n            Pixel values. Pixel values can be obtained using [`AutoImageProcessor`]. See\n            [`PoolFormerImageProcessor.__call__`] for details.\n"





@add_start_docstrings(
    '''The bare PoolFormer Model transformer outputting raw hidden-states without any specific head on top.'''	,  _a	,  )
class 							_snake_case (       _a						):
   def __init__( self			:      Any     ,SCREAMING_SNAKE_CASE__			:      List[str]							):
     super().__init__(SCREAMING_SNAKE_CASE__							)
     SCREAMING_SNAKE_CASE:Optional[int]						      =					config

     SCREAMING_SNAKE_CASE:int						      =					PoolFormerEncoder(SCREAMING_SNAKE_CASE__							)

     # Initialize weights and apply final processing
     self.post_init()
   def     __UpperCamelCase						( self			:      Optional[int]							):
     return self.embeddings.patch_embeddings







   @add_start_docstrings_to_model_forward(SCREAMING_SNAKE_CASE__							)
   @add_code_sample_docstrings(
       checkpoint=_CHECKPOINT_FOR_DOC     ,output_type=SCREAMING_SNAKE_CASE__     ,config_class=_CONFIG_FOR_DOC     ,modality="vision"     ,expected_output=_EXPECTED_OUTPUT_SHAPE     ,)
   def     __UpperCamelCase						( self			:      List[str]     ,SCREAMING_SNAKE_CASE__			:      Optional[torch.FloatTensor] = None     ,SCREAMING_SNAKE_CASE__			:      Optional[bool] = None     ,SCREAMING_SNAKE_CASE__			:      Optional[bool] = None     ,):
     SCREAMING_SNAKE_CASE:Dict						      =					(
         output_hidden_states if output_hidden_states is not None else self.config.output_hidden_states
     )
     SCREAMING_SNAKE_CASE:Tuple						      =					return_dict if return_dict is not None else self.config.use_return_dict

     if pixel_values is None:
       raise ValueError("You have to specify pixel_values"							)

     SCREAMING_SNAKE_CASE:str						      =					self.encoder(
         SCREAMING_SNAKE_CASE__     ,output_hidden_states=SCREAMING_SNAKE_CASE__     ,return_dict=SCREAMING_SNAKE_CASE__     ,)
     SCREAMING_SNAKE_CASE:str						      =					encoder_outputs[0]

     if not return_dict:
       return (sequence_output, None) + encoder_outputs[1:]

     return BaseModelOutputWithNoAttention(
         last_hidden_state=SCREAMING_SNAKE_CASE__     ,hidden_states=encoder_outputs.hidden_states     ,)





class 							_snake_case (       nn.Module						):
   def __init__( self			:      List[str]     ,SCREAMING_SNAKE_CASE__			:      Optional[Any]							):
     super().__init__()
     SCREAMING_SNAKE_CASE:Tuple						      =					nn.Linear(config.hidden_size     ,config.hidden_size							)







   def     __UpperCamelCase						( self			:      int     ,SCREAMING_SNAKE_CASE__			:      Optional[Any]							):
     SCREAMING_SNAKE_CASE:Tuple						      =					self.dense(SCREAMING_SNAKE_CASE__							)
     return output





@add_start_docstrings(
    '''
    PoolFormer Model transformer with an image classification head on top
    '''	,  _a	,  )
class 							_snake_case (       _a						):
   def __init__( self			:      Optional[Any]     ,SCREAMING_SNAKE_CASE__			:      Optional[Any]							):
     super().__init__(SCREAMING_SNAKE_CASE__							)
     SCREAMING_SNAKE_CASE:List[Any]						      =					config.num_labels
     SCREAMING_SNAKE_CASE:Optional[int]						      =					PoolFormerModel(SCREAMING_SNAKE_CASE__							)

     # Final norm
     SCREAMING_SNAKE_CASE:Union[str, Any]						      =					PoolFormerGroupNorm(config.hidden_sizes[-1]							)
     # Classifier head
     SCREAMING_SNAKE_CASE:List[str]						      =					(
         nn.Linear(config.hidden_sizes[-1]     ,config.num_labels							) if config.num_labels > 0 else nn.Identity()
     )

     # Initialize weights and apply final processing
     self.post_init()







   @add_start_docstrings_to_model_forward(SCREAMING_SNAKE_CASE__							)
   @add_code_sample_docstrings(
       checkpoint=_IMAGE_CLASS_CHECKPOINT     ,output_type=SCREAMING_SNAKE_CASE__     ,config_class=_CONFIG_FOR_DOC     ,expected_output=_IMAGE_CLASS_EXPECTED_OUTPUT     ,)
   def     __UpperCamelCase						( self			:      Dict     ,SCREAMING_SNAKE_CASE__			:      Optional[torch.FloatTensor] = None     ,SCREAMING_SNAKE_CASE__			:      Optional[torch.LongTensor] = None     ,SCREAMING_SNAKE_CASE__			:      Optional[bool] = None     ,SCREAMING_SNAKE_CASE__			:      Optional[bool] = None     ,):
     SCREAMING_SNAKE_CASE:List[Any]						      =					return_dict if return_dict is not None else self.config.use_return_dict

     SCREAMING_SNAKE_CASE:str						      =					self.poolformer(
         SCREAMING_SNAKE_CASE__     ,output_hidden_states=SCREAMING_SNAKE_CASE__     ,return_dict=SCREAMING_SNAKE_CASE__     ,)

     SCREAMING_SNAKE_CASE:List[str]						      =					outputs[0]

     SCREAMING_SNAKE_CASE:Optional[int]						      =					self.classifier(self.norm(SCREAMING_SNAKE_CASE__							).mean([-2, -1]							)							)

     SCREAMING_SNAKE_CASE:Dict						      =					None
     if labels is not None:
       if self.config.problem_type is None:
         if self.num_labels == 1:
           SCREAMING_SNAKE_CASE:Optional[Any]						      =					"regression"
         elif self.num_labels > 1 and (labels.dtype == torch.long or labels.dtype == torch.int):
           SCREAMING_SNAKE_CASE:Any						      =					"single_label_classification"
         else:
           SCREAMING_SNAKE_CASE:List[Any]						      =					"multi_label_classification"

       if self.config.problem_type == "regression":
         SCREAMING_SNAKE_CASE:Dict						      =					MSELoss()
         if self.num_labels == 1:
           SCREAMING_SNAKE_CASE:Optional[int]						      =					loss_fct(logits.squeeze()     ,labels.squeeze()							)
         else:
           SCREAMING_SNAKE_CASE:Optional[Any]						      =					loss_fct(SCREAMING_SNAKE_CASE__     ,SCREAMING_SNAKE_CASE__							)
       elif self.config.problem_type == "single_label_classification":
         SCREAMING_SNAKE_CASE:str						      =					CrossEntropyLoss()
         SCREAMING_SNAKE_CASE:Union[str, Any]						      =					loss_fct(logits.view(-1     ,self.num_labels							)     ,labels.view(-1							)							)
       elif self.config.problem_type == "multi_label_classification":
         SCREAMING_SNAKE_CASE:Dict						      =					BCEWithLogitsLoss()
         SCREAMING_SNAKE_CASE:List[str]						      =					loss_fct(SCREAMING_SNAKE_CASE__     ,SCREAMING_SNAKE_CASE__							)

     if not return_dict:
       SCREAMING_SNAKE_CASE:Dict						      =					(logits,) + outputs[2:]
       return ((loss,) + output) if loss is not None else output

     return ImageClassifierOutputWithNoAttention(loss=SCREAMING_SNAKE_CASE__     ,logits=SCREAMING_SNAKE_CASE__     ,hidden_states=outputs.hidden_states							)









'''simple docstring'''

import copy
from typing import Dict, List, Optional

from ...configuration_utils import PretrainedConfig
from ...utils import logging
from ..auto import CONFIG_MAPPING


A_       						=							{
    "facebook/mask2former-swin-small-coco-instance": (
        "https://huggingface.co/facebook/mask2former-swin-small-coco-instance/blob/main/config.json"
    )
    # See all Mask2Former models at https://huggingface.co/models?filter=mask2former
}

A_       						=							logging.get_logger(__name__)





class 							_snake_case (       _a						):
   _A       :     List[Any]       =					'''mask2former'''
   _A       :     str       =					['''swin''']
   _A       :     Tuple       =					{'''hidden_size''': '''hidden_dim'''}
   def __init__( self			:      Tuple     ,SCREAMING_SNAKE_CASE__			:      Optional[Dict] = None     ,SCREAMING_SNAKE_CASE__			:      int = 256     ,SCREAMING_SNAKE_CASE__			:      int = 256     ,SCREAMING_SNAKE_CASE__			:      int = 256     ,SCREAMING_SNAKE_CASE__			:      int = 1_024     ,SCREAMING_SNAKE_CASE__			:      str = "relu"     ,SCREAMING_SNAKE_CASE__			:      int = 6     ,SCREAMING_SNAKE_CASE__			:      int = 10     ,SCREAMING_SNAKE_CASE__			:      int = 8     ,SCREAMING_SNAKE_CASE__			:      float = 0.0     ,SCREAMING_SNAKE_CASE__			:      int = 2_048     ,SCREAMING_SNAKE_CASE__			:      bool = False     ,SCREAMING_SNAKE_CASE__			:      bool = False     ,SCREAMING_SNAKE_CASE__			:      int = 4     ,SCREAMING_SNAKE_CASE__			:      int = 255     ,SCREAMING_SNAKE_CASE__			:      int = 100     ,SCREAMING_SNAKE_CASE__			:      float = 0.1     ,SCREAMING_SNAKE_CASE__			:      float = 2.0     ,SCREAMING_SNAKE_CASE__			:      float = 5.0     ,SCREAMING_SNAKE_CASE__			:      float = 5.0     ,SCREAMING_SNAKE_CASE__			:      int = 12_544     ,SCREAMING_SNAKE_CASE__			:      float = 3.0     ,SCREAMING_SNAKE_CASE__			:      float = 0.75     ,SCREAMING_SNAKE_CASE__			:      float = 0.02     ,SCREAMING_SNAKE_CASE__			:      float = 1.0     ,SCREAMING_SNAKE_CASE__			:      bool = True     ,SCREAMING_SNAKE_CASE__			:      List[int] = [4, 8, 16, 32]     ,SCREAMING_SNAKE_CASE__			:      bool = None     ,**SCREAMING_SNAKE_CASE__			:      Dict     ,):
     if backbone_config is None:
       logger.info("`backbone_config` is `None`. Initializing the config with the default `Swin` backbone."							)
       SCREAMING_SNAKE_CASE:Union[str, Any]						      =					CONFIG_MAPPING["swin"](
           image_size=224     ,in_channels=3     ,patch_size=4     ,embed_dim=96     ,depths=[2, 2, 18, 2]     ,num_heads=[3, 6, 12, 24]     ,window_size=7     ,drop_path_rate=0.3     ,use_absolute_embeddings=SCREAMING_SNAKE_CASE__     ,out_features=["stage1", "stage2", "stage3", "stage4"]     ,)

     if isinstance(SCREAMING_SNAKE_CASE__     ,SCREAMING_SNAKE_CASE__							):
       SCREAMING_SNAKE_CASE:Any						      =					backbone_config.pop("model_type"							)
       SCREAMING_SNAKE_CASE:List[str]						      =					CONFIG_MAPPING[backbone_model_type]
       SCREAMING_SNAKE_CASE:List[str]						      =					config_class.from_dict(SCREAMING_SNAKE_CASE__							)

     # verify that the backbone is supported
     if backbone_config.model_type not in self.backbones_supported:
       logger.warning_once(
           F'''Backbone {backbone_config.model_type} is not a supported model and may not be compatible with Mask2Former. '''
           F'''Supported model types: {",".join(self.backbones_supported							)}'''							)

     SCREAMING_SNAKE_CASE:List[str]						      =					backbone_config
     SCREAMING_SNAKE_CASE:Union[str, Any]						      =					feature_size
     SCREAMING_SNAKE_CASE:Union[str, Any]						      =					mask_feature_size
     SCREAMING_SNAKE_CASE:str						      =					hidden_dim
     SCREAMING_SNAKE_CASE:Optional[int]						      =					encoder_feedforward_dim
     SCREAMING_SNAKE_CASE:Tuple						      =					activation_function
     SCREAMING_SNAKE_CASE:Optional[int]						      =					encoder_layers
     SCREAMING_SNAKE_CASE:List[Any]						      =					decoder_layers
     SCREAMING_SNAKE_CASE:Union[str, Any]						      =					num_attention_heads
     SCREAMING_SNAKE_CASE:Dict						      =					dropout
     SCREAMING_SNAKE_CASE:List[str]						      =					dim_feedforward
     SCREAMING_SNAKE_CASE:int						      =					pre_norm
     SCREAMING_SNAKE_CASE:Union[str, Any]						      =					enforce_input_projection
     SCREAMING_SNAKE_CASE:Any						      =					common_stride
     SCREAMING_SNAKE_CASE:int						      =					ignore_value
     SCREAMING_SNAKE_CASE:List[Any]						      =					num_queries
     SCREAMING_SNAKE_CASE:Dict						      =					no_object_weight
     SCREAMING_SNAKE_CASE:str						      =					class_weight
     SCREAMING_SNAKE_CASE:Tuple						      =					mask_weight
     SCREAMING_SNAKE_CASE:Optional[int]						      =					dice_weight
     SCREAMING_SNAKE_CASE:int						      =					train_num_points
     SCREAMING_SNAKE_CASE:str						      =					oversample_ratio
     SCREAMING_SNAKE_CASE:str						      =					importance_sample_ratio
     SCREAMING_SNAKE_CASE:str						      =					init_std
     SCREAMING_SNAKE_CASE:Any						      =					init_xavier_std
     SCREAMING_SNAKE_CASE:List[Any]						      =					use_auxiliary_loss
     SCREAMING_SNAKE_CASE:Union[str, Any]						      =					feature_strides
     SCREAMING_SNAKE_CASE:Union[str, Any]						      =					output_auxiliary_logits
     SCREAMING_SNAKE_CASE:Dict						      =					decoder_layers

     super().__init__(**SCREAMING_SNAKE_CASE__							)
   @classmethod
   def     __UpperCamelCase						( cls			:      Tuple     ,SCREAMING_SNAKE_CASE__			:      PretrainedConfig     ,**SCREAMING_SNAKE_CASE__			:      Union[str, Any]							):
     return cls(
         backbone_config=SCREAMING_SNAKE_CASE__     ,**SCREAMING_SNAKE_CASE__     ,)







   def     __UpperCamelCase						( self			:      List[Any]							):
     SCREAMING_SNAKE_CASE:Union[str, Any]						      =					copy.deepcopy(self.__dict__							)
     SCREAMING_SNAKE_CASE:str						      =					self.backbone_config.to_dict()
     SCREAMING_SNAKE_CASE:List[str]						      =					self.__class__.model_type
     return output






