


'''simple docstring'''


import os
import time
import warnings
from dataclasses import dataclass, field
from enum import Enum
from typing import List, Optional, Union

import torch
from filelock import FileLock
from torch.utils.data import Dataset

from ...tokenization_utils_base import PreTrainedTokenizerBase
from ...utils import logging
from ..processors.glue import glue_convert_examples_to_features, glue_output_modes, glue_processors
from ..processors.utils import InputFeatures


lowerCamelCase__    	=     logging.get_logger(__name__)






@dataclass
class 	lowerCAmelCase__			:
			lowerCAmelCase :	str          =     field(metadata={"help": "The name of the task to train on: " + ", ".join(glue_processors.keys()	)}	)
			lowerCAmelCase :	str          =     field(
			    metadata={"help": "The input data dir. Should contain the .tsv files (or other data files) for the task."}	)
			lowerCAmelCase :	int          =     field(
			    default=128    ,       metadata={
			        "help": (
			            "The maximum total input sequence length after tokenization. Sequences longer "
			            "than this will be truncated, sequences shorter will be padded."
			        )
			    }    ,       )
			lowerCAmelCase :	bool          =     field(
			    default=UpperCAmelCase__    ,       metadata={"help": "Overwrite the cached training and evaluation sets"}	)




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



					'''simple docstring'''







					_UpperCAmelCase		:       Dict								=      self.task_name.lower()






class 	lowerCAmelCase__			(			UpperCAmelCase__	):
			lowerCAmelCase :	Union[str, Any]          =     "train"
			lowerCAmelCase :	Any          =     "dev"
			lowerCAmelCase :	Union[str, Any]          =     "test"






class 	lowerCAmelCase__			(			UpperCAmelCase__	):
			lowerCAmelCase :	GlueDataTrainingArguments
			lowerCAmelCase :	str
			lowerCAmelCase :	List[InputFeatures]




			def __init__(		self  :     List[str]	,  lowerCamelCase__  :     GlueDataTrainingArguments	,  lowerCamelCase__  :     PreTrainedTokenizerBase	,  lowerCamelCase__  :     Optional[int] = None	,  lowerCamelCase__  :     Union[str, Split] = Split.train	,  lowerCamelCase__  :     Optional[str] = None	,  )   ->List[Any]:



					'''simple docstring'''







					warnings.warn(
					    "This dataset will be removed from the library soon, preprocessing should be handled with the 🤗 Datasets "
					    "library. You can have a look at this example script for pointers: "
					    "https://github.com/huggingface/transformers/blob/main/examples/pytorch/text-classification/run_glue.py"	,  lowerCamelCase__	,  )
					_UpperCAmelCase		:       Optional[int]								=      args
					_UpperCAmelCase		:       Any								=      glue_processors[args.task_name]()
					_UpperCAmelCase		:       Union[str, Any]								=      glue_output_modes[args.task_name]
					if isinstance(lowerCamelCase__	,  lowerCamelCase__ ):
							try:
									_UpperCAmelCase		:       Union[str, Any]								=      Split[mode]
							except KeyError:
									raise KeyError("mode is not a valid split name" )
        # Load data features from cache or dataset file
					_UpperCAmelCase		:       Union[str, Any]								=      os.path.join(
					    cache_dir if cache_dir is not None else args.data_dir	,  F"""cached_{mode.value}_{tokenizer.__class__.__name__}_{args.max_seq_length}_{args.task_name}"""	,  )
					_UpperCAmelCase		:       List[Any]								=      self.processor.get_labels()
					if args.task_name in ["mnli", "mnli-mm"] and tokenizer.__class__.__name__ in (
					    "RobertaTokenizer",
					    "RobertaTokenizerFast",
					    "XLMRobertaTokenizer",
					    "BartTokenizer",
					    "BartTokenizerFast",
					):
							# HACK(label indices are swapped in RoBERTa pretrained model)
							_UpperCAmelCase					,    _UpperCAmelCase		:       Union[str, Any]								=      label_list[2], label_list[1]
					_UpperCAmelCase		:       Optional[int]								=      label_list

					# Make sure only the first process in distributed training processes the dataset,
					# and the others will use the cache.
					_UpperCAmelCase		:       Dict								=      cached_features_file + ".lock"
					with FileLock(lowerCamelCase__ ):
							if os.path.exists(lowerCamelCase__ ) and not args.overwrite_cache:
									_UpperCAmelCase		:       Tuple								=      time.time()
									_UpperCAmelCase		:       Dict								=      torch.load(lowerCamelCase__ )
									logger.info(
									    F"""Loading features from cached file {cached_features_file} [took %.3f s]"""	,  time.time() - start )
							else:
									logger.info(F"""Creating features from dataset file at {args.data_dir}""" )

									if mode == Split.dev:
											_UpperCAmelCase		:       List[Any]								=      self.processor.get_dev_examples(args.data_dir )
									elif mode == Split.test:
											_UpperCAmelCase		:       Optional[int]								=      self.processor.get_test_examples(args.data_dir )
									else:
											_UpperCAmelCase		:       Tuple								=      self.processor.get_train_examples(args.data_dir )
									if limit_length is not None:
											_UpperCAmelCase		:       str								=      examples[:limit_length]
									_UpperCAmelCase		:       Optional[int]								=      glue_convert_examples_to_features(
									    lowerCamelCase__	,  lowerCamelCase__	,  max_length=args.max_seq_length	,  label_list=lowerCamelCase__	,  output_mode=self.output_mode	,  )
									_UpperCAmelCase		:       Any								=      time.time()
									torch.save(self.features	,  lowerCamelCase__ )
									# ^ This seems to take a lot of time so I want to investigate why and how we can improve.
									logger.info(
									    F"""Saving features into cached file {cached_features_file} [took {time.time() - start:.3f} s]""" )




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



					'''simple docstring'''







					return len(self.features )




			def __getitem__(		self  :     List[str]	,  lowerCamelCase__  :     Optional[int] )   ->InputFeatures:



					'''simple docstring'''







					return self.features[i]






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



					'''simple docstring'''







					return self.label_list







'''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 	lowerCAmelCase__			:




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



					'''simple docstring'''







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




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



					'''simple docstring'''







					_UpperCAmelCase		:       Optional[Any]								=      floats_tensor([self.batch_size, self.num_channels, self.min_size, self.max_size] ).to(
					    lowerCamelCase__ )

					_UpperCAmelCase		:       Optional[int]								=      torch.ones([self.batch_size, self.min_size, self.max_size]	,  device=lowerCamelCase__ )

					_UpperCAmelCase		:       Union[str, Any]								=      (
					    torch.rand([self.batch_size, self.num_labels, self.min_size, self.max_size]	,  device=lowerCamelCase__ ) > 0.5
					).float()
					_UpperCAmelCase		:       int								=      (torch.rand((self.batch_size, self.num_labels)	,  device=lowerCamelCase__ ) > 0.5).long()

					_UpperCAmelCase		:       Dict								=      self.get_config()
					return config, pixel_values, pixel_mask, mask_labels, class_labels




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



					'''simple docstring'''







					_UpperCAmelCase		:       Dict								=      MaskaFormerConfig(
					    hidden_size=self.hidden_dim	,  )
					_UpperCAmelCase		:       List[str]								=      self.num_queries
					_UpperCAmelCase		:       Any								=      self.num_labels

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

					_UpperCAmelCase		:       int								=      64
					_UpperCAmelCase		:       int								=      1_28
					_UpperCAmelCase		:       int								=      self.hidden_dim
					_UpperCAmelCase		:       List[Any]								=      self.hidden_dim
					_UpperCAmelCase		:       Any								=      self.hidden_dim
					return config




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



					'''simple docstring'''







					_UpperCAmelCase					,    _UpperCAmelCase					,    _UpperCAmelCase					,    _UpperCAmelCase					,    _UpperCAmelCase		:       str								=      self.prepare_config_and_inputs()
					_UpperCAmelCase		:       Optional[Any]								=      {"pixel_values": pixel_values, "pixel_mask": pixel_mask}
					return config, inputs_dict




			def 							lowerCAmelCase__    (		self  :     int	,  lowerCamelCase__  :     List[str]	,  lowerCamelCase__  :     str )   ->List[Any]:



					'''simple docstring'''







					_UpperCAmelCase		:       str								=      output.encoder_hidden_states
					_UpperCAmelCase		:       List[str]								=      output.pixel_decoder_hidden_states
					_UpperCAmelCase		:       Optional[Any]								=      output.transformer_decoder_hidden_states

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




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



					'''simple docstring'''







					with torch.no_grad():
							_UpperCAmelCase		:       List[Any]								=      MaskaFormerModel(config=lowerCamelCase__ )
							model.to(lowerCamelCase__ )
							model.eval()

							_UpperCAmelCase		:       int								=      model(pixel_values=lowerCamelCase__	,  pixel_mask=lowerCamelCase__ )
							_UpperCAmelCase		:       List[str]								=      model(lowerCamelCase__	,  output_hidden_states=lowerCamelCase__ )

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






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



					'''simple docstring'''







					_UpperCAmelCase		:       str								=      MaskaFormerForUniversalSegmentation(config=lowerCamelCase__ )
					model.to(lowerCamelCase__ )
					model.eval()

					def comm_check_on_output(lowerCamelCase__  :     Dict ):
							# 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		:       Union[str, Any]								=      model(pixel_values=lowerCamelCase__	,  pixel_mask=lowerCamelCase__ )
							_UpperCAmelCase		:       int								=      model(lowerCamelCase__ )

							comm_check_on_output(lowerCamelCase__ )

							_UpperCAmelCase		:       Union[str, Any]								=      model(
							    pixel_values=lowerCamelCase__	,  pixel_mask=lowerCamelCase__	,  mask_labels=lowerCamelCase__	,  class_labels=lowerCamelCase__ )

					comm_check_on_output(lowerCamelCase__ )

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






@require_torch
class 	lowerCAmelCase__			(			UpperCAmelCase__    ,       UpperCAmelCase__    ,       unittest.TestCase	):
			lowerCAmelCase :	Optional[int]          =     (MaskaFormerModel, MaskaFormerForUniversalSegmentation) if is_torch_available() else ()
			lowerCAmelCase :	str          =     {"feature-extraction": MaskaFormerModel} if is_torch_available() else {}

			lowerCAmelCase :	Optional[Any]          =     False
			lowerCAmelCase :	Any          =     False
			lowerCAmelCase :	List[Any]          =     False
			lowerCAmelCase :	Any          =     False




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



					'''simple docstring'''







					_UpperCAmelCase		:       int								=      MaskaFormerModelTester(self )
					_UpperCAmelCase		:       int								=      ConfigTester(self	,  config_class=lowerCamelCase__	,  has_text_modality=lowerCamelCase__ )




			def 							lowerCAmelCase__    (		self  :     int )   ->Any:



					'''simple docstring'''







					self.config_tester.run_common_tests()




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



					'''simple docstring'''







					_UpperCAmelCase					,    _UpperCAmelCase		:       Optional[int]								=      self.model_tester.prepare_config_and_inputs_for_common()
					self.model_tester.create_and_check_maskaformer_model(lowerCamelCase__	,  **lowerCamelCase__	,  output_hidden_states=lowerCamelCase__ )




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



					'''simple docstring'''







					_UpperCAmelCase		:       Any								=      self.model_tester.prepare_config_and_inputs()
					self.model_tester.create_and_check_maskaformer_instance_segmentation_head_model(*lowerCamelCase__ )




			@unittest.skip(reason="Mask2Former does not use inputs_embeds" )
			def 							lowerCAmelCase__    (		self  :     Tuple )   ->List[str]:



					'''simple docstring'''







					pass




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



					'''simple docstring'''







					pass




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



					'''simple docstring'''







					pass




			@unittest.skip(reason="Mask2Former does not use token embeddings" )
			def 							lowerCAmelCase__    (		self  :     Optional[int] )   ->Any:



					'''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 							lowerCAmelCase__    (		self  :     Dict )   ->str:



					'''simple docstring'''







					pass




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



					'''simple docstring'''







					pass




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



					'''simple docstring'''







					_UpperCAmelCase					,    _UpperCAmelCase		:       Optional[Any]								=      self.model_tester.prepare_config_and_inputs_for_common()

					for model_class in self.all_model_classes:
							_UpperCAmelCase		:       List[str]								=      model_class(lowerCamelCase__ )
							_UpperCAmelCase		:       Tuple								=      inspect.signature(model.forward )
							# signature.parameters is an OrderedDict => so arg_names order is deterministic
							_UpperCAmelCase		:       Tuple								=      [*signature.parameters.keys()]

							_UpperCAmelCase		:       Dict								=      ["pixel_values"]
							self.assertListEqual(arg_names[:1]	,  lowerCamelCase__ )




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



					'''simple docstring'''







					for model_name in ["facebook/mask2former-swin-small-coco-instance"]:
							_UpperCAmelCase		:       str								=      MaskaFormerModel.from_pretrained(lowerCamelCase__ )
							self.assertIsNotNone(lowerCamelCase__ )




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



					'''simple docstring'''







					_UpperCAmelCase		:       str								=      (self.model_tester.min_size,) * 2
					_UpperCAmelCase		:       Optional[Any]								=      {
					    "pixel_values": torch.randn((2, 3, *size)	,  device=lowerCamelCase__ ),
					    "mask_labels": torch.randn((2, 10, *size)	,  device=lowerCamelCase__ ),
					    "class_labels": torch.zeros(2	,  10	,  device=lowerCamelCase__ ).long(),
					}
					_UpperCAmelCase		:       int								=      self.model_tester.get_config()

					_UpperCAmelCase		:       str								=      MaskaFormerForUniversalSegmentation(lowerCamelCase__ ).to(lowerCamelCase__ )
					_UpperCAmelCase		:       str								=      model(**lowerCamelCase__ )
					self.assertTrue(outputs.loss is not None )




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



					'''simple docstring'''







					_UpperCAmelCase					,    _UpperCAmelCase		:       Union[str, Any]								=      self.model_tester.prepare_config_and_inputs_for_common()
					self.model_tester.create_and_check_maskaformer_model(lowerCamelCase__	,  **lowerCamelCase__	,  output_hidden_states=lowerCamelCase__ )




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



					'''simple docstring'''







					_UpperCAmelCase					,    _UpperCAmelCase		:       str								=      self.model_tester.prepare_config_and_inputs_for_common()

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




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



					'''simple docstring'''







					if not self.model_tester.is_training:
							return

					_UpperCAmelCase		:       Optional[Any]								=      self.all_model_classes[1]
					_UpperCAmelCase					,    _UpperCAmelCase					,    _UpperCAmelCase					,    _UpperCAmelCase					,    _UpperCAmelCase		:       Any								=      self.model_tester.prepare_config_and_inputs()

					_UpperCAmelCase		:       Optional[int]								=      model_class(lowerCamelCase__ )
					model.to(lowerCamelCase__ )
					model.train()

					_UpperCAmelCase		:       Optional[int]								=      model(lowerCamelCase__	,  mask_labels=lowerCamelCase__	,  class_labels=lowerCamelCase__ ).loss
					loss.backward()






			def 							lowerCAmelCase__    (		self  :     Dict )   ->Any:



					'''simple docstring'''







					_UpperCAmelCase		:       str								=      self.all_model_classes[1]
					_UpperCAmelCase					,    _UpperCAmelCase					,    _UpperCAmelCase					,    _UpperCAmelCase					,    _UpperCAmelCase		:       Optional[Any]								=      self.model_tester.prepare_config_and_inputs()
					_UpperCAmelCase		:       Union[str, Any]								=      True
					_UpperCAmelCase		:       Tuple								=      True

					_UpperCAmelCase		:       List[Any]								=      model_class(lowerCamelCase__ ).to(lowerCamelCase__ )
					model.train()

					_UpperCAmelCase		:       Any								=      model(lowerCamelCase__	,  mask_labels=lowerCamelCase__	,  class_labels=lowerCamelCase__ )

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

					_UpperCAmelCase		:       Dict								=      outputs.pixel_decoder_hidden_states[0]
					pixel_decoder_hidden_states.retain_grad()

					_UpperCAmelCase		:       Optional[Any]								=      outputs.transformer_decoder_hidden_states[0]
					transformer_decoder_hidden_states.retain_grad()

					_UpperCAmelCase		:       Union[str, Any]								=      outputs.attentions[0]
					attentions.retain_grad()

					outputs.loss.backward(retain_graph=lowerCamelCase__ )

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




lowerCamelCase__    	=     1e-4






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






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




			@cached_property
			def 							lowerCAmelCase__    (		self  :     str )   ->str:



					'''simple docstring'''







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




			@cached_property
			def 							lowerCAmelCase__    (		self  :     Tuple )   ->List[str]:



					'''simple docstring'''







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




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



					'''simple docstring'''







					_UpperCAmelCase		:       Union[str, Any]								=      MaskaFormerModel.from_pretrained(self.model_checkpoints ).to(lowerCamelCase__ )
					_UpperCAmelCase		:       int								=      self.default_image_processor
					_UpperCAmelCase		:       Optional[Any]								=      prepare_img()
					_UpperCAmelCase		:       str								=      image_processor(lowerCamelCase__	,  return_tensors="pt" ).to(lowerCamelCase__ )
					_UpperCAmelCase		:       Dict								=      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(lowerCamelCase__	,  (1, 3, 3_84, 3_84) )

					with torch.no_grad():
							_UpperCAmelCase		:       str								=      model(**lowerCamelCase__ )

					_UpperCAmelCase		:       List[str]								=      torch.tensor(
					    [[-0.2_7_9_0, -1.0_7_1_7, -1.1_6_6_8], [-0.5_1_2_8, -0.3_1_2_8, -0.4_9_8_7], [-0.5_8_3_2, 0.1_9_7_1, -0.0_1_9_7]] ).to(lowerCamelCase__ )
					self.assertTrue(
					    torch.allclose(
					        outputs.encoder_last_hidden_state[0, 0, :3, :3]	,  lowerCamelCase__	,  atol=lowerCamelCase__ ) )

					_UpperCAmelCase		:       List[Any]								=      torch.tensor(
					    [[0.8_9_7_3, 1.1_8_4_7, 1.1_7_7_6], [1.1_9_3_4, 1.5_0_4_0, 1.5_1_2_8], [1.1_1_5_3, 1.4_4_8_6, 1.4_9_5_1]] ).to(lowerCamelCase__ )
					self.assertTrue(
					    torch.allclose(
					        outputs.pixel_decoder_last_hidden_state[0, 0, :3, :3]	,  lowerCamelCase__	,  atol=lowerCamelCase__ ) )

					_UpperCAmelCase		:       Tuple								=      torch.tensor(
					    [[2.1_1_5_2, 1.7_0_0_0, -0.8_6_0_3], [1.5_8_0_8, 1.8_0_0_4, -0.9_3_5_3], [1.6_0_4_3, 1.7_4_9_5, -0.5_9_9_9]] ).to(lowerCamelCase__ )
					self.assertTrue(
					    torch.allclose(
					        outputs.transformer_decoder_last_hidden_state[0, :3, :3]	,  lowerCamelCase__	,  atol=lowerCamelCase__ ) )




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



					'''simple docstring'''







					_UpperCAmelCase		:       Optional[Any]								=      MaskaFormerForUniversalSegmentation.from_pretrained(self.model_checkpoints ).to(lowerCamelCase__ ).eval()
					_UpperCAmelCase		:       List[Any]								=      self.default_image_processor
					_UpperCAmelCase		:       Union[str, Any]								=      prepare_img()
					_UpperCAmelCase		:       Optional[int]								=      image_processor(lowerCamelCase__	,  return_tensors="pt" ).to(lowerCamelCase__ )
					_UpperCAmelCase		:       List[Any]								=      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(lowerCamelCase__	,  (1, 3, 3_84, 3_84) )

					with torch.no_grad():
							_UpperCAmelCase		:       List[Any]								=      model(**lowerCamelCase__ )
					# masks_queries_logits
					_UpperCAmelCase		:       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) )
					_UpperCAmelCase		:       List[str]								=      [
					    [-8.7_8_3_9, -9.0_0_5_6, -8.8_1_2_1],
					    [-7.4_1_0_4, -7.0_3_1_3, -6.5_4_0_1],
					    [-6.6_1_0_5, -6.3_4_2_7, -6.4_6_7_5],
					]
					_UpperCAmelCase		:       List[Any]								=      torch.tensor(lowerCamelCase__ ).to(lowerCamelCase__ )
					self.assertTrue(torch.allclose(masks_queries_logits[0, 0, :3, :3]	,  lowerCamelCase__	,  atol=lowerCamelCase__ ) )
					# class_queries_logits
					_UpperCAmelCase		:       Dict								=      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.8_3_2_4, -8.0_8_3_5, -4.1_9_2_2],
					        [0.8_4_5_0, -9.0_0_5_0, -3.6_0_5_3],
					        [0.3_0_4_5, -7.7_2_9_3, -3.0_2_7_5],
					    ] ).to(lowerCamelCase__ )
					self.assertTrue(torch.allclose(outputs.class_queries_logits[0, :3, :3]	,  lowerCamelCase__	,  atol=lowerCamelCase__ ) )






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



					'''simple docstring'''







					_UpperCAmelCase		:       List[Any]								=      MaskaFormerForUniversalSegmentation.from_pretrained(self.model_checkpoints ).to(lowerCamelCase__ ).eval()
					_UpperCAmelCase		:       Tuple								=      self.default_image_processor

					_UpperCAmelCase		:       List[str]								=      image_processor(
					    [np.zeros((3, 8_00, 13_33) ), np.zeros((3, 8_00, 13_33) )]	,  segmentation_maps=[np.zeros((3_84, 3_84) ).astype(np.floataa ), np.zeros((3_84, 3_84) ).astype(np.floataa )]	,  return_tensors="pt"	,  )

					_UpperCAmelCase		:       str								=      inputs["pixel_values"].to(lowerCamelCase__ )
					_UpperCAmelCase		:       List[str]								=      [el.to(lowerCamelCase__ ) for el in inputs["mask_labels"]]
					_UpperCAmelCase		:       List[str]								=      [el.to(lowerCamelCase__ ) for el in inputs["class_labels"]]

					with torch.no_grad():
							_UpperCAmelCase		:       int								=      model(**lowerCamelCase__ )

					self.assertTrue(outputs.loss is not None )



