




import subprocess
from argparse import ArgumentParser
from typing import List, Union

from huggingface_hub.hf_api import HfFolder, create_repo, whoami
from requests.exceptions import HTTPError

from . import BaseTransformersCLICommand


class       SCREAMING_SNAKE_CASE_							(					_UpperCamelCase      ):



 """simple docstring"""


 @staticmethod
 def 				lowerCamelCase__    (				lowerCAmelCase		:	ArgumentParser  )  ->					List[Any]:







      """simple docstring"""







      __UpperCamelCase				:  str								=			parser.add_parser("""login"""				,    help="""Log in using the same credentials as on huggingface.co"""  )
      login_parser.set_defaults(func=lambda lowerCAmelCase  : LoginCommand(lowerCAmelCase  )  )
      __UpperCamelCase				:  str								=			parser.add_parser("""whoami"""				,    help="""Find out which huggingface.co account you are logged in as."""  )
      whoami_parser.set_defaults(func=lambda lowerCAmelCase  : WhoamiCommand(lowerCAmelCase  )  )
      __UpperCamelCase				:  Optional[Any]								=			parser.add_parser("""logout"""				,    help="""Log out"""  )
      logout_parser.set_defaults(func=lambda lowerCAmelCase  : LogoutCommand(lowerCAmelCase  )  )

      # new system: git-based repo system
      __UpperCamelCase				:  Union[str, Any]								=			parser.add_parser(
          """repo"""				,    help="""Deprecated: use `huggingface-cli` instead. Commands to interact with your huggingface.co repos."""				,    )
      __UpperCamelCase				:  Tuple								=			repo_parser.add_subparsers(
          help="""Deprecated: use `huggingface-cli` instead. huggingface.co repos related commands"""  )
      __UpperCamelCase				:  Optional[Any]								=			repo_subparsers.add_parser(
          """create"""				,    help="""Deprecated: use `huggingface-cli` instead. Create a new repo on huggingface.co"""  )
      repo_create_parser.add_argument(
          """name"""				,    type=lowerCAmelCase				,    help="""Name for your model's repo. Will be namespaced under your username to build the model id."""				,    )
      repo_create_parser.add_argument("""--organization"""				,    type=lowerCAmelCase				,    help="""Optional: organization namespace."""  )
      repo_create_parser.add_argument("""-y"""				,    """--yes"""				,    action="""store_true"""				,    help="""Optional: answer Yes to the prompt"""  )
      repo_create_parser.set_defaults(func=lambda lowerCAmelCase  : RepoCreateCommand(lowerCAmelCase  )  )






class       SCREAMING_SNAKE_CASE_							:



 """simple docstring"""


 __magic_name__      :					Optional[int]			  =		'\u001b[1m'
 __magic_name__      :					int			  =		'\u001b[31m'
 __magic_name__      :					List[str]			  =		'\u001b[90m'
 __magic_name__      :					Optional[Any]			  =		'\u001b[0m'






 @classmethod
 def 				lowerCamelCase__    (				cls		:	List[str]				,    lowerCAmelCase		:	Any  )  ->					Optional[Any]:







      """simple docstring"""







      return F'''{cls._bold}{s}{cls._reset}'''






 @classmethod
 def 				lowerCamelCase__    (				cls		:	List[str]				,    lowerCAmelCase		:	List[Any]  )  ->					List[str]:







      """simple docstring"""







      return F'''{cls._bold}{cls._red}{s}{cls._reset}'''






 @classmethod
 def 				lowerCamelCase__    (				cls		:	Dict				,    lowerCAmelCase		:	Dict  )  ->					Any:







      """simple docstring"""







      return F'''{cls._gray}{s}{cls._reset}'''






def 							A__   (snake_case      :		List[List[Union[str, int]]]		,  snake_case      :		List[str]							)    ->	str:
     __UpperCamelCase				:  Union[str, Any]								=			[max(len(str(snake_case							)							) for x in col							) for col in zip(*snake_case		,  snake_case							)]
     __UpperCamelCase				:  Union[str, Any]								=			("""{{:{}}} """ * len(snake_case							)).format(*snake_case							)
     __UpperCamelCase				:  Any								=			[]
     lines.append(row_format.format(*snake_case							)							)
     lines.append(row_format.format(*["""-""" * w for w in col_widths]							)							)
     for row in rows:
          lines.append(row_format.format(*snake_case							)							)
     return "\n".join(snake_case							)


class       SCREAMING_SNAKE_CASE_							:



 """simple docstring"""


 def __init__(				self		:	str				,    lowerCAmelCase		:	int  )  ->					int:







      """simple docstring"""







      __UpperCamelCase				:  Optional[Any]								=			args






class       SCREAMING_SNAKE_CASE_							(					_UpperCamelCase      ):



 """simple docstring"""


 def 				lowerCamelCase__    (				self		:	Optional[Any]  )  ->					Optional[Any]:







      """simple docstring"""







      print(
          ANSI.red(
              """ERROR! `huggingface-cli login` uses an outdated login mechanism """
              """that is not compatible with the Hugging Face Hub backend anymore. """
              """Please use `huggingface-cli login instead."""  )  )






class       SCREAMING_SNAKE_CASE_							(					_UpperCamelCase      ):



 """simple docstring"""


 def 				lowerCamelCase__    (				self		:	List[str]  )  ->					Any:







      """simple docstring"""







      print(
          ANSI.red(
              """WARNING! `transformers-cli whoami` is deprecated and will be removed in v5. Please use """
              """`huggingface-cli whoami` instead."""  )  )
      __UpperCamelCase				:  int								=			HfFolder.get_token()
      if token is None:
           print("""Not logged in"""  )
           exit()
      try:
           __UpperCamelCase				:  Optional[Any]								=			whoami(lowerCAmelCase  )
           print(lowerCAmelCase  )
           if orgs:
                print(ANSI.bold("""orgs: """  )				,    """,""".join(lowerCAmelCase  )  )
      except HTTPError as e:
           print(lowerCAmelCase  )
           print(ANSI.red(e.response.text  )  )
           exit(1  )






class       SCREAMING_SNAKE_CASE_							(					_UpperCamelCase      ):



 """simple docstring"""


 def 				lowerCamelCase__    (				self		:	Union[str, Any]  )  ->					str:







      """simple docstring"""







      print(
          ANSI.red(
              """ERROR! `transformers-cli logout` uses an outdated logout mechanism """
              """that is not compatible with the Hugging Face Hub backend anymore. """
              """Please use `huggingface-cli logout instead."""  )  )






class       SCREAMING_SNAKE_CASE_							(					_UpperCamelCase      ):



 """simple docstring"""


 def 				lowerCamelCase__    (				self		:	str  )  ->					Any:







      """simple docstring"""







      print(
          ANSI.red(
              """WARNING! Managing repositories through transformers-cli is deprecated. """
              """Please use `huggingface-cli` instead."""  )  )
      __UpperCamelCase				:  Tuple								=			HfFolder.get_token()
      if token is None:
           print("""Not logged in"""  )
           exit(1  )
      try:
           __UpperCamelCase				:  str								=			subprocess.check_output(["""git""", """--version"""]  ).decode("""utf-8"""  )
           print(ANSI.gray(stdout.strip()  )  )
      except FileNotFoundError:
           print("""Looks like you do not have git installed, please install."""  )

      try:
           __UpperCamelCase				:  Tuple								=			subprocess.check_output(["""git-lfs""", """--version"""]  ).decode("""utf-8"""  )
           print(ANSI.gray(stdout.strip()  )  )
      except FileNotFoundError:
           print(
               ANSI.red(
                   """Looks like you do not have git-lfs installed, please install."""
                   """ You can install from https://git-lfs.github.com/."""
                   """ Then run `git lfs install` (you only have to do this once)."""  )  )
      print(""""""  )

      __UpperCamelCase				:  List[str]								=			whoami(lowerCAmelCase  )
      __UpperCamelCase				:  int								=			self.args.organization if self.args.organization is not None else user
      __UpperCamelCase				:  Optional[Any]								=			F'''{namespace}/{self.args.name}'''
      print(F'''You are about to create {ANSI.bold(lowerCAmelCase  )}'''  )

      if not self.args.yes:
           __UpperCamelCase				:  Tuple								=			input("""Proceed? [Y/n] """  ).lower()
           if not (choice == "" or choice == "y" or choice == "yes"):
                print("""Abort"""  )
                exit()
      try:
           __UpperCamelCase				:  Optional[int]								=			create_repo(lowerCAmelCase				,    name=self.args.name				,    organization=self.args.organization  )
      except HTTPError as e:
           print(lowerCAmelCase  )
           print(ANSI.red(e.response.text  )  )
           exit(1  )
      print("""\nYour repo now lives at:"""  )
      print(F'''  {ANSI.bold(lowerCAmelCase  )}'''  )
      print("""\nYou can clone it locally with the command below, and commit/push as usual."""  )
      print(F'''\n  git clone {url}'''  )
      print(""""""  )












from collections import OrderedDict
from typing import Mapping

from packaging import version

from ...configuration_utils import PretrainedConfig
from ...onnx import OnnxConfig
from ...utils import logging


a__		    =    logging.get_logger(__name__)

a__		    =    {
    '''apple/mobilevit-small''': '''https://huggingface.co/apple/mobilevit-small/resolve/main/config.json''',
    '''apple/mobilevit-x-small''': '''https://huggingface.co/apple/mobilevit-x-small/resolve/main/config.json''',
    '''apple/mobilevit-xx-small''': '''https://huggingface.co/apple/mobilevit-xx-small/resolve/main/config.json''',
    '''apple/deeplabv3-mobilevit-small''': (
        '''https://huggingface.co/apple/deeplabv3-mobilevit-small/resolve/main/config.json'''
    ),
    '''apple/deeplabv3-mobilevit-x-small''': (
        '''https://huggingface.co/apple/deeplabv3-mobilevit-x-small/resolve/main/config.json'''
    ),
    '''apple/deeplabv3-mobilevit-xx-small''': (
        '''https://huggingface.co/apple/deeplabv3-mobilevit-xx-small/resolve/main/config.json'''
    ),
    # See all MobileViT models at https://huggingface.co/models?filter=mobilevit
}


class       SCREAMING_SNAKE_CASE_							(					_UpperCamelCase      ):



	"""simple docstring"""


	__magic_name__      :					Any			  =		'mobilevit'






	def __init__(				self		:	int				,    lowerCAmelCase		:	Dict=3				,    lowerCAmelCase		:	Dict=256				,    lowerCAmelCase		:	Any=2				,    lowerCAmelCase		:	Any=[144, 192, 240]				,    lowerCAmelCase		:	int=[16, 32, 64, 96, 128, 160, 640]				,    lowerCAmelCase		:	List[Any]=4				,    lowerCAmelCase		:	Tuple=2.0				,    lowerCAmelCase		:	Tuple=4.0				,    lowerCAmelCase		:	List[str]="silu"				,    lowerCAmelCase		:	Tuple=3				,    lowerCAmelCase		:	Tuple=32				,    lowerCAmelCase		:	Any=0.1				,    lowerCAmelCase		:	List[str]=0.0				,    lowerCAmelCase		:	Union[str, Any]=0.1				,    lowerCAmelCase		:	List[str]=0.02				,    lowerCAmelCase		:	Optional[Any]=1E-5				,    lowerCAmelCase		:	Union[str, Any]=True				,    lowerCAmelCase		:	List[str]=256				,    lowerCAmelCase		:	List[Any]=[6, 12, 18]				,    lowerCAmelCase		:	Tuple=0.1				,    lowerCAmelCase		:	List[str]=255				,    **lowerCAmelCase		:	Union[str, Any]				,    )  ->					Optional[Any]:







						"""simple docstring"""







						super().__init__(**lowerCAmelCase  )

						__UpperCamelCase				:  Tuple								=			num_channels
						__UpperCamelCase				:  Union[str, Any]								=			image_size
						__UpperCamelCase				:  List[Any]								=			patch_size
						__UpperCamelCase				:  Optional[int]								=			hidden_sizes
						__UpperCamelCase				:  Union[str, Any]								=			neck_hidden_sizes
						__UpperCamelCase				:  List[str]								=			num_attention_heads
						__UpperCamelCase				:  Union[str, Any]								=			mlp_ratio
						__UpperCamelCase				:  Tuple								=			expand_ratio
						__UpperCamelCase				:  Optional[Any]								=			hidden_act
						__UpperCamelCase				:  int								=			conv_kernel_size
						__UpperCamelCase				:  Any								=			output_stride
						__UpperCamelCase				:  int								=			hidden_dropout_prob
						__UpperCamelCase				:  Union[str, Any]								=			attention_probs_dropout_prob
						__UpperCamelCase				:  Dict								=			classifier_dropout_prob
						__UpperCamelCase				:  Any								=			initializer_range
						__UpperCamelCase				:  List[str]								=			layer_norm_eps
						__UpperCamelCase				:  Union[str, Any]								=			qkv_bias

						# decode head attributes for semantic segmentation
						__UpperCamelCase				:  Any								=			aspp_out_channels
						__UpperCamelCase				:  Union[str, Any]								=			atrous_rates
						__UpperCamelCase				:  Union[str, Any]								=			aspp_dropout_prob
						__UpperCamelCase				:  List[str]								=			semantic_loss_ignore_index






class       SCREAMING_SNAKE_CASE_							(					_UpperCamelCase      ):



	"""simple docstring"""


	__magic_name__      :					Optional[Any]			  =		version.parse('1.11'      )






	@property
	def 				lowerCamelCase__    (				self		:	Any  )  ->					Mapping[str, Mapping[int, str]]:







						"""simple docstring"""







						return OrderedDict([("""pixel_values""", {0: """batch""", 1: """num_channels""", 2: """height""", 3: """width"""})]  )






	@property
	def 				lowerCamelCase__    (				self		:	List[Any]  )  ->					Mapping[str, Mapping[int, str]]:







						"""simple docstring"""







						if self.task == "image-classification":
											return OrderedDict([("""logits""", {0: """batch"""})]  )
						else:
											return OrderedDict([("""last_hidden_state""", {0: """batch"""}), ("""pooler_output""", {0: """batch"""})]  )






	@property
	def 				lowerCamelCase__    (				self		:	Optional[int]  )  ->					float:







						"""simple docstring"""







						return 1E-4






