



import os
import tempfile
import unittest

from transformers import FlaubertConfig, 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 (
        FlaubertForMultipleChoice,
        FlaubertForQuestionAnswering,
        FlaubertForQuestionAnsweringSimple,
        FlaubertForSequenceClassification,
        FlaubertForTokenClassification,
        FlaubertModel,
        FlaubertWithLMHeadModel,
    )
    from transformers.models.flaubert.modeling_flaubert import FLAUBERT_PRETRAINED_MODEL_ARCHIVE_LIST



class 				lowerCAmelCase_		(  a__							):
       def __init__(			self,			SCREAMING_SNAKE_CASE_,			SCREAMING_SNAKE_CASE_=13,			SCREAMING_SNAKE_CASE_=7,			SCREAMING_SNAKE_CASE_=True,			SCREAMING_SNAKE_CASE_=True,			SCREAMING_SNAKE_CASE_=True,			SCREAMING_SNAKE_CASE_=True,			SCREAMING_SNAKE_CASE_=True,			SCREAMING_SNAKE_CASE_=False,			SCREAMING_SNAKE_CASE_=False,			SCREAMING_SNAKE_CASE_=False,			SCREAMING_SNAKE_CASE_=2,			SCREAMING_SNAKE_CASE_=99,			SCREAMING_SNAKE_CASE_=0,			SCREAMING_SNAKE_CASE_=32,			SCREAMING_SNAKE_CASE_=5,			SCREAMING_SNAKE_CASE_=4,			SCREAMING_SNAKE_CASE_=0.1,			SCREAMING_SNAKE_CASE_=0.1,			SCREAMING_SNAKE_CASE_=512,			SCREAMING_SNAKE_CASE_=12,			SCREAMING_SNAKE_CASE_=2,			SCREAMING_SNAKE_CASE_=0.02,			SCREAMING_SNAKE_CASE_=3,			SCREAMING_SNAKE_CASE_=4,			SCREAMING_SNAKE_CASE_="last",			SCREAMING_SNAKE_CASE_=None,			SCREAMING_SNAKE_CASE_=None,			)     ->		int:
          UpperCamelCase    :  List[str]							=	parent
          UpperCamelCase    :  List[Any]							=	batch_size
          UpperCamelCase    :  Dict							=	seq_length
          UpperCamelCase    :  Optional[Any]							=	is_training
          UpperCamelCase    :  List[str]							=	use_input_lengths
          UpperCamelCase    :  Tuple							=	use_token_type_ids
          UpperCamelCase    :  Dict							=	use_labels
          UpperCamelCase    :  List[Any]							=	gelu_activation
          UpperCamelCase    :  List[Any]							=	sinusoidal_embeddings
          UpperCamelCase    :  Any							=	causal
          UpperCamelCase    :  Optional[Any]							=	asm
          UpperCamelCase    :  Optional[Any]							=	n_langs
          UpperCamelCase    :  Dict							=	vocab_size
          UpperCamelCase    :  Optional[int]							=	n_special
          UpperCamelCase    :  Union[str, Any]							=	hidden_size
          UpperCamelCase    :  Optional[Any]							=	num_hidden_layers
          UpperCamelCase    :  Dict							=	num_attention_heads
          UpperCamelCase    :  List[Any]							=	hidden_dropout_prob
          UpperCamelCase    :  Union[str, Any]							=	attention_probs_dropout_prob
          UpperCamelCase    :  Dict							=	max_position_embeddings
          UpperCamelCase    :  List[str]							=	type_vocab_size
          UpperCamelCase    :  str							=	type_sequence_label_size
          UpperCamelCase    :  int							=	initializer_range
          UpperCamelCase    :  Union[str, Any]							=	num_labels
          UpperCamelCase    :  List[Any]							=	num_choices
          UpperCamelCase    :  str							=	summary_type
          UpperCamelCase    :  Tuple							=	use_proj
          UpperCamelCase    :  int							=	scope
       def 					snake_case_       (			self       )     ->		int:
          UpperCamelCase    :  List[str]							=	ids_tensor([self.batch_size, self.seq_length],			self.vocab_size       )
          UpperCamelCase    :  Union[str, Any]							=	random_attention_mask([self.batch_size, self.seq_length]       )

          UpperCamelCase    :  Any							=	None
          if self.use_input_lengths:
             UpperCamelCase    :  int							=	(
                 ids_tensor([self.batch_size],			vocab_size=2       ) + self.seq_length - 2
             )  # small variation of seq_length

          UpperCamelCase    :  List[Any]							=	None
          if self.use_token_type_ids:
             UpperCamelCase    :  Tuple							=	ids_tensor([self.batch_size, self.seq_length],			self.n_langs       )

          UpperCamelCase    :  List[str]							=	None
          UpperCamelCase    :  Optional[int]							=	None
          UpperCamelCase    :  Dict							=	None
          if self.use_labels:
             UpperCamelCase    :  List[Any]							=	ids_tensor([self.batch_size],			self.type_sequence_label_size       )
             UpperCamelCase    :  List[Any]							=	ids_tensor([self.batch_size, self.seq_length],			self.num_labels       )
             UpperCamelCase    :  List[str]							=	ids_tensor([self.batch_size],			2       ).float()
             UpperCamelCase    :  Union[str, Any]							=	ids_tensor([self.batch_size],			self.num_choices       )

          UpperCamelCase    :  int							=	self.get_config()

          return (
              config,
              input_ids,
              token_type_ids,
              input_lengths,
              sequence_labels,
              token_labels,
              is_impossible_labels,
              choice_labels,
              input_mask,
          )
       def 					snake_case_       (			self       )     ->		str:
          return FlaubertConfig(
              vocab_size=self.vocab_size,			n_special=self.n_special,			emb_dim=self.hidden_size,			n_layers=self.num_hidden_layers,			n_heads=self.num_attention_heads,			dropout=self.hidden_dropout_prob,			attention_dropout=self.attention_probs_dropout_prob,			gelu_activation=self.gelu_activation,			sinusoidal_embeddings=self.sinusoidal_embeddings,			asm=self.asm,			causal=self.causal,			n_langs=self.n_langs,			max_position_embeddings=self.max_position_embeddings,			initializer_range=self.initializer_range,			summary_type=self.summary_type,			use_proj=self.use_proj,			)
       def 					snake_case_       (			self,			SCREAMING_SNAKE_CASE_,			SCREAMING_SNAKE_CASE_,			SCREAMING_SNAKE_CASE_,			SCREAMING_SNAKE_CASE_,			SCREAMING_SNAKE_CASE_,			SCREAMING_SNAKE_CASE_,			SCREAMING_SNAKE_CASE_,			SCREAMING_SNAKE_CASE_,			SCREAMING_SNAKE_CASE_,			)     ->		List[str]:
          UpperCamelCase    :  Any							=	FlaubertModel(config=SCREAMING_SNAKE_CASE_       )
          model.to(SCREAMING_SNAKE_CASE_       )
          model.eval()
          UpperCamelCase    :  Optional[Any]							=	model(SCREAMING_SNAKE_CASE_,			lengths=SCREAMING_SNAKE_CASE_,			langs=SCREAMING_SNAKE_CASE_       )
          UpperCamelCase    :  List[str]							=	model(SCREAMING_SNAKE_CASE_,			langs=SCREAMING_SNAKE_CASE_       )
          UpperCamelCase    :  Union[str, Any]							=	model(SCREAMING_SNAKE_CASE_       )
          self.parent.assertEqual(result.last_hidden_state.shape,			(self.batch_size, self.seq_length, self.hidden_size)       )
       def 					snake_case_       (			self,			SCREAMING_SNAKE_CASE_,			SCREAMING_SNAKE_CASE_,			SCREAMING_SNAKE_CASE_,			SCREAMING_SNAKE_CASE_,			SCREAMING_SNAKE_CASE_,			SCREAMING_SNAKE_CASE_,			SCREAMING_SNAKE_CASE_,			SCREAMING_SNAKE_CASE_,			SCREAMING_SNAKE_CASE_,			)     ->		Union[str, Any]:
          UpperCamelCase    :  Any							=	FlaubertWithLMHeadModel(SCREAMING_SNAKE_CASE_       )
          model.to(SCREAMING_SNAKE_CASE_       )
          model.eval()

          UpperCamelCase    :  int							=	model(SCREAMING_SNAKE_CASE_,			token_type_ids=SCREAMING_SNAKE_CASE_,			labels=SCREAMING_SNAKE_CASE_       )
          self.parent.assertEqual(result.loss.shape,			()       )
          self.parent.assertEqual(result.logits.shape,			(self.batch_size, self.seq_length, self.vocab_size)       )
       def 					snake_case_       (			self,			SCREAMING_SNAKE_CASE_,			SCREAMING_SNAKE_CASE_,			SCREAMING_SNAKE_CASE_,			SCREAMING_SNAKE_CASE_,			SCREAMING_SNAKE_CASE_,			SCREAMING_SNAKE_CASE_,			SCREAMING_SNAKE_CASE_,			SCREAMING_SNAKE_CASE_,			SCREAMING_SNAKE_CASE_,			)     ->		int:
          UpperCamelCase    :  Dict							=	FlaubertForQuestionAnsweringSimple(SCREAMING_SNAKE_CASE_       )
          model.to(SCREAMING_SNAKE_CASE_       )
          model.eval()

          UpperCamelCase    :  str							=	model(SCREAMING_SNAKE_CASE_       )

          UpperCamelCase    :  List[str]							=	model(SCREAMING_SNAKE_CASE_,			start_positions=SCREAMING_SNAKE_CASE_,			end_positions=SCREAMING_SNAKE_CASE_       )
          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 					snake_case_       (			self,			SCREAMING_SNAKE_CASE_,			SCREAMING_SNAKE_CASE_,			SCREAMING_SNAKE_CASE_,			SCREAMING_SNAKE_CASE_,			SCREAMING_SNAKE_CASE_,			SCREAMING_SNAKE_CASE_,			SCREAMING_SNAKE_CASE_,			SCREAMING_SNAKE_CASE_,			SCREAMING_SNAKE_CASE_,			)     ->		Optional[int]:
          UpperCamelCase    :  Dict							=	FlaubertForQuestionAnswering(SCREAMING_SNAKE_CASE_       )
          model.to(SCREAMING_SNAKE_CASE_       )
          model.eval()

          UpperCamelCase    :  Tuple							=	model(SCREAMING_SNAKE_CASE_       )

          UpperCamelCase    :  Any							=	model(
              SCREAMING_SNAKE_CASE_,			start_positions=SCREAMING_SNAKE_CASE_,			end_positions=SCREAMING_SNAKE_CASE_,			cls_index=SCREAMING_SNAKE_CASE_,			is_impossible=SCREAMING_SNAKE_CASE_,			p_mask=SCREAMING_SNAKE_CASE_,			)

          UpperCamelCase    :  int							=	model(
              SCREAMING_SNAKE_CASE_,			start_positions=SCREAMING_SNAKE_CASE_,			end_positions=SCREAMING_SNAKE_CASE_,			cls_index=SCREAMING_SNAKE_CASE_,			is_impossible=SCREAMING_SNAKE_CASE_,			)

          ((UpperCamelCase)	,     )    :  Optional[Any]							=	result_with_labels.to_tuple()

          UpperCamelCase    :  List[Any]							=	model(SCREAMING_SNAKE_CASE_,			start_positions=SCREAMING_SNAKE_CASE_,			end_positions=SCREAMING_SNAKE_CASE_       )

          ((UpperCamelCase)	,     )    :  str							=	result_with_labels.to_tuple()

          self.parent.assertEqual(result_with_labels.loss.shape,			()       )
          self.parent.assertEqual(result.start_top_log_probs.shape,			(self.batch_size, model.config.start_n_top)       )
          self.parent.assertEqual(result.start_top_index.shape,			(self.batch_size, model.config.start_n_top)       )
          self.parent.assertEqual(
              result.end_top_log_probs.shape,			(self.batch_size, model.config.start_n_top * model.config.end_n_top)       )
          self.parent.assertEqual(
              result.end_top_index.shape,			(self.batch_size, model.config.start_n_top * model.config.end_n_top)       )
          self.parent.assertEqual(result.cls_logits.shape,			(self.batch_size,)       )
       def 					snake_case_       (			self,			SCREAMING_SNAKE_CASE_,			SCREAMING_SNAKE_CASE_,			SCREAMING_SNAKE_CASE_,			SCREAMING_SNAKE_CASE_,			SCREAMING_SNAKE_CASE_,			SCREAMING_SNAKE_CASE_,			SCREAMING_SNAKE_CASE_,			SCREAMING_SNAKE_CASE_,			SCREAMING_SNAKE_CASE_,			)     ->		Tuple:
          UpperCamelCase    :  Optional[int]							=	FlaubertForSequenceClassification(SCREAMING_SNAKE_CASE_       )
          model.to(SCREAMING_SNAKE_CASE_       )
          model.eval()

          UpperCamelCase    :  Dict							=	model(SCREAMING_SNAKE_CASE_       )
          UpperCamelCase    :  List[str]							=	model(SCREAMING_SNAKE_CASE_,			labels=SCREAMING_SNAKE_CASE_       )

          self.parent.assertEqual(result.loss.shape,			()       )
          self.parent.assertEqual(result.logits.shape,			(self.batch_size, self.type_sequence_label_size)       )
       def 					snake_case_       (			self,			SCREAMING_SNAKE_CASE_,			SCREAMING_SNAKE_CASE_,			SCREAMING_SNAKE_CASE_,			SCREAMING_SNAKE_CASE_,			SCREAMING_SNAKE_CASE_,			SCREAMING_SNAKE_CASE_,			SCREAMING_SNAKE_CASE_,			SCREAMING_SNAKE_CASE_,			SCREAMING_SNAKE_CASE_,			)     ->		Optional[Any]:
          UpperCamelCase    :  Any							=	self.num_labels
          UpperCamelCase    :  List[str]							=	FlaubertForTokenClassification(SCREAMING_SNAKE_CASE_       )
          model.to(SCREAMING_SNAKE_CASE_       )
          model.eval()

          UpperCamelCase    :  List[str]							=	model(SCREAMING_SNAKE_CASE_,			attention_mask=SCREAMING_SNAKE_CASE_,			labels=SCREAMING_SNAKE_CASE_       )
          self.parent.assertEqual(result.logits.shape,			(self.batch_size, self.seq_length, self.num_labels)       )
       def 					snake_case_       (			self,			SCREAMING_SNAKE_CASE_,			SCREAMING_SNAKE_CASE_,			SCREAMING_SNAKE_CASE_,			SCREAMING_SNAKE_CASE_,			SCREAMING_SNAKE_CASE_,			SCREAMING_SNAKE_CASE_,			SCREAMING_SNAKE_CASE_,			SCREAMING_SNAKE_CASE_,			SCREAMING_SNAKE_CASE_,			)     ->		Tuple:
          UpperCamelCase    :  Any							=	self.num_choices
          UpperCamelCase    :  Union[str, Any]							=	FlaubertForMultipleChoice(config=SCREAMING_SNAKE_CASE_       )
          model.to(SCREAMING_SNAKE_CASE_       )
          model.eval()
          UpperCamelCase    :  str							=	input_ids.unsqueeze(1       ).expand(-1,			self.num_choices,			-1       ).contiguous()
          UpperCamelCase    :  Optional[int]							=	token_type_ids.unsqueeze(1       ).expand(-1,			self.num_choices,			-1       ).contiguous()
          UpperCamelCase    :  str							=	input_mask.unsqueeze(1       ).expand(-1,			self.num_choices,			-1       ).contiguous()
          UpperCamelCase    :  List[Any]							=	model(
              SCREAMING_SNAKE_CASE_,			attention_mask=SCREAMING_SNAKE_CASE_,			token_type_ids=SCREAMING_SNAKE_CASE_,			labels=SCREAMING_SNAKE_CASE_,			)
          self.parent.assertEqual(result.logits.shape,			(self.batch_size, self.num_choices)       )






       def 					snake_case_       (			self       )     ->		Tuple:
          UpperCamelCase    :  Dict							=	self.prepare_config_and_inputs()
          (
              (
              UpperCamelCase
          )	,     (
              UpperCamelCase
          )	,     (
              UpperCamelCase
          )	,     (
              UpperCamelCase
          )	,     (
              UpperCamelCase
          )	,     (
              UpperCamelCase
          )	,     (
              UpperCamelCase
          )	,     (
              UpperCamelCase
          )	,     (
              UpperCamelCase
          )	,     
          )    :  Optional[Any]							=	config_and_inputs
          UpperCamelCase    :  Tuple							=	{
              'input_ids': input_ids,
              'token_type_ids': token_type_ids,
              'lengths': input_lengths,
              'attention_mask': input_mask,
          }
          return config, inputs_dict






@require_torch
class 				lowerCAmelCase_		(  a__       ,    a__       ,    unittest.TestCase							):
       UpperCAmelCase__				:					Dict        =  (
           (
               FlaubertModel,
               FlaubertWithLMHeadModel,
               FlaubertForQuestionAnswering,
               FlaubertForQuestionAnsweringSimple,
               FlaubertForSequenceClassification,
               FlaubertForTokenClassification,
               FlaubertForMultipleChoice,
           )
           if is_torch_available()
           else ()
       )
       UpperCAmelCase__				:					Dict        =  (
           {
               "feature-extraction": FlaubertModel,
               "fill-mask": FlaubertWithLMHeadModel,
               "question-answering": FlaubertForQuestionAnsweringSimple,
               "text-classification": FlaubertForSequenceClassification,
               "token-classification": FlaubertForTokenClassification,
               "zero-shot": FlaubertForSequenceClassification,
           }
           if is_torch_available()
           else {}
       )
       def 					snake_case_       (			self,			SCREAMING_SNAKE_CASE_,			SCREAMING_SNAKE_CASE_,			SCREAMING_SNAKE_CASE_,			SCREAMING_SNAKE_CASE_,			SCREAMING_SNAKE_CASE_       )     ->		List[Any]:
          if (
              pipeline_test_casse_name == "QAPipelineTests"
              and tokenizer_name is not None
              and not tokenizer_name.endswith('Fast'       )
          ):
             # `QAPipelineTests` fails for a few models when the slower tokenizer are used.
             # (The slower tokenizers were never used for pipeline tests before the pipeline testing rework)
             # TODO: check (and possibly fix) the `QAPipelineTests` with slower tokenizer
             return True

          return False
       def 					snake_case_       (			self,			SCREAMING_SNAKE_CASE_,			SCREAMING_SNAKE_CASE_,			SCREAMING_SNAKE_CASE_=False       )     ->		int:
          UpperCamelCase    :  List[Any]							=	super()._prepare_for_class(SCREAMING_SNAKE_CASE_,			SCREAMING_SNAKE_CASE_,			return_labels=SCREAMING_SNAKE_CASE_       )

          if return_labels:
             if model_class.__name__ == "FlaubertForQuestionAnswering":
                UpperCamelCase    :  Optional[Any]							=	torch.zeros(
                    self.model_tester.batch_size,			dtype=torch.long,			device=SCREAMING_SNAKE_CASE_       )
                UpperCamelCase    :  Dict							=	torch.zeros(
                    self.model_tester.batch_size,			dtype=torch.long,			device=SCREAMING_SNAKE_CASE_       )

          return inputs_dict
       def 					snake_case_       (			self       )     ->		Tuple:
          UpperCamelCase    :  Tuple							=	FlaubertModelTester(self       )
          UpperCamelCase    :  Tuple							=	ConfigTester(self,			config_class=SCREAMING_SNAKE_CASE_,			emb_dim=37       )
       def 					snake_case_       (			self       )     ->		Any:
          self.config_tester.run_common_tests()
       def 					snake_case_       (			self       )     ->		int:
          UpperCamelCase    :  Optional[int]							=	self.model_tester.prepare_config_and_inputs()
          self.model_tester.create_and_check_flaubert_model(*SCREAMING_SNAKE_CASE_       )
       def 					snake_case_       (			self       )     ->		int:
          UpperCamelCase    :  str							=	self.model_tester.prepare_config_and_inputs()
          self.model_tester.create_and_check_flaubert_lm_head(*SCREAMING_SNAKE_CASE_       )
       def 					snake_case_       (			self       )     ->		int:
          UpperCamelCase    :  Optional[Any]							=	self.model_tester.prepare_config_and_inputs()
          self.model_tester.create_and_check_flaubert_simple_qa(*SCREAMING_SNAKE_CASE_       )
       def 					snake_case_       (			self       )     ->		Optional[int]:
          UpperCamelCase    :  Union[str, Any]							=	self.model_tester.prepare_config_and_inputs()
          self.model_tester.create_and_check_flaubert_qa(*SCREAMING_SNAKE_CASE_       )
       def 					snake_case_       (			self       )     ->		List[Any]:
          UpperCamelCase    :  List[str]							=	self.model_tester.prepare_config_and_inputs()
          self.model_tester.create_and_check_flaubert_sequence_classif(*SCREAMING_SNAKE_CASE_       )
       def 					snake_case_       (			self       )     ->		Dict:
          UpperCamelCase    :  List[str]							=	self.model_tester.prepare_config_and_inputs()
          self.model_tester.create_and_check_flaubert_token_classif(*SCREAMING_SNAKE_CASE_       )
       def 					snake_case_       (			self       )     ->		str:
          UpperCamelCase    :  Tuple							=	self.model_tester.prepare_config_and_inputs()
          self.model_tester.create_and_check_flaubert_multiple_choice(*SCREAMING_SNAKE_CASE_       )
       @slow
       def 					snake_case_       (			self       )     ->		List[str]:
          for model_name in FLAUBERT_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
             UpperCamelCase    :  Dict							=	FlaubertModel.from_pretrained(SCREAMING_SNAKE_CASE_       )
             self.assertIsNotNone(SCREAMING_SNAKE_CASE_       )






       @slow
       @require_torch_gpu
       def 					snake_case_       (			self       )     ->		str:
          UpperCamelCase	,     UpperCamelCase    :  Union[str, Any]							=	self.model_tester.prepare_config_and_inputs_for_common()
          for model_class in self.all_model_classes:
             # FlauBertForMultipleChoice behaves incorrectly in JIT environments.
             if model_class == FlaubertForMultipleChoice:
                return

             UpperCamelCase    :  Optional[int]							=	True
             UpperCamelCase    :  Any							=	model_class(config=SCREAMING_SNAKE_CASE_       )

             UpperCamelCase    :  Union[str, Any]							=	self._prepare_for_class(SCREAMING_SNAKE_CASE_,			SCREAMING_SNAKE_CASE_       )
             UpperCamelCase    :  Optional[int]							=	torch.jit.trace(
                 SCREAMING_SNAKE_CASE_,			(inputs_dict['input_ids'].to('cpu'       ), inputs_dict['attention_mask'].to('cpu'       ))       )

             with tempfile.TemporaryDirectory() as tmp:
                torch.jit.save(SCREAMING_SNAKE_CASE_,			os.path.join(SCREAMING_SNAKE_CASE_,			'traced_model.pt'       )       )
                UpperCamelCase    :  Dict							=	torch.jit.load(os.path.join(SCREAMING_SNAKE_CASE_,			'traced_model.pt'       ),			map_location=SCREAMING_SNAKE_CASE_       )
                loaded(inputs_dict['input_ids'].to(SCREAMING_SNAKE_CASE_       ),			inputs_dict['attention_mask'].to(SCREAMING_SNAKE_CASE_       )       )






@require_torch
class 				lowerCAmelCase_		(  unittest.TestCase							):
       @slow
       def 					snake_case_       (			self       )     ->		Dict:
          UpperCamelCase    :  List[str]							=	FlaubertModel.from_pretrained('flaubert/flaubert_base_cased'       )
          UpperCamelCase    :  str							=	torch.tensor([[0, 345, 232, 328, 740, 140, 1695, 69, 6078, 1588, 2]]       )
          with torch.no_grad():
             UpperCamelCase    :  Optional[Any]							=	model(SCREAMING_SNAKE_CASE_       )[0]
          UpperCamelCase    :  Optional[Any]							=	torch.Size((1, 11, 768)       )
          self.assertEqual(output.shape,			SCREAMING_SNAKE_CASE_       )
          UpperCamelCase    :  List[str]							=	torch.tensor(
              [[[-2.62_51, -1.42_98, -0.02_27], [-2.85_10, -1.63_87, 0.22_58], [-2.81_14, -1.18_32, -0.30_66]]]       )

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








import pytest

from datasets import inspect_metric, list_metrics, load_metric
@pytest.fixture
def 		UpperCamelCase	(   snake_case__       :    str	)	->     Optional[int]:
   monkeypatch.setattr('datasets.utils.deprecation_utils._emitted_deprecation_warnings'       ,     set()	)
@pytest.fixture
def 		UpperCamelCase	(   snake_case__       :    str	)	->     Any:



   class 				lowerCAmelCase_		:
          def __init__(			self,			SCREAMING_SNAKE_CASE_       )     ->		Optional[int]:
             UpperCamelCase    :  Tuple							=	metric_id






   class 				lowerCAmelCase_		:
          UpperCAmelCase__				:					Optional[int]        =  [MetricMock(a__							) for metric_id in ["accuracy", "mse", "precision", "codeparrot/apps_metric"]]
          def 					snake_case_       (			self       )     ->		str:
             return self._metrics






   monkeypatch.setattr('datasets.inspect.huggingface_hub'       ,     HfhMock()	)


@pytest.mark.parametrize(
    'func, args'       ,     [(load_metric, ('metrics/mse',)), (list_metrics, ()), (inspect_metric, ('metrics/mse', 'tmp_path'))]	)
def 		UpperCamelCase	(   snake_case__       :    str       ,     snake_case__       :    Any       ,     snake_case__       :    List[str]       ,     snake_case__       :    Optional[int]       ,     snake_case__       :    Union[str, Any]	)	->     int:
   if "tmp_path" in args:
      UpperCamelCase    :  Dict							=	tuple(arg if arg != 'tmp_path' else tmp_path for arg in args	)
   with pytest.warns(snake_case__       ,     match='https://huggingface.co/docs/evaluate'	):
      func(*snake_case__	)



