






import os
import unittest

from transformers import BatchEncoding
from transformers.models.bert.tokenization_bert import (
    BasicTokenizer,
    WordpieceTokenizer,
    _is_control,
    _is_punctuation,
    _is_whitespace,
)
from transformers.models.prophetnet.tokenization_prophetnet import VOCAB_FILES_NAMES, ProphetNetTokenizer
from transformers.testing_utils import require_torch, slow

from ...test_tokenization_common import TokenizerTesterMixin


class   __SCREAMING_SNAKE_CASE(	a_    ,  unittest.TestCase	):
							_UpperCAmelCase     =       ProphetNetTokenizer
							_UpperCAmelCase     =       False
							def lowerCAmelCase_ (     self:      int						)		->		Any:
											super().setUp()

											snake_case__									=     [
											    '[UNK]',
											    '[CLS]',
											    '[SEP]',
											    '[PAD]',
											    '[MASK]',
											    'want',
											    '##want',
											    '##ed',
											    'wa',
											    'un',
											    'runn',
											    '##ing',
											    ',',
											    'low',
											    'lowest',
											]
											snake_case__									=     os.path.join(self.tmpdirname       ,	VOCAB_FILES_NAMES['vocab_file']						)
											with open(self.vocab_file       ,	'w'       ,	encoding='utf-8'						) as vocab_writer:
															vocab_writer.write(''.join([x + '\n' for x in vocab_tokens]						)						)
							def lowerCAmelCase_ (     self:      Optional[int]       ,	UpperCamelCase:      int						)		->		Optional[Any]:
											snake_case__									=     'UNwant\u00E9d,running'
											snake_case__									=     'unwanted, running'
											return input_text, output_text
							def lowerCAmelCase_ (     self:      List[Any]						)		->		Any:
											snake_case__									=     self.tokenizer_class(self.vocab_file						)

											snake_case__									=     tokenizer.tokenize('UNwant\u00E9d,running'						)
											self.assertListEqual(UpperCamelCase       ,	['un', '##want', '##ed', ',', 'runn', '##ing']						)
											self.assertListEqual(tokenizer.convert_tokens_to_ids(UpperCamelCase						)       ,	[9, 6, 7, 12, 10, 11]						)
							def lowerCAmelCase_ (     self:      Optional[int]						)		->		int:
											snake_case__									=     BasicTokenizer()

											self.assertListEqual(tokenizer.tokenize('ah\u535A\u63A8zz'						)       ,	['ah', '\u535A', '\u63A8', 'zz']						)
							def lowerCAmelCase_ (     self:      int						)		->		Dict:
											snake_case__									=     BasicTokenizer(do_lower_case=UpperCamelCase						)

											self.assertListEqual(
											    tokenizer.tokenize(' \tHeLLo!how  \n Are yoU?  '						)       ,	['hello', '!', 'how', 'are', 'you', '?']						)
											self.assertListEqual(tokenizer.tokenize('H\u00E9llo'						)       ,	['hello']						)
							def lowerCAmelCase_ (     self:      Dict						)		->		List[str]:
											snake_case__									=     BasicTokenizer(do_lower_case=UpperCamelCase       ,	strip_accents=UpperCamelCase						)

											self.assertListEqual(
											    tokenizer.tokenize(' \tHäLLo!how  \n Are yoU?  '						)       ,	['hällo', '!', 'how', 'are', 'you', '?']						)
											self.assertListEqual(tokenizer.tokenize('H\u00E9llo'						)       ,	['h\u00E9llo']						)
							def lowerCAmelCase_ (     self:      Optional[int]						)		->		List[str]:
											snake_case__									=     BasicTokenizer(do_lower_case=UpperCamelCase       ,	strip_accents=UpperCamelCase						)

											self.assertListEqual(
											    tokenizer.tokenize(' \tHäLLo!how  \n Are yoU?  '						)       ,	['hallo', '!', 'how', 'are', 'you', '?']						)
											self.assertListEqual(tokenizer.tokenize('H\u00E9llo'						)       ,	['hello']						)
							def lowerCAmelCase_ (     self:      Optional[Any]						)		->		Union[str, Any]:
											snake_case__									=     BasicTokenizer(do_lower_case=UpperCamelCase						)

											self.assertListEqual(
											    tokenizer.tokenize(' \tHäLLo!how  \n Are yoU?  '						)       ,	['hallo', '!', 'how', 'are', 'you', '?']						)
											self.assertListEqual(tokenizer.tokenize('H\u00E9llo'						)       ,	['hello']						)
							def lowerCAmelCase_ (     self:      str						)		->		Tuple:
											snake_case__									=     BasicTokenizer(do_lower_case=UpperCamelCase						)

											self.assertListEqual(
											    tokenizer.tokenize(' \tHeLLo!how  \n Are yoU?  '						)       ,	['HeLLo', '!', 'how', 'Are', 'yoU', '?']						)
							def lowerCAmelCase_ (     self:      Union[str, Any]						)		->		Any:
											snake_case__									=     BasicTokenizer(do_lower_case=UpperCamelCase       ,	strip_accents=UpperCamelCase						)

											self.assertListEqual(
											    tokenizer.tokenize(' \tHäLLo!how  \n Are yoU?  '						)       ,	['HäLLo', '!', 'how', 'Are', 'yoU', '?']						)
							def lowerCAmelCase_ (     self:      str						)		->		Optional[Any]:
											snake_case__									=     BasicTokenizer(do_lower_case=UpperCamelCase       ,	strip_accents=UpperCamelCase						)

											self.assertListEqual(
											    tokenizer.tokenize(' \tHäLLo!how  \n Are yoU?  '						)       ,	['HaLLo', '!', 'how', 'Are', 'yoU', '?']						)
							def lowerCAmelCase_ (     self:      Tuple						)		->		Dict:
											snake_case__									=     BasicTokenizer(do_lower_case=UpperCamelCase       ,	never_split=['[UNK]']						)

											self.assertListEqual(
											    tokenizer.tokenize(' \tHeLLo!how  \n Are yoU? [UNK]'						)       ,	['HeLLo', '!', 'how', 'Are', 'yoU', '?', '[UNK]']						)
							def lowerCAmelCase_ (     self:      Optional[int]						)		->		List[str]:
											snake_case__									=     ['[UNK]', '[CLS]', '[SEP]', 'want', '##want', '##ed', 'wa', 'un', 'runn', '##ing']

											snake_case__									=     {}
											for i, token in enumerate(UpperCamelCase						):
															snake_case__									=     i
											snake_case__									=     WordpieceTokenizer(vocab=UpperCamelCase       ,	unk_token='[UNK]'						)

											self.assertListEqual(tokenizer.tokenize(''						)       ,	[]						)

											self.assertListEqual(tokenizer.tokenize('unwanted running'						)       ,	['un', '##want', '##ed', 'runn', '##ing']						)

											self.assertListEqual(tokenizer.tokenize('unwantedX running'						)       ,	['[UNK]', 'runn', '##ing']						)
							@require_torch
							def lowerCAmelCase_ (     self:      Any						)		->		Dict:
											snake_case__									=     self.tokenizer_class.from_pretrained('microsoft/prophetnet-large-uncased'						)

											snake_case__									=     ['A long paragraph for summarization.', 'Another paragraph for summarization.']
											snake_case__									=     [10_37, 21_46, 2_04_23, 20_05, 76_80, 78_49, 39_89, 10_12, 1_02]
											snake_case__									=     tokenizer(UpperCamelCase       ,	padding=UpperCamelCase       ,	return_tensors='pt'						)
											self.assertIsInstance(UpperCamelCase       ,	UpperCamelCase						)
											snake_case__									=     list(batch.input_ids.numpy()[0]						)
											self.assertListEqual(UpperCamelCase       ,	UpperCamelCase						)

											self.assertEqual((2, 9)       ,	batch.input_ids.shape						)
											self.assertEqual((2, 9)       ,	batch.attention_mask.shape						)
							def lowerCAmelCase_ (     self:      int						)		->		List[str]:
											self.assertTrue(_is_whitespace(' '						)						)
											self.assertTrue(_is_whitespace('\t'						)						)
											self.assertTrue(_is_whitespace('\r'						)						)
											self.assertTrue(_is_whitespace('\n'						)						)
											self.assertTrue(_is_whitespace('\u00A0'						)						)

											self.assertFalse(_is_whitespace('A'						)						)
											self.assertFalse(_is_whitespace('-'						)						)
							def lowerCAmelCase_ (     self:      Optional[Any]						)		->		List[Any]:
											self.assertTrue(_is_control('\u0005'						)						)

											self.assertFalse(_is_control('A'						)						)
											self.assertFalse(_is_control(' '						)						)
											self.assertFalse(_is_control('\t'						)						)
											self.assertFalse(_is_control('\r'						)						)
							def lowerCAmelCase_ (     self:      Union[str, Any]						)		->		Tuple:
											self.assertTrue(_is_punctuation('-'						)						)
											self.assertTrue(_is_punctuation('$'						)						)
											self.assertTrue(_is_punctuation('`'						)						)
											self.assertTrue(_is_punctuation('.'						)						)

											self.assertFalse(_is_punctuation('A'						)						)
											self.assertFalse(_is_punctuation(' '						)						)


							@slow
							def lowerCAmelCase_ (     self:      Optional[Any]						)		->		int:
											snake_case__									=     self.tokenizer_class.from_pretrained('microsoft/prophetnet-large-uncased'						)

											snake_case__									=     tokenizer.encode('sequence builders'       ,	add_special_tokens=UpperCamelCase						)
											snake_case__									=     tokenizer.encode('multi-sequence build'       ,	add_special_tokens=UpperCamelCase						)

											snake_case__									=     tokenizer.build_inputs_with_special_tokens(UpperCamelCase						)
											snake_case__									=     tokenizer.build_inputs_with_special_tokens(UpperCamelCase       ,	UpperCamelCase						)

											assert encoded_sentence == text + [1_02]
											assert encoded_pair == text + [1_02] + text_a + [1_02]












import inspect
import unittest

from transformers import RegNetConfig, is_flax_available
from transformers.testing_utils import require_flax, slow
from transformers.utils import cached_property, is_vision_available

from ...test_configuration_common import ConfigTester
from ...test_modeling_flax_common import FlaxModelTesterMixin, floats_tensor


if is_flax_available():
							import jax
							import jax.numpy as jnp

							from transformers.models.regnet.modeling_flax_regnet import FlaxRegNetForImageClassification, FlaxRegNetModel

if is_vision_available():
							from PIL import Image

							from transformers import AutoImageProcessor


class   __SCREAMING_SNAKE_CASE(	unittest.TestCase	):
							def __init__(     self:      List[str]       ,	UpperCamelCase:      Dict       ,	UpperCamelCase:      Optional[int]=3       ,	UpperCamelCase:      Union[str, Any]=32       ,	UpperCamelCase:      Optional[int]=3       ,	UpperCamelCase:      Any=10       ,	UpperCamelCase:      List[str]=[10, 20, 30, 40]       ,	UpperCamelCase:      Optional[Any]=[1, 1, 2, 1]       ,	UpperCamelCase:      Tuple=True       ,	UpperCamelCase:      List[str]=True       ,	UpperCamelCase:      Optional[int]="relu"       ,	UpperCamelCase:      List[str]=3       ,	UpperCamelCase:      Dict=None       ,	)		->		Optional[Any]:
											snake_case__									=     parent
											snake_case__									=     batch_size
											snake_case__									=     image_size
											snake_case__									=     num_channels
											snake_case__									=     embeddings_size
											snake_case__									=     hidden_sizes
											snake_case__									=     depths
											snake_case__									=     is_training
											snake_case__									=     use_labels
											snake_case__									=     hidden_act
											snake_case__									=     num_labels
											snake_case__									=     scope
											snake_case__									=     len(UpperCamelCase						)
							def lowerCAmelCase_ (     self:      Union[str, Any]						)		->		Dict:
											snake_case__									=     floats_tensor([self.batch_size, self.num_channels, self.image_size, self.image_size]						)

											snake_case__									=     self.get_config()

											return config, pixel_values
							def lowerCAmelCase_ (     self:      int						)		->		Optional[Any]:
											return RegNetConfig(
											    num_channels=self.num_channels       ,	embeddings_size=self.embeddings_size       ,	hidden_sizes=self.hidden_sizes       ,	depths=self.depths       ,	hidden_act=self.hidden_act       ,	num_labels=self.num_labels       ,	image_size=self.image_size       ,	)
							def lowerCAmelCase_ (     self:      Optional[Any]       ,	UpperCamelCase:      List[Any]       ,	UpperCamelCase:      List[Any]						)		->		Optional[Any]:
											snake_case__									=     FlaxRegNetModel(config=UpperCamelCase						)
											snake_case__									=     model(UpperCamelCase						)

											# Output shape (b, c, h, w)
											self.parent.assertEqual(
											    result.last_hidden_state.shape       ,	(self.batch_size, self.hidden_sizes[-1], self.image_size // 32, self.image_size // 32)       ,	)
							def lowerCAmelCase_ (     self:      List[str]       ,	UpperCamelCase:      Tuple       ,	UpperCamelCase:      Optional[Any]						)		->		List[str]:
											snake_case__									=     self.num_labels
											snake_case__									=     FlaxRegNetForImageClassification(config=UpperCamelCase						)
											snake_case__									=     model(UpperCamelCase						)
											self.parent.assertEqual(result.logits.shape       ,	(self.batch_size, self.num_labels)						)


							def lowerCAmelCase_ (     self:      Tuple						)		->		List[str]:
											snake_case__									=     self.prepare_config_and_inputs()
											snake_case__							,						snake_case__									=     config_and_inputs
											snake_case__									=     {'pixel_values': pixel_values}
											return config, inputs_dict


@require_flax
class   __SCREAMING_SNAKE_CASE(	a_    ,  unittest.TestCase	):
							_UpperCAmelCase     =       (FlaxRegNetModel, FlaxRegNetForImageClassification) if is_flax_available() else ()

							_UpperCAmelCase     =       False
							_UpperCAmelCase     =       False
							_UpperCAmelCase     =       False
							def lowerCAmelCase_ (     self:      Dict						)		->		None:
											snake_case__									=     FlaxRegNetModelTester(self						)
											snake_case__									=     ConfigTester(self       ,	config_class=UpperCamelCase       ,	has_text_modality=UpperCamelCase						)
							def lowerCAmelCase_ (     self:      str						)		->		Optional[int]:
											self.create_and_test_config_common_properties()
											self.config_tester.create_and_test_config_to_json_string()
											self.config_tester.create_and_test_config_to_json_file()
											self.config_tester.create_and_test_config_from_and_save_pretrained()
											self.config_tester.create_and_test_config_with_num_labels()
											self.config_tester.check_config_can_be_init_without_params()
											self.config_tester.check_config_arguments_init()
							def lowerCAmelCase_ (     self:      List[Any]						)		->		List[str]:
											return
							def lowerCAmelCase_ (     self:      Union[str, Any]						)		->		Union[str, Any]:
											snake_case__									=     self.model_tester.prepare_config_and_inputs()
											self.model_tester.create_and_check_model(*UpperCamelCase						)
							def lowerCAmelCase_ (     self:      Tuple						)		->		List[Any]:
											snake_case__									=     self.model_tester.prepare_config_and_inputs()
											self.model_tester.create_and_check_for_image_classification(*UpperCamelCase						)
							@unittest.skip(reason='RegNet does not use inputs_embeds'						)
							def lowerCAmelCase_ (     self:      Optional[Any]						)		->		Dict:
											pass
							@unittest.skip(reason='RegNet does not support input and output embeddings'						)
							def lowerCAmelCase_ (     self:      List[str]						)		->		Dict:
											pass
							def lowerCAmelCase_ (     self:      Tuple						)		->		int:
											snake_case__							,						snake_case__									=     self.model_tester.prepare_config_and_inputs_for_common()

											for model_class in self.all_model_classes:
															snake_case__									=     model_class(UpperCamelCase						)
															snake_case__									=     inspect.signature(model.__call__						)
															# signature.parameters is an OrderedDict => so arg_names order is deterministic
															snake_case__									=     [*signature.parameters.keys()]

															snake_case__									=     ['pixel_values']
															self.assertListEqual(arg_names[:1]       ,	UpperCamelCase						)
							def lowerCAmelCase_ (     self:      Union[str, Any]						)		->		int:
											def check_hidden_states_output(UpperCamelCase:      Optional[int]       ,	UpperCamelCase:      Optional[Any]       ,	UpperCamelCase:      List[Any]						):
															snake_case__									=     model_class(UpperCamelCase						)

															snake_case__									=     model(**self._prepare_for_class(UpperCamelCase       ,	UpperCamelCase						)						)

															snake_case__									=     outputs.encoder_hidden_states if config.is_encoder_decoder else outputs.hidden_states

															snake_case__									=     self.model_tester.num_stages
															self.assertEqual(len(UpperCamelCase						)       ,	expected_num_stages + 1						)

											snake_case__							,						snake_case__									=     self.model_tester.prepare_config_and_inputs_for_common()

											for model_class in self.all_model_classes:
															snake_case__									=     True
															check_hidden_states_output(UpperCamelCase       ,	UpperCamelCase       ,	UpperCamelCase						)

															# check that output_hidden_states also work using config
															del inputs_dict["output_hidden_states"]
															snake_case__									=     True

															check_hidden_states_output(UpperCamelCase       ,	UpperCamelCase       ,	UpperCamelCase						)


							def lowerCAmelCase_ (     self:      str						)		->		str:
											snake_case__							,						snake_case__									=     self.model_tester.prepare_config_and_inputs_for_common()

											for model_class in self.all_model_classes:
															with self.subTest(model_class.__name__						):
																			snake_case__									=     self._prepare_for_class(UpperCamelCase       ,	UpperCamelCase						)
																			snake_case__									=     model_class(UpperCamelCase						)

																			@jax.jit
																			def model_jitted(UpperCamelCase:      str       ,	**UpperCamelCase:      Tuple						):
																							return model(pixel_values=UpperCamelCase       ,	**UpperCamelCase						)

																			with self.subTest('JIT Enabled'						):
																							snake_case__									=     model_jitted(**UpperCamelCase						).to_tuple()

																			with self.subTest('JIT Disabled'						):
																							with jax.disable_jit():
																											snake_case__									=     model_jitted(**UpperCamelCase						).to_tuple()

																			self.assertEqual(len(UpperCamelCase						)       ,	len(UpperCamelCase						)						)
																			for jitted_output, output in zip(UpperCamelCase       ,	UpperCamelCase						):
																							self.assertEqual(jitted_output.shape       ,	output.shape						)


def      a_ (      )			->			Optional[int]:







				"""simple docstring"""
				snake_case__									=     Image.open('./tests/fixtures/tests_samples/COCO/000000039769.png'  )
				return image


@require_flax
class   __SCREAMING_SNAKE_CASE(	unittest.TestCase	):
							@cached_property
							def lowerCAmelCase_ (     self:      str						)		->		Any:
											return AutoImageProcessor.from_pretrained('facebook/regnet-y-040'						) if is_vision_available() else None


							@slow
							def lowerCAmelCase_ (     self:      List[str]						)		->		Optional[Any]:
											snake_case__									=     FlaxRegNetForImageClassification.from_pretrained('facebook/regnet-y-040'						)

											snake_case__									=     self.default_image_processor
											snake_case__									=     prepare_img()
											snake_case__									=     image_processor(images=UpperCamelCase       ,	return_tensors='np'						)

											snake_case__									=     model(**UpperCamelCase						)

											# verify the logits
											snake_case__									=     (1, 10_00)
											self.assertEqual(outputs.logits.shape       ,	UpperCamelCase						)

											snake_case__									=     jnp.array([-0.4_180, -1.5_051, -3.4_836]						)

											self.assertTrue(jnp.allclose(outputs.logits[0, :3]       ,	UpperCamelCase       ,	atol=1e-4						)						)




