
'''simple docstring'''







import warnings
from dataclasses import dataclass, field
from typing import Optional, Tuple

from .training_args import TrainingArguments
from .utils import cached_property, is_tf_available, logging, requires_backends


__SCREAMING_SNAKE_CASE		:  Any        =      logging.get_logger(__name__)

if is_tf_available():
					import tensorflow as tf
@dataclass
class  SCREAMING_SNAKE_CASE__       (  __UpperCamelCase   ):
	lowercase__	    =							"tf"
	lowercase__	    =							field(
	    default=__UpperCamelCase			,					metadata={"help": "Name of TPU"}			,					)

	lowercase__	    =							field(
	    default=__UpperCamelCase			,					metadata={"help": "Zone of TPU"}			,					)

	lowercase__	    =							field(
	    default=__UpperCamelCase			,					metadata={"help": "Name of Cloud TPU-enabled project"}			,					)

	lowercase__	    =							field(
	    default=1.0			,					metadata={"help": "Power for the Polynomial decay LR scheduler."}			,					)

	lowercase__	    =							field(default=__UpperCamelCase			,					metadata={"help": "Whether to activate the XLA compilation or not"}   )
	@cached_property
	def __lowerCamelCase    (				self			):



					'''simple docstring'''






					requires_backends(self  ,    ["""tf"""]			)
					logger.info("""Tensorflow: setting up strategy"""			)

					__a       :     int								=	tf.config.list_physical_devices("""GPU"""			)

					# Set to float16 at first
					if self.fpaa:
									tf.keras.mixed_precision.set_global_policy("""mixed_float16"""			)

					if self.no_cuda:
									__a       :     int								=	tf.distribute.OneDeviceStrategy(device="""/cpu:0"""			)
					else:
									try:
													if self.tpu_name:
																	__a       :     List[Any]								=	tf.distribute.cluster_resolver.TPUClusterResolver(
																	    self.tpu_name  ,    zone=self.tpu_zone  ,    project=self.gcp_project			)
													else:
																	__a       :     Optional[int]								=	tf.distribute.cluster_resolver.TPUClusterResolver()
									except ValueError:
													if self.tpu_name:
																	raise RuntimeError(f"""Couldn't connect to TPU {self.tpu_name}!"""			)
													else:
																	__a       :     Tuple								=	None

									if tpu:
													# Set to bfloat16 in case of TPU
													if self.fpaa:
																	tf.keras.mixed_precision.set_global_policy("""mixed_bfloat16"""			)

													tf.config.experimental_connect_to_cluster(__UpperCamelCase			)
													tf.tpu.experimental.initialize_tpu_system(__UpperCamelCase			)

													__a       :     Any								=	tf.distribute.TPUStrategy(__UpperCamelCase			)

									elif len(__UpperCamelCase			) == 0:
													__a       :     Optional[Any]								=	tf.distribute.OneDeviceStrategy(device="""/cpu:0"""			)
									elif len(__UpperCamelCase			) == 1:
													__a       :     Optional[int]								=	tf.distribute.OneDeviceStrategy(device="""/gpu:0"""			)
									elif len(__UpperCamelCase			) > 1:
													# If you only want to use a specific subset of GPUs use `CUDA_VISIBLE_DEVICES=0`
													__a       :     Union[str, Any]								=	tf.distribute.MirroredStrategy()
									else:
													raise ValueError("""Cannot find the proper strategy, please check your environment properties."""			)

					return strategy
	@property
	def __lowerCamelCase    (				self			):



					'''simple docstring'''






					requires_backends(self  ,    ["""tf"""]			)
					return self._setup_strategy
	@property
	def __lowerCamelCase    (				self			):



					'''simple docstring'''






					requires_backends(self  ,    ["""tf"""]			)
					return self._setup_strategy.num_replicas_in_sync
	@property
	def __lowerCamelCase    (				self			):



					'''simple docstring'''






					return False  # TF Logging is handled by Keras not the Trainer
	@property
	def __lowerCamelCase    (				self			):



					'''simple docstring'''






					if self.per_gpu_train_batch_size:
									logger.warning(
									    """Using deprecated `--per_gpu_train_batch_size` argument which will be removed in a future """
									    """version. Using `--per_device_train_batch_size` is preferred."""			)
					__a       :     Optional[Any]								=	self.per_gpu_train_batch_size or self.per_device_train_batch_size
					return per_device_batch_size * self.n_replicas
	@property
	def __lowerCamelCase    (				self			):



					'''simple docstring'''






					if self.per_gpu_eval_batch_size:
									logger.warning(
									    """Using deprecated `--per_gpu_eval_batch_size` argument which will be removed in a future """
									    """version. Using `--per_device_eval_batch_size` is preferred."""			)
					__a       :     int								=	self.per_gpu_eval_batch_size or self.per_device_eval_batch_size
					return per_device_batch_size * self.n_replicas

	@property
	def __lowerCamelCase    (				self			):



					'''simple docstring'''






					requires_backends(self  ,    ["""tf"""]			)
					warnings.warn(
					    """The n_gpu argument is deprecated and will be removed in a future version, use n_replicas instead."""  ,    __UpperCamelCase  ,    )
					return self._setup_strategy.num_replicas_in_sync

'''simple docstring'''







import json
import os
import unittest

from transformers.models.gpt_neox_japanese.tokenization_gpt_neox_japanese import (
    VOCAB_FILES_NAMES,
    GPTNeoXJapaneseTokenizer,
)
from transformers.testing_utils import require_tokenizers, slow

from ...test_tokenization_common import TokenizerTesterMixin
@require_tokenizers
class  SCREAMING_SNAKE_CASE__       (  __UpperCamelCase			,					unittest.TestCase   ):
	lowercase__	    =							GPTNeoXJapaneseTokenizer
	lowercase__	    =							False
	lowercase__	    =							{"do_clean_text": False, "add_prefix_space": False}
	def __lowerCamelCase    (				self			):



					'''simple docstring'''






					super().setUp()

					__a       :     Optional[int]								=	[
					    """こん""",
					    """こんに""",
					    """にちは""",
					    """ばんは""",
					    """世界,㔺界""",
					    """、""",
					    """。""",
					    """<BR>""",
					    """<SP>""",
					    """<TAB>""",
					    """<URL>""",
					    """<EMAIL>""",
					    """<TEL>""",
					    """<DATE>""",
					    """<PRICE>""",
					    """<BLOCK>""",
					    """<KIGOU>""",
					    """<U2000U2BFF>""",
					    """<|emoji1|>""",
					    """<unk>""",
					    """<|startoftext|>""",
					    """<|endoftext|>""",
					]
					__a       :     Any								=	{"""emoji""": {"""\ud83d\ude00""": """<|emoji1|>"""}, """emoji_inv""": {"""<|emoji1|>""": """\ud83d\ude00"""}}  # 😀
					__a       :     List[str]								=	{"""unk_token""": """<unk>"""}

					__a       :     Any								=	os.path.join(self.tmpdirname  ,    VOCAB_FILES_NAMES["""vocab_file"""]			)
					__a       :     Tuple								=	os.path.join(self.tmpdirname  ,    VOCAB_FILES_NAMES["""emoji_file"""]			)
					with open(self.vocab_file  ,    """w"""  ,    encoding="""utf-8"""			) as vocab_writer:
									vocab_writer.write("""""".join([x + """\n""" for x in vocab_tokens]			)			)
					with open(self.emoji_file  ,    """w"""			) as emoji_writer:
									emoji_writer.write(json.dumps(__UpperCamelCase			)			)
	def __lowerCamelCase    (				self  ,    **__UpperCamelCase			):



					'''simple docstring'''






					kwargs.update(self.special_tokens_map			)
					return GPTNeoXJapaneseTokenizer.from_pretrained(self.tmpdirname  ,    **__UpperCamelCase			)
	def __lowerCamelCase    (				self  ,    __UpperCamelCase			):



					'''simple docstring'''






					__a       :     Any								=	"""こんにちは、世界。 \nこんばんは、㔺界。😀"""
					__a       :     Optional[int]								=	"""こんにちは、世界。 \nこんばんは、世界。😀"""
					return input_text, output_text
	def __lowerCamelCase    (				self  ,    __UpperCamelCase			):



					'''simple docstring'''






					__a							,	__a       :     List[str]								=	self.get_input_output_texts(__UpperCamelCase			)
					__a       :     List[str]								=	tokenizer.encode(__UpperCamelCase  ,    add_special_tokens=__UpperCamelCase			)
					__a       :     str								=	tokenizer.decode(__UpperCamelCase  ,    clean_up_tokenization_spaces=__UpperCamelCase			)
					return text, ids
	def __lowerCamelCase    (				self			):



					'''simple docstring'''






					pass  # TODO add if relevant
	def __lowerCamelCase    (				self			):



					'''simple docstring'''






					pass  # TODO add if relevant
	def __lowerCamelCase    (				self			):



					'''simple docstring'''






					pass  # TODO add if relevant
	def __lowerCamelCase    (				self			):



					'''simple docstring'''






					__a       :     List[Any]								=	self.get_tokenizer()

					# Testing tokenization
					__a       :     Dict								=	"""こんにちは、世界。　こんばんは、㔺界。"""
					__a       :     Optional[int]								=	["""こん""", """にちは""", """、""", """世界""", """。""", """<SP>""", """こん""", """ばんは""", """、""", """㔺界""", """。"""]
					__a       :     str								=	tokenizer.tokenize(__UpperCamelCase			)
					self.assertListEqual(__UpperCamelCase  ,    __UpperCamelCase			)

					# Testing conversion to ids without special tokens
					__a       :     Optional[Any]								=	[0, 2, 5, 4, 6, 8, 0, 3, 5, 4, 6]
					__a       :     Optional[int]								=	tokenizer.convert_tokens_to_ids(__UpperCamelCase			)
					self.assertListEqual(__UpperCamelCase  ,    __UpperCamelCase			)

					# Testing conversion to ids with special tokens
					__a       :     List[str]								=	tokens + [tokenizer.unk_token]
					__a       :     Dict								=	[0, 2, 5, 4, 6, 8, 0, 3, 5, 4, 6, 19]
					__a       :     Any								=	tokenizer.convert_tokens_to_ids(__UpperCamelCase			)
					self.assertListEqual(__UpperCamelCase  ,    __UpperCamelCase			)
	@slow
	def __lowerCamelCase    (				self			):



					'''simple docstring'''






					__a       :     int								=	self.tokenizer_class.from_pretrained("""abeja/gpt-neox-japanese-2.7b"""			)

					__a       :     Union[str, Any]								=	tokenizer.encode("""ありがとう。"""  ,    add_special_tokens=__UpperCamelCase			)
					__a       :     Dict								=	tokenizer.encode("""どういたしまして。"""  ,    add_special_tokens=__UpperCamelCase			)

					__a       :     Optional[Any]								=	tokenizer.build_inputs_with_special_tokens(__UpperCamelCase			)
					__a       :     int								=	tokenizer.build_inputs_with_special_tokens(__UpperCamelCase  ,    __UpperCamelCase			)

					assert encoded_sentence == ids_a
					assert encoded_pair == ids_a + ids_a
	def __lowerCamelCase    (				self			):



					'''simple docstring'''






					pass

	def __lowerCamelCase    (				self			):



					'''simple docstring'''






					pass