

"""simple docstring"""




import unittest
import warnings
from dataclasses import dataclass

from transformers.convert_slow_tokenizer import SpmConverter
from transformers.testing_utils import get_tests_dir





@dataclass
class 				lowerCamelCase  :
			lowerCamelCase__				:						str





class 				lowerCamelCase  (unittest.TestCase     ):

			def    SCREAMING_SNAKE_CASE			(   self			:  List[str]    )				->      List[str]:
						SCREAMING_SNAKE_CASE__									= get_tests_dir("""fixtures/test_sentencepiece.model"""    )
						SCREAMING_SNAKE_CASE__									= get_tests_dir("""fixtures/test_sentencepiece_with_bytefallback.model"""    )

						SCREAMING_SNAKE_CASE__									= FakeOriginalTokenizer(vocab_file=__UpperCAmelCase    )

						with warnings.catch_warnings(record=__UpperCAmelCase    ) as w:
									SCREAMING_SNAKE_CASE__									= SpmConverter(__UpperCAmelCase    )
						self.assertEqual(len(__UpperCAmelCase    )      ,			0    )

						SCREAMING_SNAKE_CASE__									= FakeOriginalTokenizer(vocab_file=__UpperCAmelCase    )

						with warnings.catch_warnings(record=__UpperCAmelCase    ) as w:
									SCREAMING_SNAKE_CASE__									= SpmConverter(__UpperCAmelCase    )
						self.assertEqual(len(__UpperCAmelCase    )      ,			1    )

						self.assertIn(
						    """The sentencepiece tokenizer that you are converting to a fast tokenizer uses the byte fallback option"""
						    """ which is not implemented in the fast tokenizers."""      ,			str(w[0].message    )      ,			)





"""simple docstring"""




import importlib.metadata
import subprocess
import sys

def 		A    (       snake_case__ = False      ):




			'''simple docstring'''


			SCREAMING_SNAKE_CASE__									= False
			if "IPython" in sys.modules:
						SCREAMING_SNAKE_CASE__									= """google.colab""" in str(sys.modules["""IPython"""].get_ipython()      )

			if in_colab:
						if upgrade:
									SCREAMING_SNAKE_CASE__									= ["""pip""", """install""", """-U""", """torch"""]
									subprocess.run(snake_case__						,			check=snake_case__      )
						# get the current version of torch
						SCREAMING_SNAKE_CASE__									= importlib.metadata.version("""torch"""      )
						SCREAMING_SNAKE_CASE__									= torch_version[: torch_version.rindex("""."""      )]
						SCREAMING_SNAKE_CASE__									= f"""https://storage.googleapis.com/tpu-pytorch/wheels/colab/torch_xla-{torch_version_trunc}-cp37-cp37m-linux_x86_64.whl"""
						SCREAMING_SNAKE_CASE__									= ["""pip""", """install""", xla_wheel]
						subprocess.run(snake_case__						,			check=snake_case__      )
			else:
						raise RuntimeError("""`install_xla` utility works only on google colab."""      )


