





'''simple docstring'''






import inspect
import os
import unittest

import torch

import accelerate
from accelerate import debug_launcher
from accelerate.test_utils import (
    execute_subprocess_async,
    require_cpu,
    require_multi_gpu,
    require_single_gpu,
    test_sync,
)
from accelerate.utils import patch_environment







class       lowerCamelCase       (    unittest.TestCase	):


					def  SCREAMING_SNAKE_CASE_		(       self						:	List[Any]							):





											'''simple docstring'''





											_snake_case: Optional[int]	       =		inspect.getfile(accelerate.test_utils							)
											_snake_case: int	       =		os.path.sep.join(mod_file.split(os.path.sep							)[:-1] + ['scripts', 'test_sync.py']							)


					@require_cpu
					def  SCREAMING_SNAKE_CASE_		(       self						:	List[Any]							):





											'''simple docstring'''





											debug_launcher(test_sync.main							,  num_processes=1							)


					@require_cpu
					def  SCREAMING_SNAKE_CASE_		(       self						:	List[str]							):





											'''simple docstring'''





											debug_launcher(test_sync.main							)


					@require_single_gpu
					def  SCREAMING_SNAKE_CASE_		(       self						:	Union[str, Any]							):





											'''simple docstring'''





											test_sync.main()




					@require_multi_gpu
					def  SCREAMING_SNAKE_CASE_		(       self						:	Any							):





											'''simple docstring'''





											print(f'''Found {torch.cuda.device_count()} devices.'''							)
											_snake_case: Dict	       =		["torchrun", f'''--nproc_per_node={torch.cuda.device_count()}''', self.test_file_path]
											with patch_environment(omp_num_threads=1							):
																	execute_subprocess_async(_UpperCAmelCase							,  env=os.environ.copy()							)











'''simple docstring'''






import os
import unittest

from transformers.models.bertweet.tokenization_bertweet import VOCAB_FILES_NAMES, BertweetTokenizer

from ...test_tokenization_common import TokenizerTesterMixin



class    A						(					SCREAMING_SNAKE_CASE__     ,				unittest.TestCase						):




				'''simple docstring'''





				A       =							BertweetTokenizer
				A       =							False
				def 			a_			(self     )      ->			Any:
							super().setUp()

							# Adapted from Sennrich et al. 2015 and https://github.com/rsennrich/subword-nmt
							__UpperCamelCase :     str										=  ["I", "m", "V@@", "R@@", "r", "e@@"]
							__UpperCamelCase :     int										=  dict(zip(_UpperCAmelCase					,    range(len(_UpperCAmelCase     )     )     )     )
							__UpperCamelCase :     List[Any]										=  ["#version: 0.2", "a m</w>"]
							__UpperCamelCase :     str										=  {"unk_token": "<unk>"}

							__UpperCamelCase :     Any										=  os.path.join(self.tmpdirname					,    VOCAB_FILES_NAMES["vocab_file"]     )
							__UpperCamelCase :     Tuple										=  os.path.join(self.tmpdirname					,    VOCAB_FILES_NAMES["merges_file"]     )
							with open(self.vocab_file					,    "w"					,    encoding="utf-8"     ) as fp:
										for token in vocab_tokens:
													fp.write(f"{token} {vocab_tokens[token]}\n"     )
							with open(self.merges_file					,    "w"					,    encoding="utf-8"     ) as fp:
										fp.write("\n".join(_UpperCAmelCase     )     )
				def 			a_			(self					,    **_UpperCAmelCase     )      ->			str:
							kwargs.update(self.special_tokens_map     )
							return BertweetTokenizer.from_pretrained(self.tmpdirname					,    **_UpperCAmelCase     )
				def 			a_			(self					,    _UpperCAmelCase     )      ->			Dict:
							__UpperCamelCase :     Dict										=  "I am VinAI Research"
							__UpperCamelCase :     Any										=  "I <unk> m V<unk> <unk> <unk> I Re<unk> e<unk> <unk> <unk> <unk>"
							return input_text, output_text





				def 			a_			(self     )      ->			str:
							__UpperCamelCase :     Tuple										=  BertweetTokenizer(self.vocab_file					,    self.merges_file					,    **self.special_tokens_map     )
							__UpperCamelCase :     Union[str, Any]										=  "I am VinAI Research"
							__UpperCamelCase :     List[str]										=  "I a@@ m V@@ i@@ n@@ A@@ I R@@ e@@ s@@ e@@ a@@ r@@ c@@ h".split()
							__UpperCamelCase :     Optional[int]										=  tokenizer.tokenize(_UpperCAmelCase     )
							self.assertListEqual(_UpperCAmelCase					,    _UpperCAmelCase     )

							__UpperCamelCase :     Optional[Any]										=  tokens + [tokenizer.unk_token]

							__UpperCamelCase :     Any										=  [4, 3, 5, 6, 3, 3, 3, 4, 7, 9, 3, 9, 3, 3, 3, 3, 3]
							self.assertListEqual(tokenizer.convert_tokens_to_ids(_UpperCAmelCase     )					,    _UpperCAmelCase     )



