


import os
import sys
import unittest


__lowerCamelCase        =     os.path.abspath(os.path.dirname(os.path.dirname(os.path.dirname(__file__))))
sys.path.append(os.path.join(git_repo_path, '''utils'''))

import check_dummies  # noqa: E402
from check_dummies import create_dummy_files, create_dummy_object, find_backend, read_init  # noqa: E402


# Align TRANSFORMERS_PATH in check_dummies with the current path
__lowerCamelCase        =     os.path.join(git_repo_path, '''src''', '''transformers''')

__lowerCamelCase        =     '''
{0} = None
'''

__lowerCamelCase        =     '''
class {0}(metaclass=DummyObject):
    _backends = {1}

    def __init__(self, *args, **kwargs):
        requires_backends(self, {1})
'''


__lowerCamelCase        =     '''
def {0}(*args, **kwargs):
    requires_backends({0}, {1})
'''


class   a__	(						unittest.TestCase    ):

       def 						UpperCAmelCase(   self      :     Optional[int]    ):
            a_    :     Any										=    find_backend("""    _import_structure[\"models.albert\"].append(\"AlbertTokenizerFast\")"""    )
            self.assertIsNone(lowerCamelCase_    )

            a_    :     Union[str, Any]										=    find_backend("""    if not is_tokenizers_available():"""    )
            self.assertEqual(lowerCamelCase_      ,							"""tokenizers"""    )

            a_    :     Tuple										=    find_backend("""    if not is_tensorflow_text_available():"""    )
            self.assertEqual(lowerCamelCase_      ,							"""tensorflow_text"""    )

            a_    :     Optional[Any]										=    find_backend("""    if not (is_sentencepiece_available() and is_tokenizers_available()):"""    )
            self.assertEqual(lowerCamelCase_      ,							"""sentencepiece_and_tokenizers"""    )

            a_    :     Union[str, Any]										=    find_backend(
                """    if not (is_sentencepiece_available() and is_tensorflow_text_available()):"""    )
            self.assertEqual(lowerCamelCase_      ,							"""sentencepiece_and_tensorflow_text"""    )

            a_    :     Optional[Any]										=    find_backend(
                """    if not (is_sentencepiece_available() and is_tokenizers_available() and is_vision_available()):"""    )
            self.assertEqual(lowerCamelCase_      ,							"""sentencepiece_and_tokenizers_and_vision"""    )

       def 						UpperCAmelCase(   self      :     Dict    ):
            a_    :     Dict										=    read_init()
            # We don't assert on the exact list of keys to allow for smooth grow of backend-specific objects
            self.assertIn("""torch"""      ,							lowerCamelCase_    )
            self.assertIn("""tensorflow_text"""      ,							lowerCamelCase_    )
            self.assertIn("""sentencepiece_and_tokenizers"""      ,							lowerCamelCase_    )

            # Likewise, we can't assert on the exact content of a key
            self.assertIn("""BertModel"""      ,							objects["""torch"""]    )
            self.assertIn("""TFBertModel"""      ,							objects["""tf"""]    )
            self.assertIn("""FlaxBertModel"""      ,							objects["""flax"""]    )
            self.assertIn("""BertModel"""      ,							objects["""torch"""]    )
            self.assertIn("""TFBertTokenizer"""      ,							objects["""tensorflow_text"""]    )
            self.assertIn("""convert_slow_tokenizer"""      ,							objects["""sentencepiece_and_tokenizers"""]    )

       def 						UpperCAmelCase(   self      :     List[str]    ):
            a_    :     Optional[int]										=    create_dummy_object("""CONSTANT"""      ,							"""'torch'"""    )
            self.assertEqual(lowerCamelCase_      ,							"""\nCONSTANT = None\n"""    )

            a_    :     List[str]										=    create_dummy_object("""function"""      ,							"""'torch'"""    )
            self.assertEqual(
                lowerCamelCase_      ,							"""\ndef function(*args, **kwargs):\n    requires_backends(function, 'torch')\n"""    )

            a_    :     List[str]										=    "\nclass FakeClass(metaclass=DummyObject):\n    _backends = 'torch'\n\n    def __init__(self, *args, **kwargs):\n        requires_backends(self, 'torch')\n"
            a_    :     List[Any]										=    create_dummy_object("""FakeClass"""      ,							"""'torch'"""    )
            self.assertEqual(lowerCamelCase_      ,							lowerCamelCase_    )

       def 						UpperCAmelCase(   self      :     Dict    ):
            a_    :     Tuple										=    "# This file is autogenerated by the command `make fix-copies`, do not edit.\nfrom ..utils import DummyObject, requires_backends\n\n\nCONSTANT = None\n\n\ndef function(*args, **kwargs):\n    requires_backends(function, [\"torch\"])\n\n\nclass FakeClass(metaclass=DummyObject):\n    _backends = [\"torch\"]\n\n    def __init__(self, *args, **kwargs):\n        requires_backends(self, [\"torch\"])\n"
            a_    :     Any										=    create_dummy_files({"""torch""": ["""CONSTANT""", """function""", """FakeClass"""]}    )
            self.assertEqual(dummy_files["""torch"""]      ,							lowerCamelCase_    )






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


__lowerCamelCase        =     logging.get_logger(__name__)

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


class   a__	(						lowerCAmelCase_						,       lowerCAmelCase_    ):
       lowerCamelCase__:     str							    =     """convnextv2"""

       def __init__(   self      :     Tuple      ,							lowerCamelCase_      :     str=3      ,							lowerCamelCase_      :     Tuple=4      ,							lowerCamelCase_      :     Any=4      ,							lowerCamelCase_      :     Optional[int]=None      ,							lowerCamelCase_      :     Optional[int]=None      ,							lowerCamelCase_      :     Optional[int]="gelu"      ,							lowerCamelCase_      :     Optional[Any]=0.0_2      ,							lowerCamelCase_      :     str=1E-12      ,							lowerCamelCase_      :     Dict=0.0      ,							lowerCamelCase_      :     Union[str, Any]=2_2_4      ,							lowerCamelCase_      :     Dict=None      ,							lowerCamelCase_      :     Optional[Any]=None      ,							**lowerCamelCase_      :     List[Any]      ,							):
            super().__init__(**lowerCamelCase_    )

            a_    :     Dict										=    num_channels
            a_    :     Optional[int]										=    patch_size
            a_    :     int										=    num_stages
            a_    :     Any										=    [9_6, 1_9_2, 3_8_4, 7_6_8] if hidden_sizes is None else hidden_sizes
            a_    :     Any										=    [3, 3, 9, 3] if depths is None else depths
            a_    :     Any										=    hidden_act
            a_    :     Dict										=    initializer_range
            a_    :     Optional[Any]										=    layer_norm_eps
            a_    :     int										=    drop_path_rate
            a_    :     Optional[Any]										=    image_size
            a_    :     Dict										=    ["""stem"""] + [F'''stage{idx}''' for idx in range(1      ,							len(self.depths    ) + 1    )]
            a_			,			a_    :     int										=    get_aligned_output_features_output_indices(
                out_features=lowerCamelCase_      ,							out_indices=lowerCamelCase_      ,							stage_names=self.stage_names    )



