

'''simple docstring'''
import inspect
import unittest
import warnings

from transformers import DeiTConfig
from transformers.models.auto import get_values
from transformers.testing_utils import (
    require_accelerate,
    require_torch,
    require_torch_gpu,
    require_vision,
    slow,
    torch_device,
)
from transformers.utils import cached_property, is_torch_available, is_vision_available

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 (
					    MODEL_FOR_IMAGE_CLASSIFICATION_MAPPING,
					    MODEL_FOR_SEQUENCE_CLASSIFICATION_MAPPING,
					    MODEL_MAPPING,
					    DeiTForImageClassification,
					    DeiTForImageClassificationWithTeacher,
					    DeiTForMaskedImageModeling,
					    DeiTModel,
					)
					from transformers.models.deit.modeling_deit import DEIT_PRETRAINED_MODEL_ARCHIVE_LIST


if is_vision_available():
					from PIL import Image

					from transformers import DeiTImageProcessor
class 					_snake_case		:






			def __init__(  self			,_snake_case			,_snake_case=13			,_snake_case=30			,_snake_case=2			,_snake_case=3			,_snake_case=True			,_snake_case=True			,_snake_case=32			,_snake_case=5			,_snake_case=4			,_snake_case=37			,_snake_case="gelu"			,_snake_case=0.1			,_snake_case=0.1			,_snake_case=10			,_snake_case=0.02			,_snake_case=3			,_snake_case=None			,_snake_case=2			,):
				UpperCAmelCase_     :      Any						=  parent
				UpperCAmelCase_     :      Optional[Any]						=  batch_size
				UpperCAmelCase_     :      List[Any]						=  image_size
				UpperCAmelCase_     :      Dict						=  patch_size
				UpperCAmelCase_     :      List[str]						=  num_channels
				UpperCAmelCase_     :      List[Any]						=  is_training
				UpperCAmelCase_     :      Tuple						=  use_labels
				UpperCAmelCase_     :      Dict						=  hidden_size
				UpperCAmelCase_     :      Dict						=  num_hidden_layers
				UpperCAmelCase_     :      Any						=  num_attention_heads
				UpperCAmelCase_     :      Union[str, Any]						=  intermediate_size
				UpperCAmelCase_     :      Tuple						=  hidden_act
				UpperCAmelCase_     :      Optional[int]						=  hidden_dropout_prob
				UpperCAmelCase_     :      Union[str, Any]						=  attention_probs_dropout_prob
				UpperCAmelCase_     :      str						=  type_sequence_label_size
				UpperCAmelCase_     :      str						=  initializer_range
				UpperCAmelCase_     :      Dict						=  scope
				UpperCAmelCase_     :      str						=  encoder_stride

				# in DeiT, the seq length equals the number of patches + 2 (we add 2 for the [CLS] and distilation tokens)
				UpperCAmelCase_     :      List[str]						=  (image_size // patch_size) ** 2
				UpperCAmelCase_     :      Union[str, Any]						=  num_patches + 2






			def 		UpperCamelCase__							(  self     ):
				UpperCAmelCase_     :      Tuple						=  floats_tensor([self.batch_size, self.num_channels, self.image_size, self.image_size]     )

				UpperCAmelCase_     :      int						=  None
				if self.use_labels:
					UpperCAmelCase_     :      Any						=  ids_tensor([self.batch_size]			,self.type_sequence_label_size     )

				UpperCAmelCase_     :      int						=  self.get_config()

				return config, pixel_values, labels






			def 		UpperCamelCase__							(  self     ):
				return DeiTConfig(
				    image_size=self.image_size			,patch_size=self.patch_size			,num_channels=self.num_channels			,hidden_size=self.hidden_size			,num_hidden_layers=self.num_hidden_layers			,num_attention_heads=self.num_attention_heads			,intermediate_size=self.intermediate_size			,hidden_act=self.hidden_act			,hidden_dropout_prob=self.hidden_dropout_prob			,attention_probs_dropout_prob=self.attention_probs_dropout_prob			,is_decoder=_snake_case			,initializer_range=self.initializer_range			,encoder_stride=self.encoder_stride			,)






			def 		UpperCamelCase__							(  self			,_snake_case			,_snake_case			,_snake_case     ):
				UpperCAmelCase_     :      List[str]						=  DeiTModel(config=_snake_case     )
				model.to(_snake_case     )
				model.eval()
				UpperCAmelCase_     :      Dict						=  model(_snake_case     )
				self.parent.assertEqual(result.last_hidden_state.shape			,(self.batch_size, self.seq_length, self.hidden_size)     )






			def 		UpperCamelCase__							(  self			,_snake_case			,_snake_case			,_snake_case     ):
				UpperCAmelCase_     :      int						=  DeiTForMaskedImageModeling(config=_snake_case     )
				model.to(_snake_case     )
				model.eval()
				UpperCAmelCase_     :      Dict						=  model(_snake_case     )
				self.parent.assertEqual(
				    result.reconstruction.shape			,(self.batch_size, self.num_channels, self.image_size, self.image_size)     )

				# test greyscale images
				UpperCAmelCase_     :      Any						=  1
				UpperCAmelCase_     :      int						=  DeiTForMaskedImageModeling(_snake_case     )
				model.to(_snake_case     )
				model.eval()

				UpperCAmelCase_     :      int						=  floats_tensor([self.batch_size, 1, self.image_size, self.image_size]     )
				UpperCAmelCase_     :      Tuple						=  model(_snake_case     )
				self.parent.assertEqual(result.reconstruction.shape			,(self.batch_size, 1, self.image_size, self.image_size)     )






			def 		UpperCamelCase__							(  self			,_snake_case			,_snake_case			,_snake_case     ):
				UpperCAmelCase_     :      Optional[int]						=  self.type_sequence_label_size
				UpperCAmelCase_     :      List[Any]						=  DeiTForImageClassification(_snake_case     )
				model.to(_snake_case     )
				model.eval()
				UpperCAmelCase_     :      Dict						=  model(_snake_case			,labels=_snake_case     )
				self.parent.assertEqual(result.logits.shape			,(self.batch_size, self.type_sequence_label_size)     )

				# test greyscale images
				UpperCAmelCase_     :      int						=  1
				UpperCAmelCase_     :      Tuple						=  DeiTForImageClassification(_snake_case     )
				model.to(_snake_case     )
				model.eval()

				UpperCAmelCase_     :      str						=  floats_tensor([self.batch_size, 1, self.image_size, self.image_size]     )
				UpperCAmelCase_     :      int						=  model(_snake_case			,labels=_snake_case     )
				self.parent.assertEqual(result.logits.shape			,(self.batch_size, self.type_sequence_label_size)     )






			def 		UpperCamelCase__							(  self     ):
				UpperCAmelCase_     :      str						=  self.prepare_config_and_inputs()
				(
				    (
				    UpperCAmelCase_
				)					,					(
				    UpperCAmelCase_
				)					,					(
				    UpperCAmelCase_
				)					,					
				)     :      List[str]						=  config_and_inputs
				UpperCAmelCase_     :      Any						=  {"pixel_values": pixel_values}
				return config, inputs_dict




@require_torch
class 					_snake_case		(__SCREAMING_SNAKE_CASE			,			__SCREAMING_SNAKE_CASE			,			unittest.TestCase):
			__A  :	Optional[Any]        =(
			    (
			        DeiTModel,
			        DeiTForImageClassification,
			        DeiTForImageClassificationWithTeacher,
			        DeiTForMaskedImageModeling,
			    )
			    if is_torch_available()
			    else ()
			)
			__A  :	str        =(
			    {
			        "feature-extraction": DeiTModel,
			        "image-classification": (DeiTForImageClassification, DeiTForImageClassificationWithTeacher),
			    }
			    if is_torch_available()
			    else {}
			)

			__A  :	Optional[int]        =False
			__A  :	Optional[Any]        =False
			__A  :	List[str]        =False






			def 		UpperCamelCase__							(  self     ):
				UpperCAmelCase_     :      int						=  DeiTModelTester(self     )
				UpperCAmelCase_     :      Union[str, Any]						=  ConfigTester(self			,config_class=_snake_case			,has_text_modality=_snake_case			,hidden_size=37     )






			def 		UpperCamelCase__							(  self     ):
				self.config_tester.run_common_tests()






			@unittest.skip(reason="DeiT does not use inputs_embeds"     )
			def 		UpperCamelCase__							(  self     ):
				pass






			def 		UpperCamelCase__							(  self     ):
				UpperCAmelCase_					,					UpperCAmelCase_     :      str						=  self.model_tester.prepare_config_and_inputs_for_common()

				for model_class in self.all_model_classes:
					UpperCAmelCase_     :      Any						=  model_class(_snake_case     )
					self.assertIsInstance(model.get_input_embeddings()			,(nn.Module)     )
					UpperCAmelCase_     :      Optional[int]						=  model.get_output_embeddings()
					self.assertTrue(x is None or isinstance(_snake_case			,nn.Linear     )     )






			def 		UpperCamelCase__							(  self     ):
				UpperCAmelCase_					,					UpperCAmelCase_     :      Tuple						=  self.model_tester.prepare_config_and_inputs_for_common()

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

					UpperCAmelCase_     :      int						=  ["pixel_values"]
					self.assertListEqual(arg_names[:1]			,_snake_case     )






			def 		UpperCamelCase__							(  self     ):
				UpperCAmelCase_     :      int						=  self.model_tester.prepare_config_and_inputs()
				self.model_tester.create_and_check_model(*_snake_case     )






			def 		UpperCamelCase__							(  self     ):
				UpperCAmelCase_     :      Dict						=  self.model_tester.prepare_config_and_inputs()
				self.model_tester.create_and_check_for_masked_image_modeling(*_snake_case     )






			def 		UpperCamelCase__							(  self     ):
				UpperCAmelCase_     :      int						=  self.model_tester.prepare_config_and_inputs()
				self.model_tester.create_and_check_for_image_classification(*_snake_case     )






			def 		UpperCamelCase__							(  self			,_snake_case			,_snake_case			,_snake_case=False     ):
				UpperCAmelCase_     :      str						=  super()._prepare_for_class(_snake_case			,_snake_case			,return_labels=_snake_case     )

				if return_labels:
					if model_class.__name__ == "DeiTForImageClassificationWithTeacher":
						del inputs_dict["labels"]

				return inputs_dict






			def 		UpperCamelCase__							(  self     ):
				if not self.model_tester.is_training:
					return

				UpperCAmelCase_					,					UpperCAmelCase_     :      Optional[Any]						=  self.model_tester.prepare_config_and_inputs_for_common()
				UpperCAmelCase_     :      int						=  True

				for model_class in self.all_model_classes:
					# DeiTForImageClassificationWithTeacher supports inference-only
					if (
					    model_class in get_values(_snake_case     )
					    or model_class.__name__ == "DeiTForImageClassificationWithTeacher"
					):
						continue
					UpperCAmelCase_     :      Dict						=  model_class(_snake_case     )
					model.to(_snake_case     )
					model.train()
					UpperCAmelCase_     :      Any						=  self._prepare_for_class(_snake_case			,_snake_case			,return_labels=_snake_case     )
					UpperCAmelCase_     :      Union[str, Any]						=  model(**_snake_case     ).loss
					loss.backward()






			def 		UpperCamelCase__							(  self     ):
				UpperCAmelCase_					,					UpperCAmelCase_     :      List[Any]						=  self.model_tester.prepare_config_and_inputs_for_common()
				if not self.model_tester.is_training:
					return

				UpperCAmelCase_     :      Union[str, Any]						=  False
				UpperCAmelCase_     :      Union[str, Any]						=  True

				for model_class in self.all_model_classes:
					if model_class in get_values(_snake_case     ) or not model_class.supports_gradient_checkpointing:
						continue
					# DeiTForImageClassificationWithTeacher supports inference-only
					if model_class.__name__ == "DeiTForImageClassificationWithTeacher":
						continue
					UpperCAmelCase_     :      Optional[Any]						=  model_class(_snake_case     )
					model.gradient_checkpointing_enable()
					model.to(_snake_case     )
					model.train()
					UpperCAmelCase_     :      Union[str, Any]						=  self._prepare_for_class(_snake_case			,_snake_case			,return_labels=_snake_case     )
					UpperCAmelCase_     :      Dict						=  model(**_snake_case     ).loss
					loss.backward()






			def 		UpperCamelCase__							(  self     ):
				UpperCAmelCase_					,					UpperCAmelCase_     :      List[str]						=  self.model_tester.prepare_config_and_inputs_for_common()

				UpperCAmelCase_     :      Any						=  [
				    {"title": "multi_label_classification", "num_labels": 2, "dtype": torch.float},
				    {"title": "single_label_classification", "num_labels": 1, "dtype": torch.long},
				    {"title": "regression", "num_labels": 1, "dtype": torch.float},
				]

				for model_class in self.all_model_classes:
					if (
					    model_class
					    not in [
					        *get_values(_snake_case     ),
					        *get_values(_snake_case     ),
					    ]
					    or model_class.__name__ == "DeiTForImageClassificationWithTeacher"
					):
						continue

					for problem_type in problem_types:
						with self.subTest(msg=f'''Testing {model_class} with {problem_type["title"]}'''     ):
							UpperCAmelCase_     :      Tuple						=  problem_type["title"]
							UpperCAmelCase_     :      Dict						=  problem_type["num_labels"]

							UpperCAmelCase_     :      int						=  model_class(_snake_case     )
							model.to(_snake_case     )
							model.train()

							UpperCAmelCase_     :      List[Any]						=  self._prepare_for_class(_snake_case			,_snake_case			,return_labels=_snake_case     )

							if problem_type["num_labels"] > 1:
								UpperCAmelCase_     :      Tuple						=  inputs["labels"].unsqueeze(1     ).repeat(1			,problem_type["num_labels"]     )

							UpperCAmelCase_     :      Optional[Any]						=  inputs["labels"].to(problem_type["dtype"]     )

							# This tests that we do not trigger the warning form PyTorch "Using a target size that is different
							# to the input size. This will likely lead to incorrect results due to broadcasting. Please ensure
							# they have the same size." which is a symptom something in wrong for the regression problem.
							# See https://github.com/huggingface/transformers/issues/11780
							with warnings.catch_warnings(record=_snake_case     ) as warning_list:
								UpperCAmelCase_     :      Dict						=  model(**_snake_case     ).loss
							for w in warning_list:
								if "Using a target size that is different to the input size" in str(w.message     ):
									raise ValueError(
									    f'''Something is going wrong in the regression problem: intercepted {w.message}'''     )

							loss.backward()






			@slow
			def 		UpperCamelCase__							(  self     ):
				for model_name in DEIT_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
					UpperCAmelCase_     :      List[str]						=  DeiTModel.from_pretrained(_snake_case     )
					self.assertIsNotNone(_snake_case     )




def  a__       (    )     ->					str:


	"""simple docstring"""





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





@require_torch
@require_vision
class 					_snake_case		(unittest.TestCase):






			@cached_property
			def 		UpperCamelCase__							(  self     ):
				return (
				    DeiTImageProcessor.from_pretrained("facebook/deit-base-distilled-patch16-224"     )
				    if is_vision_available()
				    else None
				)






			@slow
			def 		UpperCamelCase__							(  self     ):
				UpperCAmelCase_     :      Dict						=  DeiTForImageClassificationWithTeacher.from_pretrained("facebook/deit-base-distilled-patch16-224"     ).to(
				    _snake_case     )

				UpperCAmelCase_     :      Union[str, Any]						=  self.default_image_processor
				UpperCAmelCase_     :      Tuple						=  prepare_img()
				UpperCAmelCase_     :      Union[str, Any]						=  image_processor(images=_snake_case			,return_tensors="pt"     ).to(_snake_case     )

				# forward pass
				with torch.no_grad():
					UpperCAmelCase_     :      Any						=  model(**_snake_case     )

				# verify the logits
				UpperCAmelCase_     :      Optional[int]						=  torch.Size((1, 10_00)     )
				self.assertEqual(outputs.logits.shape			,_snake_case     )

				UpperCAmelCase_     :      Tuple						=  torch.tensor([-1.0266, 0.1912, -1.2861]     ).to(_snake_case     )

				self.assertTrue(torch.allclose(outputs.logits[0, :3]			,_snake_case			,atol=1E-4     )     )






			@slow
			@require_accelerate
			@require_torch_gpu
			def 		UpperCamelCase__							(  self     ):
				UpperCAmelCase_     :      int						=  DeiTModel.from_pretrained(
				    "facebook/deit-base-distilled-patch16-224"			,torch_dtype=torch.floataa			,device_map="auto"     )
				UpperCAmelCase_     :      Optional[Any]						=  self.default_image_processor

				UpperCAmelCase_     :      List[str]						=  prepare_img()
				UpperCAmelCase_     :      List[str]						=  image_processor(images=_snake_case			,return_tensors="pt"     )
				UpperCAmelCase_     :      Union[str, Any]						=  inputs.pixel_values.to(_snake_case     )

				# forward pass to make sure inference works in fp16
				with torch.no_grad():
					UpperCAmelCase_     :      Optional[int]						=  model(_snake_case     )





'''simple docstring'''




import doctest
import glob
import importlib
import inspect
import os
import re
from contextlib import contextmanager
from functools import wraps
from unittest.mock import patch

import numpy as np
import pytest
from absl.testing import parameterized

import datasets
from datasets import load_metric

from .utils import for_all_test_methods, local, slow


# mark all tests as integration
__UpperCAmelCase					=pytest.mark.integration


__UpperCAmelCase					={"comet"}
__UpperCAmelCase					=importlib.util.find_spec("fairseq") is not None

__UpperCAmelCase					={"code_eval"}
__UpperCAmelCase					=os.name == "nt"

__UpperCAmelCase					={"bertscore", "frugalscore", "perplexity"}
__UpperCAmelCase					=importlib.util.find_spec("transformers") is not None






def __lowerCAmelCase					(				UpperCamelCase__							)      ->       Any:
    @wraps(UpperCamelCase__							)
    def wrapper(self							,    UpperCamelCase__							):
        if not _has_fairseq and metric_name in REQUIRE_FAIRSEQ:
            self.skipTest('''"test requires Fairseq"'''							)
        else:
            test_case(self							,    UpperCamelCase__							)

    return wrapper






def __lowerCAmelCase					(				UpperCamelCase__							)      ->       Any:
    @wraps(UpperCamelCase__							)
    def wrapper(self							,    UpperCamelCase__							):
        if not _has_transformers and metric_name in REQUIRE_TRANSFORMERS:
            self.skipTest('''"test requires transformers"'''							)
        else:
            test_case(self							,    UpperCamelCase__							)

    return wrapper






def __lowerCAmelCase					(				UpperCamelCase__							)      ->       List[Any]:
    @wraps(UpperCamelCase__							)
    def wrapper(self							,    UpperCamelCase__							):
        if _on_windows and metric_name in UNSUPPORTED_ON_WINDOWS:
            self.skipTest('''"test not supported on Windows"'''							)
        else:
            test_case(self							,    UpperCamelCase__							)

    return wrapper






def __lowerCAmelCase					(				)      ->       Any:
    __lowerCamelCase            =    [metric_dir.split(os.sep							)[-2] for metric_dir in glob.glob('''./metrics/*/'''							)]
    return [{"testcase_name": x, "metric_name": x} for x in metrics if x != "gleu"]  # gleu is unfinished




@parameterized.named_parameters(get_local_metric_names()					)
@for_all_test_methods(
    UpperCAmelCase__				,  UpperCAmelCase__				,  UpperCAmelCase__					)
@local
class        a__ (  parameterized.TestCase					):
     lowerCamelCase    :	str				={}
     lowerCamelCase    :	Union[str, Any]				=None






     @pytest.mark.filterwarnings('''ignore:metric_module_factory is deprecated:FutureWarning'''       )
     @pytest.mark.filterwarnings('''ignore:load_metric is deprecated:FutureWarning'''       )
     def   SCREAMING_SNAKE_CASE__  (					self						:						Tuple    ,							a						:						List[Any]       ):





         """simple docstring"""



         __lowerCamelCase            =    '''[...]'''
         __lowerCamelCase            =    importlib.import_module(
             datasets.load.metric_module_factory(os.path.join('''metrics'''    ,							a       )       ).module_path       )
         __lowerCamelCase            =    datasets.load.import_main_class(metric_module.__name__    ,							dataset=a       )
         # check parameters
         __lowerCamelCase            =    inspect.signature(metric._compute       ).parameters
         self.assertTrue(all(p.kind != p.VAR_KEYWORD for p in parameters.values()       )       )  # no **kwargs
         # run doctest
         with self.patch_intensive_calls(a    ,							metric_module.__name__       ):
             with self.use_local_metrics():
                 try:
                     __lowerCamelCase            =    doctest.testmod(a    ,							verbose=a    ,							raise_on_error=a       )
                 except doctest.UnexpectedException as e:
                     raise e.exc_info[1]  # raise the exception that doctest caught
         self.assertEqual(results.failed    ,							0       )
         self.assertGreater(results.attempted    ,							1       )






     @slow
     def   SCREAMING_SNAKE_CASE__  (					self						:						Optional[Any]    ,							a						:						Optional[int]       ):





         """simple docstring"""



         __lowerCamelCase            =    '''[...]'''
         __lowerCamelCase            =    importlib.import_module(
             datasets.load.metric_module_factory(os.path.join('''metrics'''    ,							a       )       ).module_path       )
         # run doctest
         with self.use_local_metrics():
             __lowerCamelCase            =    doctest.testmod(a    ,							verbose=a    ,							raise_on_error=a       )
         self.assertEqual(results.failed    ,							0       )
         self.assertGreater(results.attempted    ,							1       )






     @contextmanager
     def   SCREAMING_SNAKE_CASE__  (					self						:						Any    ,							a						:						Optional[Any]    ,							a						:						Any       ):





         """simple docstring"""



         if metric_name in self.INTENSIVE_CALLS_PATCHER:
             with self.INTENSIVE_CALLS_PATCHER[metric_name](a       ):
                 yield
         else:
             yield






     @contextmanager
     def   SCREAMING_SNAKE_CASE__  (					self						:						Dict       ):





         """simple docstring"""



         def load_local_metric(a						:						List[str]    ,							*a						:						Optional[int]    ,							**a						:						Tuple       ):
             return load_metric(os.path.join('''metrics'''    ,							a       )    ,							*a    ,							**a       )

         with patch('''datasets.load_metric'''       ) as mock_load_metric:
             __lowerCamelCase            =    load_local_metric
             yield






     @classmethod
     def   SCREAMING_SNAKE_CASE__  (					cls						:						List[str]    ,							a						:						Tuple       ):





         """simple docstring"""



         def wrapper(a						:						List[Any]       ):
             __lowerCamelCase            =    contextmanager(a       )
             __lowerCamelCase            =    patcher
             return patcher

         return wrapper






@LocalMetricTest.register_intensive_calls_patcher('''bleurt'''							)
def __lowerCAmelCase					(				UpperCamelCase__							)      ->       Union[str, Any]:
    import tensorflow.compat.va as tf
    from bleurt.score import Predictor

    tf.flags.DEFINE_string('''sv'''							,    ''''''							,    ''''''							)  # handle pytest cli flags




    class        a__ (  UpperCAmelCase__					):






         def   SCREAMING_SNAKE_CASE__  (					self						:						Tuple    ,							a						:						Dict       ):





             """simple docstring"""



             assert len(input_dict['''input_ids''']       ) == 2
             return np.array([1.03, 1.04]       )

    # mock predict_fn which is supposed to do a forward pass with a bleurt model
    with patch('''bleurt.score._create_predictor'''							) as mock_create_predictor:
        __lowerCamelCase            =    MockedPredictor()
        yield






@LocalMetricTest.register_intensive_calls_patcher('''bertscore'''							)
def __lowerCAmelCase					(				UpperCamelCase__							)      ->       Tuple:
    import torch

    def bert_cos_score_idf(UpperCamelCase__							,    UpperCamelCase__							,    *UpperCamelCase__							,    **UpperCamelCase__							):
        return torch.tensor([[1.0, 1.0, 1.0]] * len(UpperCamelCase__							)							)

    # mock get_model which is supposed to do download a bert model
    # mock bert_cos_score_idf which is supposed to do a forward pass with a bert model
    with patch('''bert_score.scorer.get_model'''							), patch(
        '''bert_score.scorer.bert_cos_score_idf'''							) as mock_bert_cos_score_idf:
        __lowerCamelCase            =    bert_cos_score_idf
        yield






@LocalMetricTest.register_intensive_calls_patcher('''comet'''							)
def __lowerCAmelCase					(				UpperCamelCase__							)      ->       List[str]:
    def load_from_checkpoint(UpperCamelCase__							):




        class        a__ :






             def   SCREAMING_SNAKE_CASE__  (					self						:						Optional[int]    ,							a						:						str    ,							*a						:						int    ,							**a						:						Tuple       ):





                 """simple docstring"""



                 assert len(a       ) == 2
                 __lowerCamelCase            =    [0.19, 0.92]
                 return scores, sum(a       ) / len(a       )
        return Model()

    # mock load_from_checkpoint which is supposed to do download a bert model
    # mock load_from_checkpoint which is supposed to do download a bert model
    with patch('''comet.download_model'''							) as mock_download_model:
        __lowerCamelCase            =    None
        with patch('''comet.load_from_checkpoint'''							) as mock_load_from_checkpoint:
            __lowerCamelCase            =    load_from_checkpoint
            yield






def __lowerCAmelCase					(				)      ->       List[Any]:
    __lowerCamelCase            =    load_metric(os.path.join('''metrics'''							,    '''seqeval'''							)							)
    __lowerCamelCase            =    '''ERROR'''
    __lowerCamelCase            =    f"""Scheme should be one of [IOB1, IOB2, IOE1, IOE2, IOBES, BILOU], got {wrong_scheme}"""
    with pytest.raises(UpperCamelCase__							,    match=re.escape(UpperCamelCase__							)							):
        metric.compute(predictions=[]							,    references=[]							,    scheme=UpperCamelCase__							)
