'''simple docstring'''





import copy
from typing import Dict, Optional

from ...configuration_utils import PretrainedConfig
from ...utils import logging
from ..auto import CONFIG_MAPPING
from ..detr import DetrConfig
from ..swin import SwinConfig


_lowerCAmelCase  :Any  				=    {
    """facebook/maskformer-swin-base-ade""": (
        """https://huggingface.co/facebook/maskformer-swin-base-ade/blob/main/config.json"""
    )
    # See all MaskFormer models at https://huggingface.co/models?filter=maskformer
}

_lowerCAmelCase  :Union[str, Any]  				=    logging.get_logger(__name__)






class 				UpperCAmelCase (       _SCREAMING_SNAKE_CASE ):




    '''simple docstring'''







    snake_case__							:   Dict							=						"maskformer"
    snake_case__							:   Optional[int]							=						{"hidden_size": "mask_feature_size"}
    snake_case__							:   List[Any]							=						["resnet", "swin"]
    snake_case__							:   Dict							=						["detr"]






    def __init__(       self    ,							lowercase__ = 256    ,							lowercase__ = 256    ,							lowercase__ = 0.1    ,							lowercase__ = False    ,							lowercase__ = None    ,							lowercase__ = None    ,							lowercase__ = 0.0_2    ,							lowercase__ = 1.0    ,							lowercase__ = 1.0    ,							lowercase__ = 1.0    ,							lowercase__ = 20.0    ,							lowercase__ = None    ,							**lowercase__    ,							)							-> str:
         if backbone_config is None:
              # fall back to https://huggingface.co/microsoft/swin-base-patch4-window12-384-in22k
              SCREAMING_SNAKE_CASE					:			Union[str, Any]    	=       SwinConfig(
                  image_size=384    ,							in_channels=3    ,							patch_size=4    ,							embed_dim=128    ,							depths=[2, 2, 18, 2]    ,							num_heads=[4, 8, 16, 32]    ,							window_size=12    ,							drop_path_rate=0.3    ,							out_features=['stage1', 'stage2', 'stage3', 'stage4']    ,							)

         if isinstance(lowercase__    ,							lowercase__ ):
              SCREAMING_SNAKE_CASE					:			Optional[Any]    	=       backbone_config.pop('model_type' )
              SCREAMING_SNAKE_CASE					:			str    	=       CONFIG_MAPPING[backbone_model_type]
              SCREAMING_SNAKE_CASE					:			Union[str, Any]    	=       config_class.from_dict(lowercase__ )

         # 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 MaskFormer. """
                  F"""Supported model types: {",".join(self.backbones_supported )}""" )

         if decoder_config is None:
              # fall back to https://huggingface.co/facebook/detr-resnet-50
              SCREAMING_SNAKE_CASE					:			List[Any]    	=       DetrConfig()
         else:
              # verify that the decoder is supported
              SCREAMING_SNAKE_CASE					:			List[str]    	=       (
                  decoder_config.pop('model_type' ) if isinstance(lowercase__    ,							lowercase__ ) else decoder_config.model_type
              )
              if decoder_type not in self.decoders_supported:
                   raise ValueError(
                       F"""Transformer Decoder {decoder_type} not supported, please use one of"""
                       F""" {",".join(self.decoders_supported )}""" )
              if isinstance(lowercase__    ,							lowercase__ ):
                   SCREAMING_SNAKE_CASE					:			Tuple    	=       CONFIG_MAPPING[decoder_type]
                   SCREAMING_SNAKE_CASE					:			Optional[int]    	=       config_class.from_dict(lowercase__ )

         SCREAMING_SNAKE_CASE					:			List[str]    	=       backbone_config
         SCREAMING_SNAKE_CASE					:			Optional[Any]    	=       decoder_config
         # main feature dimension for the model
         SCREAMING_SNAKE_CASE					:			Dict    	=       fpn_feature_size
         SCREAMING_SNAKE_CASE					:			Union[str, Any]    	=       mask_feature_size
         # initializer
         SCREAMING_SNAKE_CASE					:			List[Any]    	=       init_std
         SCREAMING_SNAKE_CASE					:			int    	=       init_xavier_std
         # Hungarian matcher && loss
         SCREAMING_SNAKE_CASE					:			Optional[Any]    	=       cross_entropy_weight
         SCREAMING_SNAKE_CASE					:			List[Any]    	=       dice_weight
         SCREAMING_SNAKE_CASE					:			Any    	=       mask_weight
         SCREAMING_SNAKE_CASE					:			List[str]    	=       use_auxiliary_loss
         SCREAMING_SNAKE_CASE					:			Tuple    	=       no_object_weight
         SCREAMING_SNAKE_CASE					:			Optional[Any]    	=       output_auxiliary_logits

         SCREAMING_SNAKE_CASE					:			Tuple    	=       self.decoder_config.encoder_attention_heads
         SCREAMING_SNAKE_CASE					:			Union[str, Any]    	=       self.decoder_config.num_hidden_layers
         super().__init__(**lowercase__ )






    @classmethod
    def       _UpperCamelCase    (       cls    ,							lowercase__    ,							lowercase__    ,							**lowercase__ )							-> str:
         return cls(
             backbone_config=lowercase__    ,							decoder_config=lowercase__    ,							**lowercase__    ,							)






    def       _UpperCamelCase    (       self )							-> Dict[str, any]:
         SCREAMING_SNAKE_CASE					:			List[Any]    	=       copy.deepcopy(self.__dict__ )
         SCREAMING_SNAKE_CASE					:			Optional[int]    	=       self.backbone_config.to_dict()
         SCREAMING_SNAKE_CASE					:			Optional[Any]    	=       self.decoder_config.to_dict()
         SCREAMING_SNAKE_CASE					:			int    	=       self.__class__.model_type
         return output




'''simple docstring'''





from typing import TYPE_CHECKING

from ...utils import (
    OptionalDependencyNotAvailable,
    _LazyModule,
    is_flax_available,
    is_sentencepiece_available,
    is_tf_available,
    is_tokenizers_available,
    is_torch_available,
)


_lowerCAmelCase  :int  				=    {
    """configuration_albert""": ["""ALBERT_PRETRAINED_CONFIG_ARCHIVE_MAP""", """AlbertConfig""", """AlbertOnnxConfig"""],
}

try:
 if not is_sentencepiece_available():
  raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
 pass
else:
 _lowerCAmelCase  :str  				=    ["""AlbertTokenizer"""]

try:
 if not is_tokenizers_available():
  raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
 pass
else:
 _lowerCAmelCase  :Optional[int]  				=    ["""AlbertTokenizerFast"""]

try:
 if not is_torch_available():
  raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
 pass
else:
 _lowerCAmelCase  :List[str]  				=    [
     """ALBERT_PRETRAINED_MODEL_ARCHIVE_LIST""",
     """AlbertForMaskedLM""",
     """AlbertForMultipleChoice""",
     """AlbertForPreTraining""",
     """AlbertForQuestionAnswering""",
     """AlbertForSequenceClassification""",
     """AlbertForTokenClassification""",
     """AlbertModel""",
     """AlbertPreTrainedModel""",
     """load_tf_weights_in_albert""",
 ]

try:
 if not is_tf_available():
  raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
 pass
else:
 _lowerCAmelCase  :Any  				=    [
     """TF_ALBERT_PRETRAINED_MODEL_ARCHIVE_LIST""",
     """TFAlbertForMaskedLM""",
     """TFAlbertForMultipleChoice""",
     """TFAlbertForPreTraining""",
     """TFAlbertForQuestionAnswering""",
     """TFAlbertForSequenceClassification""",
     """TFAlbertForTokenClassification""",
     """TFAlbertMainLayer""",
     """TFAlbertModel""",
     """TFAlbertPreTrainedModel""",
 ]

try:
 if not is_flax_available():
  raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
 pass
else:
 _lowerCAmelCase  :Optional[int]  				=    [
     """FlaxAlbertForMaskedLM""",
     """FlaxAlbertForMultipleChoice""",
     """FlaxAlbertForPreTraining""",
     """FlaxAlbertForQuestionAnswering""",
     """FlaxAlbertForSequenceClassification""",
     """FlaxAlbertForTokenClassification""",
     """FlaxAlbertModel""",
     """FlaxAlbertPreTrainedModel""",
 ]

if TYPE_CHECKING:
 from .configuration_albert import ALBERT_PRETRAINED_CONFIG_ARCHIVE_MAP, AlbertConfig, AlbertOnnxConfig

 try:
  if not is_sentencepiece_available():
   raise OptionalDependencyNotAvailable()
 except OptionalDependencyNotAvailable:
  pass
 else:
  from .tokenization_albert import AlbertTokenizer

 try:
  if not is_tokenizers_available():
   raise OptionalDependencyNotAvailable()
 except OptionalDependencyNotAvailable:
  pass
 else:
  from .tokenization_albert_fast import AlbertTokenizerFast

 try:
  if not is_torch_available():
   raise OptionalDependencyNotAvailable()
 except OptionalDependencyNotAvailable:
  pass
 else:
  from .modeling_albert import (
      ALBERT_PRETRAINED_MODEL_ARCHIVE_LIST,
      AlbertForMaskedLM,
      AlbertForMultipleChoice,
      AlbertForPreTraining,
      AlbertForQuestionAnswering,
      AlbertForSequenceClassification,
      AlbertForTokenClassification,
      AlbertModel,
      AlbertPreTrainedModel,
      load_tf_weights_in_albert,
  )

 try:
  if not is_tf_available():
   raise OptionalDependencyNotAvailable()
 except OptionalDependencyNotAvailable:
  pass
 else:
  from .modeling_tf_albert import (
      TF_ALBERT_PRETRAINED_MODEL_ARCHIVE_LIST,
      TFAlbertForMaskedLM,
      TFAlbertForMultipleChoice,
      TFAlbertForPreTraining,
      TFAlbertForQuestionAnswering,
      TFAlbertForSequenceClassification,
      TFAlbertForTokenClassification,
      TFAlbertMainLayer,
      TFAlbertModel,
      TFAlbertPreTrainedModel,
  )

 try:
  if not is_flax_available():
   raise OptionalDependencyNotAvailable()
 except OptionalDependencyNotAvailable:
  pass
 else:
  from .modeling_flax_albert import (
      FlaxAlbertForMaskedLM,
      FlaxAlbertForMultipleChoice,
      FlaxAlbertForPreTraining,
      FlaxAlbertForQuestionAnswering,
      FlaxAlbertForSequenceClassification,
      FlaxAlbertForTokenClassification,
      FlaxAlbertModel,
      FlaxAlbertPreTrainedModel,
  )
else:
 import sys

 _lowerCAmelCase  :Union[str, Any]  				=    _LazyModule(__name__, globals()["""__file__"""], _import_structure, module_spec=__spec__)



