'''simple docstring'''




from typing import List, Optional

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


_A								=   logging.get_logger(__name__)

_A								=   {
    'huggingface/autoformer-tourism-monthly': 'https://huggingface.co/huggingface/autoformer-tourism-monthly/resolve/main/config.json',
}


class       UpperCAmelCase__  (       _snake_case			):






   """simple docstring"""
   A							:       int     =    '''autoformer'''
   A							:       int     =    {
       '''hidden_size''': '''d_model''',
       '''num_attention_heads''': '''encoder_attention_heads''',
       '''num_hidden_layers''': '''encoder_layers''',
   }
   def __init__(self       ,				_a = None       ,				_a = None       ,				_a = "student_t"       ,				_a = "nll"       ,				_a = 1       ,				_a = [1, 2, 3, 4, 5, 6, 7]       ,				_a = True       ,				_a = 0       ,				_a = 0       ,				_a = 0       ,				_a = 0       ,				_a = None       ,				_a = None       ,				_a = 64       ,				_a = 2       ,				_a = 2       ,				_a = 2       ,				_a = 2       ,				_a = 32       ,				_a = 32       ,				_a = "gelu"       ,				_a = 0.1       ,				_a = 0.1       ,				_a = 0.1       ,				_a = 0.1       ,				_a = 0.1       ,				_a = 100       ,				_a = 0.02       ,				_a = True       ,				_a=True       ,				_a = 10       ,				_a = 25       ,				_a = 3       ,				**_a       ,				)    ->     Optional[Any]:
        # time series specific configuration
        lowercase_					:       Optional[Any]     				=					prediction_length
        lowercase_					:       str     				=					context_length if context_length is not None else prediction_length
        lowercase_					:       List[Any]     				=					distribution_output
        lowercase_					:       List[Any]     				=					loss
        lowercase_					:       int     				=					input_size
        lowercase_					:       Tuple     				=					num_time_features
        lowercase_					:       Dict     				=					lags_sequence
        lowercase_					:       int     				=					scaling
        lowercase_					:       Optional[int]     				=					num_dynamic_real_features
        lowercase_					:       str     				=					num_static_real_features
        lowercase_					:       List[Any]     				=					num_static_categorical_features
        if cardinality is not None and num_static_categorical_features > 0:
             if len(_a				) != num_static_categorical_features:
                  raise ValueError(
                      'The cardinality should be a list of the same length as `num_static_categorical_features`'				)
             lowercase_					:       Any     				=					cardinality
        else:
             lowercase_					:       str     				=					[0]
        if embedding_dimension is not None and num_static_categorical_features > 0:
             if len(_a				) != num_static_categorical_features:
                  raise ValueError(
                      'The embedding dimension should be a list of the same length as `num_static_categorical_features`'				)
             lowercase_					:       Tuple     				=					embedding_dimension
        else:
             lowercase_					:       str     				=					[min(50       ,				(cat + 1) // 2				) for cat in self.cardinality]
        lowercase_					:       Any     				=					num_parallel_samples

        # Transformer architecture configuration
        lowercase_					:       List[Any]     				=					input_size * len(self.lags_sequence				) + self._number_of_features
        lowercase_					:       Optional[int]     				=					d_model
        lowercase_					:       str     				=					encoder_attention_heads
        lowercase_					:       Any     				=					decoder_attention_heads
        lowercase_					:       Dict     				=					encoder_ffn_dim
        lowercase_					:       Optional[Any]     				=					decoder_ffn_dim
        lowercase_					:       Optional[Any]     				=					encoder_layers
        lowercase_					:       str     				=					decoder_layers

        lowercase_					:       Any     				=					dropout
        lowercase_					:       Dict     				=					attention_dropout
        lowercase_					:       Optional[int]     				=					activation_dropout
        lowercase_					:       Tuple     				=					encoder_layerdrop
        lowercase_					:       Optional[int]     				=					decoder_layerdrop

        lowercase_					:       Union[str, Any]     				=					activation_function
        lowercase_					:       Union[str, Any]     				=					init_std

        lowercase_					:       str     				=					use_cache

        # Autoformer
        lowercase_					:       List[Any]     				=					label_length
        lowercase_					:       Union[str, Any]     				=					moving_average
        lowercase_					:       Union[str, Any]     				=					autocorrelation_factor

        super().__init__(is_encoder_decoder=_a       ,				**_a				)





   @property
   def 		_lowerCamelCase (self				)    ->     int:
        return (
            sum(self.embedding_dimension				)
            + self.num_dynamic_real_features
            + self.num_time_features
            + self.num_static_real_features
            + self.input_size * 2  # the log1p(abs(loc)) and log(scale) features
        )





'''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


_A								=   {
    '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
}

_A								=   logging.get_logger(__name__)


class       UpperCAmelCase__  (       _snake_case			):






   """simple docstring"""
   A							:       List[str]     =    '''maskformer'''
   A							:       List[str]     =    {'''hidden_size''': '''mask_feature_size'''}
   A							:       Dict     =    ['''resnet''', '''swin''']
   A							:       Optional[Any]     =    ['''detr''']
   def __init__(self       ,				_a = 256       ,				_a = 256       ,				_a = 0.1       ,				_a = False       ,				_a = None       ,				_a = None       ,				_a = 0.02       ,				_a = 1.0       ,				_a = 1.0       ,				_a = 1.0       ,				_a = 20.0       ,				_a = None       ,				**_a       ,				)    ->     int:
        if backbone_config is None:
             # fall back to https://huggingface.co/microsoft/swin-base-patch4-window12-384-in22k
             lowercase_					:       List[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(_a       ,				_a				):
             lowercase_					:       Dict     				=					backbone_config.pop('model_type'				)
             lowercase_					:       Tuple     				=					CONFIG_MAPPING[backbone_model_type]
             lowercase_					:       Tuple     				=					config_class.from_dict(_a				)

        # 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
             lowercase_					:       str     				=					DetrConfig()
        else:
             # verify that the decoder is supported
             lowercase_					:       List[Any]     				=					(
                 decoder_config.pop('model_type'				) if isinstance(_a       ,				_a				) 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(_a       ,				_a				):
                  lowercase_					:       List[Any]     				=					CONFIG_MAPPING[decoder_type]
                  lowercase_					:       Tuple     				=					config_class.from_dict(_a				)

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

        lowercase_					:       List[Any]     				=					self.decoder_config.encoder_attention_heads
        lowercase_					:       Tuple     				=					self.decoder_config.num_hidden_layers
        super().__init__(**_a				)
   @classmethod
   def 		_lowerCamelCase (cls       ,				_a       ,				_a       ,				**_a				)    ->     Union[str, Any]:
        return cls(
            backbone_config=_a       ,				decoder_config=_a       ,				**_a       ,				)





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




