
import inspect
import unittest

import numpy as np

from tests.test_modeling_common import floats_tensor
from transformers import MaskaFormerConfig, is_torch_available, is_vision_available
from transformers.testing_utils import require_torch, require_torch_multi_gpu, require_vision, slow, torch_device
from transformers.utils import cached_property

from ...test_configuration_common import ConfigTester
from ...test_modeling_common import ModelTesterMixin
from ...test_pipeline_mixin import PipelineTesterMixin


if is_torch_available():
		import torch

		from transformers import MaskaFormerForUniversalSegmentation, MaskaFormerModel

		if is_vision_available():
				from transformers import MaskaFormerImageProcessor

if is_vision_available():
		from PIL import Image




class 					lowerCamelCase__				:




	'''simple docstring'''




	def __init__(   self						:Optional[Any]	,  a						:Union[str, Any]	,  a						:int=2	,  a						:Dict=True	,  a						:str=False	,  a						:Any=1_0	,  a						:Dict=3	,  a						:Tuple=3_2 * 8	,  a						:Tuple=3_2 * 8	,  a						:Dict=4	,  a						:Optional[int]=6_4	,  )						->					int:
								__UpperCamelCase      :  Union[str, Any]       =   parent
								__UpperCamelCase      :  Union[str, Any]       =   batch_size
								__UpperCamelCase      :  Union[str, Any]       =   is_training
								__UpperCamelCase      :  Tuple       =   use_auxiliary_loss
								__UpperCamelCase      :  Optional[int]       =   num_queries
								__UpperCamelCase      :  str       =   num_channels
								__UpperCamelCase      :  List[str]       =   min_size
								__UpperCamelCase      :  Dict       =   max_size
								__UpperCamelCase      :  List[str]       =   num_labels
								__UpperCamelCase      :  Tuple       =   hidden_dim
								__UpperCamelCase      :  int       =   hidden_dim







	def   _lowerCamelCase							(   self						:Tuple		)						->					Optional[Any]:
								__UpperCamelCase      :  Tuple       =   floats_tensor([self.batch_size, self.num_channels, self.min_size, self.max_size]		).to(
								    a		)

								__UpperCamelCase      :  List[Any]       =   torch.ones([self.batch_size, self.min_size, self.max_size]	,  device=a		)

								__UpperCamelCase      :  Optional[int]       =   (
								    torch.rand([self.batch_size, self.num_labels, self.min_size, self.max_size]	,  device=a		) > 0.5
								).float()
								__UpperCamelCase      :  Dict       =   (torch.rand((self.batch_size, self.num_labels)	,  device=a		) > 0.5).long()

								__UpperCamelCase      :  Any       =   self.get_config()
								return config, pixel_values, pixel_mask, mask_labels, class_labels







	def   _lowerCamelCase							(   self						:List[str]		)						->					Dict:
								__UpperCamelCase      :  List[str]       =   MaskaFormerConfig(
								    hidden_size=self.hidden_dim	,  )
								__UpperCamelCase      :  Tuple       =   self.num_queries
								__UpperCamelCase      :  str       =   self.num_labels

								__UpperCamelCase      :  Tuple       =   [1, 1, 1, 1]
								__UpperCamelCase      :  Union[str, Any]       =   self.num_channels

								__UpperCamelCase      :  Optional[int]       =   6_4
								__UpperCamelCase      :  Optional[Any]       =   1_2_8
								__UpperCamelCase      :  Any       =   self.hidden_dim
								__UpperCamelCase      :  str       =   self.hidden_dim
								__UpperCamelCase      :  Any       =   self.hidden_dim
								return config







	def   _lowerCamelCase							(   self						:List[str]		)						->					Union[str, Any]:
								__UpperCamelCase  ,		__UpperCamelCase  ,		__UpperCamelCase  ,		__UpperCamelCase  ,		__UpperCamelCase      :  Tuple       =   self.prepare_config_and_inputs()
								__UpperCamelCase      :  Any       =   {"pixel_values": pixel_values, "pixel_mask": pixel_mask}
								return config, inputs_dict







	def   _lowerCamelCase							(   self						:Tuple	,  a						:Tuple	,  a						:Any		)						->					Optional[int]:
								__UpperCamelCase      :  List[str]       =   output.encoder_hidden_states
								__UpperCamelCase      :  List[str]       =   output.pixel_decoder_hidden_states
								__UpperCamelCase      :  Optional[int]       =   output.transformer_decoder_hidden_states

								self.parent.assertTrue(len(a		)	,  len(config.backbone_config.depths		)		)
								self.parent.assertTrue(len(a		)	,  len(config.backbone_config.depths		)		)
								self.parent.assertTrue(len(a		)	,  config.decoder_layers		)







	def   _lowerCamelCase							(   self						:Dict	,  a						:List[Any]	,  a						:List[Any]	,  a						:List[str]	,  a						:Union[str, Any]=False		)						->					Any:
								with torch.no_grad():
															__UpperCamelCase      :  List[Any]       =   MaskaFormerModel(config=a		)
															model.to(a		)
															model.eval()

															__UpperCamelCase      :  Optional[int]       =   model(pixel_values=a	,  pixel_mask=a		)
															__UpperCamelCase      :  Tuple       =   model(a	,  output_hidden_states=a		)

								self.parent.assertEqual(
								    output.transformer_decoder_last_hidden_state.shape	,  (self.batch_size, self.num_queries, self.hidden_dim)	,  )
								# let's ensure the other two hidden state exists
								self.parent.assertTrue(output.pixel_decoder_last_hidden_state is not None		)
								self.parent.assertTrue(output.encoder_last_hidden_state is not None		)

								if output_hidden_states:
															self.check_output_hidden_state(a	,  a		)







	def   _lowerCamelCase							(   self						:Optional[Any]	,  a						:List[Any]	,  a						:Union[str, Any]	,  a						:int	,  a						:Dict	,  a						:str		)						->					List[Any]:
								__UpperCamelCase      :  Any       =   MaskaFormerForUniversalSegmentation(config=a		)
								model.to(a		)
								model.eval()

								def comm_check_on_output(a						:Any		):
															# let's still check that all the required stuff is there
															self.parent.assertTrue(result.transformer_decoder_last_hidden_state is not None		)
															self.parent.assertTrue(result.pixel_decoder_last_hidden_state is not None		)
															self.parent.assertTrue(result.encoder_last_hidden_state is not None		)
															# okay, now we need to check the logits shape
															# due to the encoder compression, masks have a //4 spatial size
															self.parent.assertEqual(
															    result.masks_queries_logits.shape	,  (self.batch_size, self.num_queries, self.min_size // 4, self.max_size // 4)	,  )
															# + 1 for null class
															self.parent.assertEqual(
															    result.class_queries_logits.shape	,  (self.batch_size, self.num_queries, self.num_labels + 1)		)

								with torch.no_grad():
															__UpperCamelCase      :  Optional[int]       =   model(pixel_values=a	,  pixel_mask=a		)
															__UpperCamelCase      :  str       =   model(a		)

															comm_check_on_output(a		)

															__UpperCamelCase      :  Optional[int]       =   model(
															    pixel_values=a	,  pixel_mask=a	,  mask_labels=a	,  class_labels=a		)

								comm_check_on_output(a		)

								self.parent.assertTrue(result.loss is not None		)
								self.parent.assertEqual(result.loss.shape	,  torch.Size([1]		)		)




@require_torch
class 					lowerCamelCase__				(							__lowercase	,		__lowercase	,		unittest.TestCase):




	'''simple docstring'''




	_A								=	(MaskaFormerModel, MaskaFormerForUniversalSegmentation) if is_torch_available() else ()
	_A								=	{'feature-extraction': MaskaFormerModel} if is_torch_available() else {}

	_A								=	False
	_A								=	False
	_A								=	False
	_A								=	False







	def   _lowerCamelCase							(   self						:Optional[int]		)						->					Optional[int]:
								__UpperCamelCase      :  Dict       =   MaskaFormerModelTester(self		)
								__UpperCamelCase      :  int       =   ConfigTester(self	,  config_class=a	,  has_text_modality=a		)







	def   _lowerCamelCase							(   self						:str		)						->					List[Any]:
								self.config_tester.run_common_tests()







	def   _lowerCamelCase							(   self						:Tuple		)						->					Any:
								__UpperCamelCase  ,		__UpperCamelCase      :  Union[str, Any]       =   self.model_tester.prepare_config_and_inputs_for_common()
								self.model_tester.create_and_check_maskaformer_model(a	,  **a	,  output_hidden_states=a		)







	def   _lowerCamelCase							(   self						:Any		)						->					List[str]:
								__UpperCamelCase      :  Optional[Any]       =   self.model_tester.prepare_config_and_inputs()
								self.model_tester.create_and_check_maskaformer_instance_segmentation_head_model(*a		)







	@unittest.skip(reason="Mask2Former does not use inputs_embeds"		)
	def   _lowerCamelCase							(   self						:Dict		)						->					Optional[int]:
								pass







	@unittest.skip(reason="Mask2Former does not have a get_input_embeddings method"		)
	def   _lowerCamelCase							(   self						:Optional[Any]		)						->					Any:
								pass







	@unittest.skip(reason="Mask2Former is not a generative model"		)
	def   _lowerCamelCase							(   self						:Any		)						->					List[str]:
								pass







	@unittest.skip(reason="Mask2Former does not use token embeddings"		)
	def   _lowerCamelCase							(   self						:Any		)						->					Tuple:
								pass







	@require_torch_multi_gpu
	@unittest.skip(
	    reason="Mask2Former has some layers using `add_module` which doesn't work well with `nn.DataParallel`"		)
	def   _lowerCamelCase							(   self						:Tuple		)						->					Union[str, Any]:
								pass







	@unittest.skip("Will be fixed soon by reducing the size of the model used for common tests."		)
	def   _lowerCamelCase							(   self						:Dict		)						->					List[str]:
								pass







	def   _lowerCamelCase							(   self						:Union[str, Any]		)						->					int:
								__UpperCamelCase  ,		__UpperCamelCase      :  Dict       =   self.model_tester.prepare_config_and_inputs_for_common()

								for model_class in self.all_model_classes:
															__UpperCamelCase      :  Dict       =   model_class(a		)
															__UpperCamelCase      :  Any       =   inspect.signature(model.forward		)
															# signature.parameters is an OrderedDict => so arg_names order is deterministic
															__UpperCamelCase      :  Dict       =   [*signature.parameters.keys()]

															__UpperCamelCase      :  int       =   ["pixel_values"]
															self.assertListEqual(arg_names[:1]	,  a		)







	@slow
	def   _lowerCamelCase							(   self						:int		)						->					Optional[Any]:
								for model_name in ["facebook/mask2former-swin-small-coco-instance"]:
															__UpperCamelCase      :  Optional[Any]       =   MaskaFormerModel.from_pretrained(a		)
															self.assertIsNotNone(a		)







	def   _lowerCamelCase							(   self						:str		)						->					Tuple:
								__UpperCamelCase      :  Optional[int]       =   (self.model_tester.min_size,) * 2
								__UpperCamelCase      :  List[Any]       =   {
								    "pixel_values": torch.randn((2, 3, *size)	,  device=a		),
								    "mask_labels": torch.randn((2, 1_0, *size)	,  device=a		),
								    "class_labels": torch.zeros(2	,  1_0	,  device=a		).long(),
								}
								__UpperCamelCase      :  List[str]       =   self.model_tester.get_config()

								__UpperCamelCase      :  Any       =   MaskaFormerForUniversalSegmentation(a		).to(a		)
								__UpperCamelCase      :  int       =   model(**a		)
								self.assertTrue(outputs.loss is not None		)







	def   _lowerCamelCase							(   self						:List[Any]		)						->					str:
								__UpperCamelCase  ,		__UpperCamelCase      :  List[Any]       =   self.model_tester.prepare_config_and_inputs_for_common()
								self.model_tester.create_and_check_maskaformer_model(a	,  **a	,  output_hidden_states=a		)







	def   _lowerCamelCase							(   self						:int		)						->					Tuple:
								__UpperCamelCase  ,		__UpperCamelCase      :  Optional[Any]       =   self.model_tester.prepare_config_and_inputs_for_common()

								for model_class in self.all_model_classes:
															__UpperCamelCase      :  List[Any]       =   model_class(a		).to(a		)
															__UpperCamelCase      :  str       =   model(**a	,  output_attentions=a		)
															self.assertTrue(outputs.attentions is not None		)







	def   _lowerCamelCase							(   self						:str		)						->					List[str]:
								if not self.model_tester.is_training:
															return

								__UpperCamelCase      :  List[str]       =   self.all_model_classes[1]
								__UpperCamelCase  ,		__UpperCamelCase  ,		__UpperCamelCase  ,		__UpperCamelCase  ,		__UpperCamelCase      :  Optional[int]       =   self.model_tester.prepare_config_and_inputs()

								__UpperCamelCase      :  int       =   model_class(a		)
								model.to(a		)
								model.train()

								__UpperCamelCase      :  Optional[int]       =   model(a	,  mask_labels=a	,  class_labels=a		).loss
								loss.backward()







	def   _lowerCamelCase							(   self						:Any		)						->					Optional[int]:
								__UpperCamelCase      :  Optional[int]       =   self.all_model_classes[1]
								__UpperCamelCase  ,		__UpperCamelCase  ,		__UpperCamelCase  ,		__UpperCamelCase  ,		__UpperCamelCase      :  Any       =   self.model_tester.prepare_config_and_inputs()
								__UpperCamelCase      :  Any       =   True
								__UpperCamelCase      :  List[Any]       =   True

								__UpperCamelCase      :  str       =   model_class(a		).to(a		)
								model.train()

								__UpperCamelCase      :  Optional[int]       =   model(a	,  mask_labels=a	,  class_labels=a		)

								__UpperCamelCase      :  Optional[Any]       =   outputs.encoder_hidden_states[0]
								encoder_hidden_states.retain_grad()

								__UpperCamelCase      :  Union[str, Any]       =   outputs.pixel_decoder_hidden_states[0]
								pixel_decoder_hidden_states.retain_grad()

								__UpperCamelCase      :  Tuple       =   outputs.transformer_decoder_hidden_states[0]
								transformer_decoder_hidden_states.retain_grad()

								__UpperCamelCase      :  List[str]       =   outputs.attentions[0]
								attentions.retain_grad()

								outputs.loss.backward(retain_graph=a		)

								self.assertIsNotNone(encoder_hidden_states.grad		)
								self.assertIsNotNone(pixel_decoder_hidden_states.grad		)
								self.assertIsNotNone(transformer_decoder_hidden_states.grad		)
								self.assertIsNotNone(attentions.grad		)
lowercase    :   List[str]						=			1E-4




def       _SCREAMING_SNAKE_CASE   (						)   ->       Optional[Any]:






							'''simple docstring'''





							__UpperCamelCase      :  Optional[Any]       =   Image.open("./tests/fixtures/tests_samples/COCO/000000039769.png")
							return image




@require_vision
@slow
class 					lowerCamelCase__				(							unittest.TestCase):




	'''simple docstring'''




	@cached_property
	def   _lowerCamelCase							(   self						:Optional[Any]		)						->					Any:
								return "facebook/mask2former-swin-small-coco-instance"







	@cached_property
	def   _lowerCamelCase							(   self						:int		)						->					int:
								return MaskaFormerImageProcessor.from_pretrained(self.model_checkpoints		) if is_vision_available() else None







	def   _lowerCamelCase							(   self						:List[Any]		)						->					List[Any]:
								__UpperCamelCase      :  Optional[Any]       =   MaskaFormerModel.from_pretrained(self.model_checkpoints		).to(a		)
								__UpperCamelCase      :  Optional[int]       =   self.default_image_processor
								__UpperCamelCase      :  List[Any]       =   prepare_img()
								__UpperCamelCase      :  Any       =   image_processor(a	,  return_tensors="pt"		).to(a		)
								__UpperCamelCase      :  Any       =   inputs["pixel_values"].shape
								# check size is divisible by 32
								self.assertTrue((inputs_shape[-1] % 3_2) == 0 and (inputs_shape[-2] % 3_2) == 0		)
								# check size
								self.assertEqual(a	,  (1, 3, 3_8_4, 3_8_4)		)

								with torch.no_grad():
															__UpperCamelCase      :  List[str]       =   model(**a		)

								__UpperCamelCase      :  str       =   torch.tensor(
								    [[-0.2790, -1.0717, -1.1668], [-0.5128, -0.3128, -0.4987], [-0.5832, 0.1971, -0.0197]]		).to(a		)
								self.assertTrue(
								    torch.allclose(
								        outputs.encoder_last_hidden_state[0, 0, :3, :3]	,  a	,  atol=a		)		)

								__UpperCamelCase      :  Any       =   torch.tensor(
								    [[0.8973, 1.1847, 1.1776], [1.1934, 1.5040, 1.5128], [1.1153, 1.4486, 1.4951]]		).to(a		)
								self.assertTrue(
								    torch.allclose(
								        outputs.pixel_decoder_last_hidden_state[0, 0, :3, :3]	,  a	,  atol=a		)		)

								__UpperCamelCase      :  Dict       =   torch.tensor(
								    [[2.1152, 1.7000, -0.8603], [1.5808, 1.8004, -0.9353], [1.6043, 1.7495, -0.5999]]		).to(a		)
								self.assertTrue(
								    torch.allclose(
								        outputs.transformer_decoder_last_hidden_state[0, :3, :3]	,  a	,  atol=a		)		)







	def   _lowerCamelCase							(   self						:Tuple		)						->					List[str]:
								__UpperCamelCase      :  Union[str, Any]       =   MaskaFormerForUniversalSegmentation.from_pretrained(self.model_checkpoints		).to(a		).eval()
								__UpperCamelCase      :  str       =   self.default_image_processor
								__UpperCamelCase      :  str       =   prepare_img()
								__UpperCamelCase      :  Optional[Any]       =   image_processor(a	,  return_tensors="pt"		).to(a		)
								__UpperCamelCase      :  str       =   inputs["pixel_values"].shape
								# check size is divisible by 32
								self.assertTrue((inputs_shape[-1] % 3_2) == 0 and (inputs_shape[-2] % 3_2) == 0		)
								# check size
								self.assertEqual(a	,  (1, 3, 3_8_4, 3_8_4)		)

								with torch.no_grad():
															__UpperCamelCase      :  int       =   model(**a		)
								# masks_queries_logits
								__UpperCamelCase      :  Optional[Any]       =   outputs.masks_queries_logits
								self.assertEqual(
								    masks_queries_logits.shape	,  (1, model.config.num_queries, inputs_shape[-2] // 4, inputs_shape[-1] // 4)		)
								__UpperCamelCase      :  str       =   [
								    [-8.7839, -9.0056, -8.8121],
								    [-7.4104, -7.0313, -6.5401],
								    [-6.6105, -6.3427, -6.4675],
								]
								__UpperCamelCase      :  Tuple       =   torch.tensor(a		).to(a		)
								self.assertTrue(torch.allclose(masks_queries_logits[0, 0, :3, :3]	,  a	,  atol=a		)		)
								# class_queries_logits
								__UpperCamelCase      :  Optional[int]       =   outputs.class_queries_logits
								self.assertEqual(class_queries_logits.shape	,  (1, model.config.num_queries, model.config.num_labels + 1)		)
								__UpperCamelCase      :  str       =   torch.tensor(
								    [
								        [1.8324, -8.0835, -4.1922],
								        [0.8450, -9.0050, -3.6053],
								        [0.3045, -7.7293, -3.0275],
								    ]		).to(a		)
								self.assertTrue(torch.allclose(outputs.class_queries_logits[0, :3, :3]	,  a	,  atol=a		)		)







	def   _lowerCamelCase							(   self						:int		)						->					Any:
								__UpperCamelCase      :  Union[str, Any]       =   MaskaFormerForUniversalSegmentation.from_pretrained(self.model_checkpoints		).to(a		).eval()
								__UpperCamelCase      :  Dict       =   self.default_image_processor

								__UpperCamelCase      :  Tuple       =   image_processor(
								    [np.zeros((3, 8_0_0, 1_3_3_3)		), np.zeros((3, 8_0_0, 1_3_3_3)		)]	,  segmentation_maps=[np.zeros((3_8_4, 3_8_4)		).astype(np.floataa		), np.zeros((3_8_4, 3_8_4)		).astype(np.floataa		)]	,  return_tensors="pt"	,  )

								__UpperCamelCase      :  Any       =   inputs["pixel_values"].to(a		)
								__UpperCamelCase      :  Any       =   [el.to(a		) for el in inputs["mask_labels"]]
								__UpperCamelCase      :  Union[str, Any]       =   [el.to(a		) for el in inputs["class_labels"]]

								with torch.no_grad():
															__UpperCamelCase      :  Optional[int]       =   model(**a		)

								self.assertTrue(outputs.loss is not None		)

import unittest
from pathlib import Path
from tempfile import TemporaryDirectory

from transformers import AutoConfig, TFAutoModel, is_tensorflow_text_available, is_tf_available
from transformers.models.bert.tokenization_bert import BertTokenizer
from transformers.testing_utils import require_tensorflow_text, require_tf, slow


if is_tf_available():
		import tensorflow as tf

if is_tensorflow_text_available():
		from transformers.models.bert import TFBertTokenizer


lowercase    :   Union[str, Any]						=			['bert-base-uncased', 'bert-base-cased']
lowercase    :   Any						=			'hf-internal-testing/tiny-bert-tf-only'

if is_tf_available():




		class 					lowerCamelCase__				(							tf.keras.Model):




			'''simple docstring'''




			def __init__(   self						:List[Any]	,  a						:int		)						->					int:
										super().__init__()
										__UpperCamelCase      :  Any       =   tokenizer
										__UpperCamelCase      :  Union[str, Any]       =   AutoConfig.from_pretrained(a		)
										__UpperCamelCase      :  Dict       =   TFAutoModel.from_config(a		)







			def   _lowerCamelCase							(   self						:List[Any]	,  a						:Dict		)						->					Any:
										__UpperCamelCase      :  int       =   self.tokenizer(a		)
										__UpperCamelCase      :  int       =   self.bert(**a		)
										return out["pooler_output"]




@require_tf
@require_tensorflow_text
class 					lowerCamelCase__				(							unittest.TestCase):




	'''simple docstring'''




	def   _lowerCamelCase							(   self						:str		)						->					str:
								super().setUp()

								__UpperCamelCase      :  Dict       =   [
								    BertTokenizer.from_pretrained(a		) for checkpoint in (TOKENIZER_CHECKPOINTS * 2)
								]  # repeat for when fast_bert_tokenizer=false
								__UpperCamelCase      :  List[Any]       =   [TFBertTokenizer.from_pretrained(a		) for checkpoint in TOKENIZER_CHECKPOINTS] + [
								    TFBertTokenizer.from_pretrained(a	,  use_fast_bert_tokenizer=a		)
								    for checkpoint in TOKENIZER_CHECKPOINTS
								]
								assert len(self.tokenizers		) == len(self.tf_tokenizers		)

								__UpperCamelCase      :  Dict       =   [
								    "This is a straightforward English test sentence.",
								    "This one has some weird characters\rto\nsee\r\nif  those\u00E9break things.",
								    "Now we're going to add some Chinese: 一 二 三 一二三",
								    "And some much more rare Chinese: 齉 堃 齉堃",
								    "Je vais aussi écrire en français pour tester les accents",
								    "Classical Irish also has some unusual characters, so in they go: Gaelaċ, ꝼ",
								]
								__UpperCamelCase      :  Dict       =   list(zip(self.test_sentences	,  self.test_sentences[::-1]		)		)







	def   _lowerCamelCase							(   self						:List[Any]		)						->					int:
								for tokenizer, tf_tokenizer in zip(self.tokenizers	,  self.tf_tokenizers		):
															for test_inputs in (self.test_sentences, self.paired_sentences):
																						__UpperCamelCase      :  str       =   tokenizer(a	,  return_tensors="tf"	,  padding="longest"		)
																						__UpperCamelCase      :  Any       =   tf_tokenizer(a		)

																						for key in python_outputs.keys():
																													self.assertTrue(tf.reduce_all(python_outputs[key].shape == tf_outputs[key].shape		)		)
																													self.assertTrue(tf.reduce_all(tf.cast(python_outputs[key]	,  tf.intaa		) == tf_outputs[key]		)		)







	@slow
	def   _lowerCamelCase							(   self						:Union[str, Any]		)						->					Any:
								for tf_tokenizer in self.tf_tokenizers:
															__UpperCamelCase      :  List[str]       =   tf_tokenizer(self.paired_sentences		)
															__UpperCamelCase      :  Union[str, Any]       =   tf_tokenizer(
															    text=[sentence[0] for sentence in self.paired_sentences]	,  text_pair=[sentence[1] for sentence in self.paired_sentences]	,  )
															for key in merged_outputs.keys():
																						self.assertTrue(tf.reduce_all(tf.cast(merged_outputs[key]	,  tf.intaa		) == separated_outputs[key]		)		)







	@slow
	def   _lowerCamelCase							(   self						:Any		)						->					Optional[int]:
								for tf_tokenizer in self.tf_tokenizers:
															__UpperCamelCase      :  Optional[Any]       =   tf.function(a		)
															for test_inputs in (self.test_sentences, self.paired_sentences):
																						__UpperCamelCase      :  Tuple       =   tf.constant(a		)
																						__UpperCamelCase      :  List[str]       =   compiled_tokenizer(a		)
																						__UpperCamelCase      :  Any       =   tf_tokenizer(a		)

																						for key in eager_outputs.keys():
																													self.assertTrue(tf.reduce_all(eager_outputs[key] == compiled_outputs[key]		)		)







	@slow
	def   _lowerCamelCase							(   self						:List[Any]		)						->					Tuple:
								for tf_tokenizer in self.tf_tokenizers:
															__UpperCamelCase      :  str       =   ModelToSave(tokenizer=a		)
															__UpperCamelCase      :  List[Any]       =   tf.convert_to_tensor(self.test_sentences		)
															__UpperCamelCase      :  Optional[int]       =   model(a		)  # Build model with some sample inputs
															with TemporaryDirectory() as tempdir:
																						__UpperCamelCase      :  Optional[Any]       =   Path(a		) / "saved.model"
																						model.save(a		)
																						__UpperCamelCase      :  List[Any]       =   tf.keras.models.load_model(a		)
															__UpperCamelCase      :  Optional[Any]       =   loaded_model(a		)
															# We may see small differences because the loaded model is compiled, so we need an epsilon for the test
															self.assertLessEqual(tf.reduce_max(tf.abs(out - loaded_output		)		)	,  1E-5		)