



"""simple docstring"""






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     A__     :




	'''simple docstring'''





	def __init__(  self:	Dict ,    _SCREAMING_SNAKE_CASE:	Any ,    _SCREAMING_SNAKE_CASE:	Any=2 ,    _SCREAMING_SNAKE_CASE:	str=True ,    _SCREAMING_SNAKE_CASE:	str=False ,    _SCREAMING_SNAKE_CASE:	Union[str, Any]=10 ,    _SCREAMING_SNAKE_CASE:	Optional[Any]=3 ,    _SCREAMING_SNAKE_CASE:	int=32 * 8 ,    _SCREAMING_SNAKE_CASE:	Optional[Any]=32 * 8 ,    _SCREAMING_SNAKE_CASE:	str=4 ,    _SCREAMING_SNAKE_CASE:	Union[str, Any]=64 ,    )       -> Optional[int]:

				"""simple docstring"""

				__lowerCAmelCase   :						Tuple				= parent
				__lowerCAmelCase   :						Dict				= batch_size
				__lowerCAmelCase   :						Any				= is_training
				__lowerCAmelCase   :						List[Any]				= use_auxiliary_loss
				__lowerCAmelCase   :						Optional[int]				= num_queries
				__lowerCAmelCase   :						Optional[Any]				= num_channels
				__lowerCAmelCase   :						Any				= min_size
				__lowerCAmelCase   :						int				= max_size
				__lowerCAmelCase   :						int				= num_labels
				__lowerCAmelCase   :						List[str]				= hidden_dim
				__lowerCAmelCase   :						Tuple				= hidden_dim

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

				"""simple docstring"""

				__lowerCAmelCase   :						Any				= floats_tensor([self.batch_size, self.num_channels, self.min_size, self.max_size]).to(
				    _SCREAMING_SNAKE_CASE)

				__lowerCAmelCase   :						Dict				= torch.ones([self.batch_size, self.min_size, self.max_size] ,    device=_SCREAMING_SNAKE_CASE)

				__lowerCAmelCase   :						Optional[Any]				= (
				    torch.rand([self.batch_size, self.num_labels, self.min_size, self.max_size] ,    device=_SCREAMING_SNAKE_CASE) > 0.5
				).float()
				__lowerCAmelCase   :						List[Any]				= (torch.rand((self.batch_size, self.num_labels) ,    device=_SCREAMING_SNAKE_CASE) > 0.5).long()

				__lowerCAmelCase   :						str				= self.get_config()
				return config, pixel_values, pixel_mask, mask_labels, class_labels

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

				"""simple docstring"""

				__lowerCAmelCase   :						int				= MaskaFormerConfig(
				    hidden_size=self.hidden_dim ,    )
				__lowerCAmelCase   :						Optional[Any]				= self.num_queries
				__lowerCAmelCase   :						List[str]				= self.num_labels

				__lowerCAmelCase   :						List[Any]				= [1, 1, 1, 1]
				__lowerCAmelCase   :						Optional[Any]				= self.num_channels

				__lowerCAmelCase   :						List[Any]				= 64
				__lowerCAmelCase   :						Tuple				= 128
				__lowerCAmelCase   :						str				= self.hidden_dim
				__lowerCAmelCase   :						int				= self.hidden_dim
				__lowerCAmelCase   :						Union[str, Any]				= self.hidden_dim
				return config

	def 							_SCREAMING_SNAKE_CASE     (  self:	Dict)       -> Tuple:

				"""simple docstring"""

				__lowerCAmelCase		,			__lowerCAmelCase		,			__lowerCAmelCase		,			__lowerCAmelCase		,			__lowerCAmelCase   :						str				= self.prepare_config_and_inputs()
				__lowerCAmelCase   :						Any				= {"pixel_values": pixel_values, "pixel_mask": pixel_mask}
				return config, inputs_dict

	def 							_SCREAMING_SNAKE_CASE     (  self:	str ,    _SCREAMING_SNAKE_CASE:	Any ,    _SCREAMING_SNAKE_CASE:	Tuple)       -> Any:

				"""simple docstring"""

				__lowerCAmelCase   :						Tuple				= output.encoder_hidden_states
				__lowerCAmelCase   :						Union[str, Any]				= output.pixel_decoder_hidden_states
				__lowerCAmelCase   :						Union[str, Any]				= output.transformer_decoder_hidden_states

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

	def 							_SCREAMING_SNAKE_CASE     (  self:	int ,    _SCREAMING_SNAKE_CASE:	int ,    _SCREAMING_SNAKE_CASE:	List[Any] ,    _SCREAMING_SNAKE_CASE:	List[Any] ,    _SCREAMING_SNAKE_CASE:	Dict=False)       -> str:

				"""simple docstring"""

				with torch.no_grad():
							__lowerCAmelCase   :						Tuple				= MaskaFormerModel(config=_SCREAMING_SNAKE_CASE)
							model.to(_SCREAMING_SNAKE_CASE)
							model.eval()

							__lowerCAmelCase   :						Dict				= model(pixel_values=_SCREAMING_SNAKE_CASE ,    pixel_mask=_SCREAMING_SNAKE_CASE)
							__lowerCAmelCase   :						Optional[Any]				= model(_SCREAMING_SNAKE_CASE ,    output_hidden_states=_SCREAMING_SNAKE_CASE)

				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(_SCREAMING_SNAKE_CASE ,    _SCREAMING_SNAKE_CASE)







	def 							_SCREAMING_SNAKE_CASE     (  self:	Union[str, Any] ,    _SCREAMING_SNAKE_CASE:	List[str] ,    _SCREAMING_SNAKE_CASE:	Optional[Any] ,    _SCREAMING_SNAKE_CASE:	Any ,    _SCREAMING_SNAKE_CASE:	List[str] ,    _SCREAMING_SNAKE_CASE:	Optional[Any])       -> str:

				"""simple docstring"""

				__lowerCAmelCase   :						Optional[Any]				= MaskaFormerForUniversalSegmentation(config=_SCREAMING_SNAKE_CASE)
				model.to(_SCREAMING_SNAKE_CASE)
				model.eval()

				def comm_check_on_output(_SCREAMING_SNAKE_CASE:	Optional[int]):
							# 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():
							__lowerCAmelCase   :						Optional[int]				= model(pixel_values=_SCREAMING_SNAKE_CASE ,    pixel_mask=_SCREAMING_SNAKE_CASE)
							__lowerCAmelCase   :						List[Any]				= model(_SCREAMING_SNAKE_CASE)

							comm_check_on_output(_SCREAMING_SNAKE_CASE)

							__lowerCAmelCase   :						List[Any]				= model(
							    pixel_values=_SCREAMING_SNAKE_CASE ,    pixel_mask=_SCREAMING_SNAKE_CASE ,    mask_labels=_SCREAMING_SNAKE_CASE ,    class_labels=_SCREAMING_SNAKE_CASE)

				comm_check_on_output(_SCREAMING_SNAKE_CASE)

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






@require_torch
class     A__     (						__SCREAMING_SNAKE_CASE						,	__SCREAMING_SNAKE_CASE						,	unittest.TestCase							):




	'''simple docstring'''





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

	SCREAMING_SNAKE_CASE					   =			False
	SCREAMING_SNAKE_CASE					   =			False
	SCREAMING_SNAKE_CASE					   =			False
	SCREAMING_SNAKE_CASE					   =			False

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

				"""simple docstring"""

				__lowerCAmelCase   :						List[Any]				= MaskaFormerModelTester(self)
				__lowerCAmelCase   :						Dict				= ConfigTester(self ,    config_class=_SCREAMING_SNAKE_CASE ,    has_text_modality=_SCREAMING_SNAKE_CASE)

	def 							_SCREAMING_SNAKE_CASE     (  self:	Any)       -> Any:

				"""simple docstring"""

				self.config_tester.run_common_tests()

	def 							_SCREAMING_SNAKE_CASE     (  self:	List[Any])       -> Tuple:

				"""simple docstring"""

				__lowerCAmelCase		,			__lowerCAmelCase   :						List[Any]				= self.model_tester.prepare_config_and_inputs_for_common()
				self.model_tester.create_and_check_maskaformer_model(_SCREAMING_SNAKE_CASE ,    **_SCREAMING_SNAKE_CASE ,    output_hidden_states=_SCREAMING_SNAKE_CASE)

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

				"""simple docstring"""

				__lowerCAmelCase   :						List[Any]				= self.model_tester.prepare_config_and_inputs()
				self.model_tester.create_and_check_maskaformer_instance_segmentation_head_model(*_SCREAMING_SNAKE_CASE)

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

				"""simple docstring"""

				pass

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

				"""simple docstring"""

				pass

	@unittest.skip(reason="Mask2Former is not a generative model")
	def 							_SCREAMING_SNAKE_CASE     (  self:	Optional[Any])       -> Union[str, Any]:

				"""simple docstring"""

				pass

	@unittest.skip(reason="Mask2Former does not use token embeddings")
	def 							_SCREAMING_SNAKE_CASE     (  self:	List[str])       -> str:

				"""simple docstring"""

				pass

	@require_torch_multi_gpu
	@unittest.skip(
	    reason="Mask2Former has some layers using `add_module` which doesn't work well with `nn.DataParallel`")
	def 							_SCREAMING_SNAKE_CASE     (  self:	int)       -> List[str]:

				"""simple docstring"""

				pass

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

				"""simple docstring"""

				pass

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

				"""simple docstring"""

				__lowerCAmelCase		,			__lowerCAmelCase   :						Union[str, Any]				= self.model_tester.prepare_config_and_inputs_for_common()

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

							__lowerCAmelCase   :						Union[str, Any]				= ["pixel_values"]
							self.assertListEqual(arg_names[:1] ,    _SCREAMING_SNAKE_CASE)

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

				"""simple docstring"""

				for model_name in ["facebook/mask2former-swin-small-coco-instance"]:
							__lowerCAmelCase   :						Optional[int]				= MaskaFormerModel.from_pretrained(_SCREAMING_SNAKE_CASE)
							self.assertIsNotNone(_SCREAMING_SNAKE_CASE)

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

				"""simple docstring"""

				__lowerCAmelCase   :						Dict				= (self.model_tester.min_size,) * 2
				__lowerCAmelCase   :						str				= {
				    "pixel_values": torch.randn((2, 3, *size) ,    device=_SCREAMING_SNAKE_CASE),
				    "mask_labels": torch.randn((2, 10, *size) ,    device=_SCREAMING_SNAKE_CASE),
				    "class_labels": torch.zeros(2 ,    10 ,    device=_SCREAMING_SNAKE_CASE).long(),
				}
				__lowerCAmelCase   :						Any				= self.model_tester.get_config()

				__lowerCAmelCase   :						Dict				= MaskaFormerForUniversalSegmentation(_SCREAMING_SNAKE_CASE).to(_SCREAMING_SNAKE_CASE)
				__lowerCAmelCase   :						str				= model(**_SCREAMING_SNAKE_CASE)
				self.assertTrue(outputs.loss is not None)

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

				"""simple docstring"""

				__lowerCAmelCase		,			__lowerCAmelCase   :						str				= self.model_tester.prepare_config_and_inputs_for_common()
				self.model_tester.create_and_check_maskaformer_model(_SCREAMING_SNAKE_CASE ,    **_SCREAMING_SNAKE_CASE ,    output_hidden_states=_SCREAMING_SNAKE_CASE)

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

				"""simple docstring"""

				__lowerCAmelCase		,			__lowerCAmelCase   :						List[str]				= self.model_tester.prepare_config_and_inputs_for_common()

				for model_class in self.all_model_classes:
							__lowerCAmelCase   :						Dict				= model_class(_SCREAMING_SNAKE_CASE).to(_SCREAMING_SNAKE_CASE)
							__lowerCAmelCase   :						Any				= model(**_SCREAMING_SNAKE_CASE ,    output_attentions=_SCREAMING_SNAKE_CASE)
							self.assertTrue(outputs.attentions is not None)

	def 							_SCREAMING_SNAKE_CASE     (  self:	str)       -> Tuple:

				"""simple docstring"""

				if not self.model_tester.is_training:
							return

				__lowerCAmelCase   :						Any				= self.all_model_classes[1]
				__lowerCAmelCase		,			__lowerCAmelCase		,			__lowerCAmelCase		,			__lowerCAmelCase		,			__lowerCAmelCase   :						Tuple				= self.model_tester.prepare_config_and_inputs()

				__lowerCAmelCase   :						Union[str, Any]				= model_class(_SCREAMING_SNAKE_CASE)
				model.to(_SCREAMING_SNAKE_CASE)
				model.train()

				__lowerCAmelCase   :						int				= model(_SCREAMING_SNAKE_CASE ,    mask_labels=_SCREAMING_SNAKE_CASE ,    class_labels=_SCREAMING_SNAKE_CASE).loss
				loss.backward()







	def 							_SCREAMING_SNAKE_CASE     (  self:	Tuple)       -> Any:

				"""simple docstring"""

				__lowerCAmelCase   :						Optional[Any]				= self.all_model_classes[1]
				__lowerCAmelCase		,			__lowerCAmelCase		,			__lowerCAmelCase		,			__lowerCAmelCase		,			__lowerCAmelCase   :						str				= self.model_tester.prepare_config_and_inputs()
				__lowerCAmelCase   :						int				= True
				__lowerCAmelCase   :						int				= True

				__lowerCAmelCase   :						Any				= model_class(_SCREAMING_SNAKE_CASE).to(_SCREAMING_SNAKE_CASE)
				model.train()

				__lowerCAmelCase   :						Dict				= model(_SCREAMING_SNAKE_CASE ,    mask_labels=_SCREAMING_SNAKE_CASE ,    class_labels=_SCREAMING_SNAKE_CASE)

				__lowerCAmelCase   :						int				= outputs.encoder_hidden_states[0]
				encoder_hidden_states.retain_grad()

				__lowerCAmelCase   :						int				= outputs.pixel_decoder_hidden_states[0]
				pixel_decoder_hidden_states.retain_grad()

				__lowerCAmelCase   :						Optional[int]				= outputs.transformer_decoder_hidden_states[0]
				transformer_decoder_hidden_states.retain_grad()

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

				outputs.loss.backward(retain_graph=_SCREAMING_SNAKE_CASE)

				self.assertIsNotNone(encoder_hidden_states.grad)
				self.assertIsNotNone(pixel_decoder_hidden_states.grad)
				self.assertIsNotNone(transformer_decoder_hidden_states.grad)
				self.assertIsNotNone(attentions.grad)






__snake_case							:     Tuple   =					1e-4


def     _lowercase       (						)		->     Any:
			__lowerCAmelCase   :						Union[str, Any]				= Image.open("./tests/fixtures/tests_samples/COCO/000000039769.png"			)
			return image





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




	'''simple docstring'''





	@cached_property
	def 							_SCREAMING_SNAKE_CASE     (  self:	int)       -> List[Any]:

				"""simple docstring"""

				return "facebook/mask2former-swin-small-coco-instance"

	@cached_property
	def 							_SCREAMING_SNAKE_CASE     (  self:	Tuple)       -> Optional[int]:

				"""simple docstring"""

				return MaskaFormerImageProcessor.from_pretrained(self.model_checkpoints) if is_vision_available() else None

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

				"""simple docstring"""

				__lowerCAmelCase   :						Any				= MaskaFormerModel.from_pretrained(self.model_checkpoints).to(_SCREAMING_SNAKE_CASE)
				__lowerCAmelCase   :						Any				= self.default_image_processor
				__lowerCAmelCase   :						Tuple				= prepare_img()
				__lowerCAmelCase   :						List[Any]				= image_processor(_SCREAMING_SNAKE_CASE ,    return_tensors="pt").to(_SCREAMING_SNAKE_CASE)
				__lowerCAmelCase   :						str				= inputs["pixel_values"].shape
				# check size is divisible by 32
				self.assertTrue((inputs_shape[-1] % 32) == 0 and (inputs_shape[-2] % 32) == 0)
				# check size
				self.assertEqual(_SCREAMING_SNAKE_CASE ,    (1, 3, 384, 384))

				with torch.no_grad():
							__lowerCAmelCase   :						List[Any]				= model(**_SCREAMING_SNAKE_CASE)

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

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

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

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

				"""simple docstring"""

				__lowerCAmelCase   :						List[Any]				= MaskaFormerForUniversalSegmentation.from_pretrained(self.model_checkpoints).to(_SCREAMING_SNAKE_CASE).eval()
				__lowerCAmelCase   :						Tuple				= self.default_image_processor
				__lowerCAmelCase   :						Any				= prepare_img()
				__lowerCAmelCase   :						int				= image_processor(_SCREAMING_SNAKE_CASE ,    return_tensors="pt").to(_SCREAMING_SNAKE_CASE)
				__lowerCAmelCase   :						int				= inputs["pixel_values"].shape
				# check size is divisible by 32
				self.assertTrue((inputs_shape[-1] % 32) == 0 and (inputs_shape[-2] % 32) == 0)
				# check size
				self.assertEqual(_SCREAMING_SNAKE_CASE ,    (1, 3, 384, 384))

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







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

				"""simple docstring"""

				__lowerCAmelCase   :						str				= MaskaFormerForUniversalSegmentation.from_pretrained(self.model_checkpoints).to(_SCREAMING_SNAKE_CASE).eval()
				__lowerCAmelCase   :						List[Any]				= self.default_image_processor

				__lowerCAmelCase   :						List[str]				= image_processor(
				    [np.zeros((3, 800, 1333)), np.zeros((3, 800, 1333))] ,    segmentation_maps=[np.zeros((384, 384)).astype(np.floataa), np.zeros((384, 384)).astype(np.floataa)] ,    return_tensors="pt" ,    )

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

				with torch.no_grad():
							__lowerCAmelCase   :						str				= model(**_SCREAMING_SNAKE_CASE)

				self.assertTrue(outputs.loss is not None)




"""simple docstring"""






import logging

from transformers.configuration_utils import PretrainedConfig


__snake_case							:     Tuple   =					logging.getLogger(__name__)



class     A__     (						__SCREAMING_SNAKE_CASE							):




	'''simple docstring'''





	SCREAMING_SNAKE_CASE					   =			'masked_bert'

	def __init__(  self:	str ,    _SCREAMING_SNAKE_CASE:	Tuple=3_0522 ,    _SCREAMING_SNAKE_CASE:	Optional[int]=768 ,    _SCREAMING_SNAKE_CASE:	List[str]=12 ,    _SCREAMING_SNAKE_CASE:	Any=12 ,    _SCREAMING_SNAKE_CASE:	Optional[int]=3072 ,    _SCREAMING_SNAKE_CASE:	List[str]="gelu" ,    _SCREAMING_SNAKE_CASE:	List[str]=0.1 ,    _SCREAMING_SNAKE_CASE:	str=0.1 ,    _SCREAMING_SNAKE_CASE:	Dict=512 ,    _SCREAMING_SNAKE_CASE:	List[Any]=2 ,    _SCREAMING_SNAKE_CASE:	Tuple=0.02 ,    _SCREAMING_SNAKE_CASE:	int=1e-12 ,    _SCREAMING_SNAKE_CASE:	int=0 ,    _SCREAMING_SNAKE_CASE:	Tuple="topK" ,    _SCREAMING_SNAKE_CASE:	Any="constant" ,    _SCREAMING_SNAKE_CASE:	int=0.0 ,    **_SCREAMING_SNAKE_CASE:	Any ,    )       -> List[str]:

				"""simple docstring"""

				super().__init__(pad_token_id=_SCREAMING_SNAKE_CASE ,    **_SCREAMING_SNAKE_CASE)

				__lowerCAmelCase   :						Union[str, Any]				= vocab_size
				__lowerCAmelCase   :						List[str]				= hidden_size
				__lowerCAmelCase   :						Any				= num_hidden_layers
				__lowerCAmelCase   :						Dict				= num_attention_heads
				__lowerCAmelCase   :						Union[str, Any]				= hidden_act
				__lowerCAmelCase   :						Optional[Any]				= intermediate_size
				__lowerCAmelCase   :						int				= hidden_dropout_prob
				__lowerCAmelCase   :						List[Any]				= attention_probs_dropout_prob
				__lowerCAmelCase   :						int				= max_position_embeddings
				__lowerCAmelCase   :						str				= type_vocab_size
				__lowerCAmelCase   :						Any				= initializer_range
				__lowerCAmelCase   :						Optional[int]				= layer_norm_eps
				__lowerCAmelCase   :						Tuple				= pruning_method
				__lowerCAmelCase   :						Union[str, Any]				= mask_init
				__lowerCAmelCase   :						str				= mask_scale