
"""simple docstring"""




import unittest

from transformers.utils.backbone_utils import (
    BackboneMixin,
    get_aligned_output_features_output_indices,
    verify_out_features_out_indices,
)


class 			__magic_name__       (       unittest.TestCase ):
       def 							lowercase_							(     self       )     ->	Optional[Any]:





         """simple docstring"""




         _lowercase:			Optional[int]       =     ['''a''', '''b''', '''c''']

         # Defaults to last layer if both are None
         _lowercase ,				_lowercase:			int       =     get_aligned_output_features_output_indices(A_ ,				A_ ,				A_       )
         self.assertEqual(A_ ,				['''c''']       )
         self.assertEqual(A_ ,				[2]       )

         # Out indices set to match out features
         _lowercase ,				_lowercase:			Optional[int]       =     get_aligned_output_features_output_indices(['''a''', '''c'''] ,				A_ ,				A_       )
         self.assertEqual(A_ ,				['''a''', '''c''']       )
         self.assertEqual(A_ ,				[0, 2]       )

         # Out features set to match out indices
         _lowercase ,				_lowercase:			Tuple       =     get_aligned_output_features_output_indices(A_ ,				[0, 2] ,				A_       )
         self.assertEqual(A_ ,				['''a''', '''c''']       )
         self.assertEqual(A_ ,				[0, 2]       )

         # Out features selected from negative indices
         _lowercase ,				_lowercase:			Optional[int]       =     get_aligned_output_features_output_indices(A_ ,				[-3, -1] ,				A_       )
         self.assertEqual(A_ ,				['''a''', '''c''']       )
         self.assertEqual(A_ ,				[-3, -1]       )
       def 							lowercase_							(     self       )     ->	str:





         """simple docstring"""




         with self.assertRaises(A_       ):
           verify_out_features_out_indices(['''a''', '''b'''] ,				(0, 1) ,				A_       )

         # Out features must be a list
         with self.assertRaises(A_       ):
           verify_out_features_out_indices(('''a''', '''b''') ,				(0, 1) ,				['''a''', '''b''']       )

         # Out features must be a subset of stage names
         with self.assertRaises(A_       ):
           verify_out_features_out_indices(['''a''', '''b'''] ,				(0, 1) ,				['''a''']       )

         # Out indices must be a list or tuple
         with self.assertRaises(A_       ):
           verify_out_features_out_indices(A_ ,				0 ,				['''a''', '''b''']       )

         # Out indices must be a subset of stage names
         with self.assertRaises(A_       ):
           verify_out_features_out_indices(A_ ,				(0, 1) ,				['''a''']       )

         # Out features and out indices must be the same length
         with self.assertRaises(A_       ):
           verify_out_features_out_indices(['''a''', '''b'''] ,				(0,) ,				['''a''', '''b''', '''c''']       )

         # Out features should match out indices
         with self.assertRaises(A_       ):
           verify_out_features_out_indices(['''a''', '''b'''] ,				(0, 2) ,				['''a''', '''b''', '''c''']       )

         # Out features and out indices should be in order
         with self.assertRaises(A_       ):
           verify_out_features_out_indices(['''b''', '''a'''] ,				(0, 1) ,				['''a''', '''b''']       )

         # Check passes with valid inputs
         verify_out_features_out_indices(['''a''', '''b''', '''d'''] ,				(0, 1, -1) ,				['''a''', '''b''', '''c''', '''d''']       )



       def 							lowercase_							(     self       )     ->	List[Any]:





         """simple docstring"""




         _lowercase:			List[str]       =     BackboneMixin()

         _lowercase:			List[Any]       =     ['''a''', '''b''', '''c''']
         _lowercase:			List[Any]       =     ['''a''', '''c''']
         _lowercase:			Tuple       =     [0, 2]

         # Check that the output features and indices are set correctly
         self.assertEqual(backbone.out_features ,				['''a''', '''c''']       )
         self.assertEqual(backbone.out_indices ,				[0, 2]       )

         # Check out features and indices are updated correctly
         _lowercase:			Union[str, Any]       =     ['''a''', '''b''']
         self.assertEqual(backbone.out_features ,				['''a''', '''b''']       )
         self.assertEqual(backbone.out_indices ,				[0, 1]       )

         _lowercase:			List[str]       =     [-3, -1]
         self.assertEqual(backbone.out_features ,				['''a''', '''c''']       )
         self.assertEqual(backbone.out_indices ,				[-3, -1]       )


"""simple docstring"""




import copy

from ...configuration_utils import PretrainedConfig
from ...utils import logging
from ..bit import BitConfig


A__   :					Dict							=   logging.get_logger(__name__)

A__   :					int							=   {
    'Intel/dpt-large': 'https://huggingface.co/Intel/dpt-large/resolve/main/config.json',
    # See all DPT models at https://huggingface.co/models?filter=dpt
}


class 			__magic_name__       (       SCREAMING_SNAKE_CASE__ ):
       UpperCamelCase_   =		'''dpt'''
       def __init__(     self ,				A_=768 ,				A_=12 ,				A_=12 ,				A_=3072 ,				A_="gelu" ,				A_=0.0 ,				A_=0.0 ,				A_=0.02 ,				A_=1E-12 ,				A_=384 ,				A_=16 ,				A_=3 ,				A_=False ,				A_=True ,				A_=[2, 5, 8, 11] ,				A_="project" ,				A_=[4, 2, 1, 0.5] ,				A_=[96, 192, 384, 768] ,				A_=256 ,				A_=-1 ,				A_=False ,				A_=True ,				A_=0.4 ,				A_=255 ,				A_=0.1 ,				A_=[1, 1024, 24, 24] ,				A_=[0, 1] ,				A_=None ,				**A_ ,				)     ->	int:





         """simple docstring"""




         super().__init__(**A_       )

         _lowercase:			Union[str, Any]       =     hidden_size
         _lowercase:			str       =     is_hybrid

         if self.is_hybrid:
           if backbone_config is None:
             logger.info('''Initializing the config with a `BiT` backbone.'''       )
             _lowercase:			Dict       =     {
                 '''global_padding''': '''same''',
                 '''layer_type''': '''bottleneck''',
                 '''depths''': [3, 4, 9],
                 '''out_features''': ['''stage1''', '''stage2''', '''stage3'''],
                 '''embedding_dynamic_padding''': True,
             }
             _lowercase:			List[str]       =     BitConfig(**A_       )
           elif isinstance(A_ ,				A_       ):
             logger.info('''Initializing the config with a `BiT` backbone.'''       )
             _lowercase:			Dict       =     BitConfig(**A_       )
           elif isinstance(A_ ,				A_       ):
             _lowercase:			str       =     backbone_config
           else:
             raise ValueError(
                 f'''backbone_config must be a dictionary or a `PretrainedConfig`, got {backbone_config.__class__}.'''       )

           _lowercase:			Dict       =     backbone_featmap_shape
           _lowercase:			Optional[int]       =     neck_ignore_stages

           if readout_type != "project":
             raise ValueError('''Readout type must be \'project\' when using `DPT-hybrid` mode.'''       )
         else:
           _lowercase:			Any       =     None
           _lowercase:			str       =     None
           _lowercase:			Optional[Any]       =     []

         _lowercase:			Tuple       =     num_hidden_layers
         _lowercase:			Optional[int]       =     num_attention_heads
         _lowercase:			Any       =     intermediate_size
         _lowercase:			List[Any]       =     hidden_act
         _lowercase:			Union[str, Any]       =     hidden_dropout_prob
         _lowercase:			Tuple       =     attention_probs_dropout_prob
         _lowercase:			Dict       =     initializer_range
         _lowercase:			Dict       =     layer_norm_eps
         _lowercase:			Any       =     image_size
         _lowercase:			Optional[int]       =     patch_size
         _lowercase:			Optional[int]       =     num_channels
         _lowercase:			int       =     qkv_bias
         _lowercase:			List[str]       =     backbone_out_indices
         if readout_type not in ["ignore", "add", "project"]:
           raise ValueError('''Readout_type must be one of [\'ignore\', \'add\', \'project\']'''       )
         _lowercase:			Union[str, Any]       =     readout_type
         _lowercase:			Optional[Any]       =     reassemble_factors
         _lowercase:			List[str]       =     neck_hidden_sizes
         _lowercase:			Tuple       =     fusion_hidden_size
         _lowercase:			int       =     head_in_index
         _lowercase:			Optional[int]       =     use_batch_norm_in_fusion_residual
         # auxiliary head attributes (semantic segmentation)
         _lowercase:			int       =     use_auxiliary_head
         _lowercase:			Dict       =     auxiliary_loss_weight
         _lowercase:			List[Any]       =     semantic_loss_ignore_index
         _lowercase:			Dict       =     semantic_classifier_dropout



       def 							lowercase_							(     self       )     ->	str:





         """simple docstring"""




         _lowercase:			Optional[int]       =     copy.deepcopy(self.__dict__       )

         if output["backbone_config"] is not None:
           _lowercase:			List[str]       =     self.backbone_config.to_dict()

         _lowercase:			List[Any]       =     self.__class__.model_type
         return output
