import os
import string
import sys


lowerCAmelCase			:							Optional[int]     =1 << 8

lowerCAmelCase			:							int     ={
    "tab": ord("\t"),
    "newline": ord("\r"),
    "esc": 27,
    "up": 65 + ARROW_KEY_FLAG,
    "down": 66 + ARROW_KEY_FLAG,
    "right": 67 + ARROW_KEY_FLAG,
    "left": 68 + ARROW_KEY_FLAG,
    "mod_int": 91,
    "undefined": sys.maxsize,
    "interrupt": 3,
    "insert": 50,
    "delete": 51,
    "pg_up": 53,
    "pg_down": 54,
}

lowerCAmelCase			:							str     =KEYMAP["up"]
lowerCAmelCase			:							str     =KEYMAP["left"]

if sys.platform == "win32":
    lowerCAmelCase			:							str     =[]
    lowerCAmelCase			:							Tuple     ={
        B"\xe0H": KEYMAP["up"] - ARROW_KEY_FLAG,
        B"\x00H": KEYMAP["up"] - ARROW_KEY_FLAG,
        B"\xe0P": KEYMAP["down"] - ARROW_KEY_FLAG,
        B"\x00P": KEYMAP["down"] - ARROW_KEY_FLAG,
        B"\xe0M": KEYMAP["right"] - ARROW_KEY_FLAG,
        B"\x00M": KEYMAP["right"] - ARROW_KEY_FLAG,
        B"\xe0K": KEYMAP["left"] - ARROW_KEY_FLAG,
        B"\x00K": KEYMAP["left"] - ARROW_KEY_FLAG,
    }

for i in range(10):
    lowerCAmelCase			:							str     =ord(str(i))







def 						A__  (					):







    '''simple docstring'''
    if os.name == "nt":
        import msvcrt

        _lowerCamelCase     :		Union[str, Any] 						=						"""mbcs"""
        # Flush the keyboard buffer
        while msvcrt.kbhit():
            msvcrt.getch()
        if len(__A	) == 0:
            # Read the keystroke
            _lowerCamelCase     :		Any 						=						msvcrt.getch()

            # If it is a prefix char, get second part
            if ch in (b"\x00", b"\xe0"):
                _lowerCamelCase     :		List[str] 						=						ch + msvcrt.getch()
                # Translate actual Win chars to bullet char types
                try:
                    _lowerCamelCase     :		Dict 						=						chr(WIN_KEYMAP[cha]	)
                    WIN_CH_BUFFER.append(chr(KEYMAP["""mod_int"""]	)	)
                    WIN_CH_BUFFER.append(__A	)
                    if ord(__A	) in (
                        KEYMAP["insert"] - 1 << 9,
                        KEYMAP["delete"] - 1 << 9,
                        KEYMAP["pg_up"] - 1 << 9,
                        KEYMAP["pg_down"] - 1 << 9,
                    ):
                        WIN_CH_BUFFER.append(chr(126	)	)
                    _lowerCamelCase     :		Any 						=						chr(KEYMAP["""esc"""]	)
                except KeyError:
                    _lowerCamelCase     :		List[Any] 						=						cha[1]
            else:
                _lowerCamelCase     :		List[Any] 						=						ch.decode(__A	)
        else:
            _lowerCamelCase     :		Tuple 						=						WIN_CH_BUFFER.pop(0	)
    elif os.name == "posix":
        import termios
        import tty

        _lowerCamelCase     :		List[str] 						=						sys.stdin.fileno()
        _lowerCamelCase     :		Union[str, Any] 						=						termios.tcgetattr(__A	)
        try:
            tty.setraw(__A	)
            _lowerCamelCase     :		str 						=						sys.stdin.read(1	)
        finally:
            termios.tcsetattr(__A   , termios.TCSADRAIN   , __A	)
    return ch







def 						A__  (					):







    '''simple docstring'''
    _lowerCamelCase     :		List[Any] 						=						get_raw_chars()
    if ord(__A	) in [KEYMAP["interrupt"], KEYMAP["newline"]]:
        return char

    elif ord(__A	) == KEYMAP["esc"]:
        _lowerCamelCase     :		int 						=						get_raw_chars()
        if ord(__A	) == KEYMAP["mod_int"]:
            _lowerCamelCase     :		Optional[Any] 						=						get_raw_chars()
            if ord(__A	) >= KEYMAP["arrow_begin"] - ARROW_KEY_FLAG and ord(__A	) <= KEYMAP["arrow_end"] - ARROW_KEY_FLAG:
                return chr(ord(__A	) + ARROW_KEY_FLAG	)
            else:
                return KEYMAP["undefined"]
        else:
            return get_raw_chars()

    else:
        if char in string.printable:
            return char
        else:
            return KEYMAP["undefined"]





import unittest

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


if is_torch_available():
    import torch

    from transformers import XLMRobertaModel




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





      '''simple docstring'''






      @slow
      def 	_SCREAMING_SNAKE_CASE    (					self     :				Tuple)				->int:


          """simple docstring"""


          _lowerCamelCase     :		Tuple 						=						XLMRobertaModel.from_pretrained("""xlm-roberta-base""")
          _lowerCamelCase     :		Optional[int] 						=						torch.tensor([[0, 581, 1_0269, 83, 9_9942, 136, 6_0742, 23, 70, 8_0583, 1_8276, 2]])
          # The dog is cute and lives in the garden house

          _lowerCamelCase     :		Optional[Any] 						=						torch.Size((1, 12, 768))  # batch_size, sequence_length, embedding_vector_dim
          _lowerCamelCase     :		str 						=						torch.tensor(
              [[-0.0_1_0_1, 0.1_2_1_8, -0.0_8_0_3, 0.0_8_0_1, 0.1_3_2_7, 0.0_7_7_6, -0.1_2_1_5, 0.2_3_8_3, 0.3_3_3_8, 0.3_1_0_6, 0.0_3_0_0, 0.0_2_5_2]])
          #  xlmr = torch.hub.load('pytorch/fairseq', 'xlmr.base')
          #  xlmr.eval()
          #  expected_output_values_last_dim = xlmr.extract_features(input_ids[0])[:, :, -1]
          with torch.no_grad():
              _lowerCamelCase     :		List[str] 						=						model(_UpperCamelCase)["""last_hidden_state"""].detach()
          self.assertEqual(output.shape    ,  _UpperCamelCase)
          # compare the actual values for a slice of last dim
          self.assertTrue(torch.allclose(output[:, :, -1]    ,  _UpperCamelCase    ,  atol=1E-3))




      @slow
      def 	_SCREAMING_SNAKE_CASE    (					self     :				List[Any])				->Optional[Any]:


          """simple docstring"""


          _lowerCamelCase     :		List[Any] 						=						XLMRobertaModel.from_pretrained("""xlm-roberta-large""")
          _lowerCamelCase     :		Optional[Any] 						=						torch.tensor([[0, 581, 1_0269, 83, 9_9942, 136, 6_0742, 23, 70, 8_0583, 1_8276, 2]])
          # The dog is cute and lives in the garden house

          _lowerCamelCase     :		str 						=						torch.Size((1, 12, 1024))  # batch_size, sequence_length, embedding_vector_dim
          _lowerCamelCase     :		Union[str, Any] 						=						torch.tensor(
              [[-0.0_6_9_9, -0.0_3_1_8, 0.0_7_0_5, -0.1_2_4_1, 0.0_9_9_9, -0.0_5_2_0, 0.1_0_0_4, -0.1_8_3_8, -0.4_7_0_4, 0.1_4_3_7, 0.0_8_2_1, 0.0_1_2_6]])
          #  xlmr = torch.hub.load('pytorch/fairseq', 'xlmr.large')
          #  xlmr.eval()
          #  expected_output_values_last_dim = xlmr.extract_features(input_ids[0])[:, :, -1]
          with torch.no_grad():
              _lowerCamelCase     :		int 						=						model(_UpperCamelCase)["""last_hidden_state"""].detach()
          self.assertEqual(output.shape    ,  _UpperCamelCase)
          # compare the actual values for a slice of last dim
          self.assertTrue(torch.allclose(output[:, :, -1]    ,  _UpperCamelCase    ,  atol=1E-3))




