

'''simple docstring'''



from typing import Dict, Optional

import numpy as np

import datasets


__snake_case			:     Any										=      '\nIoU is the area of overlap between the predicted segmentation and the ground truth divided by the area of union\nbetween the predicted segmentation and the ground truth. For binary (two classes) or multi-class segmentation,\nthe mean IoU of the image is calculated by taking the IoU of each class and averaging them.\n'

__snake_case			:     str										=      '\nArgs:\n    predictions (`List[ndarray]`):\n        List of predicted segmentation maps, each of shape (height, width). Each segmentation map can be of a different size.\n    references (`List[ndarray]`):\n        List of ground truth segmentation maps, each of shape (height, width). Each segmentation map can be of a different size.\n    num_labels (`int`):\n        Number of classes (categories).\n    ignore_index (`int`):\n        Index that will be ignored during evaluation.\n    nan_to_num (`int`, *optional*):\n        If specified, NaN values will be replaced by the number defined by the user.\n    label_map (`dict`, *optional*):\n        If specified, dictionary mapping old label indices to new label indices.\n    reduce_labels (`bool`, *optional*, defaults to `False`):\n        Whether or not to reduce all label values of segmentation maps by 1. Usually used for datasets where 0 is used for background,\n        and background itself is not included in all classes of a dataset (e.g. ADE20k). The background label will be replaced by 255.\n\nReturns:\n    `Dict[str, float | ndarray]` comprising various elements:\n    - *mean_iou* (`float`):\n        Mean Intersection-over-Union (IoU averaged over all categories).\n    - *mean_accuracy* (`float`):\n        Mean accuracy (averaged over all categories).\n    - *overall_accuracy* (`float`):\n        Overall accuracy on all images.\n    - *per_category_accuracy* (`ndarray` of shape `(num_labels,)`):\n        Per category accuracy.\n    - *per_category_iou* (`ndarray` of shape `(num_labels,)`):\n        Per category IoU.\n\nExamples:\n\n    >>> import numpy as np\n\n    >>> mean_iou = datasets.load_metric("mean_iou")\n\n    >>> # suppose one has 3 different segmentation maps predicted\n    >>> predicted_1 = np.array([[1, 2], [3, 4], [5, 255]])\n    >>> actual_1 = np.array([[0, 3], [5, 4], [6, 255]])\n\n    >>> predicted_2 = np.array([[2, 7], [9, 2], [3, 6]])\n    >>> actual_2 = np.array([[1, 7], [9, 2], [3, 6]])\n\n    >>> predicted_3 = np.array([[2, 2, 3], [8, 2, 4], [3, 255, 2]])\n    >>> actual_3 = np.array([[1, 2, 2], [8, 2, 1], [3, 255, 1]])\n\n    >>> predicted = [predicted_1, predicted_2, predicted_3]\n    >>> ground_truth = [actual_1, actual_2, actual_3]\n\n    >>> results = mean_iou.compute(predictions=predicted, references=ground_truth, num_labels=10, ignore_index=255, reduce_labels=False)\n    >>> print(results) # doctest: +NORMALIZE_WHITESPACE\n    {\'mean_iou\': 0.47750000000000004, \'mean_accuracy\': 0.5916666666666666, \'overall_accuracy\': 0.5263157894736842, \'per_category_iou\': array([0.   , 0.   , 0.375, 0.4  , 0.5  , 0.   , 0.5  , 1.   , 1.   , 1.   ]), \'per_category_accuracy\': array([0.        , 0.        , 0.75      , 0.66666667, 1.        , 0.        , 0.5       , 1.        , 1.        , 1.        ])}\n'

__snake_case			:     Tuple										=      '\\n@software{MMSegmentation_Contributors_OpenMMLab_Semantic_Segmentation_2020,\nauthor = {{MMSegmentation Contributors}},\nlicense = {Apache-2.0},\nmonth = {7},\ntitle = {{OpenMMLab Semantic Segmentation Toolbox and Benchmark}},\nurl = {https://github.com/open-mmlab/mmsegmentation},\nyear = {2020}\n}'
def 						__lowerCamelCase	(       __snake_case					:		int,		__snake_case					:		str,		__snake_case					:		List[str],		__snake_case					:		bool,		__snake_case					:		Optional[Dict[int, int]] = None,		__snake_case					:		bool = False,		)	->							Dict:






						"""simple docstring"""





						if label_map is not None:
												for old_id, new_id in label_map.items():
																		A__					:       Dict     =new_id

    # turn into Numpy arrays
						A__					:       Any     =np.array(__snake_case	)
						A__					:       Union[str, Any]     =np.array(__snake_case	)

						if reduce_labels:
												A__					:       Optional[Any]     =255
												A__					:       Dict     =label - 1
												A__					:       str     =255

						A__					:       List[str]     =label != ignore_index
						A__					:       Tuple     =np.not_equal(__snake_case,		__snake_case	)
						A__					:       Tuple     =pred_label[mask]
						A__					:       Union[str, Any]     =np.array(__snake_case	)[mask]

						A__					:       Optional[Any]     =pred_label[pred_label == label]

						A__					:       Any     =np.histogram(__snake_case,		bins=__snake_case,		range=(0, num_labels - 1)	)[0]
						A__					:       List[Any]     =np.histogram(__snake_case,		bins=__snake_case,		range=(0, num_labels - 1)	)[0]
						A__					:       int     =np.histogram(__snake_case,		bins=__snake_case,		range=(0, num_labels - 1)	)[0]

						A__					:       List[str]     =area_pred_label + area_label - area_intersect

						return area_intersect, area_union, area_pred_label, area_label
def 						__lowerCamelCase	(       __snake_case					:		int,		__snake_case					:		List[Any],		__snake_case					:		Any,		__snake_case					:		bool,		__snake_case					:		Optional[Dict[int, int]] = None,		__snake_case					:		bool = False,		)	->							str:






						"""simple docstring"""





						A__					:       Dict     =np.zeros((num_labels,),		dtype=np.floataa	)
						A__					:       Any     =np.zeros((num_labels,),		dtype=np.floataa	)
						A__					:       Tuple     =np.zeros((num_labels,),		dtype=np.floataa	)
						A__					:       Optional[Any]     =np.zeros((num_labels,),		dtype=np.floataa	)
						for result, gt_seg_map in zip(__snake_case,		__snake_case	):
												A__   ,						A__   ,						A__   ,						A__					:       List[str]     =intersect_and_union(
												    __snake_case,		__snake_case,		__snake_case,		__snake_case,		__snake_case,		__snake_case	)
												total_area_intersect += area_intersect
												total_area_union += area_union
												total_area_pred_label += area_pred_label
												total_area_label += area_label
						return total_area_intersect, total_area_union, total_area_pred_label, total_area_label
def 						__lowerCamelCase	(       __snake_case					:		Union[str, Any],		__snake_case					:		int,		__snake_case					:		int,		__snake_case					:		bool,		__snake_case					:		Optional[int] = None,		__snake_case					:		Optional[Dict[int, int]] = None,		__snake_case					:		bool = False,		)	->							List[Any]:






						"""simple docstring"""





						A__   ,						A__   ,						A__   ,						A__					:       List[Any]     =total_intersect_and_union(
						    __snake_case,		__snake_case,		__snake_case,		__snake_case,		__snake_case,		__snake_case	)

						# compute metrics
						A__					:       Dict     ={}

						A__					:       Optional[int]     =total_area_intersect.sum() / total_area_label.sum()
						A__					:       Optional[int]     =total_area_intersect / total_area_union
						A__					:       Optional[Any]     =total_area_intersect / total_area_label

						A__					:       str     =np.nanmean(__snake_case	)
						A__					:       Optional[int]     =np.nanmean(__snake_case	)
						A__					:       Optional[int]     =all_acc
						A__					:       Union[str, Any]     =iou
						A__					:       int     =acc

						if nan_to_num is not None:
												A__					:       int     ={metric: np.nan_to_num(__snake_case,		nan=__snake_case	) for metric, metric_value in metrics.items()}

						return metrics



@datasets.utils.file_utils.add_start_docstrings(_DESCRIPTION	,						_KWARGS_DESCRIPTION						)
class lowerCamelCase			(  datasets.Metric						):



			'''simple docstring'''






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





									'''simple docstring'''
									return datasets.MetricInfo(
									    description=_DESCRIPTION		,      citation=_CITATION		,      inputs_description=_KWARGS_DESCRIPTION		,      features=datasets.Features(
									        # 1st Seq - height dim, 2nd - width dim
									        {
									            """predictions""": datasets.Sequence(datasets.Sequence(datasets.Value("""uint16"""			)			)			),
									            """references""": datasets.Sequence(datasets.Sequence(datasets.Value("""uint16"""			)			)			),
									        }			)		,      reference_urls=[
									        """https://github.com/open-mmlab/mmsegmentation/blob/71c201b1813267d78764f306a297ca717827c4bf/mmseg/core/evaluation/metrics.py"""
									    ]		,      )



			def lowercase__						(				self	:						Optional[int]		,      lowerCAmelCase_	:						Union[str, Any]		,      lowerCAmelCase_	:						Union[str, Any]		,      lowerCAmelCase_	:						int		,      lowerCAmelCase_	:						bool		,      lowerCAmelCase_	:						Optional[int] = None		,      lowerCAmelCase_	:						Optional[Dict[int, int]] = None		,      lowerCAmelCase_	:						bool = False		,      )      ->		List[str]:





									'''simple docstring'''
									A__					:       Tuple     =mean_iou(
									    results=lowerCAmelCase_		,      gt_seg_maps=lowerCAmelCase_		,      num_labels=lowerCAmelCase_		,      ignore_index=lowerCAmelCase_		,      nan_to_num=lowerCAmelCase_		,      label_map=lowerCAmelCase_		,      reduce_labels=lowerCAmelCase_		,      )
									return iou_result




'''simple docstring'''



import os
import tempfile
import unittest

from transformers import DistilBertConfig, is_torch_available
from transformers.testing_utils import require_torch, require_torch_gpu, slow, torch_device

from ...test_configuration_common import ConfigTester
from ...test_modeling_common import ModelTesterMixin, ids_tensor, random_attention_mask
from ...test_pipeline_mixin import PipelineTesterMixin


if is_torch_available():
		import torch

		from transformers import (
		    DISTILBERT_PRETRAINED_MODEL_ARCHIVE_LIST,
		    DistilBertForMaskedLM,
		    DistilBertForMultipleChoice,
		    DistilBertForQuestionAnswering,
		    DistilBertForSequenceClassification,
		    DistilBertForTokenClassification,
		    DistilBertModel,
		)



class lowerCamelCase			(  lowercase_						):



			'''simple docstring'''






			def __init__(				self	:						Dict		,      lowerCAmelCase_	:						Optional[int]		,      lowerCAmelCase_	:						List[str]=13		,      lowerCAmelCase_	:						Dict=7		,      lowerCAmelCase_	:						Union[str, Any]=True		,      lowerCAmelCase_	:						str=True		,      lowerCAmelCase_	:						int=False		,      lowerCAmelCase_	:						int=True		,      lowerCAmelCase_	:						int=99		,      lowerCAmelCase_	:						str=32		,      lowerCAmelCase_	:						str=5		,      lowerCAmelCase_	:						List[Any]=4		,      lowerCAmelCase_	:						Dict=37		,      lowerCAmelCase_	:						Optional[Any]="gelu"		,      lowerCAmelCase_	:						Tuple=0.1		,      lowerCAmelCase_	:						Dict=0.1		,      lowerCAmelCase_	:						str=5_12		,      lowerCAmelCase_	:						Dict=16		,      lowerCAmelCase_	:						Any=2		,      lowerCAmelCase_	:						Dict=0.02		,      lowerCAmelCase_	:						Optional[int]=3		,      lowerCAmelCase_	:						List[Any]=4		,      lowerCAmelCase_	:						Optional[int]=None		,      )      ->		List[str]:





									'''simple docstring'''
									A__					:       List[str]     =parent
									A__					:       Optional[Any]     =batch_size
									A__					:       List[Any]     =seq_length
									A__					:       Tuple     =is_training
									A__					:       Optional[int]     =use_input_mask
									A__					:       Optional[int]     =use_token_type_ids
									A__					:       Tuple     =use_labels
									A__					:       Dict     =vocab_size
									A__					:       Optional[Any]     =hidden_size
									A__					:       Tuple     =num_hidden_layers
									A__					:       Tuple     =num_attention_heads
									A__					:       Union[str, Any]     =intermediate_size
									A__					:       Dict     =hidden_act
									A__					:       List[Any]     =hidden_dropout_prob
									A__					:       Optional[int]     =attention_probs_dropout_prob
									A__					:       List[str]     =max_position_embeddings
									A__					:       str     =type_vocab_size
									A__					:       Union[str, Any]     =type_sequence_label_size
									A__					:       Tuple     =initializer_range
									A__					:       List[Any]     =num_labels
									A__					:       str     =num_choices
									A__					:       Union[str, Any]     =scope


			def lowercase__						(				self	:						int			)      ->		Tuple:





									'''simple docstring'''
									A__					:       Dict     =ids_tensor([self.batch_size, self.seq_length]		,      self.vocab_size			)

									A__					:       List[str]     =None
									if self.use_input_mask:
															A__					:       Union[str, Any]     =random_attention_mask([self.batch_size, self.seq_length]			)

									A__					:       List[str]     =None
									A__					:       int     =None
									A__					:       List[Any]     =None
									if self.use_labels:
															A__					:       str     =ids_tensor([self.batch_size]		,      self.type_sequence_label_size			)
															A__					:       Union[str, Any]     =ids_tensor([self.batch_size, self.seq_length]		,      self.num_labels			)
															A__					:       Any     =ids_tensor([self.batch_size]		,      self.num_choices			)

									A__					:       str     =self.get_config()

									return config, input_ids, input_mask, sequence_labels, token_labels, choice_labels


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





									'''simple docstring'''
									return DistilBertConfig(
									    vocab_size=self.vocab_size		,      dim=self.hidden_size		,      n_layers=self.num_hidden_layers		,      n_heads=self.num_attention_heads		,      hidden_dim=self.intermediate_size		,      hidden_act=self.hidden_act		,      dropout=self.hidden_dropout_prob		,      attention_dropout=self.attention_probs_dropout_prob		,      max_position_embeddings=self.max_position_embeddings		,      initializer_range=self.initializer_range		,      )


			def lowercase__						(				self	:						Optional[Any]		,      lowerCAmelCase_	:						Dict		,      lowerCAmelCase_	:						Dict		,      lowerCAmelCase_	:						List[Any]		,      lowerCAmelCase_	:						Any		,      lowerCAmelCase_	:						Any		,      lowerCAmelCase_	:						List[Any]			)      ->		str:





									'''simple docstring'''
									A__					:       Union[str, Any]     =DistilBertModel(config=lowerCAmelCase_			)
									model.to(lowerCAmelCase_			)
									model.eval()
									A__					:       Dict     =model(lowerCAmelCase_		,      lowerCAmelCase_			)
									A__					:       List[str]     =model(lowerCAmelCase_			)
									self.parent.assertEqual(result.last_hidden_state.shape		,      (self.batch_size, self.seq_length, self.hidden_size)			)


			def lowercase__						(				self	:						Tuple		,      lowerCAmelCase_	:						Tuple		,      lowerCAmelCase_	:						Tuple		,      lowerCAmelCase_	:						Dict		,      lowerCAmelCase_	:						Optional[int]		,      lowerCAmelCase_	:						str		,      lowerCAmelCase_	:						Any			)      ->		List[str]:





									'''simple docstring'''
									A__					:       Union[str, Any]     =DistilBertForMaskedLM(config=lowerCAmelCase_			)
									model.to(lowerCAmelCase_			)
									model.eval()
									A__					:       Union[str, Any]     =model(lowerCAmelCase_		,      attention_mask=lowerCAmelCase_		,      labels=lowerCAmelCase_			)
									self.parent.assertEqual(result.logits.shape		,      (self.batch_size, self.seq_length, self.vocab_size)			)


			def lowercase__						(				self	:						Dict		,      lowerCAmelCase_	:						List[str]		,      lowerCAmelCase_	:						str		,      lowerCAmelCase_	:						str		,      lowerCAmelCase_	:						List[Any]		,      lowerCAmelCase_	:						str		,      lowerCAmelCase_	:						Optional[Any]			)      ->		Dict:





									'''simple docstring'''
									A__					:       Dict     =DistilBertForQuestionAnswering(config=lowerCAmelCase_			)
									model.to(lowerCAmelCase_			)
									model.eval()
									A__					:       Tuple     =model(
									    lowerCAmelCase_		,      attention_mask=lowerCAmelCase_		,      start_positions=lowerCAmelCase_		,      end_positions=lowerCAmelCase_			)
									self.parent.assertEqual(result.start_logits.shape		,      (self.batch_size, self.seq_length)			)
									self.parent.assertEqual(result.end_logits.shape		,      (self.batch_size, self.seq_length)			)


			def lowercase__						(				self	:						Optional[int]		,      lowerCAmelCase_	:						List[Any]		,      lowerCAmelCase_	:						Union[str, Any]		,      lowerCAmelCase_	:						Optional[Any]		,      lowerCAmelCase_	:						Optional[int]		,      lowerCAmelCase_	:						List[Any]		,      lowerCAmelCase_	:						Dict			)      ->		Tuple:





									'''simple docstring'''
									A__					:       List[Any]     =self.num_labels
									A__					:       Dict     =DistilBertForSequenceClassification(lowerCAmelCase_			)
									model.to(lowerCAmelCase_			)
									model.eval()
									A__					:       Union[str, Any]     =model(lowerCAmelCase_		,      attention_mask=lowerCAmelCase_		,      labels=lowerCAmelCase_			)
									self.parent.assertEqual(result.logits.shape		,      (self.batch_size, self.num_labels)			)


			def lowercase__						(				self	:						str		,      lowerCAmelCase_	:						List[str]		,      lowerCAmelCase_	:						Dict		,      lowerCAmelCase_	:						Tuple		,      lowerCAmelCase_	:						List[str]		,      lowerCAmelCase_	:						Tuple		,      lowerCAmelCase_	:						List[Any]			)      ->		int:





									'''simple docstring'''
									A__					:       Optional[int]     =self.num_labels
									A__					:       Union[str, Any]     =DistilBertForTokenClassification(config=lowerCAmelCase_			)
									model.to(lowerCAmelCase_			)
									model.eval()

									A__					:       List[Any]     =model(lowerCAmelCase_		,      attention_mask=lowerCAmelCase_		,      labels=lowerCAmelCase_			)
									self.parent.assertEqual(result.logits.shape		,      (self.batch_size, self.seq_length, self.num_labels)			)


			def lowercase__						(				self	:						Union[str, Any]		,      lowerCAmelCase_	:						Optional[int]		,      lowerCAmelCase_	:						int		,      lowerCAmelCase_	:						Tuple		,      lowerCAmelCase_	:						Dict		,      lowerCAmelCase_	:						List[str]		,      lowerCAmelCase_	:						Optional[int]			)      ->		Dict:





									'''simple docstring'''
									A__					:       int     =self.num_choices
									A__					:       Tuple     =DistilBertForMultipleChoice(config=lowerCAmelCase_			)
									model.to(lowerCAmelCase_			)
									model.eval()
									A__					:       int     =input_ids.unsqueeze(1			).expand(-1		,      self.num_choices		,      -1			).contiguous()
									A__					:       int     =input_mask.unsqueeze(1			).expand(-1		,      self.num_choices		,      -1			).contiguous()
									A__					:       Tuple     =model(
									    lowerCAmelCase_		,      attention_mask=lowerCAmelCase_		,      labels=lowerCAmelCase_		,      )
									self.parent.assertEqual(result.logits.shape		,      (self.batch_size, self.num_choices)			)



			def lowercase__						(				self	:						Tuple			)      ->		Optional[Any]:





									'''simple docstring'''
									A__					:       Optional[Any]     =self.prepare_config_and_inputs()
									((A__)   ,						(A__)   ,						(A__)   ,						(A__)   ,						(A__)   ,						(A__))					:       List[str]     =config_and_inputs
									A__					:       str     ={"""input_ids""": input_ids, """attention_mask""": input_mask}
									return config, inputs_dict



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



			'''simple docstring'''






			__snake_case        =	(
			    (
			        DistilBertModel,
			        DistilBertForMaskedLM,
			        DistilBertForMultipleChoice,
			        DistilBertForQuestionAnswering,
			        DistilBertForSequenceClassification,
			        DistilBertForTokenClassification,
			    )
			    if is_torch_available()
			    else None
			)
			__snake_case        =	(
			    {
			        'feature-extraction': DistilBertModel,
			        'fill-mask': DistilBertForMaskedLM,
			        'question-answering': DistilBertForQuestionAnswering,
			        'text-classification': DistilBertForSequenceClassification,
			        'token-classification': DistilBertForTokenClassification,
			        'zero-shot': DistilBertForSequenceClassification,
			    }
			    if is_torch_available()
			    else {}
			)
			__snake_case        =	True
			__snake_case        =	True
			__snake_case        =	True
			__snake_case        =	True


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





									'''simple docstring'''
									A__					:       Any     =DistilBertModelTester(self			)
									A__					:       Tuple     =ConfigTester(self		,      config_class=lowerCAmelCase_		,      dim=37			)


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





									'''simple docstring'''
									self.config_tester.run_common_tests()


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





									'''simple docstring'''
									A__					:       int     =self.model_tester.prepare_config_and_inputs()
									self.model_tester.create_and_check_distilbert_model(*lowerCAmelCase_			)


			def lowercase__						(				self	:						Any			)      ->		Tuple:





									'''simple docstring'''
									A__					:       Tuple     =self.model_tester.prepare_config_and_inputs()
									self.model_tester.create_and_check_distilbert_for_masked_lm(*lowerCAmelCase_			)


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





									'''simple docstring'''
									A__					:       str     =self.model_tester.prepare_config_and_inputs()
									self.model_tester.create_and_check_distilbert_for_question_answering(*lowerCAmelCase_			)


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





									'''simple docstring'''
									A__					:       Any     =self.model_tester.prepare_config_and_inputs()
									self.model_tester.create_and_check_distilbert_for_sequence_classification(*lowerCAmelCase_			)


			def lowercase__						(				self	:						Optional[int]			)      ->		Optional[int]:





									'''simple docstring'''
									A__					:       Dict     =self.model_tester.prepare_config_and_inputs()
									self.model_tester.create_and_check_distilbert_for_token_classification(*lowerCAmelCase_			)


			def lowercase__						(				self	:						List[str]			)      ->		Optional[int]:





									'''simple docstring'''
									A__					:       List[Any]     =self.model_tester.prepare_config_and_inputs()
									self.model_tester.create_and_check_distilbert_for_multiple_choice(*lowerCAmelCase_			)


			@slow
			def lowercase__						(				self	:						Union[str, Any]			)      ->		Dict:





									'''simple docstring'''
									for model_name in DISTILBERT_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
															A__					:       Optional[int]     =DistilBertModel.from_pretrained(lowerCAmelCase_			)
															self.assertIsNotNone(lowerCAmelCase_			)



			@slow
			@require_torch_gpu
			def lowercase__						(				self	:						Tuple			)      ->		Any:





									'''simple docstring'''
									A__   ,						A__					:       List[str]     =self.model_tester.prepare_config_and_inputs_for_common()
									for model_class in self.all_model_classes:
															# BertForMultipleChoice behaves incorrectly in JIT environments.
															if model_class == DistilBertForMultipleChoice:
																					return

															A__					:       Any     =True
															A__					:       Optional[Any]     =model_class(config=lowerCAmelCase_			)

															A__					:       Dict     =self._prepare_for_class(lowerCAmelCase_		,      lowerCAmelCase_			)
															A__					:       Optional[int]     =torch.jit.trace(
															    lowerCAmelCase_		,      (inputs_dict["""input_ids"""].to("""cpu"""			), inputs_dict["""attention_mask"""].to("""cpu"""			))			)

															with tempfile.TemporaryDirectory() as tmp:
																					torch.jit.save(lowerCAmelCase_		,      os.path.join(lowerCAmelCase_		,      """traced_model.pt"""			)			)
																					A__					:       List[Any]     =torch.jit.load(os.path.join(lowerCAmelCase_		,      """traced_model.pt"""			)		,      map_location=lowerCAmelCase_			)
																					loaded(inputs_dict["""input_ids"""].to(lowerCAmelCase_			)		,      inputs_dict["""attention_mask"""].to(lowerCAmelCase_			)			)



@require_torch
class lowerCamelCase			(  unittest.TestCase						):



			'''simple docstring'''






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





									'''simple docstring'''
									A__					:       List[str]     =DistilBertModel.from_pretrained("""distilbert-base-uncased"""			)
									A__					:       Optional[Any]     =torch.tensor([[0, 3_45, 2_32, 3_28, 7_40, 1_40, 16_95, 69, 60_78, 15_88, 2]]			)
									A__					:       int     =torch.tensor([[0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]]			)
									with torch.no_grad():
															A__					:       Any     =model(lowerCAmelCase_		,      attention_mask=lowerCAmelCase_			)[0]
									A__					:       Tuple     =torch.Size((1, 11, 7_68)			)
									self.assertEqual(output.shape		,      lowerCAmelCase_			)
									A__					:       Optional[int]     =torch.tensor(
									    [[[-0.1639, 0.3299, 0.1648], [-0.1746, 0.3289, 0.1710], [-0.1884, 0.3357, 0.1810]]]			)

									self.assertTrue(torch.allclose(output[:, 1:4, 1:4]		,      lowerCAmelCase_		,      atol=1e-4			)			)

