




'''simple docstring'''






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    A						(					SCREAMING_SNAKE_CASE__						):




				'''simple docstring'''





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

							# 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 :     List[str]										=  repo_parser.add_subparsers(
							    help="Deprecated: use `huggingface-cli` instead. huggingface.co repos related commands"     )
							__UpperCamelCase :     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=_UpperCAmelCase					,    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=_UpperCAmelCase					,    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 _UpperCAmelCase     : RepoCreateCommand(_UpperCAmelCase     )     )







class    A						:




				'''simple docstring'''





				A       =							"\u001b[1m"
				A       =							"\u001b[31m"
				A       =							"\u001b[90m"
				A       =							"\u001b[0m"
				@classmethod
				def 			a_			(cls					,    _UpperCAmelCase     )      ->			Optional[int]:
							return f"{cls._bold}{s}{cls._reset}"
				@classmethod
				def 			a_			(cls					,    _UpperCAmelCase     )      ->			Union[str, Any]:
							return f"{cls._bold}{cls._red}{s}{cls._reset}"





				@classmethod
				def 			a_			(cls					,    _UpperCAmelCase     )      ->			Tuple:
							return f"{cls._gray}{s}{cls._reset}"







def      __lowerCAmelCase   (       snake_case__   , snake_case__		):
			__UpperCamelCase :     Tuple										=  [max(len(str(snake_case__		)		) for x in col		) for col in zip(*snake_case__   , snake_case__		)]
			__UpperCamelCase :     List[Any]										=  ("{{:{}}} " * len(snake_case__		)).format(*snake_case__		)
			__UpperCamelCase :     Union[str, 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    A						:




				'''simple docstring'''





				def __init__(self					,    _UpperCAmelCase     )      ->			Union[str, Any]:
							__UpperCamelCase :     Tuple										=  args







class    A						(					SCREAMING_SNAKE_CASE__						):




				'''simple docstring'''





				def 			a_			(self     )      ->			Union[str, Any]:
							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    A						(					SCREAMING_SNAKE_CASE__						):




				'''simple docstring'''





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







class    A						(					SCREAMING_SNAKE_CASE__						):




				'''simple docstring'''





				def 			a_			(self     )      ->			List[Any]:
							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    A						(					SCREAMING_SNAKE_CASE__						):




				'''simple docstring'''





				def 			a_			(self     )      ->			int:
							print(
							    ANSI.red(
							        "WARNING! Managing repositories through transformers-cli is deprecated. "
							        "Please use `huggingface-cli` instead."     )     )
							__UpperCamelCase :     Union[str, Any]										=  HfFolder.get_token()
							if token is None:
										print("Not logged in"     )
										exit(1     )
							try:
										__UpperCamelCase :     List[Any]										=  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 :     Optional[int]										=  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						,   __UpperCamelCase :     str										=  whoami(_UpperCAmelCase     )
							__UpperCamelCase :     Dict										=  self.args.organization if self.args.organization is not None else user
							__UpperCamelCase :     int										=  f"{namespace}/{self.args.name}"
							print(f"You are about to create {ANSI.bold(_UpperCAmelCase     )}"     )

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









'''simple docstring'''






import torch
import torch.nn as nn
from transformers.modeling_utils import ModuleUtilsMixin
from transformers.models.ta.modeling_ta import (
    TaBlock,
    TaConfig,
    TaLayerNorm,
)

from ...configuration_utils import ConfigMixin, register_to_config
from ...models import ModelMixin



class    A						(					SCREAMING_SNAKE_CASE__     ,				SCREAMING_SNAKE_CASE__     ,				SCREAMING_SNAKE_CASE__						):




				'''simple docstring'''





				@register_to_config
				def __init__(self					,    _UpperCAmelCase					,    _UpperCAmelCase					,    _UpperCAmelCase					,    _UpperCAmelCase					,    _UpperCAmelCase					,    _UpperCAmelCase					,    _UpperCAmelCase					,    _UpperCAmelCase					,    _UpperCAmelCase					,    _UpperCAmelCase = False					,    )      ->			Tuple:
							super().__init__()

							__UpperCamelCase :     Optional[int]										=  nn.Linear(_UpperCAmelCase					,    _UpperCAmelCase					,    bias=_UpperCAmelCase     )

							__UpperCamelCase :     str										=  nn.Embedding(_UpperCAmelCase					,    _UpperCAmelCase     )
							__UpperCamelCase :     Any										=  False

							__UpperCamelCase :     Union[str, Any]										=  nn.Dropout(p=_UpperCAmelCase     )

							__UpperCamelCase :     Dict										=  TaConfig(
							    d_model=_UpperCAmelCase					,    num_heads=_UpperCAmelCase					,    d_kv=_UpperCAmelCase					,    d_ff=_UpperCAmelCase					,    feed_forward_proj=_UpperCAmelCase					,    dropout_rate=_UpperCAmelCase					,    is_decoder=_UpperCAmelCase					,    is_encoder_decoder=_UpperCAmelCase					,    )
							__UpperCamelCase :     Tuple										=  nn.ModuleList()
							for lyr_num in range(_UpperCAmelCase     ):
										__UpperCamelCase :     List[str]										=  TaBlock(_UpperCAmelCase     )
										self.encoders.append(_UpperCAmelCase     )

							__UpperCamelCase :     Tuple										=  TaLayerNorm(_UpperCAmelCase     )
							__UpperCamelCase :     Any										=  nn.Dropout(p=_UpperCAmelCase     )





				def 			a_			(self					,    _UpperCAmelCase					,    _UpperCAmelCase     )      ->			int:
							__UpperCamelCase :     Any										=  self.input_proj(_UpperCAmelCase     )

							# terminal relative positional encodings
							__UpperCamelCase :     Optional[Any]										=  encoder_inputs.shape[1]
							__UpperCamelCase :     Optional[int]										=  torch.arange(_UpperCAmelCase					,    device=encoder_inputs.device     )

							__UpperCamelCase :     Tuple										=  encoder_inputs_mask.sum(-1     )
							__UpperCamelCase :     Optional[Any]										=  torch.roll(input_positions.unsqueeze(0     )					,    tuple(seq_lens.tolist()     )					,    dims=0     )
							x += self.position_encoding(_UpperCAmelCase     )

							__UpperCamelCase :     Any										=  self.dropout_pre(_UpperCAmelCase     )

							# inverted the attention mask
							__UpperCamelCase :     Union[str, Any]										=  encoder_inputs.size()
							__UpperCamelCase :     Optional[Any]										=  self.get_extended_attention_mask(_UpperCAmelCase					,    _UpperCAmelCase     )

							for lyr in self.encoders:
										__UpperCamelCase :     List[Any]										=  lyr(_UpperCAmelCase					,    _UpperCAmelCase     )[0]
							__UpperCamelCase :     Union[str, Any]										=  self.layer_norm(_UpperCAmelCase     )

							return self.dropout_post(_UpperCAmelCase     ), encoder_inputs_mask



