



import math
import unittest

from transformers import BioGptConfig, is_torch_available
from transformers.testing_utils import require_torch, slow, torch_device

from ...generation.test_utils import GenerationTesterMixin
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 (
							    BioGptForCausalLM,
							    BioGptForSequenceClassification,
							    BioGptForTokenClassification,
							    BioGptModel,
							    BioGptTokenizer,
							)
							from transformers.models.biogpt.modeling_biogpt import BIOGPT_PRETRAINED_MODEL_ARCHIVE_LIST







class       __lowerCAmelCase   :



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



						"""simple docstring"""






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



			def    _lowerCamelCase	(						self       :  str)       ->   Optional[int]:



						"""simple docstring"""






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

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

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

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

						_UpperCAmelCase			=       self.get_config()

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



			def    _lowerCamelCase	(						self       :  Any)       ->   Tuple:



						"""simple docstring"""






						return BioGptConfig(
						    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			,		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    _lowerCamelCase	(						self       :  Any			,		A       :  Any			,		A       :  Tuple			,		A       :  List[str]			,		A       :  Optional[int]			,		A       :  Optional[int]			,		A       :  List[str]			,		A       :  Dict)       ->   Union[str, Any]:



						"""simple docstring"""






						_UpperCAmelCase			=       BioGptModel(config=A)
						model.to(A)
						model.eval()
						_UpperCAmelCase			=       model(A			,		attention_mask=A)
						_UpperCAmelCase			=       model(A)
						self.parent.assertEqual(result.last_hidden_state.shape			,		(self.batch_size, self.seq_length, self.hidden_size))



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



						"""simple docstring"""






						_UpperCAmelCase			=       BioGptForCausalLM(config=A)
						model.to(A)
						model.eval()
						_UpperCAmelCase			=       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    _lowerCamelCase	(						self       :  str			,		A       :  str			,		A       :  int			,		A       :  Union[str, Any]			,		A       :  List[Any]			,		A       :  List[str]			,		*A       :  List[str])       ->   Tuple:



						"""simple docstring"""






						_UpperCAmelCase			=       BioGptModel(config=A)
						model.to(A)
						model.eval()

						# create attention mask
						_UpperCAmelCase			=       torch.ones(input_ids.shape			,		dtype=torch.long			,		device=A)
						_UpperCAmelCase			=       self.seq_length // 2
						_UpperCAmelCase			=       0

						# first forward pass
						_UpperCAmelCase	,					_UpperCAmelCase			=       model(A			,		attention_mask=A).to_tuple()

						# create hypothetical next token and extent to next_input_ids
						_UpperCAmelCase			=       ids_tensor((self.batch_size, 1)			,		config.vocab_size)

						# change a random masked slice from input_ids
						_UpperCAmelCase			=       ids_tensor((1,)			,		A).item() + 1
						_UpperCAmelCase			=       ids_tensor((self.batch_size, 1)			,		config.vocab_size).squeeze(-1)
						_UpperCAmelCase			=       random_other_next_tokens

						# append to next input_ids and attn_mask
						_UpperCAmelCase			=       torch.cat([input_ids, next_tokens]			,		dim=-1)
						_UpperCAmelCase			=       torch.cat(
						    [attn_mask, torch.ones((attn_mask.shape[0], 1)			,		dtype=torch.long			,		device=A)]			,		dim=1			,		)

						# get two different outputs
						_UpperCAmelCase			=       model(A			,		attention_mask=A)['last_hidden_state']
						_UpperCAmelCase			=       model(A			,		past_key_values=A			,		attention_mask=A)['last_hidden_state']

						# select random slice
						_UpperCAmelCase			=       ids_tensor((1,)			,		output_from_past.shape[-1]).item()
						_UpperCAmelCase			=       output_from_no_past[:, -1, random_slice_idx].detach()
						_UpperCAmelCase			=       output_from_past[:, 0, random_slice_idx].detach()

						# test that outputs are equal for slice
						self.parent.assertTrue(torch.allclose(A			,		A			,		atol=1E-3))



			def    _lowerCamelCase	(						self       :  Optional[int]			,		A       :  List[str]			,		A       :  Union[str, Any]			,		A       :  List[Any]			,		A       :  Union[str, Any]			,		A       :  Dict			,		*A       :  Optional[Any])       ->   Dict:



						"""simple docstring"""






						_UpperCAmelCase			=       BioGptModel(config=A).to(A).eval()

						_UpperCAmelCase			=       torch.ones(input_ids.shape			,		dtype=torch.long			,		device=A)

						# first forward pass
						_UpperCAmelCase			=       model(A			,		attention_mask=A			,		use_cache=A)

						_UpperCAmelCase	,					_UpperCAmelCase			=       outputs.to_tuple()

						# create hypothetical multiple next token and extent to next_input_ids
						_UpperCAmelCase			=       ids_tensor((self.batch_size, 3)			,		config.vocab_size)
						_UpperCAmelCase			=       ids_tensor((self.batch_size, 3)			,		2)

						# append to next input_ids and
						_UpperCAmelCase			=       torch.cat([input_ids, next_tokens]			,		dim=-1)
						_UpperCAmelCase			=       torch.cat([attention_mask, next_attn_mask]			,		dim=-1)

						_UpperCAmelCase			=       model(A			,		attention_mask=A)['last_hidden_state']
						_UpperCAmelCase			=       model(A			,		attention_mask=A			,		past_key_values=A)[
						    'last_hidden_state'
						]

						# select random slice
						_UpperCAmelCase			=       ids_tensor((1,)			,		output_from_past.shape[-1]).item()
						_UpperCAmelCase			=       output_from_no_past[:, -3:, random_slice_idx].detach()
						_UpperCAmelCase			=       output_from_past[:, :, random_slice_idx].detach()

						self.parent.assertTrue(output_from_past_slice.shape[1] == next_tokens.shape[1])

						# test that outputs are equal for slice
						self.parent.assertTrue(torch.allclose(A			,		A			,		atol=1E-3))



			def    _lowerCamelCase	(						self       :  str			,		A       :  int			,		A       :  List[str]			,		A       :  Dict			,		A       :  Union[str, Any]			,		A       :  Optional[int]			,		*A       :  int			,		A       :  List[Any]=False)       ->   Optional[int]:



						"""simple docstring"""






						_UpperCAmelCase			=       BioGptForCausalLM(A)
						model.to(A)
						if gradient_checkpointing:
									model.gradient_checkpointing_enable()

						_UpperCAmelCase			=       model(A			,		labels=A)
						self.parent.assertEqual(result.loss.shape			,		())
						self.parent.assertEqual(result.logits.shape			,		(self.batch_size, self.seq_length, self.vocab_size))
						result.loss.backward()



			def    _lowerCamelCase	(						self       :  List[str]			,		A       :  int			,		*A       :  Union[str, Any])       ->   List[Any]:



						"""simple docstring"""






						_UpperCAmelCase			=       BioGptModel(A)
						_UpperCAmelCase			=       model.config.initializer_range / math.sqrt(2 * model.config.num_hidden_layers)
						for key in model.state_dict().keys():
									if "c_proj" in key and "weight" in key:
												self.parent.assertLessEqual(abs(torch.std(model.state_dict()[key]) - model_std)			,		0.0_0_1)
												self.parent.assertLessEqual(abs(torch.mean(model.state_dict()[key]) - 0.0)			,		0.0_1)



			def    _lowerCamelCase	(						self       :  List[Any]			,		A       :  str			,		A       :  List[str]			,		A       :  Optional[Any]			,		A       :  List[str]			,		A       :  Optional[Any]			,		*A       :  Optional[int])       ->   Any:



						"""simple docstring"""






						_UpperCAmelCase			=       self.num_labels
						_UpperCAmelCase			=       BioGptForTokenClassification(A)
						model.to(A)
						model.eval()
						_UpperCAmelCase			=       model(A			,		attention_mask=A			,		token_type_ids=A)
						self.parent.assertEqual(result.logits.shape			,		(self.batch_size, self.seq_length, self.num_labels))



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



						"""simple docstring"""






						_UpperCAmelCase			=       self.prepare_config_and_inputs()
						(
						    (
						    _UpperCAmelCase   
						)	,					(
						    _UpperCAmelCase   
						)	,					(
						    _UpperCAmelCase   
						)	,					(
						    _UpperCAmelCase   
						)	,					(
						    _UpperCAmelCase   
						)	,					(
						    _UpperCAmelCase   
						)	,					(
						    _UpperCAmelCase   
						)	,					   
						)			=       config_and_inputs
						_UpperCAmelCase			=       {'input_ids': input_ids, 'attention_mask': input_mask}
						return config, inputs_dict







@require_torch
class       __lowerCAmelCase   (      snake_case_    ,						snake_case_    ,						snake_case_    ,						unittest.TestCase						):
			UpperCamelCase        =					(
			    (BioGptModel, BioGptForCausalLM, BioGptForSequenceClassification, BioGptForTokenClassification)
			    if is_torch_available()
			    else ()
			)
			UpperCamelCase        =					(BioGptForCausalLM,) if is_torch_available() else ()
			UpperCamelCase        =					(
			    {
			        '''feature-extraction''': BioGptModel,
			        '''text-classification''': BioGptForSequenceClassification,
			        '''text-generation''': BioGptForCausalLM,
			        '''token-classification''': BioGptForTokenClassification,
			        '''zero-shot''': BioGptForSequenceClassification,
			    }
			    if is_torch_available()
			    else {}
			)
			UpperCamelCase        =					False



			def    _lowerCamelCase	(						self       :  str)       ->   Any:



						"""simple docstring"""






						_UpperCAmelCase			=       BioGptModelTester(self)
						_UpperCAmelCase			=       ConfigTester(self			,		config_class=A			,		hidden_size=37)



			def    _lowerCamelCase	(						self       :  str)       ->   Optional[Any]:



						"""simple docstring"""






						self.config_tester.run_common_tests()



			def    _lowerCamelCase	(						self       :  Dict)       ->   List[str]:



						"""simple docstring"""






						_UpperCAmelCase			=       self.model_tester.prepare_config_and_inputs()
						self.model_tester.create_and_check_model(*A)



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



						"""simple docstring"""






						_UpperCAmelCase			=       self.model_tester.prepare_config_and_inputs()
						for type in ["absolute", "relative_key", "relative_key_query"]:
									_UpperCAmelCase			=       type
									self.model_tester.create_and_check_model(*A)



			def    _lowerCamelCase	(						self       :  Dict)       ->   Optional[int]:



						"""simple docstring"""






						_UpperCAmelCase			=       self.model_tester.prepare_config_and_inputs()
						self.model_tester.create_and_check_biogpt_model_attention_mask_past(*A)



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



						"""simple docstring"""






						_UpperCAmelCase			=       self.model_tester.prepare_config_and_inputs()
						self.model_tester.create_and_check_forward_and_backwards(*A			,		gradient_checkpointing=A)



			def    _lowerCamelCase	(						self       :  List[Any])       ->   Dict:



						"""simple docstring"""






						_UpperCAmelCase			=       self.model_tester.prepare_config_and_inputs()
						self.model_tester.create_and_check_biogpt_model_past_large_inputs(*A)



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



						"""simple docstring"""






						_UpperCAmelCase			=       self.model_tester.prepare_config_and_inputs()
						self.model_tester.create_and_check_biogpt_weight_initialization(*A)



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



						"""simple docstring"""






						_UpperCAmelCase			=       self.model_tester.prepare_config_and_inputs()
						self.model_tester.create_and_check_biogpt_for_token_classification(*A)



			@slow
			def    _lowerCamelCase	(						self       :  List[str])       ->   Dict:



						"""simple docstring"""






						_UpperCAmelCase			=       BioGptForCausalLM.from_pretrained('microsoft/biogpt')
						model.to(A)
						_UpperCAmelCase			=       BioGptTokenizer.from_pretrained('microsoft/biogpt')

						_UpperCAmelCase			=       'left'

						# Define PAD Token = EOS Token = 50256
						_UpperCAmelCase			=       tokenizer.eos_token
						_UpperCAmelCase			=       model.config.eos_token_id

						# use different length sentences to test batching
						_UpperCAmelCase			=       [
						    'Hello, my dog is a little',
						    'Today, I',
						]

						_UpperCAmelCase			=       tokenizer(A			,		return_tensors='pt'			,		padding=A)
						_UpperCAmelCase			=       inputs['input_ids'].to(A)

						_UpperCAmelCase			=       model.generate(
						    input_ids=A			,		attention_mask=inputs['attention_mask'].to(A)			,		)

						_UpperCAmelCase			=       tokenizer(sentences[0]			,		return_tensors='pt').input_ids.to(A)
						_UpperCAmelCase			=       model.generate(input_ids=A)

						_UpperCAmelCase			=       inputs_non_padded.shape[-1] - inputs['attention_mask'][-1].long().sum().cpu().item()
						_UpperCAmelCase			=       tokenizer(sentences[1]			,		return_tensors='pt').input_ids.to(A)
						_UpperCAmelCase			=       model.generate(input_ids=A			,		max_length=model.config.max_length - num_paddings)

						_UpperCAmelCase			=       tokenizer.batch_decode(A			,		skip_special_tokens=A)
						_UpperCAmelCase			=       tokenizer.decode(output_non_padded[0]			,		skip_special_tokens=A)
						_UpperCAmelCase			=       tokenizer.decode(output_padded[0]			,		skip_special_tokens=A)

						_UpperCAmelCase			=       [
						    'Hello, my dog is a little bit bigger than a little bit.',
						    'Today, I have a good idea of how to use the information',
						]
						self.assertListEqual(A			,		A)
						self.assertListEqual(A			,		[non_padded_sentence, padded_sentence])



			@slow
			def    _lowerCamelCase	(						self       :  Optional[int])       ->   int:



						"""simple docstring"""






						for model_name in BIOGPT_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
									_UpperCAmelCase			=       BioGptModel.from_pretrained(A)
									self.assertIsNotNone(A)



			def    _lowerCamelCase	(						self       :  Union[str, Any])       ->   Tuple:



						"""simple docstring"""






						_UpperCAmelCase	,					_UpperCAmelCase			=       self.model_tester.prepare_config_and_inputs_for_common()
						_UpperCAmelCase			=       3
						_UpperCAmelCase			=       input_dict['input_ids']
						_UpperCAmelCase			=       input_ids.ne(1).to(A)
						_UpperCAmelCase			=       ids_tensor([self.model_tester.batch_size]			,		self.model_tester.type_sequence_label_size)
						_UpperCAmelCase			=       BioGptForSequenceClassification(A)
						model.to(A)
						model.eval()
						_UpperCAmelCase			=       model(A			,		attention_mask=A			,		labels=A)
						self.assertEqual(result.logits.shape			,		(self.model_tester.batch_size, self.model_tester.num_labels))



			def    _lowerCamelCase	(						self       :  List[Any])       ->   Dict:



						"""simple docstring"""






						_UpperCAmelCase	,					_UpperCAmelCase			=       self.model_tester.prepare_config_and_inputs_for_common()
						_UpperCAmelCase			=       3
						_UpperCAmelCase			=       'multi_label_classification'
						_UpperCAmelCase			=       input_dict['input_ids']
						_UpperCAmelCase			=       input_ids.ne(1).to(A)
						_UpperCAmelCase			=       ids_tensor(
						    [self.model_tester.batch_size, config.num_labels]			,		self.model_tester.type_sequence_label_size).to(torch.float)
						_UpperCAmelCase			=       BioGptForSequenceClassification(A)
						model.to(A)
						model.eval()
						_UpperCAmelCase			=       model(A			,		attention_mask=A			,		labels=A)
						self.assertEqual(result.logits.shape			,		(self.model_tester.batch_size, self.model_tester.num_labels))







@require_torch
class       __lowerCAmelCase   (      unittest.TestCase						):



			@slow
			def    _lowerCamelCase	(						self       :  Optional[int])       ->   Optional[int]:



						"""simple docstring"""






						_UpperCAmelCase			=       BioGptForCausalLM.from_pretrained('microsoft/biogpt')
						_UpperCAmelCase			=       torch.tensor([[2, 48_05, 9, 6_56, 21]])
						_UpperCAmelCase			=       model(A)[0]

						_UpperCAmelCase			=       4_23_84

						_UpperCAmelCase			=       torch.Size((1, 5, vocab_size))
						self.assertEqual(output.shape			,		A)

						_UpperCAmelCase			=       torch.tensor(
						    [[[-9.5_2_3_6, -9.8_9_1_8, 10.45_57], [-11.04_69, -9.6_4_2_3, 8.1_0_2_2], [-8.8_6_6_4, -7.8_8_2_6, 5.5_3_2_5]]])

						self.assertTrue(torch.allclose(output[:, :3, :3]			,		A			,		atol=1E-4))



			@slow
			def    _lowerCamelCase	(						self       :  str)       ->   List[Any]:



						"""simple docstring"""






						_UpperCAmelCase			=       BioGptTokenizer.from_pretrained('microsoft/biogpt')
						_UpperCAmelCase			=       BioGptForCausalLM.from_pretrained('microsoft/biogpt')
						model.to(A)

						torch.manual_seed(0)
						_UpperCAmelCase			=       tokenizer('COVID-19 is'			,		return_tensors='pt').to(A)
						_UpperCAmelCase			=       model.generate(
						    **A			,		min_length=1_00			,		max_length=10_24			,		num_beams=5			,		early_stopping=A			,		)
						_UpperCAmelCase			=       tokenizer.decode(output_ids[0]			,		skip_special_tokens=A)

						_UpperCAmelCase			=       (
						    'COVID-19 is a global pandemic caused by severe acute respiratory syndrome coronavirus 2 (SARS-CoV-2), the'
						    ' causative agent of coronavirus disease 2019 (COVID-19), which has spread to more than 200 countries and'
						    ' territories, including the United States (US), Canada, Australia, New Zealand, the United Kingdom (UK),'
						    ' and the United States of America (USA), as of March 11, 2020, with more than 800,000 confirmed cases and'
						    ' more than 800,000 deaths.'
						)
						self.assertEqual(A			,		A)





import json
import os
import unittest

from transformers import CLIPTokenizer, CLIPTokenizerFast
from transformers.models.clip.tokenization_clip import VOCAB_FILES_NAMES
from transformers.testing_utils import require_ftfy, require_tokenizers

from ...test_tokenization_common import TokenizerTesterMixin







@require_tokenizers
class       __lowerCAmelCase   (      A    ,						unittest.TestCase						):
			UpperCamelCase        =					CLIPTokenizer
			UpperCamelCase        =					CLIPTokenizerFast
			UpperCamelCase        =					True
			UpperCamelCase        =					{}
			UpperCamelCase        =					False



			def    _lowerCamelCase	(						self       :  List[str])       ->   List[str]:



						"""simple docstring"""






						super().setUp()

						# fmt: off
						_UpperCAmelCase			=       ['l', 'o', 'w', 'e', 'r', 's', 't', 'i', 'd', 'n', 'lo', 'l</w>', 'w</w>', 'r</w>', 't</w>', 'low</w>', 'er</w>', 'lowest</w>', 'newer</w>', 'wider', '<unk>', '<|startoftext|>', '<|endoftext|>']
						# fmt: on
						_UpperCAmelCase			=       dict(zip(A			,		range(len(A))))
						_UpperCAmelCase			=       ['#version: 0.2', 'l o', 'lo w</w>', 'e r</w>']
						_UpperCAmelCase			=       {'unk_token': '<unk>'}

						_UpperCAmelCase			=       os.path.join(self.tmpdirname			,		VOCAB_FILES_NAMES['vocab_file'])
						_UpperCAmelCase			=       os.path.join(self.tmpdirname			,		VOCAB_FILES_NAMES['merges_file'])
						with open(self.vocab_file			,		'w'			,		encoding='utf-8') as fp:
									fp.write(json.dumps(A) + '\n')
						with open(self.merges_file			,		'w'			,		encoding='utf-8') as fp:
									fp.write('\n'.join(A))



			def    _lowerCamelCase	(						self       :  Optional[Any]			,		**A       :  str)       ->   Optional[int]:



						"""simple docstring"""






						kwargs.update(self.special_tokens_map)
						return CLIPTokenizer.from_pretrained(self.tmpdirname			,		**A)



			def    _lowerCamelCase	(						self       :  Any			,		**A       :  Dict)       ->   Union[str, Any]:



						"""simple docstring"""






						kwargs.update(self.special_tokens_map)
						return CLIPTokenizerFast.from_pretrained(self.tmpdirname			,		**A)



			def    _lowerCamelCase	(						self       :  Optional[int]			,		A       :  Union[str, Any])       ->   int:



						"""simple docstring"""






						_UpperCAmelCase			=       'lower newer'
						_UpperCAmelCase			=       'lower newer'
						return input_text, output_text



			def    _lowerCamelCase	(						self       :  Dict)       ->   Any:



						"""simple docstring"""






						_UpperCAmelCase			=       CLIPTokenizer(self.vocab_file			,		self.merges_file			,		**self.special_tokens_map)
						_UpperCAmelCase			=       'lower newer'
						_UpperCAmelCase			=       ['lo', 'w', 'er</w>', 'n', 'e', 'w', 'er</w>']
						_UpperCAmelCase			=       tokenizer.tokenize(A)
						self.assertListEqual(A			,		A)

						_UpperCAmelCase			=       tokens + [tokenizer.unk_token]
						_UpperCAmelCase			=       [10, 2, 16, 9, 3, 2, 16, 20]
						self.assertListEqual(tokenizer.convert_tokens_to_ids(A)			,		A)



			@require_ftfy
			def    _lowerCamelCase	(						self       :  List[Any])       ->   Dict:



						"""simple docstring"""






						for tokenizer, pretrained_name, kwargs in self.tokenizers_list:
									with self.subTest(F"{tokenizer.__class__.__name__} ({pretrained_name})"):
												_UpperCAmelCase			=       self.tokenizer_class.from_pretrained(A			,		**A)
												_UpperCAmelCase			=       self.rust_tokenizer_class.from_pretrained(A			,		**A)

												_UpperCAmelCase			=       'A\n\'ll 11p223RF☆ho!!to?\'d\'d\'\'d of a cat to-$\'\'d.'
												_UpperCAmelCase			=       tokenizer_s.tokenize(A)
												_UpperCAmelCase			=       tokenizer_r.tokenize(A)

												self.assertListEqual(A			,		A)

												# Test that the tokenization is identical on an example containing a character (Latin Small Letter A
												# with Tilde) encoded in 2 different ways
												_UpperCAmelCase			=       'xa\u0303y' + ' ' + 'x\xe3y'
												_UpperCAmelCase			=       tokenizer_s.tokenize(A)
												_UpperCAmelCase			=       tokenizer_r.tokenize(A)

												self.assertListEqual(A			,		A)

												# Test that the tokenization is identical on unicode of space type
												_UpperCAmelCase			=       [
												    '\u0009',  # (horizontal tab, '\t')
												    '\u000B',  # (vertical tab)
												    '\u000C',  # (form feed)
												    '\u0020',  # (space, ' ')
												    '\u200E',  # (left-to-right mark):w
												    '\u200F',  # (right-to-left mark)
												]
												for unicode_seq in spaces_unicodes:
															_UpperCAmelCase			=       tokenizer_s.tokenize(A)
															_UpperCAmelCase			=       tokenizer_r.tokenize(A)

															self.assertListEqual(A			,		A)

												# Test that the tokenization is identical on unicode of line break type
												_UpperCAmelCase			=       [
												    '\u000A',  # (line feed, '\n')
												    '\r\n',  # (carriage return and line feed, '\r\n')
												    '\u000D',  # (carriage return, '\r')
												    '\r',  # (carriage return, '\r')
												    '\u000D',  # (carriage return, '\r')
												    '\u2028',  # (line separator)
												    '\u2029',  # (paragraph separator)
												    # "\u0085", # (next line)
												]

												# The tokenization is not identical for the character "\u0085" (next line). The slow version using ftfy transforms
												# it into the Horizontal Ellipsis character "…" ("\u2026") while the fast version transforms it into a
												# space (and thus into an empty list).

												for unicode_seq in line_break_unicodes:
															_UpperCAmelCase			=       tokenizer_s.tokenize(A)
															_UpperCAmelCase			=       tokenizer_r.tokenize(A)

															self.assertListEqual(A			,		A)



			def    _lowerCamelCase	(						self       :  str)       ->   Optional[Any]:



						"""simple docstring"""






						for tokenizer, pretrained_name, kwargs in self.tokenizers_list:
									with self.subTest(F"{tokenizer.__class__.__name__} ({pretrained_name})"):
												_UpperCAmelCase			=       'hello'  # `hello` is a token in the vocabulary of `pretrained_name`
												_UpperCAmelCase			=       F"{text_of_1_token} {text_of_1_token}"

												_UpperCAmelCase			=       self.rust_tokenizer_class.from_pretrained(
												    A			,		use_fast=A			,		)
												_UpperCAmelCase			=       tokenizer_r(A			,		return_offsets_mapping=A			,		add_special_tokens=A)
												self.assertEqual(encoding.offset_mapping[0]			,		(0, len(A)))
												self.assertEqual(
												    encoding.offset_mapping[1]			,		(len(A) + 1, len(A) + 1 + len(A))			,		)

												_UpperCAmelCase			=       F" {text}"

												_UpperCAmelCase			=       self.rust_tokenizer_class.from_pretrained(
												    A			,		use_fast=A			,		)
												_UpperCAmelCase			=       tokenizer_r(A			,		return_offsets_mapping=A			,		add_special_tokens=A)
												self.assertEqual(encoding.offset_mapping[0]			,		(1, 1 + len(A)))
												self.assertEqual(
												    encoding.offset_mapping[1]			,		(1 + len(A) + 1, 1 + len(A) + 1 + len(A))			,		)



			def    _lowerCamelCase	(						self       :  Tuple)       ->   str:



						"""simple docstring"""






						with self.assertRaises(A) as context:
									self.rust_tokenizer_class.from_pretrained('robot-test/old-clip-tokenizer')

						self.assertTrue(
						    context.exception.args[0].startswith(
						        'The `backend_tokenizer` provided does not match the expected format.'))



			@require_ftfy
			def    _lowerCamelCase	(						self       :  int)       ->   int:



						"""simple docstring"""






						super().test_tokenization_python_rust_equals()



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



						"""simple docstring"""






						pass
