



"""simple docstring"""
import itertools
import os
from collections import Counter, defaultdict
from concurrent.futures import ThreadPoolExecutor, as_completed

import numpy as np

import datasets

from .execute import check_correctness


__a      =				"\\n@misc{chen2021evaluating,\n      title={Evaluating Large Language Models Trained on Code},\n      author={Mark Chen and Jerry Tworek and Heewoo Jun and Qiming Yuan \\nand Henrique Ponde de Oliveira Pinto and Jared Kaplan and Harri Edwards \\nand Yuri Burda and Nicholas Joseph and Greg Brockman and Alex Ray \\nand Raul Puri and Gretchen Krueger and Michael Petrov and Heidy Khlaaf \\nand Girish Sastry and Pamela Mishkin and Brooke Chan and Scott Gray \\nand Nick Ryder and Mikhail Pavlov and Alethea Power and Lukasz Kaiser \\nand Mohammad Bavarian and Clemens Winter and Philippe Tillet \\nand Felipe Petroski Such and Dave Cummings and Matthias Plappert \\nand Fotios Chantzis and Elizabeth Barnes and Ariel Herbert-Voss \\nand William Hebgen Guss and Alex Nichol and Alex Paino and Nikolas Tezak \\nand Jie Tang and Igor Babuschkin and Suchir Balaji and Shantanu Jain \\nand William Saunders and Christopher Hesse and Andrew N. Carr \\nand Jan Leike and Josh Achiam and Vedant Misra and Evan Morikawa \\nand Alec Radford and Matthew Knight and Miles Brundage and Mira Murati \\nand Katie Mayer and Peter Welinder and Bob McGrew and Dario Amodei \\nand Sam McCandlish and Ilya Sutskever and Wojciech Zaremba},\n      year={2021},\n      eprint={2107.03374},\n      archivePrefix={arXiv},\n      primaryClass={cs.LG}\n}\n"

__a      =				"\\nThis metric implements the evaluation harness for the HumanEval problem solving dataset\ndescribed in the paper \"Evaluating Large Language Models Trained on Code\"\n(https://arxiv.org/abs/2107.03374).\n"


__a      =				"\nCalculates how good are predictions given some references, using certain scores\nArgs:\n    predictions: list of candidates to evaluate. Each candidates should be a list\n        of strings with several code candidates to solve the problem.\n    references: a list with a test for each prediction. Each test should evaluate the\n        correctness of a code candidate.\n    k: number of code candidates to consider in the evaluation (Default: [1, 10, 100])\n    num_workers: number of workers used to evaluate the canidate programs (Default: 4).\n    timeout:\nReturns:\n    pass_at_k: dict with pass rates for each k\n    results: dict with granular results of each unittest\nExamples:\n    >>> code_eval = datasets.load_metric(\"code_eval\")\n    >>> test_cases = [\"assert add(2,3)==5\"]\n    >>> candidates = [[\"def add(a,b): return a*b\", \"def add(a, b): return a+b\"]]\n    >>> pass_at_k, results = code_eval.compute(references=test_cases, predictions=candidates, k=[1, 2])\n    >>> print(pass_at_k)\n    {'pass@1': 0.5, 'pass@2': 1.0}\n"


__a      =				"\n################################################################################\n                                  !!!WARNING!!!\n################################################################################\nThe \"code_eval\" metric executes untrusted model-generated code in Python.\nAlthough it is highly unlikely that model-generated code will do something\novertly malicious in response to this test suite, model-generated code may act\ndestructively due to a lack of model capability or alignment.\nUsers are strongly encouraged to sandbox this evaluation suite so that it\ndoes not perform destructive actions on their host or network. For more\ninformation on how OpenAI sandboxes its code, see the paper \"Evaluating Large\nLanguage Models Trained on Code\" (https://arxiv.org/abs/2107.03374).\n\nOnce you have read this disclaimer and taken appropriate precautions,\nset the environment variable HF_ALLOW_CODE_EVAL=\"1\". Within Python you can to this\nwith:\n\n>>> import os\n>>> os.environ[\"HF_ALLOW_CODE_EVAL\"] = \"1\"\n\n################################################################################\\n"

__a      =				"The MIT License\n\nCopyright (c) OpenAI (https://openai.com)\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in\nall copies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\nTHE SOFTWARE."
@datasets.utils.file_utils.add_start_docstrings(_DESCRIPTION    ,						_KWARGS_DESCRIPTION				)
class 				lowerCamelCase  (			datasets.Metric				):






					'''simple docstring'''





					def    lowerCAmelCase_				(       self:							Union[str, Any]						)   ->	Optional[int]:
											return datasets.MetricInfo(
											    # This is the description that will appear on the metrics page.
											    description=_DESCRIPTION						,     citation=_CITATION						,     inputs_description=_KWARGS_DESCRIPTION						,     features=datasets.Features(
											        {
											            """predictions""": datasets.Sequence(datasets.Value("""string"""						)						),
											            """references""": datasets.Value("""string"""						),
											        }						)						,     homepage="""https://github.com/openai/human-eval"""						,     codebase_urls=["""https://github.com/openai/human-eval"""]						,     reference_urls=["""https://github.com/openai/human-eval"""]						,     license=_LICENSE						,     )






					def    lowerCAmelCase_				(       self:							Union[str, Any]						,     snake_case:							Union[str, Any]						,     snake_case:							Tuple						,     snake_case:							Optional[int]=[1, 10, 100]						,     snake_case:							Dict=4						,     snake_case:							List[str]=3.0						)   ->	List[Any]:

											if os.getenv("""HF_ALLOW_CODE_EVAL"""						,     0						) != "1":
																	raise ValueError(_WARNING						)

											if os.name == "nt":
																	raise NotImplementedError("""This metric is currently not supported on Windows."""						)

											with ThreadPoolExecutor(max_workers=snake_case						) as executor:
																	snake_case_ :Union[str, Any]						=			[]
																	snake_case_ :Optional[Any]						=			Counter()
																	snake_case_ :List[Any]						=			0
																	snake_case_ :Optional[Any]						=			defaultdict(snake_case						)

																	for task_id, (candidates, test_case) in enumerate(zip(snake_case						,     snake_case						)						):
																							for candidate in candidates:
																													snake_case_ :Dict						=			candidate + """\n""" + test_case
																													snake_case_ :List[Any]						=			(test_program, timeout, task_id, completion_id[task_id])
																													snake_case_ :List[Any]						=			executor.submit(snake_case						,     *snake_case						)
																													futures.append(snake_case						)
																													completion_id[task_id] += 1
																													n_samples += 1

																	for future in as_completed(snake_case						):
																							snake_case_ :Any						=			future.result()
																							results[result["task_id"]].append((result["""completion_id"""], result)						)

											snake_case_,       snake_case_ :Union[str, Any]						=			[], []
											for result in results.values():
																	result.sort()
																	snake_case_ :Dict						=			[r[1]["""passed"""] for r in result]
																	total.append(len(snake_case						)						)
																	correct.append(sum(snake_case						)						)
											snake_case_ :Union[str, Any]						=			np.array(snake_case						)
											snake_case_ :Any						=			np.array(snake_case						)

											snake_case_ :int						=			k
											snake_case_ :str						=			{f"""pass@{k}""": estimate_pass_at_k(snake_case						,     snake_case						,     snake_case						).mean() for k in ks if (total >= k).all()}

											return pass_at_k, results

def    A_  (			_lowercase,					_lowercase,					_lowercase	):







						'''simple docstring'''


						def estimator(_lowercase,					_lowercase,					_lowercase	) -> float:
												if n - c < k:
																		return 1.0
												return 1.0 - np.prod(1.0 - k / np.arange(n - c + 1,					n + 1	)	)

						if isinstance(_lowercase,					_lowercase	):
												snake_case_ :List[Any]						=			itertools.repeat(_lowercase,					len(_lowercase	)	)
						else:
												assert len(_lowercase	) == len(_lowercase	)
												snake_case_ :Optional[int]						=			iter(_lowercase	)

						return np.array([estimator(int(_lowercase	),					int(_lowercase	),					_lowercase	) for n, c in zip(_lowercase,					_lowercase	)]	)





"""simple docstring"""
import collections
import inspect
import unittest
from typing import Dict, List, Tuple

from transformers import MaskFormerSwinConfig
from transformers.testing_utils import require_torch, require_torch_multi_gpu, torch_device
from transformers.utils import is_torch_available

from ...test_backbone_common import BackboneTesterMixin
from ...test_configuration_common import ConfigTester
from ...test_modeling_common import ModelTesterMixin, floats_tensor, ids_tensor
from ...test_pipeline_mixin import PipelineTesterMixin


if is_torch_available():
						import torch
						from torch import nn

						from transformers import MaskFormerSwinBackbone
						from transformers.models.maskformer import MaskFormerSwinModel
class 				lowerCamelCase  :






					'''simple docstring'''





					def __init__(       self:							Dict						,     snake_case:							Optional[Any]						,     snake_case:							Tuple=13						,     snake_case:							Any=32						,     snake_case:							Union[str, Any]=2						,     snake_case:							Tuple=3						,     snake_case:							Union[str, Any]=16						,     snake_case:							Union[str, Any]=[1, 2, 1]						,     snake_case:							Optional[Any]=[2, 2, 4]						,     snake_case:							str=2						,     snake_case:							List[str]=2.0						,     snake_case:							Optional[int]=True						,     snake_case:							Union[str, Any]=0.0						,     snake_case:							Optional[int]=0.0						,     snake_case:							Optional[Any]=0.1						,     snake_case:							List[str]="gelu"						,     snake_case:							Any=False						,     snake_case:							Optional[Any]=True						,     snake_case:							Optional[int]=0.0_2						,     snake_case:							Any=1E-5						,     snake_case:							Optional[int]=True						,     snake_case:							int=None						,     snake_case:							Any=True						,     snake_case:							str=10						,     snake_case:							Optional[Any]=8						,     snake_case:							Union[str, Any]=["stage1", "stage2", "stage3"]						,     snake_case:							Tuple=[1, 2, 3]						,     )   ->	Dict:
											snake_case_ :Dict						=			parent
											snake_case_ :List[Any]						=			batch_size
											snake_case_ :Dict						=			image_size
											snake_case_ :Dict						=			patch_size
											snake_case_ :Tuple						=			num_channels
											snake_case_ :List[Any]						=			embed_dim
											snake_case_ :List[str]						=			depths
											snake_case_ :str						=			num_heads
											snake_case_ :Tuple						=			window_size
											snake_case_ :Tuple						=			mlp_ratio
											snake_case_ :int						=			qkv_bias
											snake_case_ :Tuple						=			hidden_dropout_prob
											snake_case_ :Optional[Any]						=			attention_probs_dropout_prob
											snake_case_ :Dict						=			drop_path_rate
											snake_case_ :Any						=			hidden_act
											snake_case_ :Any						=			use_absolute_embeddings
											snake_case_ :int						=			patch_norm
											snake_case_ :List[Any]						=			layer_norm_eps
											snake_case_ :Tuple						=			initializer_range
											snake_case_ :str						=			is_training
											snake_case_ :int						=			scope
											snake_case_ :Tuple						=			use_labels
											snake_case_ :Tuple						=			type_sequence_label_size
											snake_case_ :str						=			encoder_stride
											snake_case_ :List[Any]						=			out_features
											snake_case_ :str						=			out_indices






					def    lowerCAmelCase_				(       self:							Tuple						)   ->	Dict:
											snake_case_ :Optional[int]						=			floats_tensor([self.batch_size, self.num_channels, self.image_size, self.image_size]						)

											snake_case_ :str						=			None
											if self.use_labels:
																	snake_case_ :Optional[int]						=			ids_tensor([self.batch_size]						,     self.type_sequence_label_size						)

											snake_case_ :Union[str, Any]						=			self.get_config()

											return config, pixel_values, labels






					def    lowerCAmelCase_				(       self:							int						)   ->	Optional[Any]:
											return MaskFormerSwinConfig(
											    image_size=self.image_size						,     patch_size=self.patch_size						,     num_channels=self.num_channels						,     embed_dim=self.embed_dim						,     depths=self.depths						,     num_heads=self.num_heads						,     window_size=self.window_size						,     mlp_ratio=self.mlp_ratio						,     qkv_bias=self.qkv_bias						,     hidden_dropout_prob=self.hidden_dropout_prob						,     attention_probs_dropout_prob=self.attention_probs_dropout_prob						,     drop_path_rate=self.drop_path_rate						,     hidden_act=self.hidden_act						,     use_absolute_embeddings=self.use_absolute_embeddings						,     path_norm=self.patch_norm						,     layer_norm_eps=self.layer_norm_eps						,     initializer_range=self.initializer_range						,     encoder_stride=self.encoder_stride						,     out_features=self.out_features						,     out_indices=self.out_indices						,     )






					def    lowerCAmelCase_				(       self:							List[Any]						,     snake_case:							str						,     snake_case:							int						,     snake_case:							List[str]						)   ->	Any:
											snake_case_ :Dict						=			MaskFormerSwinModel(config=snake_case						)
											model.to(snake_case						)
											model.eval()
											snake_case_ :Tuple						=			model(snake_case						)

											snake_case_ :Dict						=			((config.image_size // config.patch_size) ** 2) // (4 ** (len(config.depths						) - 1))
											snake_case_ :Any						=			int(config.embed_dim * 2 ** (len(config.depths						) - 1)						)

											self.parent.assertEqual(result.last_hidden_state.shape						,     (self.batch_size, expected_seq_len, expected_dim)						)






					def    lowerCAmelCase_				(       self:							Optional[Any]						,     snake_case:							int						,     snake_case:							List[str]						,     snake_case:							Tuple						)   ->	Union[str, Any]:
											snake_case_ :Any						=			MaskFormerSwinBackbone(config=snake_case						)
											model.to(snake_case						)
											model.eval()
											snake_case_ :Optional[Any]						=			model(snake_case						)

											# verify feature maps
											self.parent.assertEqual(len(result.feature_maps						)						,     len(config.out_features						)						)
											self.parent.assertListEqual(list(result.feature_maps[0].shape						)						,     [13, 16, 16, 16]						)

											# verify channels
											self.parent.assertEqual(len(model.channels						)						,     len(config.out_features						)						)
											self.parent.assertListEqual(model.channels						,     [16, 32, 64]						)

											# verify ValueError
											with self.parent.assertRaises(snake_case						):
																	snake_case_ :Optional[Any]						=			["""stem"""]
																	snake_case_ :str						=			MaskFormerSwinBackbone(config=snake_case						)






					def    lowerCAmelCase_				(       self:							List[str]						)   ->	Optional[Any]:
											snake_case_ :Optional[int]						=			self.prepare_config_and_inputs()
											snake_case_,       snake_case_,       snake_case_ :str						=			config_and_inputs
											snake_case_ :Tuple						=			{"""pixel_values""": pixel_values}
											return config, inputs_dict

@require_torch
class 				lowerCamelCase  (			_lowerCAmelCase    ,						_lowerCAmelCase    ,						unittest.TestCase				):






					'''simple docstring'''





					_A		:			Union[str, Any]						=     (
					    (
					        MaskFormerSwinModel,
					        MaskFormerSwinBackbone,
					    )
					    if is_torch_available()
					    else ()
					)
					_A		:			str						=     {"""feature-extraction""": MaskFormerSwinModel} if is_torch_available() else {}
					_A		:			List[str]						=     False
					_A		:			Any						=     False
					_A		:			Dict						=     False
					_A		:			List[Any]						=     False
					_A		:			Optional[int]						=     False






					def    lowerCAmelCase_				(       self:							Dict						)   ->	Any:
											snake_case_ :str						=			MaskFormerSwinModelTester(self						)
											snake_case_ :Optional[Any]						=			ConfigTester(self						,     config_class=snake_case						,     embed_dim=37						)






					@require_torch_multi_gpu
					@unittest.skip(
					    reason=(
					        """`MaskFormerSwinModel` outputs `hidden_states_spatial_dimensions` which doesn't work well with"""
					        """ `nn.DataParallel`"""
					    )						)
					def    lowerCAmelCase_				(       self:							List[str]						)   ->	Optional[int]:
											pass






					def    lowerCAmelCase_				(       self:							Union[str, Any]						)   ->	Dict:
											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:							Any						)   ->	Tuple:
											return






					def    lowerCAmelCase_				(       self:							Any						)   ->	Any:
											snake_case_ :List[Any]						=			self.model_tester.prepare_config_and_inputs()
											self.model_tester.create_and_check_model(*snake_case						)






					def    lowerCAmelCase_				(       self:							Union[str, Any]						)   ->	int:
											snake_case_ :Any						=			self.model_tester.prepare_config_and_inputs()
											self.model_tester.create_and_check_backbone(*snake_case						)






					@unittest.skip("""Swin does not use inputs_embeds"""						)
					def    lowerCAmelCase_				(       self:							str						)   ->	List[str]:
											pass






					@unittest.skip("""Swin does not support feedforward chunking"""						)
					def    lowerCAmelCase_				(       self:							int						)   ->	Optional[int]:
											pass






					def    lowerCAmelCase_				(       self:							List[str]						)   ->	List[Any]:
											snake_case_,       snake_case_ :List[Any]						=			self.model_tester.prepare_config_and_inputs_for_common()

											for model_class in self.all_model_classes:
																	snake_case_ :str						=			model_class(snake_case						)
																	self.assertIsInstance(model.get_input_embeddings()						,     (nn.Module)						)
																	snake_case_ :Dict						=			model.get_output_embeddings()
																	self.assertTrue(x is None or isinstance(snake_case						,     nn.Linear						)						)






					def    lowerCAmelCase_				(       self:							Tuple						)   ->	Dict:
											snake_case_,       snake_case_ :int						=			self.model_tester.prepare_config_and_inputs_for_common()

											for model_class in self.all_model_classes:
																	snake_case_ :Optional[int]						=			model_class(snake_case						)
																	snake_case_ :str						=			inspect.signature(model.forward						)
																	# signature.parameters is an OrderedDict => so arg_names order is deterministic
																	snake_case_ :str						=			[*signature.parameters.keys()]

																	snake_case_ :str						=			["""pixel_values"""]
																	self.assertListEqual(arg_names[:1]						,     snake_case						)






					@unittest.skip(reason="""MaskFormerSwin is only used as backbone and doesn't support output_attentions"""						)
					def    lowerCAmelCase_				(       self:							List[Any]						)   ->	List[Any]:
											pass






					@unittest.skip(reason="""MaskFormerSwin is only used as an internal backbone"""						)
					def    lowerCAmelCase_				(       self:							Dict						)   ->	List[Any]:
											pass






					def    lowerCAmelCase_				(       self:							Union[str, Any]						,     snake_case:							Union[str, Any]						,     snake_case:							int						,     snake_case:							Any						,     snake_case:							List[str]						)   ->	str:
											snake_case_ :List[str]						=			model_class(snake_case						)
											model.to(snake_case						)
											model.eval()

											with torch.no_grad():
																	snake_case_ :List[Any]						=			model(**self._prepare_for_class(snake_case						,     snake_case						)						)

											snake_case_ :Any						=			outputs.hidden_states

											snake_case_ :Optional[int]						=			getattr(
											    self.model_tester						,     """expected_num_hidden_layers"""						,     len(self.model_tester.depths						) + 1						)
											self.assertEqual(len(snake_case						)						,     snake_case						)

											# Swin has a different seq_length
											snake_case_ :str						=			(
											    config.patch_size
											    if isinstance(config.patch_size						,     collections.abc.Iterable						)
											    else (config.patch_size, config.patch_size)
											)

											snake_case_ :int						=			(image_size[1] // patch_size[1]) * (image_size[0] // patch_size[0])

											self.assertListEqual(
											    list(hidden_states[0].shape[-2:]						)						,     [num_patches, self.model_tester.embed_dim]						,     )






					def    lowerCAmelCase_				(       self:							List[Any]						)   ->	Optional[int]:
											snake_case_,       snake_case_ :Any						=			self.model_tester.prepare_config_and_inputs_for_common()

											snake_case_ :List[Any]						=			(
											    self.model_tester.image_size
											    if isinstance(self.model_tester.image_size						,     collections.abc.Iterable						)
											    else (self.model_tester.image_size, self.model_tester.image_size)
											)

											for model_class in self.all_model_classes:
																	snake_case_ :Tuple						=			True
																	self.check_hidden_states_output(snake_case						,     snake_case						,     snake_case						,     snake_case						)

																	# check that output_hidden_states also work using config
																	del inputs_dict["output_hidden_states"]
																	snake_case_ :List[Any]						=			True

																	self.check_hidden_states_output(snake_case						,     snake_case						,     snake_case						,     snake_case						)






					def    lowerCAmelCase_				(       self:							Optional[Any]						)   ->	Tuple:
											snake_case_,       snake_case_ :int						=			self.model_tester.prepare_config_and_inputs_for_common()
											snake_case_ :List[Any]						=			3

											snake_case_ :List[Any]						=			(
											    self.model_tester.image_size
											    if isinstance(self.model_tester.image_size						,     collections.abc.Iterable						)
											    else (self.model_tester.image_size, self.model_tester.image_size)
											)
											snake_case_ :Any						=			(
											    config.patch_size
											    if isinstance(config.patch_size						,     collections.abc.Iterable						)
											    else (config.patch_size, config.patch_size)
											)

											snake_case_ :Tuple						=			image_size[0] + patch_size[0] - (image_size[0] % patch_size[0])
											snake_case_ :List[str]						=			image_size[1] + patch_size[1] - (image_size[1] % patch_size[1])

											for model_class in self.all_model_classes:
																	snake_case_ :str						=			True
																	self.check_hidden_states_output(snake_case						,     snake_case						,     snake_case						,     (padded_height, padded_width)						)

																	# check that output_hidden_states also work using config
																	del inputs_dict["output_hidden_states"]
																	snake_case_ :Any						=			True
																	self.check_hidden_states_output(snake_case						,     snake_case						,     snake_case						,     (padded_height, padded_width)						)






					@unittest.skip(reason="""MaskFormerSwin doesn't have pretrained checkpoints"""						)
					def    lowerCAmelCase_				(       self:							Union[str, Any]						)   ->	List[str]:
											pass






					@unittest.skip(reason="""This will be fixed once MaskFormerSwin is replaced by native Swin"""						)
					def    lowerCAmelCase_				(       self:							List[str]						)   ->	str:
											pass






					@unittest.skip(reason="""This will be fixed once MaskFormerSwin is replaced by native Swin"""						)
					def    lowerCAmelCase_				(       self:							str						)   ->	List[Any]:
											pass






					def    lowerCAmelCase_				(       self:							Union[str, Any]						)   ->	Optional[Any]:
											snake_case_,       snake_case_ :Dict						=			self.model_tester.prepare_config_and_inputs_for_common()

											def set_nan_tensor_to_zero(snake_case:							str						):
																	snake_case_ :Optional[int]						=			0
																	return t

											def check_equivalence(snake_case:							List[Any]						,     snake_case:							Union[str, Any]						,     snake_case:							int						,     snake_case:							Tuple={}						):
																	with torch.no_grad():
																							snake_case_ :List[Any]						=			model(**snake_case						,     return_dict=snake_case						,     **snake_case						)
																							snake_case_ :Any						=			model(**snake_case						,     return_dict=snake_case						,     **snake_case						).to_tuple()

																							def recursive_check(snake_case:							List[Any]						,     snake_case:							int						):
																													if isinstance(snake_case						,     (List, Tuple)						):
																																			for tuple_iterable_value, dict_iterable_value in zip(snake_case						,     snake_case						):
																																									recursive_check(snake_case						,     snake_case						)
																													elif isinstance(snake_case						,     snake_case						):
																																			for tuple_iterable_value, dict_iterable_value in zip(
																																			    tuple_object.values()						,     dict_object.values()						):
																																									recursive_check(snake_case						,     snake_case						)
																													elif tuple_object is None:
																																			return
																													else:
																																			self.assertTrue(
																																			    torch.allclose(
																																			        set_nan_tensor_to_zero(snake_case						)						,     set_nan_tensor_to_zero(snake_case						)						,     atol=1E-5						)						,     msg=(
																																			        """Tuple and dict output are not equal. Difference:"""
																																			        f""" {torch.max(torch.abs(tuple_object - dict_object						)						)}. Tuple has `nan`:"""
																																			        f""" {torch.isnan(snake_case						).any()} and `inf`: {torch.isinf(snake_case						)}. Dict has"""
																																			        f""" `nan`: {torch.isnan(snake_case						).any()} and `inf`: {torch.isinf(snake_case						)}."""
																																			    )						,     )

																							recursive_check(snake_case						,     snake_case						)

											for model_class in self.all_model_classes:
																	snake_case_ :int						=			model_class(snake_case						)
																	model.to(snake_case						)
																	model.eval()

																	snake_case_ :Any						=			self._prepare_for_class(snake_case						,     snake_case						)
																	snake_case_ :List[Any]						=			self._prepare_for_class(snake_case						,     snake_case						)
																	check_equivalence(snake_case						,     snake_case						,     snake_case						)

																	snake_case_ :Tuple						=			self._prepare_for_class(snake_case						,     snake_case						,     return_labels=snake_case						)
																	snake_case_ :Dict						=			self._prepare_for_class(snake_case						,     snake_case						,     return_labels=snake_case						)
																	check_equivalence(snake_case						,     snake_case						,     snake_case						)

																	snake_case_ :Tuple						=			self._prepare_for_class(snake_case						,     snake_case						)
																	snake_case_ :Any						=			self._prepare_for_class(snake_case						,     snake_case						)
																	check_equivalence(snake_case						,     snake_case						,     snake_case						,     {"""output_hidden_states""": True}						)

																	snake_case_ :Dict						=			self._prepare_for_class(snake_case						,     snake_case						,     return_labels=snake_case						)
																	snake_case_ :List[str]						=			self._prepare_for_class(snake_case						,     snake_case						,     return_labels=snake_case						)
																	check_equivalence(snake_case						,     snake_case						,     snake_case						,     {"""output_hidden_states""": True}						)

@require_torch
class 				lowerCamelCase  (			unittest.TestCase    ,						_lowerCAmelCase				):






					'''simple docstring'''





					_A		:			int						=     (MaskFormerSwinBackbone,) if is_torch_available() else ()
					_A		:			Tuple						=     MaskFormerSwinConfig






					def    lowerCAmelCase_				(       self:							List[str]						)   ->	Optional[int]:
											snake_case_ :Optional[Any]						=			MaskFormerSwinModelTester(self						)






					def    lowerCAmelCase_				(       self:							int						)   ->	Optional[int]:
											snake_case_,       snake_case_ :Any						=			self.model_tester.prepare_config_and_inputs_for_common()
											snake_case_ :Tuple						=			inputs_dict["""pixel_values"""].shape[0]

											for backbone_class in self.all_model_classes:
																	snake_case_ :List[str]						=			backbone_class(snake_case						)
																	backbone.to(snake_case						)
																	backbone.eval()

																	snake_case_ :List[Any]						=			backbone(**snake_case						)

																	# Test default outputs and verify feature maps
																	self.assertIsInstance(outputs.feature_maps						,     snake_case						)
																	self.assertTrue(len(outputs.feature_maps						) == len(backbone.channels						)						)
																	for feature_map, n_channels in zip(outputs.feature_maps						,     backbone.channels						):
																							self.assertTrue(feature_map.shape[:2]						,     (batch_size, n_channels)						)
																	self.assertIsNone(outputs.hidden_states						)
																	self.assertIsNone(outputs.attentions						)

																	# Test output_hidden_states=True
																	snake_case_ :Union[str, Any]						=			backbone(**snake_case						,     output_hidden_states=snake_case						)
																	self.assertIsNotNone(outputs.hidden_states						)
																	self.assertTrue(len(outputs.hidden_states						)						,     len(backbone.stage_names						)						)
																	# We skip the stem layer
																	for hidden_states, n_channels in zip(outputs.hidden_states[1:]						,     backbone.channels						):
																							for hidden_state in hidden_states:
																													# Hidden states are in the format (batch_size, (height * width), n_channels)
																													snake_case_,       snake_case_,       snake_case_ :List[Any]						=			hidden_state.shape
																													self.assertTrue((h_batch_size, h_n_channels)						,     (batch_size, n_channels)						)

            # Test output_attentions=True
																	if self.has_attentions:
																							snake_case_ :List[Any]						=			backbone(**snake_case						,     output_attentions=snake_case						)
																							self.assertIsNotNone(outputs.attentions						)
