


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_					(       __UpperCamelCase    ):




      '''simple docstring'''


      @staticmethod
      def      _snake_case	(				a:       ArgumentParser				):
       __lowerCamelCase		:							Dict							=						parser.add_parser('login'						,      help='Log in using the same credentials as on huggingface.co'				)
       login_parser.set_defaults(func=lambda a				: LoginCommand(a				)				)
       __lowerCamelCase		:							Union[str, Any]							=						parser.add_parser('whoami'						,      help='Find out which huggingface.co account you are logged in as.'				)
       whoami_parser.set_defaults(func=lambda a				: WhoamiCommand(a				)				)
       __lowerCamelCase		:							Tuple							=						parser.add_parser('logout'						,      help='Log out'				)
       logout_parser.set_defaults(func=lambda a				: LogoutCommand(a				)				)

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



class        A_					:




      '''simple docstring'''


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




      @classmethod
      def      _snake_case	(				cls:       str						,      a:       Union[str, Any]				):
       return F'{cls._bold}{s}{cls._reset}'




      @classmethod
      def      _snake_case	(				cls:       Any						,      a:       Tuple				):
       return F'{cls._bold}{cls._red}{s}{cls._reset}'




      @classmethod
      def      _snake_case	(				cls:       Any						,      a:       List[Any]				):
       return F'{cls._gray}{s}{cls._reset}'



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


class        A_					:




      '''simple docstring'''


      def __init__(				self:       int						,      a:       Dict				):
       __lowerCamelCase		:							List[str]							=						args



class        A_					(       __UpperCamelCase    ):




      '''simple docstring'''


      def      _snake_case	(				self:       str				):
       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_					(       __UpperCamelCase    ):




      '''simple docstring'''


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



class        A_					(       __UpperCamelCase    ):




      '''simple docstring'''


      def      _snake_case	(				self:       Optional[int]				):
       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_					(       __UpperCamelCase    ):




      '''simple docstring'''


      def      _snake_case	(				self:       Union[str, Any]				):
       print(
           ANSI.red(
               'WARNING! Managing repositories through transformers-cli is deprecated. '
               'Please use `huggingface-cli` instead.'				)				)
       __lowerCamelCase		:							List[Any]							=						HfFolder.get_token()
       if token is None:
        print('Not logged in'				)
        exit(1				)
       try:
        __lowerCamelCase		:							List[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:
        __lowerCamelCase		:							List[Any]							=						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(''				)

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

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





import unittest

from transformers import is_torch_available
from transformers.testing_utils import require_sentencepiece, require_tokenizers, require_torch, slow, torch_device


if is_torch_available():
       import torch

       from transformers import CamembertModel


@require_torch
@require_sentencepiece
@require_tokenizers
class        A_					(       unittest.TestCase    ):




      '''simple docstring'''


      @slow
      def      _snake_case	(				self:       Any				):
       __lowerCamelCase		:							Dict							=						CamembertModel.from_pretrained('camembert-base'				)
       model.to(a				)

       __lowerCamelCase		:							List[Any]							=						torch.tensor(
           [[5, 121, 11, 660, 16, 730, 2_5543, 110, 83, 6]]						,      device=a						,      dtype=torch.long						,      )  # J'aime le camembert !
       with torch.no_grad():
        __lowerCamelCase		:							Tuple							=						model(a				)['last_hidden_state']
       __lowerCamelCase		:							Union[str, Any]							=						torch.Size((1, 10, 768)				)
       self.assertEqual(output.shape						,      a				)
       # compare the actual values for a slice.
       __lowerCamelCase		:							Tuple							=						torch.tensor(
           [[[-0.0_2_5_4, 0.0_2_3_5, 0.1_0_2_7], [0.0_6_0_6, -0.1_8_1_1, -0.0_4_1_8], [-0.1_5_6_1, -0.1_1_2_7, 0.2_6_8_7]]]						,      device=a						,      dtype=torch.float						,      )
       # camembert = torch.hub.load('pytorch/fairseq', 'camembert.v0')
       # camembert.eval()
       # expected_slice = roberta.model.forward(input_ids)[0][:, :3, :3].detach()

       self.assertTrue(torch.allclose(output[:, :3, :3]						,      a						,      atol=1e-4				)				)

