

import unittest

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







class lowerCAmelCase_						(			unittest.TestCase	):

 '''simple docstring'''

 def 						UpperCamelCase__					(     self ):
       snake_case_	=				['''a''', '''b''', '''c''']

       # Defaults to last layer if both are None
       snake_case_	,   snake_case_	=				get_aligned_output_features_output_indices(_UpperCAmelCase		,				_UpperCAmelCase		,				_UpperCAmelCase )
       self.assertEqual(_UpperCAmelCase		,				['''c'''] )
       self.assertEqual(_UpperCAmelCase		,				[2] )

       # Out indices set to match out features
       snake_case_	,   snake_case_	=				get_aligned_output_features_output_indices(['''a''', '''c''']		,				_UpperCAmelCase		,				_UpperCAmelCase )
       self.assertEqual(_UpperCAmelCase		,				['''a''', '''c'''] )
       self.assertEqual(_UpperCAmelCase		,				[0, 2] )

       # Out features set to match out indices
       snake_case_	,   snake_case_	=				get_aligned_output_features_output_indices(_UpperCAmelCase		,				[0, 2]		,				_UpperCAmelCase )
       self.assertEqual(_UpperCAmelCase		,				['''a''', '''c'''] )
       self.assertEqual(_UpperCAmelCase		,				[0, 2] )

       # Out features selected from negative indices
       snake_case_	,   snake_case_	=				get_aligned_output_features_output_indices(_UpperCAmelCase		,				[-3, -1]		,				_UpperCAmelCase )
       self.assertEqual(_UpperCAmelCase		,				['''a''', '''c'''] )
       self.assertEqual(_UpperCAmelCase		,				[-3, -1] )



 def 						UpperCamelCase__					(     self ):
       # Stage names must be set
       with self.assertRaises(_UpperCAmelCase ):
             verify_out_features_out_indices(['''a''', '''b''']		,				(0, 1)		,				_UpperCAmelCase )

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

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

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

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

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

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

       # Out features and out indices should be in order
       with self.assertRaises(_UpperCAmelCase ):
             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 						UpperCamelCase__					(     self ):
       snake_case_	=				BackboneMixin()

       snake_case_	=				['''a''', '''b''', '''c''']
       snake_case_	=				['''a''', '''c''']
       snake_case_	=				[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
       snake_case_	=				['''a''', '''b''']
       self.assertEqual(backbone.out_features		,				['''a''', '''b'''] )
       self.assertEqual(backbone.out_indices		,				[0, 1] )

       snake_case_	=				[-3, -1]
       self.assertEqual(backbone.out_features		,				['''a''', '''c'''] )
       self.assertEqual(backbone.out_indices		,				[-3, -1] )



from ...configuration_utils import PretrainedConfig
from ...utils import logging
from ...utils.backbone_utils import BackboneConfigMixin, get_aligned_output_features_output_indices


UpperCAmelCase      =   logging.get_logger(__name__)

UpperCAmelCase      =   {
    """facebook/convnextv2-tiny-1k-224""": """https://huggingface.co/facebook/convnextv2-tiny-1k-224/resolve/main/config.json""",
}







class lowerCAmelCase_						(			lowerCamelCase__ ,						lowerCamelCase__	):

 '''simple docstring'''

 __snake_case												=  "convnextv2"



 def __init__(     self		,				_UpperCAmelCase=3		,				_UpperCAmelCase=4		,				_UpperCAmelCase=4		,				_UpperCAmelCase=None		,				_UpperCAmelCase=None		,				_UpperCAmelCase="gelu"		,				_UpperCAmelCase=0.02		,				_UpperCAmelCase=1E-12		,				_UpperCAmelCase=0.0		,				_UpperCAmelCase=2_24		,				_UpperCAmelCase=None		,				_UpperCAmelCase=None		,				**_UpperCAmelCase		,				):
       super().__init__(**_UpperCAmelCase )

       snake_case_	=				num_channels
       snake_case_	=				patch_size
       snake_case_	=				num_stages
       snake_case_	=				[96, 1_92, 3_84, 7_68] if hidden_sizes is None else hidden_sizes
       snake_case_	=				[3, 3, 9, 3] if depths is None else depths
       snake_case_	=				hidden_act
       snake_case_	=				initializer_range
       snake_case_	=				layer_norm_eps
       snake_case_	=				drop_path_rate
       snake_case_	=				image_size
       snake_case_	=				['''stem'''] + [F'''stage{idx}''' for idx in range(1		,				len(self.depths ) + 1 )]
       snake_case_	,   snake_case_	=				get_aligned_output_features_output_indices(
           out_features=_UpperCAmelCase		,				out_indices=_UpperCAmelCase		,				stage_names=self.stage_names )