





'''simple docstring'''


import collections
import inspect
import unittest

from transformers import FocalNetConfig
from transformers.testing_utils import require_torch, require_vision, slow, torch_device
from transformers.utils import cached_property, is_torch_available, is_vision_available

from ...test_backbone_common import BackboneTesterMixin
from ...test_configuration_common import ConfigTester
from ...test_modeling_common import ModelTesterMixin, _config_zero_init, floats_tensor, ids_tensor
from ...test_pipeline_mixin import PipelineTesterMixin


if is_torch_available():
 import torch
 from torch import nn

 from transformers import (
     FocalNetBackbone,
     FocalNetForImageClassification,
     FocalNetForMaskedImageModeling,
     FocalNetModel,
 )
 from transformers.models.focalnet.modeling_focalnet import FOCALNET_PRETRAINED_MODEL_ARCHIVE_LIST

if is_vision_available():
 from PIL import Image

 from transformers import AutoImageProcessor
class       a_   :





     def __init__( self		:					int	,      lowercase		:					List[str]	,      lowercase		:					Optional[int]=13	,      lowercase		:					Optional[Any]=32	,      lowercase		:					List[str]=2	,      lowercase		:					int=3	,      lowercase		:					List[str]=16	,      lowercase		:					Dict=[32, 64, 128]	,      lowercase		:					Dict=[1, 2, 1]	,      lowercase		:					int=[2, 2, 4]	,      lowercase		:					List[str]=2	,      lowercase		:					Optional[Any]=2.0	,      lowercase		:					Tuple=True	,      lowercase		:					Optional[int]=0.0	,      lowercase		:					Tuple=0.0	,      lowercase		:					List[Any]=0.1	,      lowercase		:					Tuple="gelu"	,      lowercase		:					Tuple=False	,      lowercase		:					str=True	,      lowercase		:					Optional[Any]=0.02	,      lowercase		:					int=1e-5	,      lowercase		:					Tuple=True	,      lowercase		:					Optional[int]=None	,      lowercase		:					Optional[Any]=True	,      lowercase		:					List[str]=10	,      lowercase		:					str=8	,      lowercase		:					Tuple=["stage1", "stage2"]	,      lowercase		:					str=[1, 2]	,      ):





        """simple docstring"""




        lowercase_			:Tuple    			= parent
        lowercase_			:List[str]    			= batch_size
        lowercase_			:Optional[Any]    			= image_size
        lowercase_			:Tuple    			= patch_size
        lowercase_			:List[str]    			= num_channels
        lowercase_			:Any    			= embed_dim
        lowercase_			:List[Any]    			= hidden_sizes
        lowercase_			:Any    			= depths
        lowercase_			:Optional[Any]    			= num_heads
        lowercase_			:Union[str, Any]    			= window_size
        lowercase_			:Optional[int]    			= mlp_ratio
        lowercase_			:List[Any]    			= qkv_bias
        lowercase_			:List[Any]    			= hidden_dropout_prob
        lowercase_			:Optional[Any]    			= attention_probs_dropout_prob
        lowercase_			:int    			= drop_path_rate
        lowercase_			:Dict    			= hidden_act
        lowercase_			:Union[str, Any]    			= use_absolute_embeddings
        lowercase_			:Dict    			= patch_norm
        lowercase_			:Dict    			= layer_norm_eps
        lowercase_			:Optional[Any]    			= initializer_range
        lowercase_			:int    			= is_training
        lowercase_			:Tuple    			= scope
        lowercase_			:int    			= use_labels
        lowercase_			:Optional[Any]    			= type_sequence_label_size
        lowercase_			:List[str]    			= encoder_stride
        lowercase_			:Optional[Any]    			= out_features
        lowercase_			:Dict    			= out_indices





     def 							lowercase__      ( self		:					Tuple						):





        """simple docstring"""




        lowercase_			:Dict    			= floats_tensor([self.batch_size, self.num_channels, self.image_size, self.image_size]						)

        lowercase_			:Tuple    			= None
        if self.use_labels:
           lowercase_			:str    			= ids_tensor([self.batch_size]	,      self.type_sequence_label_size						)

        lowercase_			:Tuple    			= self.get_config()

        return config, pixel_values, labels





     def 							lowercase__      ( self		:					Optional[int]						):





        """simple docstring"""




        return FocalNetConfig(
            image_size=self.image_size	,      patch_size=self.patch_size	,      num_channels=self.num_channels	,      embed_dim=self.embed_dim	,      hidden_sizes=self.hidden_sizes	,      depths=self.depths	,      num_heads=self.num_heads	,      window_size=self.window_size	,      mlp_ratio=self.mlp_ratio	,      qkv_bias=self.qkv_bias	,      hidden_dropout_prob=self.hidden_dropout_prob	,      attention_probs_dropout_prob=self.attention_probs_dropout_prob	,      drop_path_rate=self.drop_path_rate	,      hidden_act=self.hidden_act	,      use_absolute_embeddings=self.use_absolute_embeddings	,      path_norm=self.patch_norm	,      layer_norm_eps=self.layer_norm_eps	,      initializer_range=self.initializer_range	,      encoder_stride=self.encoder_stride	,      out_features=self.out_features	,      out_indices=self.out_indices	,      )





     def 							lowercase__      ( self		:					Dict	,      lowercase		:					Dict	,      lowercase		:					Optional[int]	,      lowercase		:					Union[str, Any]						):





        """simple docstring"""




        lowercase_			:List[Any]    			= FocalNetModel(config=SCREAMING_SNAKE_CASE__						)
        model.to(SCREAMING_SNAKE_CASE__						)
        model.eval()
        lowercase_			:Union[str, Any]    			= model(SCREAMING_SNAKE_CASE__						)

        lowercase_			:str    			= ((config.image_size // config.patch_size) ** 2) // (4 ** (len(config.depths						) - 1))
        lowercase_			:List[Any]    			= int(config.embed_dim * 2 ** (len(config.depths						) - 1)						)

        self.parent.assertEqual(result.last_hidden_state.shape	,      (self.batch_size, expected_seq_len, expected_dim)						)





     def 							lowercase__      ( self		:					Any	,      lowercase		:					Dict	,      lowercase		:					Tuple	,      lowercase		:					List[str]						):





        """simple docstring"""




        lowercase_			:List[str]    			= FocalNetBackbone(config=SCREAMING_SNAKE_CASE__						)
        model.to(SCREAMING_SNAKE_CASE__						)
        model.eval()
        lowercase_			:Dict    			= model(SCREAMING_SNAKE_CASE__						)

        # verify feature maps
        self.parent.assertEqual(len(result.feature_maps						)	,      len(config.out_features						)						)
        self.parent.assertListEqual(list(result.feature_maps[0].shape						)	,      [self.batch_size, self.image_size, 8, 8]						)

        # verify channels
        self.parent.assertEqual(len(model.channels						)	,      len(config.out_features						)						)
        self.parent.assertListEqual(model.channels	,      config.hidden_sizes[:-1]						)

        # verify backbone works with out_features=None
        lowercase_			:Union[str, Any]    			= None
        lowercase_			:Optional[int]    			= FocalNetBackbone(config=SCREAMING_SNAKE_CASE__						)
        model.to(SCREAMING_SNAKE_CASE__						)
        model.eval()
        lowercase_			:List[Any]    			= model(SCREAMING_SNAKE_CASE__						)

        # verify feature maps
        self.parent.assertEqual(len(result.feature_maps						)	,      1						)
        self.parent.assertListEqual(list(result.feature_maps[0].shape						)	,      [self.batch_size, self.image_size * 2, 4, 4]						)

        # verify channels
        self.parent.assertEqual(len(model.channels						)	,      1						)
        self.parent.assertListEqual(model.channels	,      [config.hidden_sizes[-1]]						)





     def 							lowercase__      ( self		:					Any	,      lowercase		:					str	,      lowercase		:					Any	,      lowercase		:					Any						):





        """simple docstring"""




        lowercase_			:int    			= FocalNetForMaskedImageModeling(config=SCREAMING_SNAKE_CASE__						)
        model.to(SCREAMING_SNAKE_CASE__						)
        model.eval()
        lowercase_			:Union[str, Any]    			= model(SCREAMING_SNAKE_CASE__						)
        self.parent.assertEqual(
            result.reconstruction.shape	,      (self.batch_size, self.num_channels, self.image_size, self.image_size)						)

        # test greyscale images
        lowercase_			:Optional[int]    			= 1
        lowercase_			:Tuple    			= FocalNetForMaskedImageModeling(SCREAMING_SNAKE_CASE__						)
        model.to(SCREAMING_SNAKE_CASE__						)
        model.eval()

        lowercase_			:List[str]    			= floats_tensor([self.batch_size, 1, self.image_size, self.image_size]						)
        lowercase_			:List[str]    			= model(SCREAMING_SNAKE_CASE__						)
        self.parent.assertEqual(result.reconstruction.shape	,      (self.batch_size, 1, self.image_size, self.image_size)						)





     def 							lowercase__      ( self		:					Optional[Any]	,      lowercase		:					Optional[Any]	,      lowercase		:					Optional[Any]	,      lowercase		:					List[Any]						):





        """simple docstring"""




        lowercase_			:Dict    			= self.type_sequence_label_size
        lowercase_			:str    			= FocalNetForImageClassification(SCREAMING_SNAKE_CASE__						)
        model.to(SCREAMING_SNAKE_CASE__						)
        model.eval()
        lowercase_			:List[Any]    			= model(SCREAMING_SNAKE_CASE__	,      labels=SCREAMING_SNAKE_CASE__						)
        self.parent.assertEqual(result.logits.shape	,      (self.batch_size, self.type_sequence_label_size)						)

        # test greyscale images
        lowercase_			:List[Any]    			= 1
        lowercase_			:Dict    			= FocalNetForImageClassification(SCREAMING_SNAKE_CASE__						)
        model.to(SCREAMING_SNAKE_CASE__						)
        model.eval()

        lowercase_			:Optional[int]    			= floats_tensor([self.batch_size, 1, self.image_size, self.image_size]						)
        lowercase_			:List[str]    			= model(SCREAMING_SNAKE_CASE__						)
        self.parent.assertEqual(result.logits.shape	,      (self.batch_size, self.type_sequence_label_size)						)







     def 							lowercase__      ( self		:					List[Any]						):





        """simple docstring"""




        lowercase_			:Optional[Any]    			= self.prepare_config_and_inputs()

        lowercase_			,							lowercase_			,							lowercase_			:Optional[int]    			= config_and_inputs
        lowercase_			:int    			= {"pixel_values": pixel_values}
        return config, inputs_dict







@require_torch
class       a_   (				__lowercase	,						__lowercase	,						unittest.TestCase							):
     __A      =			(
         (
             FocalNetModel,
             FocalNetForImageClassification,
             FocalNetForMaskedImageModeling,
             FocalNetBackbone,
         )
         if is_torch_available()
         else ()
     )
     __A      =			(
         {"""feature-extraction""": FocalNetModel, """image-classification""": FocalNetForImageClassification}
         if is_torch_available()
         else {}
     )
     __A      =			False

     __A      =			False
     __A      =			False
     __A      =			False
     __A      =			False





     def 							lowercase__      ( self		:					List[Any]						):





        """simple docstring"""




        lowercase_			:Any    			= FocalNetModelTester(self						)
        lowercase_			:Dict    			= ConfigTester(self	,      config_class=SCREAMING_SNAKE_CASE__	,      embed_dim=37	,      has_text_modality=SCREAMING_SNAKE_CASE__						)





     def 							lowercase__      ( self		:					Optional[int]						):





        """simple docstring"""




        self.create_and_test_config_common_properties()
        self.config_tester.create_and_test_config_to_json_string()
        self.config_tester.create_and_test_config_to_json_file()
        self.config_tester.create_and_test_config_from_and_save_pretrained()
        self.config_tester.create_and_test_config_with_num_labels()
        self.config_tester.check_config_can_be_init_without_params()
        self.config_tester.check_config_arguments_init()





     def 							lowercase__      ( self		:					Union[str, Any]						):





        """simple docstring"""




        return





     def 							lowercase__      ( self		:					int						):





        """simple docstring"""




        lowercase_			:Any    			= self.model_tester.prepare_config_and_inputs()
        self.model_tester.create_and_check_model(*SCREAMING_SNAKE_CASE__						)





     def 							lowercase__      ( self		:					int						):





        """simple docstring"""




        lowercase_			:str    			= self.model_tester.prepare_config_and_inputs()
        self.model_tester.create_and_check_backbone(*SCREAMING_SNAKE_CASE__						)





     def 							lowercase__      ( self		:					List[Any]						):





        """simple docstring"""




        lowercase_			:int    			= self.model_tester.prepare_config_and_inputs()
        self.model_tester.create_and_check_for_masked_image_modeling(*SCREAMING_SNAKE_CASE__						)





     def 							lowercase__      ( self		:					Tuple						):





        """simple docstring"""




        lowercase_			:Union[str, Any]    			= self.model_tester.prepare_config_and_inputs()
        self.model_tester.create_and_check_for_image_classification(*SCREAMING_SNAKE_CASE__						)





     @unittest.skip(reason="FocalNet does not use inputs_embeds"						)
     def 							lowercase__      ( self		:					Any						):





        """simple docstring"""




        pass





     @unittest.skip(reason="FocalNet does not use feedforward chunking"						)
     def 							lowercase__      ( self		:					str						):





        """simple docstring"""




        pass





     def 							lowercase__      ( self		:					List[Any]						):





        """simple docstring"""




        lowercase_			,							lowercase_			:List[str]    			= self.model_tester.prepare_config_and_inputs_for_common()

        for model_class in self.all_model_classes[:-1]:
           lowercase_			:List[str]    			= model_class(SCREAMING_SNAKE_CASE__						)
           self.assertIsInstance(model.get_input_embeddings()	,      (nn.Module)						)
           lowercase_			:Any    			= model.get_output_embeddings()
           self.assertTrue(x is None or isinstance(SCREAMING_SNAKE_CASE__	,      nn.Linear						)						)





     def 							lowercase__      ( self		:					List[Any]						):





        """simple docstring"""




        lowercase_			,							lowercase_			:Optional[int]    			= self.model_tester.prepare_config_and_inputs_for_common()

        for model_class in self.all_model_classes[:-1]:
           lowercase_			:List[str]    			= model_class(SCREAMING_SNAKE_CASE__						)
           lowercase_			:Tuple    			= inspect.signature(model.forward						)
           # signature.parameters is an OrderedDict => so arg_names order is deterministic
           lowercase_			:str    			= [*signature.parameters.keys()]

           lowercase_			:List[str]    			= ["pixel_values"]
           self.assertListEqual(arg_names[:1]	,      SCREAMING_SNAKE_CASE__						)





     def 							lowercase__      ( self		:					int	,      lowercase		:					int	,      lowercase		:					List[Any]	,      lowercase		:					Tuple	,      lowercase		:					List[Any]						):





        """simple docstring"""




        lowercase_			:Optional[int]    			= model_class(SCREAMING_SNAKE_CASE__						)
        model.to(SCREAMING_SNAKE_CASE__						)
        model.eval()

        with torch.no_grad():
           lowercase_			:Optional[Any]    			= model(**self._prepare_for_class(SCREAMING_SNAKE_CASE__	,      SCREAMING_SNAKE_CASE__						)						)

        lowercase_			:Tuple    			= outputs.hidden_states

        lowercase_			:Optional[int]    			= getattr(
            self.model_tester	,      "expected_num_hidden_layers"	,      len(self.model_tester.depths						) + 1						)
        self.assertEqual(len(SCREAMING_SNAKE_CASE__						)	,      SCREAMING_SNAKE_CASE__						)

        # FocalNet has a different seq_length
        lowercase_			:Optional[int]    			= (
            config.patch_size
            if isinstance(config.patch_size	,      collections.abc.Iterable						)
            else (config.patch_size, config.patch_size)
        )

        lowercase_			:str    			= (image_size[1] // patch_size[1]) * (image_size[0] // patch_size[0])

        self.assertListEqual(
            list(hidden_states[0].shape[-2:]						)	,      [num_patches, self.model_tester.embed_dim]	,      )

        lowercase_			:Dict    			= outputs.reshaped_hidden_states
        self.assertEqual(len(SCREAMING_SNAKE_CASE__						)	,      SCREAMING_SNAKE_CASE__						)

        lowercase_			,							lowercase_			,							lowercase_			,							lowercase_			:str    			= reshaped_hidden_states[0].shape
        lowercase_			:List[str]    			= (
            reshaped_hidden_states[0].view(SCREAMING_SNAKE_CASE__	,      SCREAMING_SNAKE_CASE__	,      height * width						).permute(0	,      2	,      1						)
        )
        self.assertListEqual(
            list(reshaped_hidden_states.shape[-2:]						)	,      [num_patches, self.model_tester.embed_dim]	,      )





     def 							lowercase__      ( self		:					str						):





        """simple docstring"""




        lowercase_			,							lowercase_			:int    			= self.model_tester.prepare_config_and_inputs_for_common()

        lowercase_			:Any    			= (
            self.model_tester.image_size
            if isinstance(self.model_tester.image_size	,      collections.abc.Iterable						)
            else (self.model_tester.image_size, self.model_tester.image_size)
        )

        for model_class in self.all_model_classes[:-1]:
           lowercase_			:str    			= True
           self.check_hidden_states_output(SCREAMING_SNAKE_CASE__	,      SCREAMING_SNAKE_CASE__	,      SCREAMING_SNAKE_CASE__	,      SCREAMING_SNAKE_CASE__						)

           # check that output_hidden_states also work using config
           del inputs_dict["output_hidden_states"]
           lowercase_			:str    			= True

           self.check_hidden_states_output(SCREAMING_SNAKE_CASE__	,      SCREAMING_SNAKE_CASE__	,      SCREAMING_SNAKE_CASE__	,      SCREAMING_SNAKE_CASE__						)





     def 							lowercase__      ( self		:					Optional[Any]						):





        """simple docstring"""




        lowercase_			,							lowercase_			:List[str]    			= self.model_tester.prepare_config_and_inputs_for_common()
        lowercase_			:Any    			= 3

        lowercase_			:Dict    			= (
            self.model_tester.image_size
            if isinstance(self.model_tester.image_size	,      collections.abc.Iterable						)
            else (self.model_tester.image_size, self.model_tester.image_size)
        )
        lowercase_			:List[str]    			= (
            config.patch_size
            if isinstance(config.patch_size	,      collections.abc.Iterable						)
            else (config.patch_size, config.patch_size)
        )

        lowercase_			:int    			= image_size[0] + patch_size[0] - (image_size[0] % patch_size[0])
        lowercase_			:Any    			= image_size[1] + patch_size[1] - (image_size[1] % patch_size[1])

        for model_class in self.all_model_classes[:-1]:
           lowercase_			:Any    			= True
           self.check_hidden_states_output(SCREAMING_SNAKE_CASE__	,      SCREAMING_SNAKE_CASE__	,      SCREAMING_SNAKE_CASE__	,      (padded_height, padded_width)						)

           # check that output_hidden_states also work using config
           del inputs_dict["output_hidden_states"]
           lowercase_			:int    			= True
           self.check_hidden_states_output(SCREAMING_SNAKE_CASE__	,      SCREAMING_SNAKE_CASE__	,      SCREAMING_SNAKE_CASE__	,      (padded_height, padded_width)						)





     @slow
     def 							lowercase__      ( self		:					int						):





        """simple docstring"""




        for model_name in FOCALNET_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
           lowercase_			:Any    			= FocalNetModel.from_pretrained(SCREAMING_SNAKE_CASE__						)
           self.assertIsNotNone(SCREAMING_SNAKE_CASE__						)







     def 							lowercase__      ( self		:					int						):





        """simple docstring"""




        lowercase_			,							lowercase_			:Tuple    			= self.model_tester.prepare_config_and_inputs_for_common()

        lowercase_			:List[str]    			= _config_zero_init(SCREAMING_SNAKE_CASE__						)
        for model_class in self.all_model_classes:
           lowercase_			:Tuple    			= model_class(config=SCREAMING_SNAKE_CASE__						)
           for name, param in model.named_parameters():
              if "embeddings" not in name and param.requires_grad:
                 self.assertIn(
                     ((param.data.mean() * 1e9).round() / 1e9).item()	,      [0.0, 1.0]	,      msg=F'Parameter {name} of model {model_class} seems not properly initialized'	,      )







@require_vision
@require_torch
class       a_   (				unittest.TestCase							):





     @cached_property
     def 							lowercase__      ( self		:					List[Any]						):





        """simple docstring"""




        return AutoImageProcessor.from_pretrained("microsoft/focalnet-tiny"						) if is_vision_available() else None







     @slow
     def 							lowercase__      ( self		:					Tuple						):





        """simple docstring"""




        lowercase_			:int    			= FocalNetForImageClassification.from_pretrained("microsoft/focalnet-tiny"						).to(SCREAMING_SNAKE_CASE__						)
        lowercase_			:int    			= self.default_image_processor

        lowercase_			:Optional[int]    			= Image.open("./tests/fixtures/tests_samples/COCO/000000039769.png"						)
        lowercase_			:List[Any]    			= image_processor(images=SCREAMING_SNAKE_CASE__	,      return_tensors="pt"						).to(SCREAMING_SNAKE_CASE__						)

        # forward pass
        with torch.no_grad():
           lowercase_			:Optional[int]    			= model(**SCREAMING_SNAKE_CASE__						)

        # verify the logits
        lowercase_			:int    			= torch.Size((1, 1_000)						)
        self.assertEqual(outputs.logits.shape	,      SCREAMING_SNAKE_CASE__						)
        lowercase_			:Union[str, Any]    			= torch.tensor([0.21_66, -0.43_68, 0.21_91]						).to(SCREAMING_SNAKE_CASE__						)
        self.assertTrue(torch.allclose(outputs.logits[0, :3]	,      SCREAMING_SNAKE_CASE__	,      atol=1e-4						)						)
        self.assertTrue(outputs.logits.argmax(dim=-1						).item()	,      281						)







@require_torch
class       a_   (				__lowercase	,						unittest.TestCase							):
     __A      =			(FocalNetBackbone,) if is_torch_available() else ()
     __A      =			FocalNetConfig

     __A      =			False





     def 							lowercase__      ( self		:					Union[str, Any]						):





        """simple docstring"""




        lowercase_			:Union[str, Any]    			= FocalNetModelTester(self						)




import copy
from typing import Dict, List, Optional

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


SCREAMING_SNAKE_CASE__   :			Dict												=    {
    "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
}

SCREAMING_SNAKE_CASE__   :			int												=    logging.get_logger(__name__)

class    lowerCAmelCase__     (	__lowercase			):
		a__       :						Any        =		"""mask2former"""
		a__       :						Dict        =		["""swin"""]
		a__       :						Any        =		{"""hidden_size""": """hidden_dim"""}






		def __init__(		self		:							Any							,			SCREAMING_SNAKE_CASE__		:							Optional[Dict] = None							,			SCREAMING_SNAKE_CASE__		:							int = 2_56							,			SCREAMING_SNAKE_CASE__		:							int = 2_56							,			SCREAMING_SNAKE_CASE__		:							int = 2_56							,			SCREAMING_SNAKE_CASE__		:							int = 10_24							,			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 = 20_48							,			SCREAMING_SNAKE_CASE__		:							bool = False							,			SCREAMING_SNAKE_CASE__		:							bool = False							,			SCREAMING_SNAKE_CASE__		:							int = 4							,			SCREAMING_SNAKE_CASE__		:							int = 2_55							,			SCREAMING_SNAKE_CASE__		:							int = 1_00							,			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 = 1_25_44							,			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__		:							Tuple							,			)     ->							str:
						if backbone_config is None:
										logger.info('''`backbone_config` is `None`. Initializing the config with the default `Swin` backbone.'''  )
										__lowerCamelCase    					=	CONFIG_MAPPING['''swin'''](
										    image_size=2_24							,			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__  ):
										__lowerCamelCase    					=	backbone_config.pop('''model_type'''  )
										__lowerCamelCase    					=	CONFIG_MAPPING[backbone_model_type]
										__lowerCamelCase    					=	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  )}'''  )

						__lowerCamelCase    					=	backbone_config
						__lowerCamelCase    					=	feature_size
						__lowerCamelCase    					=	mask_feature_size
						__lowerCamelCase    					=	hidden_dim
						__lowerCamelCase    					=	encoder_feedforward_dim
						__lowerCamelCase    					=	activation_function
						__lowerCamelCase    					=	encoder_layers
						__lowerCamelCase    					=	decoder_layers
						__lowerCamelCase    					=	num_attention_heads
						__lowerCamelCase    					=	dropout
						__lowerCamelCase    					=	dim_feedforward
						__lowerCamelCase    					=	pre_norm
						__lowerCamelCase    					=	enforce_input_projection
						__lowerCamelCase    					=	common_stride
						__lowerCamelCase    					=	ignore_value
						__lowerCamelCase    					=	num_queries
						__lowerCamelCase    					=	no_object_weight
						__lowerCamelCase    					=	class_weight
						__lowerCamelCase    					=	mask_weight
						__lowerCamelCase    					=	dice_weight
						__lowerCamelCase    					=	train_num_points
						__lowerCamelCase    					=	oversample_ratio
						__lowerCamelCase    					=	importance_sample_ratio
						__lowerCamelCase    					=	init_std
						__lowerCamelCase    					=	init_xavier_std
						__lowerCamelCase    					=	use_auxiliary_loss
						__lowerCamelCase    					=	feature_strides
						__lowerCamelCase    					=	output_auxiliary_logits
						__lowerCamelCase    					=	decoder_layers

						super().__init__(**SCREAMING_SNAKE_CASE__  )






		@classmethod
		def  __A       (		cls		:							Any							,			SCREAMING_SNAKE_CASE__		:							PretrainedConfig							,			**SCREAMING_SNAKE_CASE__		:							Optional[Any]  )     ->							List[Any]:
						return cls(
						    backbone_config=SCREAMING_SNAKE_CASE__							,			**SCREAMING_SNAKE_CASE__							,			)







		def  __A       (		self		:							Any  )     ->							Dict[str, any]:
						__lowerCamelCase    					=	copy.deepcopy(self.__dict__  )
						__lowerCamelCase    					=	self.backbone_config.to_dict()
						__lowerCamelCase    					=	self.__class__.model_type
						return output



