



"""simple docstring"""

import inspect
import tempfile
from collections import OrderedDict, UserDict
from collections.abc import MutableMapping
from contextlib import ExitStack, contextmanager
from dataclasses import fields
from enum import Enum
from typing import Any, ContextManager, List, Tuple

import numpy as np

from .import_utils import is_flax_available, is_tf_available, is_torch_available, is_torch_fx_proxy


if is_flax_available():
			import jax.numpy as jnp







class    __lowercase     (					_UpperCAmelCase):







						"""simple docstring"""







						def __get__(self   ,		lowercase__   ,		lowercase__=None       ):
											# See docs.python.org/3/howto/descriptor.html#properties
											if obj is None:
																return self
											if self.fget is None:
																raise AttributeError("""unreadable attribute"""       )
											snake_case_					:		int 					=					"""__cached_""" + self.fget.__name__
											snake_case_					:		str 					=					getattr(lowercase__   ,		lowercase__   ,		lowercase__       )
											if cached is None:
																snake_case_					:		Any 					=					self.fget(lowercase__       )
																setattr(lowercase__   ,		lowercase__   ,		lowercase__       )
											return cached







def 							SCREAMING_SNAKE_CASE__      (		SCREAMING_SNAKE_CASE__ :  Dict			):



					"""simple docstring"""





					snake_case_					:		List[Any] 					=					val.lower()
					if val in {"y", "yes", "t", "true", "on", "1"}:
										return 1
					if val in {"n", "no", "f", "false", "off", "0"}:
										return 0
					raise ValueError(f'invalid truth value {val!r}'			)







def 							SCREAMING_SNAKE_CASE__      (		SCREAMING_SNAKE_CASE__ :  Optional[Any]			):



					"""simple docstring"""





					if is_torch_fx_proxy(SCREAMING_SNAKE_CASE__			):
										return True
					if is_torch_available():
										import torch

										if isinstance(SCREAMING_SNAKE_CASE__				,    torch.Tensor			):
															return True
					if is_tf_available():
										import tensorflow as tf

										if isinstance(SCREAMING_SNAKE_CASE__				,    tf.Tensor			):
															return True

					if is_flax_available():
										import jax.numpy as jnp
										from jax.core import Tracer

										if isinstance(SCREAMING_SNAKE_CASE__				,    (jnp.ndarray, Tracer)			):
															return True

					return isinstance(SCREAMING_SNAKE_CASE__				,    np.ndarray			)







def 							SCREAMING_SNAKE_CASE__      (		SCREAMING_SNAKE_CASE__ :  List[Any]			):



					"""simple docstring"""





					return isinstance(SCREAMING_SNAKE_CASE__				,    np.ndarray			)







def 							SCREAMING_SNAKE_CASE__      (		SCREAMING_SNAKE_CASE__ :  Any			):



					"""simple docstring"""





					return _is_numpy(SCREAMING_SNAKE_CASE__			)







def 							SCREAMING_SNAKE_CASE__      (		SCREAMING_SNAKE_CASE__ :  List[str]			):



					"""simple docstring"""





					import torch

					return isinstance(SCREAMING_SNAKE_CASE__				,    torch.Tensor			)







def 							SCREAMING_SNAKE_CASE__      (		SCREAMING_SNAKE_CASE__ :  List[Any]			):



					"""simple docstring"""





					return False if not is_torch_available() else _is_torch(SCREAMING_SNAKE_CASE__			)







def 							SCREAMING_SNAKE_CASE__      (		SCREAMING_SNAKE_CASE__ :  Optional[int]			):



					"""simple docstring"""





					import torch

					return isinstance(SCREAMING_SNAKE_CASE__				,    torch.device			)







def 							SCREAMING_SNAKE_CASE__      (		SCREAMING_SNAKE_CASE__ :  Union[str, Any]			):



					"""simple docstring"""





					return False if not is_torch_available() else _is_torch_device(SCREAMING_SNAKE_CASE__			)







def 							SCREAMING_SNAKE_CASE__      (		SCREAMING_SNAKE_CASE__ :  List[Any]			):



					"""simple docstring"""





					import torch

					if isinstance(SCREAMING_SNAKE_CASE__				,    SCREAMING_SNAKE_CASE__			):
										if hasattr(SCREAMING_SNAKE_CASE__				,    SCREAMING_SNAKE_CASE__			):
															snake_case_					:		List[Any] 					=					getattr(SCREAMING_SNAKE_CASE__				,    SCREAMING_SNAKE_CASE__			)
										else:
															return False
					return isinstance(SCREAMING_SNAKE_CASE__				,    torch.dtype			)







def 							SCREAMING_SNAKE_CASE__      (		SCREAMING_SNAKE_CASE__ :  int			):



					"""simple docstring"""





					return False if not is_torch_available() else _is_torch_dtype(SCREAMING_SNAKE_CASE__			)







def 							SCREAMING_SNAKE_CASE__      (		SCREAMING_SNAKE_CASE__ :  Union[str, Any]			):



					"""simple docstring"""





					import tensorflow as tf

					return isinstance(SCREAMING_SNAKE_CASE__				,    tf.Tensor			)







def 							SCREAMING_SNAKE_CASE__      (		SCREAMING_SNAKE_CASE__ :  Any			):



					"""simple docstring"""





					return False if not is_tf_available() else _is_tensorflow(SCREAMING_SNAKE_CASE__			)







def 							SCREAMING_SNAKE_CASE__      (		SCREAMING_SNAKE_CASE__ :  str			):



					"""simple docstring"""





					import tensorflow as tf

					# the `is_symbolic_tensor` predicate is only available starting with TF 2.14
					if hasattr(SCREAMING_SNAKE_CASE__				,    """is_symbolic_tensor"""			):
										return tf.is_symbolic_tensor(SCREAMING_SNAKE_CASE__			)
					return type(SCREAMING_SNAKE_CASE__			) == tf.Tensor







def 							SCREAMING_SNAKE_CASE__      (		SCREAMING_SNAKE_CASE__ :  Optional[Any]			):



					"""simple docstring"""





					return False if not is_tf_available() else _is_tf_symbolic_tensor(SCREAMING_SNAKE_CASE__			)







def 							SCREAMING_SNAKE_CASE__      (		SCREAMING_SNAKE_CASE__ :  int			):



					"""simple docstring"""





					import jax.numpy as jnp  # noqa: F811

					return isinstance(SCREAMING_SNAKE_CASE__				,    jnp.ndarray			)







def 							SCREAMING_SNAKE_CASE__      (		SCREAMING_SNAKE_CASE__ :  Union[str, Any]			):



					"""simple docstring"""





					return False if not is_flax_available() else _is_jax(SCREAMING_SNAKE_CASE__			)







def 							SCREAMING_SNAKE_CASE__      (		SCREAMING_SNAKE_CASE__ :  Tuple			):



					"""simple docstring"""





					if isinstance(SCREAMING_SNAKE_CASE__				,    (dict, UserDict)			):
										return {k: to_py_obj(SCREAMING_SNAKE_CASE__			) for k, v in obj.items()}
					elif isinstance(SCREAMING_SNAKE_CASE__				,    (list, tuple)			):
										return [to_py_obj(SCREAMING_SNAKE_CASE__			) for o in obj]
					elif is_tf_tensor(SCREAMING_SNAKE_CASE__			):
										return obj.numpy().tolist()
					elif is_torch_tensor(SCREAMING_SNAKE_CASE__			):
										return obj.detach().cpu().tolist()
					elif is_jax_tensor(SCREAMING_SNAKE_CASE__			):
										return np.asarray(SCREAMING_SNAKE_CASE__			).tolist()
					elif isinstance(SCREAMING_SNAKE_CASE__				,    (np.ndarray, np.number)			):  # tolist also works on 0d np arrays
										return obj.tolist()
					else:
										return obj







def 							SCREAMING_SNAKE_CASE__      (		SCREAMING_SNAKE_CASE__ :  Tuple			):



					"""simple docstring"""





					if isinstance(SCREAMING_SNAKE_CASE__				,    (dict, UserDict)			):
										return {k: to_numpy(SCREAMING_SNAKE_CASE__			) for k, v in obj.items()}
					elif isinstance(SCREAMING_SNAKE_CASE__				,    (list, tuple)			):
										return np.array(SCREAMING_SNAKE_CASE__			)
					elif is_tf_tensor(SCREAMING_SNAKE_CASE__			):
										return obj.numpy()
					elif is_torch_tensor(SCREAMING_SNAKE_CASE__			):
										return obj.detach().cpu().numpy()
					elif is_jax_tensor(SCREAMING_SNAKE_CASE__			):
										return np.asarray(SCREAMING_SNAKE_CASE__			)
					else:
										return obj







class    __lowercase     (					_UpperCAmelCase):







						"""simple docstring"""







						def 						__UpperCamelCase							(self       ):
											snake_case_					:		str 					=					fields(self       )

											# Safety and consistency checks
											if not len(lowercase__       ):
																raise ValueError(f'{self.__class__.__name__} has no fields.'       )
											if not all(field.default is None for field in class_fields[1:]       ):
																raise ValueError(f'{self.__class__.__name__} should not have more than one required field.'       )

											snake_case_					:		Union[str, Any] 					=					getattr(self   ,		class_fields[0].name       )
											snake_case_					:		Any 					=					all(getattr(self   ,		field.name       ) is None for field in class_fields[1:]       )

											if other_fields_are_none and not is_tensor(lowercase__       ):
																if isinstance(lowercase__   ,		lowercase__       ):
																					snake_case_					:		Optional[Any] 					=					first_field.items()
																					snake_case_					:		int 					=					True
																else:
																					try:
																										snake_case_					:		Any 					=					iter(lowercase__       )
																										snake_case_					:		str 					=					True
																					except TypeError:
																										snake_case_					:		List[Any] 					=					False

            # if we provided an iterator as first field and the iterator is a (key, value) iterator
            # set the associated fields
																if first_field_iterator:
																					for idx, element in enumerate(lowercase__       ):
																										if (
																										    not isinstance(lowercase__   ,		(list, tuple)       )
																										    or not len(lowercase__       ) == 2
																										    or not isinstance(element[0]   ,		lowercase__       )
																										):
																															if idx == 0:
																																				# If we do not have an iterator of key/values, set it as attribute
																																				snake_case_					:		Dict 					=					first_field
																															else:
																																				# If we have a mixed iterator, raise an error
																																				raise ValueError(
																																				    f'Cannot set key/value for {element}. It needs to be a tuple (key, value).'       )
																															break
																										setattr(self   ,		element[0]   ,		element[1]       )
																										if element[1] is not None:
																															snake_case_					:		Union[str, Any] 					=					element[1]
																elif first_field is not None:
																					snake_case_					:		Tuple 					=					first_field
											else:
																for field in class_fields:
																					snake_case_					:		Optional[int] 					=					getattr(self   ,		field.name       )
																					if v is not None:
																										snake_case_					:		Optional[int] 					=					v







						def __delitem__(self   ,		*lowercase__   ,		**lowercase__       ):
											raise Exception(f'You cannot use ``__delitem__`` on a {self.__class__.__name__} instance.'       )







						def 						__UpperCamelCase							(self   ,		*lowercase__   ,		**lowercase__       ):
											raise Exception(f'You cannot use ``setdefault`` on a {self.__class__.__name__} instance.'       )







						def 						__UpperCamelCase							(self   ,		*lowercase__   ,		**lowercase__       ):
											raise Exception(f'You cannot use ``pop`` on a {self.__class__.__name__} instance.'       )







						def 						__UpperCamelCase							(self   ,		*lowercase__   ,		**lowercase__       ):
											raise Exception(f'You cannot use ``update`` on a {self.__class__.__name__} instance.'       )







						def __getitem__(self   ,		lowercase__       ):
											if isinstance(lowercase__   ,		lowercase__       ):
																snake_case_					:		Union[str, Any] 					=					dict(self.items()       )
																return inner_dict[k]
											else:
																return self.to_tuple()[k]







						def __setattr__(self   ,		lowercase__   ,		lowercase__       ):
											if name in self.keys() and value is not None:
																# Don't call self.__setitem__ to avoid recursion errors
																super().__setitem__(lowercase__   ,		lowercase__       )
											super().__setattr__(lowercase__   ,		lowercase__       )







						def __setitem__(self   ,		lowercase__   ,		lowercase__       ):
											# Will raise a KeyException if needed
											super().__setitem__(lowercase__   ,		lowercase__       )
											# Don't call self.__setattr__ to avoid recursion errors
											super().__setattr__(lowercase__   ,		lowercase__       )







						def 						__UpperCamelCase							(self       ):
											return tuple(self[k] for k in self.keys()       )







class    __lowercase     (					_UpperCAmelCase					,    _UpperCAmelCase):







						"""simple docstring"""







						@classmethod
						def 						__UpperCamelCase							(cls   ,		lowercase__       ):
											raise ValueError(
											    f'{value} is not a valid {cls.__name__}, please select one of {list(cls._valueamember_map_.keys()       )}'       )







class    __lowercase     (					_UpperCAmelCase):







						"""simple docstring"""







						_A		:							str							       =		"""longest"""
						_A		:							Optional[Any]							       =		"""max_length"""
						_A		:							Optional[int]							       =		"""do_not_pad"""







class    __lowercase     (					_UpperCAmelCase):







						"""simple docstring"""







						_A		:							Any							       =		"""pt"""
						_A		:							Tuple							       =		"""tf"""
						_A		:							Any							       =		"""np"""
						_A		:							Dict							       =		"""jax"""







class    __lowercase     :







						"""simple docstring"""







						def __init__(self   ,		lowercase__       ):
											snake_case_					:		Any 					=					context_managers
											snake_case_					:		int 					=					ExitStack()







						def __enter__(self       ):
											for context_manager in self.context_managers:
																self.stack.enter_context(lowercase__       )







						def __exit__(self   ,		*lowercase__   ,		**lowercase__       ):
											self.stack.__exit__(*lowercase__   ,		**lowercase__       )







def 							SCREAMING_SNAKE_CASE__      (		SCREAMING_SNAKE_CASE__ :  Optional[Any]			):



					"""simple docstring"""





					snake_case_					:		Dict 					=					infer_framework(SCREAMING_SNAKE_CASE__			)
					if framework == "tf":
										snake_case_					:		Dict 					=					inspect.signature(model_class.call			)  # TensorFlow models
					elif framework == "pt":
										snake_case_					:		Union[str, Any] 					=					inspect.signature(model_class.forward			)  # PyTorch models
					else:
										snake_case_					:		List[str] 					=					inspect.signature(model_class.__call__			)  # Flax models

					for p in signature.parameters:
										if p == "return_loss" and signature.parameters[p].default is True:
															return True

					return False







def 							SCREAMING_SNAKE_CASE__      (		SCREAMING_SNAKE_CASE__ :  Union[str, Any]			):



					"""simple docstring"""





					snake_case_					:		Optional[int] 					=					model_class.__name__
					snake_case_					:		Tuple 					=					infer_framework(SCREAMING_SNAKE_CASE__			)
					if framework == "tf":
										snake_case_					:		int 					=					inspect.signature(model_class.call			)  # TensorFlow models
					elif framework == "pt":
										snake_case_					:		List[str] 					=					inspect.signature(model_class.forward			)  # PyTorch models
					else:
										snake_case_					:		List[Any] 					=					inspect.signature(model_class.__call__			)  # Flax models

					if "QuestionAnswering" in model_name:
										return [p for p in signature.parameters if "label" in p or p in ("start_positions", "end_positions")]
					else:
										return [p for p in signature.parameters if "label" in p]







def 							SCREAMING_SNAKE_CASE__      (		SCREAMING_SNAKE_CASE__ :  MutableMapping				,    SCREAMING_SNAKE_CASE__ :  str = ""				,    SCREAMING_SNAKE_CASE__ :  str = "."			):



					"""simple docstring"""





					def _flatten_dict(SCREAMING_SNAKE_CASE__ :  int				,    SCREAMING_SNAKE_CASE__ :  Optional[int]=""				,    SCREAMING_SNAKE_CASE__ :  List[Any]="."			):
										for k, v in d.items():
															snake_case_					:		Tuple 					=					str(SCREAMING_SNAKE_CASE__			) + delimiter + str(SCREAMING_SNAKE_CASE__			) if parent_key else k
															if v and isinstance(SCREAMING_SNAKE_CASE__				,    SCREAMING_SNAKE_CASE__			):
																				yield from flatten_dict(SCREAMING_SNAKE_CASE__				,    SCREAMING_SNAKE_CASE__				,    delimiter=SCREAMING_SNAKE_CASE__			).items()
															else:
																				yield key, v

					return dict(_flatten_dict(SCREAMING_SNAKE_CASE__				,    SCREAMING_SNAKE_CASE__				,    SCREAMING_SNAKE_CASE__			)			)







@contextmanager
def 							SCREAMING_SNAKE_CASE__      (		SCREAMING_SNAKE_CASE__ :  List[Any]				,    SCREAMING_SNAKE_CASE__ :  bool = False			):



					"""simple docstring"""





					if use_temp_dir:
										with tempfile.TemporaryDirectory() as tmp_dir:
															yield tmp_dir
					else:
										yield working_dir







def 							SCREAMING_SNAKE_CASE__      (		SCREAMING_SNAKE_CASE__ :  List[str]				,    SCREAMING_SNAKE_CASE__ :  Union[str, Any]=None			):



					"""simple docstring"""





					if is_numpy_array(SCREAMING_SNAKE_CASE__			):
										return np.transpose(SCREAMING_SNAKE_CASE__				,    axes=SCREAMING_SNAKE_CASE__			)
					elif is_torch_tensor(SCREAMING_SNAKE_CASE__			):
										return array.T if axes is None else array.permute(*SCREAMING_SNAKE_CASE__			)
					elif is_tf_tensor(SCREAMING_SNAKE_CASE__			):
										import tensorflow as tf

										return tf.transpose(SCREAMING_SNAKE_CASE__				,    perm=SCREAMING_SNAKE_CASE__			)
					elif is_jax_tensor(SCREAMING_SNAKE_CASE__			):
										return jnp.transpose(SCREAMING_SNAKE_CASE__				,    axes=SCREAMING_SNAKE_CASE__			)
					else:
										raise ValueError(f'Type not supported for transpose: {type(SCREAMING_SNAKE_CASE__			)}.'			)







def 							SCREAMING_SNAKE_CASE__      (		SCREAMING_SNAKE_CASE__ :  int				,    SCREAMING_SNAKE_CASE__ :  Optional[Any]			):



					"""simple docstring"""





					if is_numpy_array(SCREAMING_SNAKE_CASE__			):
										return np.reshape(SCREAMING_SNAKE_CASE__				,    SCREAMING_SNAKE_CASE__			)
					elif is_torch_tensor(SCREAMING_SNAKE_CASE__			):
										return array.reshape(*SCREAMING_SNAKE_CASE__			)
					elif is_tf_tensor(SCREAMING_SNAKE_CASE__			):
										import tensorflow as tf

										return tf.reshape(SCREAMING_SNAKE_CASE__				,    SCREAMING_SNAKE_CASE__			)
					elif is_jax_tensor(SCREAMING_SNAKE_CASE__			):
										return jnp.reshape(SCREAMING_SNAKE_CASE__				,    SCREAMING_SNAKE_CASE__			)
					else:
										raise ValueError(f'Type not supported for reshape: {type(SCREAMING_SNAKE_CASE__			)}.'			)







def 							SCREAMING_SNAKE_CASE__      (		SCREAMING_SNAKE_CASE__ :  Tuple				,    SCREAMING_SNAKE_CASE__ :  List[str]=None			):



					"""simple docstring"""





					if is_numpy_array(SCREAMING_SNAKE_CASE__			):
										return np.squeeze(SCREAMING_SNAKE_CASE__				,    axis=SCREAMING_SNAKE_CASE__			)
					elif is_torch_tensor(SCREAMING_SNAKE_CASE__			):
										return array.squeeze() if axis is None else array.squeeze(dim=SCREAMING_SNAKE_CASE__			)
					elif is_tf_tensor(SCREAMING_SNAKE_CASE__			):
										import tensorflow as tf

										return tf.squeeze(SCREAMING_SNAKE_CASE__				,    axis=SCREAMING_SNAKE_CASE__			)
					elif is_jax_tensor(SCREAMING_SNAKE_CASE__			):
										return jnp.squeeze(SCREAMING_SNAKE_CASE__				,    axis=SCREAMING_SNAKE_CASE__			)
					else:
										raise ValueError(f'Type not supported for squeeze: {type(SCREAMING_SNAKE_CASE__			)}.'			)







def 							SCREAMING_SNAKE_CASE__      (		SCREAMING_SNAKE_CASE__ :  List[str]				,    SCREAMING_SNAKE_CASE__ :  Optional[int]			):



					"""simple docstring"""





					if is_numpy_array(SCREAMING_SNAKE_CASE__			):
										return np.expand_dims(SCREAMING_SNAKE_CASE__				,    SCREAMING_SNAKE_CASE__			)
					elif is_torch_tensor(SCREAMING_SNAKE_CASE__			):
										return array.unsqueeze(dim=SCREAMING_SNAKE_CASE__			)
					elif is_tf_tensor(SCREAMING_SNAKE_CASE__			):
										import tensorflow as tf

										return tf.expand_dims(SCREAMING_SNAKE_CASE__				,    axis=SCREAMING_SNAKE_CASE__			)
					elif is_jax_tensor(SCREAMING_SNAKE_CASE__			):
										return jnp.expand_dims(SCREAMING_SNAKE_CASE__				,    axis=SCREAMING_SNAKE_CASE__			)
					else:
										raise ValueError(f'Type not supported for expand_dims: {type(SCREAMING_SNAKE_CASE__			)}.'			)







def 							SCREAMING_SNAKE_CASE__      (		SCREAMING_SNAKE_CASE__ :  List[str]			):



					"""simple docstring"""





					if is_numpy_array(SCREAMING_SNAKE_CASE__			):
										return np.size(SCREAMING_SNAKE_CASE__			)
					elif is_torch_tensor(SCREAMING_SNAKE_CASE__			):
										return array.numel()
					elif is_tf_tensor(SCREAMING_SNAKE_CASE__			):
										import tensorflow as tf

										return tf.size(SCREAMING_SNAKE_CASE__			)
					elif is_jax_tensor(SCREAMING_SNAKE_CASE__			):
										return array.size
					else:
										raise ValueError(f'Type not supported for expand_dims: {type(SCREAMING_SNAKE_CASE__			)}.'			)







def 							SCREAMING_SNAKE_CASE__      (		SCREAMING_SNAKE_CASE__ :  Union[str, Any]				,    SCREAMING_SNAKE_CASE__ :  List[str]			):



					"""simple docstring"""





					for key, value in auto_map.items():
										if isinstance(SCREAMING_SNAKE_CASE__				,    (tuple, list)			):
															snake_case_					:		Dict 					=					[f'{repo_id}--{v}' if (v is not None and """--""" not in v) else v for v in value]
										elif value is not None and "--" not in value:
															snake_case_					:		Union[str, Any] 					=					f'{repo_id}--{value}'

					return auto_map







def 							SCREAMING_SNAKE_CASE__      (		SCREAMING_SNAKE_CASE__ :  Tuple			):



					"""simple docstring"""





					for base_class in inspect.getmro(SCREAMING_SNAKE_CASE__			):
										snake_case_					:		Dict 					=					base_class.__module__
										snake_case_					:		int 					=					base_class.__name__
										if module.startswith("""tensorflow"""			) or module.startswith("""keras"""			) or name == "TFPreTrainedModel":
															return "tf"
										elif module.startswith("""torch"""			) or name == "PreTrainedModel":
															return "pt"
										elif module.startswith("""flax"""			) or module.startswith("""jax"""			) or name == "FlaxPreTrainedModel":
															return "flax"
					else:
										raise TypeError(f'Could not infer framework from class {model_class}.'			)









"""simple docstring"""

import tempfile
import unittest
from pathlib import Path
from shutil import copyfile

from transformers import BatchEncoding, MarianTokenizer
from transformers.testing_utils import get_tests_dir, require_sentencepiece, slow
from transformers.utils import is_sentencepiece_available, is_tf_available, is_torch_available


if is_sentencepiece_available():
			from transformers.models.marian.tokenization_marian import VOCAB_FILES_NAMES, save_json

from ...test_tokenization_common import TokenizerTesterMixin


a_			   =					get_tests_dir('''fixtures/test_sentencepiece.model''')

a_			   =					{'''target_lang''': '''fi''', '''source_lang''': '''en'''}
a_			   =					'''>>zh<<'''
a_			   =					'''Helsinki-NLP/'''

if is_torch_available():
			a_			   =					'''pt'''
elif is_tf_available():
			a_			   =					'''tf'''
else:
			a_			   =					'''jax'''







@require_sentencepiece
class    __lowercase     (					_UpperCAmelCase					,    unittest.TestCase):







						"""simple docstring"""







						_A		:							str							       =		MarianTokenizer
						_A		:							List[str]							       =		False
						_A		:							List[str]							       =		True







						def 						__UpperCamelCase							(self       ):
											super().setUp()
											snake_case_					:		Optional[int] 					=					["""</s>""", """<unk>""", """▁This""", """▁is""", """▁a""", """▁t""", """est""", """\u0120""", """<pad>"""]
											snake_case_					:		Any 					=					dict(zip(lowercase__   ,		range(len(lowercase__       )       )       )       )
											snake_case_					:		Any 					=					Path(self.tmpdirname       )
											save_json(lowercase__   ,		save_dir / VOCAB_FILES_NAMES["""vocab"""]       )
											save_json(lowercase__   ,		save_dir / VOCAB_FILES_NAMES["""tokenizer_config_file"""]       )
											if not (save_dir / VOCAB_FILES_NAMES["source_spm"]).exists():
																copyfile(lowercase__   ,		save_dir / VOCAB_FILES_NAMES["""source_spm"""]       )
																copyfile(lowercase__   ,		save_dir / VOCAB_FILES_NAMES["""target_spm"""]       )

											snake_case_					:		Optional[Any] 					=					MarianTokenizer.from_pretrained(self.tmpdirname       )
											tokenizer.save_pretrained(self.tmpdirname       )







						def 						__UpperCamelCase							(self   ,		**lowercase__       ):
											return MarianTokenizer.from_pretrained(self.tmpdirname   ,		**lowercase__       )







						def 						__UpperCamelCase							(self   ,		lowercase__       ):
											return (
											    "This is a test",
											    "This is a test",
											)







						def 						__UpperCamelCase							(self       ):
											snake_case_					:		Union[str, Any] 					=					"""</s>"""
											snake_case_					:		Tuple 					=					0

											self.assertEqual(self.get_tokenizer()._convert_token_to_id(lowercase__       )   ,		lowercase__       )
											self.assertEqual(self.get_tokenizer()._convert_id_to_token(lowercase__       )   ,		lowercase__       )







						def 						__UpperCamelCase							(self       ):
											snake_case_					:		List[str] 					=					list(self.get_tokenizer().get_vocab().keys()       )

											self.assertEqual(vocab_keys[0]   ,		"""</s>"""       )
											self.assertEqual(vocab_keys[1]   ,		"""<unk>"""       )
											self.assertEqual(vocab_keys[-1]   ,		"""<pad>"""       )
											self.assertEqual(len(lowercase__       )   ,		9       )







						def 						__UpperCamelCase							(self       ):
											self.assertEqual(self.get_tokenizer().vocab_size   ,		9       )







						def 						__UpperCamelCase							(self       ):
											snake_case_					:		Any 					=					MarianTokenizer.from_pretrained(f'{ORG_NAME}opus-mt-en-de'       )
											snake_case_					:		Tuple 					=					en_de_tokenizer(["""I am a small frog"""]   ,		return_tensors=lowercase__       )
											self.assertIsInstance(lowercase__   ,		lowercase__       )
											snake_case_					:		Dict 					=					[38, 1_21, 14, 6_97, 3_88_48, 0]
											self.assertListEqual(lowercase__   ,		batch.input_ids[0]       )

											snake_case_					:		Tuple 					=					tempfile.mkdtemp()
											en_de_tokenizer.save_pretrained(lowercase__       )
											snake_case_					:		str 					=					[x.name for x in Path(lowercase__       ).glob("""*"""       )]
											self.assertIn("""source.spm"""   ,		lowercase__       )
											MarianTokenizer.from_pretrained(lowercase__       )







						def 						__UpperCamelCase							(self       ):
											snake_case_					:		Union[str, Any] 					=					self.get_tokenizer()

											snake_case_					:		List[str] 					=					tok(
											    ["""I am a small frog""" * 10_00, """I am a small frog"""]   ,		padding=lowercase__   ,		truncation=lowercase__   ,		return_tensors=lowercase__       )
											self.assertIsInstance(lowercase__   ,		lowercase__       )
											self.assertEqual(batch.input_ids.shape   ,		(2, 5_12)       )







						def 						__UpperCamelCase							(self       ):
											snake_case_					:		Tuple 					=					self.get_tokenizer()
											snake_case_					:		Tuple 					=					tok(["""I am a tiny frog""", """I am a small frog"""]   ,		padding=lowercase__   ,		return_tensors=lowercase__       )
											self.assertIsInstance(lowercase__   ,		lowercase__       )
											self.assertEqual(batch_smaller.input_ids.shape   ,		(2, 10)       )







						@slow
						def 						__UpperCamelCase							(self       ):
											# fmt: off
											snake_case_					:		str 					=					{"""input_ids""": [[4_34_95, 4_62, 20, 4_21_64, 13_69, 52, 4_64, 1_32, 17_03, 4_92, 13, 74_91, 3_89_99, 6, 8, 4_64, 1_32, 17_03, 4_92, 13, 46_69, 3_78_67, 13, 75_25, 27, 15_93, 9_88, 13, 3_39_72, 70_29, 6, 20, 82_51, 3_83, 2, 2_70, 58_66, 37_88, 2, 23_53, 82_51, 1_23_38, 2, 1_39_58, 3_87, 2, 36_29, 69_53, 1_88, 29_00, 2, 1_39_58, 80_11, 1_15_01, 23, 84_60, 40_73, 3_40_09, 20, 4_35, 1_14_39, 27, 8, 84_60, 40_73, 60_04, 20, 99_88, 3_75, 27, 33, 2_66, 19_45, 10_76, 13_50, 3_78_67, 32_88, 5, 5_77, 10_76, 43_74, 8, 50_82, 5, 2_64_53, 2_57, 5_56, 4_03, 2, 2_42, 1_32, 3_83, 3_16, 4_92, 8, 1_07_67, 6, 3_16, 3_04, 42_39, 3, 0], [1_48, 1_57_22, 19, 18_39, 12, 13_50, 13, 2_23_27, 50_82, 54_18, 4_75_67, 3_59_38, 59, 3_18, 1_95_52, 1_08, 21_83, 54, 1_49_76, 48_35, 32, 5_47, 11_14, 8, 3_15, 24_17, 5, 92, 1_90_88, 3, 0, 5_81_00, 5_81_00, 5_81_00, 5_81_00, 5_81_00, 5_81_00, 5_81_00, 5_81_00, 5_81_00, 5_81_00, 5_81_00, 5_81_00, 5_81_00, 5_81_00, 5_81_00, 5_81_00, 5_81_00, 5_81_00, 5_81_00, 5_81_00, 5_81_00, 5_81_00, 5_81_00, 5_81_00, 5_81_00, 5_81_00, 5_81_00, 5_81_00, 5_81_00, 5_81_00, 5_81_00, 5_81_00, 5_81_00, 5_81_00, 5_81_00, 5_81_00, 5_81_00, 5_81_00, 5_81_00, 5_81_00, 5_81_00, 5_81_00, 5_81_00, 5_81_00, 5_81_00, 5_81_00, 5_81_00, 5_81_00, 5_81_00, 5_81_00, 5_81_00, 5_81_00, 5_81_00, 5_81_00, 5_81_00, 5_81_00, 5_81_00, 5_81_00, 5_81_00, 5_81_00, 5_81_00, 5_81_00, 5_81_00, 5_81_00, 5_81_00, 5_81_00, 5_81_00, 5_81_00, 5_81_00, 5_81_00, 5_81_00], [36, 63_95, 1_25_70, 3_91_47, 1_15_97, 6, 2_66, 4, 4_54_05, 72_96, 3, 0, 5_81_00, 5_81_00, 5_81_00, 5_81_00, 5_81_00, 5_81_00, 5_81_00, 5_81_00, 5_81_00, 5_81_00, 5_81_00, 5_81_00, 5_81_00, 5_81_00, 5_81_00, 5_81_00, 5_81_00, 5_81_00, 5_81_00, 5_81_00, 5_81_00, 5_81_00, 5_81_00, 5_81_00, 5_81_00, 5_81_00, 5_81_00, 5_81_00, 5_81_00, 5_81_00, 5_81_00, 5_81_00, 5_81_00, 5_81_00, 5_81_00, 5_81_00, 5_81_00, 5_81_00, 5_81_00, 5_81_00, 5_81_00, 5_81_00, 5_81_00, 5_81_00, 5_81_00, 5_81_00, 5_81_00, 5_81_00, 5_81_00, 5_81_00, 5_81_00, 5_81_00, 5_81_00, 5_81_00, 5_81_00, 5_81_00, 5_81_00, 5_81_00, 5_81_00, 5_81_00, 5_81_00, 5_81_00, 5_81_00, 5_81_00, 5_81_00, 5_81_00, 5_81_00, 5_81_00, 5_81_00, 5_81_00, 5_81_00, 5_81_00, 5_81_00, 5_81_00, 5_81_00, 5_81_00, 5_81_00, 5_81_00, 5_81_00, 5_81_00, 5_81_00, 5_81_00, 5_81_00, 5_81_00, 5_81_00, 5_81_00, 5_81_00, 5_81_00, 5_81_00, 5_81_00]], """attention_mask""": [[1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]]}  # noqa: E501
											# fmt: on

											self.tokenizer_integration_test_util(
											    expected_encoding=lowercase__   ,		model_name="""Helsinki-NLP/opus-mt-en-de"""   ,		revision="""1a8c2263da11e68e50938f97e10cd57820bd504c"""   ,		decode_kwargs={"""use_source_tokenizer""": True}   ,		)







						def 						__UpperCamelCase							(self       ):
											snake_case_					:		Any 					=					MarianTokenizer.from_pretrained("""hf-internal-testing/test-marian-two-vocabs"""       )

											snake_case_					:		Dict 					=					"""Tämä on testi"""
											snake_case_					:		List[Any] 					=					"""This is a test"""

											snake_case_					:		Optional[int] 					=					[76, 7, 20_47, 2]
											snake_case_					:		List[str] 					=					[69, 12, 11, 9_40, 2]

											snake_case_					:		Any 					=					tokenizer(lowercase__       ).input_ids
											self.assertListEqual(lowercase__   ,		lowercase__       )

											snake_case_					:		str 					=					tokenizer(text_target=lowercase__       ).input_ids
											self.assertListEqual(lowercase__   ,		lowercase__       )

											snake_case_					:		int 					=					tokenizer.decode(lowercase__   ,		skip_special_tokens=lowercase__       )
											self.assertEqual(lowercase__   ,		lowercase__       )




