






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 					snake_case_							(       _a      ):







   """simple docstring"""



   @staticmethod
   def 			SCREAMING_SNAKE_CASE__				(    snake_case__:	Optional[Any]	)  ->		Any:


         """simple docstring"""



         _lowercase     =	parser.add_parser('login'   ,       help='Log in using the same credentials as on huggingface.co'	)
         login_parser.set_defaults(func=lambda snake_case__	: LoginCommand(lowerCamelCase__	)	)
         _lowercase     =	parser.add_parser('whoami'   ,       help='Find out which huggingface.co account you are logged in as.'	)
         whoami_parser.set_defaults(func=lambda snake_case__	: WhoamiCommand(lowerCamelCase__	)	)
         _lowercase     =	parser.add_parser('logout'   ,       help='Log out'	)
         logout_parser.set_defaults(func=lambda snake_case__	: LogoutCommand(lowerCamelCase__	)	)

         # new system: git-based repo system
         _lowercase     =	parser.add_parser(
             'repo'   ,       help='Deprecated: use `huggingface-cli` instead. Commands to interact with your huggingface.co repos.'   ,       )
         _lowercase     =	repo_parser.add_subparsers(
             help='Deprecated: use `huggingface-cli` instead. huggingface.co repos related commands'	)
         _lowercase     =	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 snake_case__	: RepoCreateCommand(lowerCamelCase__	)	)






class 					snake_case_							:







   """simple docstring"""



   __lowerCAmelCase      =						"""\u001b[1m"""
   __lowerCAmelCase      =						"""\u001b[31m"""
   __lowerCAmelCase      =						"""\u001b[90m"""
   __lowerCAmelCase      =						"""\u001b[0m"""

   @classmethod
   def 			SCREAMING_SNAKE_CASE__				(    cls:	Optional[int]   ,       snake_case__:	Union[str, Any]	)  ->		Any:


         """simple docstring"""



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

   @classmethod
   def 			SCREAMING_SNAKE_CASE__				(    cls:	Any   ,       snake_case__:	Union[str, Any]	)  ->		Any:


         """simple docstring"""



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

   @classmethod
   def 			SCREAMING_SNAKE_CASE__				(    cls:	Any   ,       snake_case__:	Union[str, Any]	)  ->		Union[str, Any]:


         """simple docstring"""



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






def        UpperCAmelCase      (   _lowercase,      _lowercase      ):


      '''simple docstring'''



      _lowercase     =	[max(len(str(_lowercase      )      ) for x in col      ) for col in zip(*_lowercase,      _lowercase      )]
      _lowercase     =	("{{:{}}} " * len(_lowercase      )).format(*_lowercase      )
      _lowercase     =	[]
      lines.append(row_format.format(*_lowercase      )      )
      lines.append(row_format.format(*['-' * w for w in col_widths]      )      )
      for row in rows:
            lines.append(row_format.format(*_lowercase      )      )
      return "\n".join(_lowercase      )

class 					snake_case_							:







   """simple docstring"""



   def __init__(    self:	List[str]   ,       snake_case__:	str	)  ->		Optional[int]:


         """simple docstring"""



         _lowercase     =	args






class 					snake_case_							(       _a      ):







   """simple docstring"""



   def 			SCREAMING_SNAKE_CASE__				(    self:	List[str]	)  ->		str:


         """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 					snake_case_							(       _a      ):







   """simple docstring"""



   def 			SCREAMING_SNAKE_CASE__				(    self:	Dict	)  ->		int:


         """simple docstring"""



         print(
             ANSI.red(
                 'WARNING! `transformers-cli whoami` is deprecated and will be removed in v5. Please use '
                 '`huggingface-cli whoami` instead.'	)	)
         _lowercase     =	HfFolder.get_token()
         if token is None:
               print('Not logged in'	)
               exit()
         try:
               _lowercase     =	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 					snake_case_							(       _a      ):







   """simple docstring"""



   def 			SCREAMING_SNAKE_CASE__				(    self:	Tuple	)  ->		Dict:


         """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 					snake_case_							(       _a      ):







   """simple docstring"""



   def 			SCREAMING_SNAKE_CASE__				(    self:	str	)  ->		List[str]:


         """simple docstring"""



         print(
             ANSI.red(
                 'WARNING! Managing repositories through transformers-cli is deprecated. '
                 'Please use `huggingface-cli` instead.'	)	)
         _lowercase     =	HfFolder.get_token()
         if token is None:
               print('Not logged in'	)
               exit(1	)
         try:
               _lowercase     =	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:
               _lowercase     =	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(''	)

         _lowercase     =	whoami(lowerCamelCase__	)
         _lowercase     =	self.args.organization if self.args.organization is not None else user
         _lowercase     =	f'''{namespace}/{self.args.name}'''
         print(f'''You are about to create {ANSI.bold(lowerCamelCase__	)}'''	)

         if not self.args.yes:
               _lowercase     =	input('Proceed? [Y/n] '	).lower()
               if not (choice == "" or choice == "y" or choice == "yes"):
                     print('Abort'	)
                     exit()
         try:
               _lowercase     =	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(''	)








import functools
import operator

from ...configuration_utils import PretrainedConfig
from ...utils import logging


lowerCamelCase										=  logging.get_logger(__name__)

lowerCamelCase										=  {
    '''facebook/hubert-base-ls960''': '''https://huggingface.co/facebook/hubert-base-ls960/resolve/main/config.json''',
    # See all Hubert models at https://huggingface.co/models?filter=hubert
}

class 					snake_case_							(       lowercase_      ):







   """simple docstring"""



   __lowerCAmelCase      =						"""hubert"""

   def __init__(    self:	Any   ,       snake_case__:	str=32   ,       snake_case__:	int=768   ,       snake_case__:	Dict=12   ,       snake_case__:	Optional[int]=12   ,       snake_case__:	List[str]=3_072   ,       snake_case__:	Optional[Any]="gelu"   ,       snake_case__:	Optional[int]=0.1   ,       snake_case__:	List[str]=0.1   ,       snake_case__:	Optional[int]=0.1   ,       snake_case__:	List[str]=True   ,       snake_case__:	Union[str, Any]=0.0   ,       snake_case__:	Union[str, Any]=0.1   ,       snake_case__:	List[str]=0.1   ,       snake_case__:	List[Any]=0.02   ,       snake_case__:	Dict=1E-5   ,       snake_case__:	Any="group"   ,       snake_case__:	Union[str, Any]="gelu"   ,       snake_case__:	List[str]=(512, 512, 512, 512, 512, 512, 512)   ,       snake_case__:	Union[str, Any]=(5, 2, 2, 2, 2, 2, 2)   ,       snake_case__:	Any=(10, 3, 3, 3, 3, 2, 2)   ,       snake_case__:	int=False   ,       snake_case__:	Any=128   ,       snake_case__:	Dict=16   ,       snake_case__:	Optional[Any]=False   ,       snake_case__:	Tuple=True   ,       snake_case__:	int=0.05   ,       snake_case__:	List[Any]=10   ,       snake_case__:	Tuple=2   ,       snake_case__:	List[Any]=0.0   ,       snake_case__:	Optional[int]=10   ,       snake_case__:	Optional[int]=0   ,       snake_case__:	Union[str, Any]="sum"   ,       snake_case__:	Union[str, Any]=False   ,       snake_case__:	int=False   ,       snake_case__:	Any=256   ,       snake_case__:	Union[str, Any]=0   ,       snake_case__:	Optional[int]=1   ,       snake_case__:	List[str]=2   ,       **snake_case__:	Optional[int]   ,       )  ->		Any:


       """simple docstring"""



       super().__init__(**snake_case__   ,       pad_token_id=snake_case__   ,       bos_token_id=snake_case__   ,       eos_token_id=snake_case__	)
       _lowercase     =	hidden_size
       _lowercase     =	feat_extract_norm
       _lowercase     =	feat_extract_activation
       _lowercase     =	list(snake_case__	)
       _lowercase     =	list(snake_case__	)
       _lowercase     =	list(snake_case__	)
       _lowercase     =	conv_bias
       _lowercase     =	num_conv_pos_embeddings
       _lowercase     =	num_conv_pos_embedding_groups
       _lowercase     =	len(self.conv_dim	)
       _lowercase     =	num_hidden_layers
       _lowercase     =	intermediate_size
       _lowercase     =	hidden_act
       _lowercase     =	num_attention_heads
       _lowercase     =	hidden_dropout
       _lowercase     =	attention_dropout
       _lowercase     =	activation_dropout
       _lowercase     =	feat_proj_layer_norm
       _lowercase     =	feat_proj_dropout
       _lowercase     =	final_dropout
       _lowercase     =	layerdrop
       _lowercase     =	layer_norm_eps
       _lowercase     =	initializer_range
       _lowercase     =	vocab_size
       _lowercase     =	do_stable_layer_norm
       _lowercase     =	use_weighted_layer_sum
       _lowercase     =	classifier_proj_size

       if (
           (len(self.conv_stride	) != self.num_feat_extract_layers)
           or (len(self.conv_kernel	) != self.num_feat_extract_layers)
           or (len(self.conv_dim	) != self.num_feat_extract_layers)
       ):
           raise ValueError(
               'Configuration for convolutional layers is incorrect. It is required that `len(config.conv_dim)` =='
               ' `len(config.conv_stride)` == `len(config.conv_kernel)`, but is `len(config.conv_dim) ='
               f''' {len(self.conv_dim	)}`, `len(config.conv_stride) = {len(self.conv_stride	)}`,'''
               f''' `len(config.conv_kernel) = {len(self.conv_kernel	)}`.'''	)

       # fine-tuning config parameters for SpecAugment: https://arxiv.org/abs/1904.08779
       _lowercase     =	apply_spec_augment
       _lowercase     =	mask_time_prob
       _lowercase     =	mask_time_length
       _lowercase     =	mask_time_min_masks
       _lowercase     =	mask_feature_prob
       _lowercase     =	mask_feature_length
       _lowercase     =	mask_feature_min_masks

       # ctc loss
       _lowercase     =	ctc_loss_reduction
       _lowercase     =	ctc_zero_infinity

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


       """simple docstring"""



       return functools.reduce(operator.mul   ,       self.conv_stride   ,       1	)
