





import math
import os
import unittest

from transformers import MegatronBertConfig, is_torch_available
from transformers.models.auto import get_values
from transformers.testing_utils import require_sentencepiece, require_tokenizers, require_torch, slow, torch_device

from ...test_configuration_common import ConfigTester
from ...test_modeling_common import ModelTesterMixin, ids_tensor, random_attention_mask
from ...test_pipeline_mixin import PipelineTesterMixin


if is_torch_available():
	import torch

	from transformers import (
	    MODEL_FOR_PRETRAINING_MAPPING,
	    MegatronBertForCausalLM,
	    MegatronBertForMaskedLM,
	    MegatronBertForMultipleChoice,
	    MegatronBertForNextSentencePrediction,
	    MegatronBertForPreTraining,
	    MegatronBertForQuestionAnswering,
	    MegatronBertForSequenceClassification,
	    MegatronBertForTokenClassification,
	    MegatronBertModel,
	)




class 	UpperCamelCase_							:


							def __init__(				self     :int				,					__A     :Optional[Any]				,					__A     :Any=13				,					__A     :Optional[int]=7				,					__A     :str=True				,					__A     :Tuple=True				,					__A     :Union[str, Any]=True				,					__A     :int=True				,					__A     :Any=99				,					__A     :Union[str, Any]=64				,					__A     :int=32				,					__A     :Tuple=5				,					__A     :int=4				,					__A     :Tuple=37				,					__A     :Optional[Any]="gelu"				,					__A     :Union[str, Any]=0.1				,					__A     :Any=0.1				,					__A     :str=512				,					__A     :Tuple=16				,					__A     :Optional[Any]=2				,					__A     :Tuple=0.0_2				,					__A     :int=3				,					__A     :Union[str, Any]=4				,					__A     :List[Any]=None				,					) -> Any:



									"""simple docstring"""



									SCREAMING_SNAKE_CASE__								=   parent
									SCREAMING_SNAKE_CASE__								=   batch_size
									SCREAMING_SNAKE_CASE__								=   seq_length
									SCREAMING_SNAKE_CASE__								=   is_training
									SCREAMING_SNAKE_CASE__								=   use_input_mask
									SCREAMING_SNAKE_CASE__								=   use_token_type_ids
									SCREAMING_SNAKE_CASE__								=   use_labels
									SCREAMING_SNAKE_CASE__								=   vocab_size
									SCREAMING_SNAKE_CASE__								=   hidden_size
									SCREAMING_SNAKE_CASE__								=   embedding_size
									SCREAMING_SNAKE_CASE__								=   num_hidden_layers
									SCREAMING_SNAKE_CASE__								=   num_attention_heads
									SCREAMING_SNAKE_CASE__								=   intermediate_size
									SCREAMING_SNAKE_CASE__								=   hidden_act
									SCREAMING_SNAKE_CASE__								=   hidden_dropout_prob
									SCREAMING_SNAKE_CASE__								=   attention_probs_dropout_prob
									SCREAMING_SNAKE_CASE__								=   max_position_embeddings
									SCREAMING_SNAKE_CASE__								=   type_vocab_size
									SCREAMING_SNAKE_CASE__								=   type_sequence_label_size
									SCREAMING_SNAKE_CASE__								=   initializer_range
									SCREAMING_SNAKE_CASE__								=   num_labels
									SCREAMING_SNAKE_CASE__								=   num_choices
									SCREAMING_SNAKE_CASE__								=   scope


							def   _snake_case	(				self     :Dict		) -> Optional[Any]:



									"""simple docstring"""



									SCREAMING_SNAKE_CASE__								=   ids_tensor([self.batch_size, self.seq_length]				,					self.vocab_size		)

									SCREAMING_SNAKE_CASE__								=   None
									if self.use_input_mask:
											SCREAMING_SNAKE_CASE__								=   random_attention_mask([self.batch_size, self.seq_length]		)

									SCREAMING_SNAKE_CASE__								=   None
									if self.use_token_type_ids:
											SCREAMING_SNAKE_CASE__								=   ids_tensor([self.batch_size, self.seq_length]				,					self.type_vocab_size		)

									SCREAMING_SNAKE_CASE__								=   None
									SCREAMING_SNAKE_CASE__								=   None
									SCREAMING_SNAKE_CASE__								=   None
									if self.use_labels:
											SCREAMING_SNAKE_CASE__								=   ids_tensor([self.batch_size]				,					self.type_sequence_label_size		)
											SCREAMING_SNAKE_CASE__								=   ids_tensor([self.batch_size, self.seq_length]				,					self.num_labels		)
											SCREAMING_SNAKE_CASE__								=   ids_tensor([self.batch_size]				,					self.num_choices		)

									SCREAMING_SNAKE_CASE__								=   self.get_config()

									return config, input_ids, token_type_ids, input_mask, sequence_labels, token_labels, choice_labels


							def   _snake_case	(				self     :int		) -> Union[str, Any]:



									"""simple docstring"""



									return MegatronBertConfig(
									    vocab_size=self.vocab_size				,					hidden_size=self.hidden_size				,					num_hidden_layers=self.num_hidden_layers				,					num_attention_heads=self.num_attention_heads				,					intermediate_size=self.intermediate_size				,					embedding_size=self.embedding_size				,					hidden_act=self.hidden_act				,					hidden_dropout_prob=self.hidden_dropout_prob				,					attention_probs_dropout_prob=self.attention_probs_dropout_prob				,					max_position_embeddings=self.max_position_embeddings				,					type_vocab_size=self.type_vocab_size				,					is_decoder=__A				,					initializer_range=self.initializer_range				,					)


							def   _snake_case	(				self     :Optional[int]				,					__A     :Any				,					__A     :Union[str, Any]				,					__A     :Union[str, Any]				,					__A     :int				,					__A     :str				,					__A     :List[Any]				,					__A     :List[str]		) -> Union[str, Any]:



									"""simple docstring"""



									SCREAMING_SNAKE_CASE__								=   MegatronBertModel(config=__A		)
									model.to(__A		)
									model.eval()
									SCREAMING_SNAKE_CASE__								=   model(__A				,					attention_mask=__A				,					token_type_ids=__A		)
									SCREAMING_SNAKE_CASE__								=   model(__A				,					token_type_ids=__A		)
									SCREAMING_SNAKE_CASE__								=   model(__A		)

									self.parent.assertEqual(result.last_hidden_state.shape				,					(self.batch_size, self.seq_length, self.hidden_size)		)
									self.parent.assertEqual(result.pooler_output.shape				,					(self.batch_size, self.hidden_size)		)


							def   _snake_case	(				self     :List[Any]				,					__A     :List[str]				,					__A     :Optional[Any]				,					__A     :Optional[int]				,					__A     :List[str]				,					__A     :List[Any]				,					__A     :int				,					__A     :Any		) -> str:



									"""simple docstring"""



									SCREAMING_SNAKE_CASE__								=   MegatronBertForMaskedLM(config=__A		)
									model.to(__A		)
									model.eval()
									SCREAMING_SNAKE_CASE__								=   model(__A				,					attention_mask=__A				,					token_type_ids=__A				,					labels=__A		)
									self.parent.assertEqual(result.logits.shape				,					(self.batch_size, self.seq_length, self.vocab_size)		)


							def   _snake_case	(				self     :List[Any]				,					__A     :Any				,					__A     :Tuple				,					__A     :str				,					__A     :str				,					__A     :List[str]				,					__A     :Union[str, Any]				,					__A     :Optional[int]		) -> int:



									"""simple docstring"""



									SCREAMING_SNAKE_CASE__								=   MegatronBertForCausalLM(config=__A		)
									model.to(__A		)
									model.eval()
									SCREAMING_SNAKE_CASE__								=   model(__A				,					attention_mask=__A				,					token_type_ids=__A				,					labels=__A		)
									self.parent.assertEqual(result.logits.shape				,					(self.batch_size, self.seq_length, self.vocab_size)		)


							def   _snake_case	(				self     :Tuple				,					__A     :int				,					__A     :Optional[int]				,					__A     :Union[str, Any]				,					__A     :Union[str, Any]				,					__A     :int				,					__A     :Union[str, Any]				,					__A     :str		) -> Tuple:



									"""simple docstring"""



									SCREAMING_SNAKE_CASE__								=   MegatronBertForNextSentencePrediction(config=__A		)
									model.to(__A		)
									model.eval()
									SCREAMING_SNAKE_CASE__								=   model(
									    __A				,					attention_mask=__A				,					token_type_ids=__A				,					labels=__A				,					)
									self.parent.assertEqual(result.logits.shape				,					(self.batch_size, 2)		)


							def   _snake_case	(				self     :Union[str, Any]				,					__A     :str				,					__A     :Any				,					__A     :Union[str, Any]				,					__A     :List[Any]				,					__A     :Any				,					__A     :str				,					__A     :Dict		) -> Optional[int]:



									"""simple docstring"""



									SCREAMING_SNAKE_CASE__								=   MegatronBertForPreTraining(config=__A		)
									model.to(__A		)
									model.eval()
									SCREAMING_SNAKE_CASE__								=   model(
									    __A				,					attention_mask=__A				,					token_type_ids=__A				,					labels=__A				,					next_sentence_label=__A				,					)
									self.parent.assertEqual(result.prediction_logits.shape				,					(self.batch_size, self.seq_length, self.vocab_size)		)
									self.parent.assertEqual(result.seq_relationship_logits.shape				,					(self.batch_size, 2)		)


							def   _snake_case	(				self     :Optional[Any]				,					__A     :int				,					__A     :Optional[Any]				,					__A     :List[Any]				,					__A     :Tuple				,					__A     :Any				,					__A     :Union[str, Any]				,					__A     :Any		) -> Optional[int]:



									"""simple docstring"""



									SCREAMING_SNAKE_CASE__								=   MegatronBertForQuestionAnswering(config=__A		)
									model.to(__A		)
									model.eval()
									SCREAMING_SNAKE_CASE__								=   model(
									    __A				,					attention_mask=__A				,					token_type_ids=__A				,					start_positions=__A				,					end_positions=__A				,					)
									self.parent.assertEqual(result.start_logits.shape				,					(self.batch_size, self.seq_length)		)
									self.parent.assertEqual(result.end_logits.shape				,					(self.batch_size, self.seq_length)		)


							def   _snake_case	(				self     :str				,					__A     :int				,					__A     :List[Any]				,					__A     :Tuple				,					__A     :Optional[Any]				,					__A     :Optional[int]				,					__A     :Dict				,					__A     :Optional[int]		) -> str:



									"""simple docstring"""



									SCREAMING_SNAKE_CASE__								=   self.num_labels
									SCREAMING_SNAKE_CASE__								=   MegatronBertForSequenceClassification(__A		)
									model.to(__A		)
									model.eval()
									SCREAMING_SNAKE_CASE__								=   model(__A				,					attention_mask=__A				,					token_type_ids=__A				,					labels=__A		)
									self.parent.assertEqual(result.logits.shape				,					(self.batch_size, self.num_labels)		)


							def   _snake_case	(				self     :Optional[Any]				,					__A     :List[Any]				,					__A     :List[Any]				,					__A     :Any				,					__A     :Tuple				,					__A     :Any				,					__A     :Optional[int]				,					__A     :str		) -> List[Any]:



									"""simple docstring"""



									SCREAMING_SNAKE_CASE__								=   self.num_labels
									SCREAMING_SNAKE_CASE__								=   MegatronBertForTokenClassification(config=__A		)
									model.to(__A		)
									model.eval()
									SCREAMING_SNAKE_CASE__								=   model(__A				,					attention_mask=__A				,					token_type_ids=__A				,					labels=__A		)
									self.parent.assertEqual(result.logits.shape				,					(self.batch_size, self.seq_length, self.num_labels)		)


							def   _snake_case	(				self     :Optional[Any]				,					__A     :int				,					__A     :List[Any]				,					__A     :List[str]				,					__A     :Any				,					__A     :List[Any]				,					__A     :Any				,					__A     :Optional[int]		) -> int:



									"""simple docstring"""



									SCREAMING_SNAKE_CASE__								=   self.num_choices
									SCREAMING_SNAKE_CASE__								=   MegatronBertForMultipleChoice(config=__A		)
									model.to(__A		)
									model.eval()
									SCREAMING_SNAKE_CASE__								=   input_ids.unsqueeze(1		).expand(-1				,					self.num_choices				,					-1		).contiguous()
									SCREAMING_SNAKE_CASE__								=   token_type_ids.unsqueeze(1		).expand(-1				,					self.num_choices				,					-1		).contiguous()
									SCREAMING_SNAKE_CASE__								=   input_mask.unsqueeze(1		).expand(-1				,					self.num_choices				,					-1		).contiguous()
									SCREAMING_SNAKE_CASE__								=   model(
									    __A				,					attention_mask=__A				,					token_type_ids=__A				,					labels=__A				,					)
									self.parent.assertEqual(result.logits.shape				,					(self.batch_size, self.num_choices)		)


							def   _snake_case	(				self     :Optional[Any]		) -> Optional[Any]:



									"""simple docstring"""



									SCREAMING_SNAKE_CASE__								=   self.prepare_config_and_inputs()
									(
									    (
									    SCREAMING_SNAKE_CASE__
									)						,    (
									    SCREAMING_SNAKE_CASE__
									)						,    (
									    SCREAMING_SNAKE_CASE__
									)						,    (
									    SCREAMING_SNAKE_CASE__
									)						,    (
									    SCREAMING_SNAKE_CASE__
									)						,    (
									    SCREAMING_SNAKE_CASE__
									)						,    (
									    SCREAMING_SNAKE_CASE__
									)						,    
									)								=   config_and_inputs
									SCREAMING_SNAKE_CASE__								=   {"""input_ids""": input_ids, """token_type_ids""": token_type_ids, """attention_mask""": input_mask}
									return config, inputs_dict




@require_torch
class 	UpperCamelCase_							(  UpperCamelCase__					,	UpperCamelCase__					,	unittest.TestCase     ):
							lowerCamelCase_							     =       (
							    (
							        MegatronBertModel,
							        MegatronBertForMaskedLM,
							        MegatronBertForCausalLM,
							        MegatronBertForMultipleChoice,
							        MegatronBertForNextSentencePrediction,
							        MegatronBertForPreTraining,
							        MegatronBertForQuestionAnswering,
							        MegatronBertForSequenceClassification,
							        MegatronBertForTokenClassification,
							    )
							    if is_torch_available()
							    else ()
							)
							lowerCamelCase_							     =       (
							    {
							        "feature-extraction": MegatronBertModel,
							        "fill-mask": MegatronBertForMaskedLM,
							        "question-answering": MegatronBertForQuestionAnswering,
							        "text-classification": MegatronBertForSequenceClassification,
							        "text-generation": MegatronBertForCausalLM,
							        "token-classification": MegatronBertForTokenClassification,
							        "zero-shot": MegatronBertForSequenceClassification,
							    }
							    if is_torch_available()
							    else {}
							)
							lowerCamelCase_							     =       True
							# test_resize_embeddings = False
							lowerCamelCase_							     =       False


							def   _snake_case	(				self     :int				,					__A     :Tuple				,					__A     :List[str]				,					__A     :int=False		) -> int:



									"""simple docstring"""



									SCREAMING_SNAKE_CASE__								=   super()._prepare_for_class(__A				,					__A				,					return_labels=__A		)

									if return_labels:
											if model_class in get_values(__A		):
													SCREAMING_SNAKE_CASE__								=   torch.zeros(
													    (self.model_tester.batch_size, self.model_tester.seq_length)				,					dtype=torch.long				,					device=__A		)
													SCREAMING_SNAKE_CASE__								=   torch.zeros(
													    self.model_tester.batch_size				,					dtype=torch.long				,					device=__A		)
									return inputs_dict


							def   _snake_case	(				self     :Tuple		) -> List[str]:



									"""simple docstring"""



									SCREAMING_SNAKE_CASE__								=   MegatronBertModelTester(self		)
									SCREAMING_SNAKE_CASE__								=   ConfigTester(self				,					config_class=__A				,					hidden_size=37		)


							def   _snake_case	(				self     :List[Any]		) -> Optional[int]:



									"""simple docstring"""



									self.config_tester.run_common_tests()


							def   _snake_case	(				self     :int		) -> Dict:



									"""simple docstring"""



									SCREAMING_SNAKE_CASE__								=   self.model_tester.prepare_config_and_inputs()
									self.model_tester.create_and_check_megatron_bert_model(*__A		)


							def   _snake_case	(				self     :List[Any]		) -> Any:



									"""simple docstring"""



									SCREAMING_SNAKE_CASE__								=   self.model_tester.prepare_config_and_inputs()
									self.model_tester.create_and_check_megatron_bert_for_masked_lm(*__A		)


							def   _snake_case	(				self     :Optional[Any]		) -> Dict:



									"""simple docstring"""



									SCREAMING_SNAKE_CASE__								=   self.model_tester.prepare_config_and_inputs()
									self.model_tester.create_and_check_megatron_bert_for_multiple_choice(*__A		)


							def   _snake_case	(				self     :Any		) -> List[Any]:



									"""simple docstring"""



									SCREAMING_SNAKE_CASE__								=   self.model_tester.prepare_config_and_inputs()
									self.model_tester.create_and_check_megatron_bert_for_next_sequence_prediction(*__A		)


							def   _snake_case	(				self     :Optional[Any]		) -> Dict:



									"""simple docstring"""



									SCREAMING_SNAKE_CASE__								=   self.model_tester.prepare_config_and_inputs()
									self.model_tester.create_and_check_megatron_bert_for_pretraining(*__A		)


							def   _snake_case	(				self     :List[Any]		) -> List[str]:



									"""simple docstring"""



									SCREAMING_SNAKE_CASE__								=   self.model_tester.prepare_config_and_inputs()
									self.model_tester.create_and_check_megatron_bert_for_question_answering(*__A		)


							def   _snake_case	(				self     :Tuple		) -> Optional[int]:



									"""simple docstring"""



									SCREAMING_SNAKE_CASE__								=   self.model_tester.prepare_config_and_inputs()
									self.model_tester.create_and_check_megatron_bert_for_sequence_classification(*__A		)


							def   _snake_case	(				self     :Optional[int]		) -> Any:



									"""simple docstring"""



									SCREAMING_SNAKE_CASE__								=   self.model_tester.prepare_config_and_inputs()
									self.model_tester.create_and_check_megatron_bert_for_token_classification(*__A		)






def 					SCREAMING_SNAKE_CASE__				(							UpperCamelCase__:				List[str]     ):
		return torch.tensor(
		    UpperCamelCase__       , dtype=torch.long       , device=UpperCamelCase__       , )


_lowerCamelCase 					=      1e-4




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


							@slow
							@unittest.skip("""Model is not available."""		)
							def   _snake_case	(				self     :int		) -> List[Any]:



									"""simple docstring"""



									SCREAMING_SNAKE_CASE__								=   """nvidia/megatron-bert-uncased-345m"""
									if "MYDIR" in os.environ:
											SCREAMING_SNAKE_CASE__								=   os.path.join(os.environ["""MYDIR"""]				,					__A		)
									SCREAMING_SNAKE_CASE__								=   MegatronBertModel.from_pretrained(__A		)
									model.to(__A		)
									model.half()
									SCREAMING_SNAKE_CASE__								=   _long_tensor([[101, 7110, 1005, 1056, 2023, 1_1333, 1_7413, 1029, 102]]		)
									with torch.no_grad():
											SCREAMING_SNAKE_CASE__								=   model(__A		)[0]
									SCREAMING_SNAKE_CASE__								=   torch.Size((1, 9, 1024)		)
									self.assertEqual(output.shape				,					__A		)

									SCREAMING_SNAKE_CASE__								=   [-0.6_0_4_0, -0.2_5_1_7, -0.1_0_2_5, 0.3_4_2_0, -0.6_7_5_8, -0.0_0_1_7, -0.1_0_8_9, -0.1_9_9_0, 0.5_7_2_8]
									for ii in range(3		):
											for jj in range(3		):
													SCREAMING_SNAKE_CASE__								=   output[0, ii, jj]
													SCREAMING_SNAKE_CASE__								=   expected[3 * ii + jj]
													SCREAMING_SNAKE_CASE__								=   """ii={} jj={} a={} b={}""".format(__A				,					__A				,					__A				,					__A		)
													self.assertTrue(math.isclose(__A				,					__A				,					rel_tol=__A				,					abs_tol=__A		)				,					msg=__A		)



import os
from shutil import copyfile
from typing import List, Optional, Tuple

from ...tokenization_utils import AddedToken
from ...tokenization_utils_fast import PreTrainedTokenizerFast
from ...utils import is_sentencepiece_available, logging


if is_sentencepiece_available():
						from .tokenization_big_bird import BigBirdTokenizer
else:
						__UpperCamelCase     		=							None

__UpperCamelCase     		=							logging.get_logger(__name__)
__UpperCamelCase     		=							{'vocab_file': 'spiece.model', 'tokenizer_file': 'tokenizer.json'}

__UpperCamelCase     		=							{
    'vocab_file': {
        'google/bigbird-roberta-base': 'https://huggingface.co/google/bigbird-roberta-base/resolve/main/spiece.model',
        'google/bigbird-roberta-large': (
            'https://huggingface.co/google/bigbird-roberta-large/resolve/main/spiece.model'
        ),
        'google/bigbird-base-trivia-itc': (
            'https://huggingface.co/google/bigbird-base-trivia-itc/resolve/main/spiece.model'
        ),
    },
    'tokenizer_file': {
        'google/bigbird-roberta-base': (
            'https://huggingface.co/google/bigbird-roberta-base/resolve/main/tokenizer.json'
        ),
        'google/bigbird-roberta-large': (
            'https://huggingface.co/google/bigbird-roberta-large/resolve/main/tokenizer.json'
        ),
        'google/bigbird-base-trivia-itc': (
            'https://huggingface.co/google/bigbird-base-trivia-itc/resolve/main/tokenizer.json'
        ),
    },
}

__UpperCamelCase     		=							{
    'google/bigbird-roberta-base': 4_0_9_6,
    'google/bigbird-roberta-large': 4_0_9_6,
    'google/bigbird-base-trivia-itc': 4_0_9_6,
}


__UpperCamelCase     		=							'▁'







class 							lowerCamelCase__						(				UpperCAmelCase   ):






			"""simple docstring"""






			_UpperCamelCase		:       Dict 			=		VOCAB_FILES_NAMES
			_UpperCamelCase		:       int 			=		PRETRAINED_VOCAB_FILES_MAP
			_UpperCamelCase		:       List[Any] 			=		PRETRAINED_POSITIONAL_EMBEDDINGS_SIZES
			_UpperCamelCase		:       Optional[Any] 			=		BigBirdTokenizer
			_UpperCamelCase		:       Dict 			=		['input_ids', 'attention_mask']
			_UpperCamelCase		:       List[int] 			=		[]




			def __init__(				self   ,    snake_case=None   ,    snake_case=None   ,    snake_case="<unk>"   ,    snake_case="<s>"   ,    snake_case="</s>"   ,    snake_case="<pad>"   ,    snake_case="[SEP]"   ,    snake_case="[MASK]"   ,    snake_case="[CLS]"   ,    **snake_case   ,    ):

						'''simple docstring'''


						UpperCamelCase__       =							AddedToken(snake_case   ,    lstrip=snake_case   ,    rstrip=snake_case  ) if isinstance(snake_case   ,    snake_case  ) else bos_token
						UpperCamelCase__       =							AddedToken(snake_case   ,    lstrip=snake_case   ,    rstrip=snake_case  ) if isinstance(snake_case   ,    snake_case  ) else eos_token
						UpperCamelCase__       =							AddedToken(snake_case   ,    lstrip=snake_case   ,    rstrip=snake_case  ) if isinstance(snake_case   ,    snake_case  ) else unk_token
						UpperCamelCase__       =							AddedToken(snake_case   ,    lstrip=snake_case   ,    rstrip=snake_case  ) if isinstance(snake_case   ,    snake_case  ) else pad_token
						UpperCamelCase__       =							AddedToken(snake_case   ,    lstrip=snake_case   ,    rstrip=snake_case  ) if isinstance(snake_case   ,    snake_case  ) else cls_token
						UpperCamelCase__       =							AddedToken(snake_case   ,    lstrip=snake_case   ,    rstrip=snake_case  ) if isinstance(snake_case   ,    snake_case  ) else sep_token

						# Mask token behave like a normal word, i.e. include the space before it
						UpperCamelCase__       =							AddedToken(snake_case   ,    lstrip=snake_case   ,    rstrip=snake_case  ) if isinstance(snake_case   ,    snake_case  ) else mask_token

						super().__init__(
						    snake_case   ,    tokenizer_file=snake_case   ,    bos_token=snake_case   ,    eos_token=snake_case   ,    unk_token=snake_case   ,    sep_token=snake_case   ,    pad_token=snake_case   ,    cls_token=snake_case   ,    mask_token=snake_case   ,    **snake_case   ,    )

						UpperCamelCase__       =							vocab_file
						UpperCamelCase__       =							False if not self.vocab_file else True




			def 					snake_case__					(				self   ,    snake_case   ,    snake_case = None  ):

						'''simple docstring'''


						UpperCamelCase__       =							[self.sep_token_id]
						UpperCamelCase__       =							[self.cls_token_id]
						if token_ids_a is None:
									return cls + token_ids_a + sep
						return cls + token_ids_a + sep + token_ids_a + sep




			def 					snake_case__					(				self   ,    snake_case   ,    snake_case = None   ,    snake_case = False  ):

						'''simple docstring'''


						if already_has_special_tokens:
									if token_ids_a is not None:
												raise ValueError(
												    "You should not supply a second sequence if the provided sequence of "
												    "ids is already formatted with special tokens for the model."  )
									return [1 if x in [self.sep_token_id, self.cls_token_id] else 0 for x in token_ids_a]

						if token_ids_a is None:
									return [1] + ([0] * len(snake_case  )) + [1]
						return [1] + ([0] * len(snake_case  )) + [1] + ([0] * len(snake_case  )) + [1]




			def 					snake_case__					(				self   ,    snake_case   ,    snake_case = None  ):

						'''simple docstring'''


						UpperCamelCase__       =							[self.sep_token_id]
						UpperCamelCase__       =							[self.cls_token_id]

						if token_ids_a is None:
									return len(cls + token_ids_a + sep  ) * [0]
						return len(cls + token_ids_a + sep  ) * [0] + len(token_ids_a + sep  ) * [1]







			def 					snake_case__					(				self   ,    snake_case   ,    snake_case = None  ):

						'''simple docstring'''


						if not self.can_save_slow_tokenizer:
									raise ValueError(
									    "Your fast tokenizer does not have the necessary information to save the vocabulary for a slow "
									    "tokenizer."  )

						if not os.path.isdir(snake_case  ):
									logger.error(F'''Vocabulary path ({save_directory}) should be a directory'''  )
									return
						UpperCamelCase__       =							os.path.join(
						    snake_case   ,    (filename_prefix + "-" if filename_prefix else "") + VOCAB_FILES_NAMES["vocab_file"]  )

						if os.path.abspath(self.vocab_file  ) != os.path.abspath(snake_case  ):
									copyfile(self.vocab_file   ,    snake_case  )

						return (out_vocab_file,)


