






import unittest

from parameterized import parameterized

from transformers import LlamaConfig, is_torch_available, set_seed
from transformers.testing_utils import require_torch, slow, torch_device

from ...generation.test_utils import GenerationTesterMixin
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 LlamaForCausalLM, LlamaForSequenceClassification, LlamaModel, LlamaTokenizer



class  A__       :





      def __init__(			self	,							A_	,							A_=13	,							A_=7	,							A_=True	,							A_=True	,							A_=False	,							A_=True	,							A_=99	,							A_=32	,							A_=5	,							A_=4	,							A_=37	,							A_="gelu"	,							A_=0.1	,							A_=0.1	,							A_=512	,							A_=16	,							A_=2	,							A_=0.02	,							A_=3	,							A_=4	,							A_=None	,							):
       '''simple docstring'''




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





      def 	__UpperCamelCase(			self       ):
       '''simple docstring'''




       UpperCamelCase     : Union[str, Any]	     =       ids_tensor([self.batch_size, self.seq_length]	,							self.vocab_size       )

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

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

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

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

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





      def 	__UpperCamelCase(			self       ):
       '''simple docstring'''




       return LlamaConfig(
           vocab_size=self.vocab_size	,							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	,							max_position_embeddings=self.max_position_embeddings	,							type_vocab_size=self.type_vocab_size	,							is_decoder=A_	,							initializer_range=self.initializer_range	,							)





      def 	__UpperCamelCase(			self	,							A_	,							A_	,							A_	,							A_	,							A_	,							A_	,							A_       ):
       '''simple docstring'''




       UpperCamelCase     : List[str]	     =       LlamaModel(config=A_       )
       model.to(A_       )
       model.eval()
       UpperCamelCase     : Tuple	     =       model(A_	,							attention_mask=A_       )
       UpperCamelCase     : List[str]	     =       model(A_       )
       self.parent.assertEqual(result.last_hidden_state.shape	,							(self.batch_size, self.seq_length, self.hidden_size)       )





      def 	__UpperCamelCase(			self	,							A_	,							A_	,							A_	,							A_	,							A_	,							A_	,							A_	,							A_	,							A_	,							):
       '''simple docstring'''




       UpperCamelCase     : Optional[Any]	     =       True
       UpperCamelCase     : Any	     =       LlamaModel(A_       )
       model.to(A_       )
       model.eval()
       UpperCamelCase     : Tuple	     =       model(
           A_	,							attention_mask=A_	,							encoder_hidden_states=A_	,							encoder_attention_mask=A_	,							)
       UpperCamelCase     : int	     =       model(
           A_	,							attention_mask=A_	,							encoder_hidden_states=A_	,							)
       UpperCamelCase     : str	     =       model(A_	,							attention_mask=A_       )
       self.parent.assertEqual(result.last_hidden_state.shape	,							(self.batch_size, self.seq_length, self.hidden_size)       )





      def 	__UpperCamelCase(			self	,							A_	,							A_	,							A_	,							A_	,							A_	,							A_	,							A_	,							A_	,							A_	,							):
       '''simple docstring'''




       UpperCamelCase     : Any	     =       LlamaForCausalLM(config=A_       )
       model.to(A_       )
       model.eval()
       UpperCamelCase     : Dict	     =       model(A_	,							attention_mask=A_	,							labels=A_       )
       self.parent.assertEqual(result.logits.shape	,							(self.batch_size, self.seq_length, self.vocab_size)       )





      def 	__UpperCamelCase(			self	,							A_	,							A_	,							A_	,							A_	,							A_	,							A_	,							A_	,							A_	,							A_	,							):
       '''simple docstring'''




       UpperCamelCase     : str	     =       True
       UpperCamelCase     : Optional[Any]	     =       True
       UpperCamelCase     : Dict	     =       LlamaForCausalLM(config=A_       )
       model.to(A_       )
       model.eval()

       # first forward pass
       UpperCamelCase     : Optional[Any]	     =       model(
           A_	,							attention_mask=A_	,							encoder_hidden_states=A_	,							encoder_attention_mask=A_	,							use_cache=A_	,							)
       UpperCamelCase     : Optional[Any]	     =       outputs.past_key_values

       # create hypothetical multiple next token and extent to next_input_ids
       UpperCamelCase     : List[str]	     =       ids_tensor((self.batch_size, 3)	,							config.vocab_size       )
       UpperCamelCase     : Union[str, Any]	     =       ids_tensor((self.batch_size, 3)	,							vocab_size=2       )

       # append to next input_ids and
       UpperCamelCase     : Dict	     =       torch.cat([input_ids, next_tokens]	,							dim=-1       )
       UpperCamelCase     : Dict	     =       torch.cat([input_mask, next_mask]	,							dim=-1       )

       UpperCamelCase     : Optional[int]	     =       model(
           A_	,							attention_mask=A_	,							encoder_hidden_states=A_	,							encoder_attention_mask=A_	,							output_hidden_states=A_	,							)["hidden_states"][0]
       UpperCamelCase     : Tuple	     =       model(
           A_	,							attention_mask=A_	,							encoder_hidden_states=A_	,							encoder_attention_mask=A_	,							past_key_values=A_	,							output_hidden_states=A_	,							)["hidden_states"][0]

       # select random slice
       UpperCamelCase     : Optional[Any]	     =       ids_tensor((1,)	,							output_from_past.shape[-1]       ).item()
       UpperCamelCase     : List[Any]	     =       output_from_no_past[:, -3:, random_slice_idx].detach()
       UpperCamelCase     : Union[str, Any]	     =       output_from_past[:, :, random_slice_idx].detach()

       self.parent.assertTrue(output_from_past_slice.shape[1] == next_tokens.shape[1]       )

       # test that outputs are equal for slice
       self.parent.assertTrue(torch.allclose(A_	,							A_	,							atol=1e-3       )       )





      def 	__UpperCamelCase(			self       ):
       '''simple docstring'''




       UpperCamelCase     : int	     =       self.prepare_config_and_inputs()
       (
           UpperCamelCase   
       )     : Optional[Any]	     =       config_and_inputs
       UpperCamelCase     : Tuple	     =       {"input_ids": input_ids, "attention_mask": input_mask}
       return config, inputs_dict



@require_torch
class  A__       (	__snake_case	,       __snake_case	,       __snake_case	,       unittest.TestCase      ):
      _UpperCAmelCase     :Any						   =       (LlamaModel, LlamaForCausalLM, LlamaForSequenceClassification) if is_torch_available() else ()
      _UpperCAmelCase     :List[Any]						   =       (LlamaForCausalLM,) if is_torch_available() else ()
      _UpperCAmelCase     :Optional[int]						   =       (
          {
              'feature-extraction': LlamaModel,
              'text-classification': LlamaForSequenceClassification,
              'text-generation': LlamaForCausalLM,
              'zero-shot': LlamaForSequenceClassification,
          }
          if is_torch_available()
          else {}
      )
      _UpperCAmelCase     :int						   =       False
      _UpperCAmelCase     :Optional[Any]						   =       False





      def 	__UpperCamelCase(			self       ):
       '''simple docstring'''




       UpperCamelCase     : Union[str, Any]	     =       LlamaModelTester(self       )
       UpperCamelCase     : int	     =       ConfigTester(self	,							config_class=A_	,							hidden_size=37       )





      def 	__UpperCamelCase(			self       ):
       '''simple docstring'''




       self.config_tester.run_common_tests()





      def 	__UpperCamelCase(			self       ):
       '''simple docstring'''




       UpperCamelCase     : Optional[int]	     =       self.model_tester.prepare_config_and_inputs()
       self.model_tester.create_and_check_model(*A_       )





      def 	__UpperCamelCase(			self       ):
       '''simple docstring'''




       UpperCamelCase     : List[Any]	     =       self.model_tester.prepare_config_and_inputs()
       for type in ["absolute", "relative_key", "relative_key_query"]:
        UpperCamelCase     : str	     =       type
        self.model_tester.create_and_check_model(*A_       )





      def 	__UpperCamelCase(			self       ):
       '''simple docstring'''




       UpperCamelCase     : Optional[Any]	     =       self.model_tester.prepare_config_and_inputs_for_common()
       UpperCamelCase     : str	     =       3
       UpperCamelCase     : Optional[Any]	     =       input_dict["input_ids"]
       UpperCamelCase     : int	     =       input_ids.ne(1       ).to(A_       )
       UpperCamelCase     : List[Any]	     =       ids_tensor([self.model_tester.batch_size]	,							self.model_tester.type_sequence_label_size       )
       UpperCamelCase     : Any	     =       LlamaForSequenceClassification(A_       )
       model.to(A_       )
       model.eval()
       UpperCamelCase     : int	     =       model(A_	,							attention_mask=A_	,							labels=A_       )
       self.assertEqual(result.logits.shape	,							(self.model_tester.batch_size, self.model_tester.num_labels)       )





      def 	__UpperCamelCase(			self       ):
       '''simple docstring'''




       UpperCamelCase     : Dict	     =       self.model_tester.prepare_config_and_inputs_for_common()
       UpperCamelCase     : Dict	     =       3
       UpperCamelCase     : Union[str, Any]	     =       "single_label_classification"
       UpperCamelCase     : Optional[int]	     =       input_dict["input_ids"]
       UpperCamelCase     : Union[str, Any]	     =       input_ids.ne(1       ).to(A_       )
       UpperCamelCase     : int	     =       ids_tensor([self.model_tester.batch_size]	,							self.model_tester.type_sequence_label_size       )
       UpperCamelCase     : Tuple	     =       LlamaForSequenceClassification(A_       )
       model.to(A_       )
       model.eval()
       UpperCamelCase     : int	     =       model(A_	,							attention_mask=A_	,							labels=A_       )
       self.assertEqual(result.logits.shape	,							(self.model_tester.batch_size, self.model_tester.num_labels)       )





      def 	__UpperCamelCase(			self       ):
       '''simple docstring'''




       UpperCamelCase     : List[Any]	     =       self.model_tester.prepare_config_and_inputs_for_common()
       UpperCamelCase     : List[str]	     =       3
       UpperCamelCase     : Union[str, Any]	     =       "multi_label_classification"
       UpperCamelCase     : Union[str, Any]	     =       input_dict["input_ids"]
       UpperCamelCase     : str	     =       input_ids.ne(1       ).to(A_       )
       UpperCamelCase     : int	     =       ids_tensor(
           [self.model_tester.batch_size, config.num_labels]	,							self.model_tester.type_sequence_label_size       ).to(torch.float       )
       UpperCamelCase     : str	     =       LlamaForSequenceClassification(A_       )
       model.to(A_       )
       model.eval()
       UpperCamelCase     : Optional[int]	     =       model(A_	,							attention_mask=A_	,							labels=A_       )
       self.assertEqual(result.logits.shape	,							(self.model_tester.batch_size, self.model_tester.num_labels)       )





      @unittest.skip("LLaMA buffers include complex numbers, which breaks this test"       )
      def 	__UpperCamelCase(			self       ):
       '''simple docstring'''




       pass





      @parameterized.expand([("linear",), ("dynamic",)]       )
      def 	__UpperCamelCase(			self	,							A_       ):
       '''simple docstring'''




       UpperCamelCase     : Optional[int]	     =       self.model_tester.prepare_config_and_inputs_for_common()
       UpperCamelCase     : Optional[Any]	     =       ids_tensor([1, 10]	,							config.vocab_size       )
       UpperCamelCase     : List[str]	     =       ids_tensor([1, int(config.max_position_embeddings * 1.5       )]	,							config.vocab_size       )

       set_seed(42       )  # Fixed seed at init time so the two models get the same random weights
       UpperCamelCase     : Optional[int]	     =       LlamaModel(A_       )
       original_model.to(A_       )
       original_model.eval()
       UpperCamelCase     : str	     =       original_model(A_       ).last_hidden_state
       UpperCamelCase     : Union[str, Any]	     =       original_model(A_       ).last_hidden_state

       set_seed(42       )  # Fixed seed at init time so the two models get the same random weights
       UpperCamelCase     : Any	     =       {"type": scaling_type, "factor": 10.0}
       UpperCamelCase     : Optional[Any]	     =       LlamaModel(A_       )
       scaled_model.to(A_       )
       scaled_model.eval()
       UpperCamelCase     : Dict	     =       scaled_model(A_       ).last_hidden_state
       UpperCamelCase     : Optional[int]	     =       scaled_model(A_       ).last_hidden_state

       # Dynamic scaling does not change the RoPE embeddings until it receives an input longer than the original
       # maximum sequence length, so the outputs for the short input should match.
       if scaling_type == "dynamic":
        self.assertTrue(torch.allclose(A_	,							A_	,							atol=1e-5       )       )
       else:
        self.assertFalse(torch.allclose(A_	,							A_	,							atol=1e-5       )       )

       # The output should be different for long inputs
       self.assertFalse(torch.allclose(A_	,							A_	,							atol=1e-5       )       )



@require_torch
class  A__       (	unittest.TestCase      ):





      @unittest.skip("Logits are not exactly the same, once we fix the instabalities somehow, will update!"       )
      @slow
      def 	__UpperCamelCase(			self       ):
       '''simple docstring'''




       UpperCamelCase     : Union[str, Any]	     =       [1, 306, 4658, 278, 6593, 310, 2834, 338]
       UpperCamelCase     : Optional[Any]	     =       LlamaForCausalLM.from_pretrained("meta-llama/Llama-2-7b-hf"	,							device_map="auto"       )
       UpperCamelCase     : Dict	     =       model(torch.tensor([input_ids]       )       )
       # Expected mean on dim = -1
       UpperCamelCase     : int	     =       torch.tensor([[-6.65_50, -4.12_27, -4.98_59, -3.24_06, 0.82_62, -3.00_33, 1.29_64, -3.36_99]]       )
       torch.testing.assert_close(out.mean(-1       )	,							A_	,							atol=1e-2	,							rtol=1e-2       )
       # slicing logits[0, 0, 0:30]
       # fmt: off
       UpperCamelCase     : Optional[Any]	     =       torch.tensor([-12.82_81, -7.44_53, -0.46_39, -8.06_25, -7.25_00, -8.00_00, -6.48_83, -7.76_95, -7.84_38, -7.03_12, -6.21_88, -7.13_28, -1.84_96, 1.99_61, -8.62_50, -6.72_27, -12.82_81, -6.94_92, -7.07_42, -7.78_52, -7.58_20, -7.90_62, -6.93_75, -7.98_05, -8.34_38, -8.15_62, -8.04_69, -7.62_50, -7.74_22, -7.33_98,]       )
       # fmt: on
       torch.testing.assert_close(out[0, 0, :30]	,							A_	,							atol=1e-5	,							rtol=1e-5       )





      @unittest.skip("Logits are not exactly the same, once we fix the instabalities somehow, will update!"       )
      @slow
      def 	__UpperCamelCase(			self       ):
       '''simple docstring'''




       UpperCamelCase     : Dict	     =       [1, 306, 4658, 278, 6593, 310, 2834, 338]
       UpperCamelCase     : List[Any]	     =       LlamaForCausalLM.from_pretrained("meta-llama/Llama-2-13b-hf"	,							device_map="auto"       )
       UpperCamelCase     : Any	     =       model(torch.tensor(A_       )       )
       # Expected mean on dim = -1
       UpperCamelCase     : Tuple	     =       torch.tensor([[-2.06_22, -1.27_94, -1.16_38, -0.97_88, -1.46_03, -1.02_38, -1.78_93, -1.44_11]]       )
       torch.testing.assert_close(out.mean(-1       )	,							A_	,							atol=1e-2	,							rtol=1e-2       )
       # slicing logits[0, 0, 0:30]
       # fmt: off
       UpperCamelCase     : List[str]	     =       torch.tensor([-8.14_06, -8.05_47, 2.74_61, -1.23_44, -0.14_48, -1.82_62, -1.00_20, -1.81_54, -1.68_95, -1.85_16, -2.35_74, -0.92_77, 3.75_98, 6.57_42, -1.29_98, -0.11_77, -8.14_06, -2.96_88, -2.91_99, -3.16_99, -3.52_54, -2.35_55, -2.79_88, -3.41_41, -2.82_62, -4.51_95, -3.33_79, -3.31_64, -2.78_32, -3.02_73]       )
       # fmt: on
       torch.testing.assert_close(out[0, 0, :30]	,							A_	,							atol=1e-5	,							rtol=1e-5       )





      @unittest.skip("Logits are not exactly the same, once we fix the instabalities somehow, will update!"       )
      @slow
      def 	__UpperCamelCase(			self       ):
       '''simple docstring'''




       UpperCamelCase     : str	     =       [1, 306, 4658, 278, 6593, 310, 2834, 338]
       UpperCamelCase     : List[Any]	     =       LlamaForCausalLM.from_pretrained("meta-llama/Llama-2-13b-chat-hf"	,							device_map="auto"       )
       UpperCamelCase     : List[str]	     =       model(torch.tensor(A_       )       )
       # Expected mean on dim = -1
       UpperCamelCase     : List[str]	     =       torch.tensor([[-0.85_62, -1.85_20, -0.75_51, -0.41_62, -1.51_61, -1.20_38, -2.48_23, -2.32_54]]       )
       torch.testing.assert_close(out.mean(-1       )	,							A_	,							atol=1e-2	,							rtol=1e-2       )
       # slicing logits[0, 0, 0:30]
       # fmt: off
       UpperCamelCase     : Tuple	     =       torch.tensor([-2.22_27, 4.88_28, 0.90_23, -0.45_78, -0.78_71, -0.10_33, -0.62_21, -0.57_86, -0.78_03, -1.06_74, -1.29_20, -0.15_70, 0.80_08, 2.07_23, -0.94_97, 0.27_71, -2.22_27, -0.76_12, -1.43_46, -1.20_61, -1.64_26, -0.30_00, -0.71_39, -1.19_34, -1.86_91, -1.69_73, -1.59_47, -1.27_05, -0.35_23, -0.55_13]       )
       # fmt: on
       torch.testing.assert_close(out.mean(-1       )	,							A_	,							atol=1e-2	,							rtol=1e-2       )





      @unittest.skip(
          "Logits are not exactly the same, once we fix the instabalities somehow, will update! Also it is gonna be a `too_slow` test"       )
      @slow
      def 	__UpperCamelCase(			self       ):
       '''simple docstring'''




       UpperCamelCase     : Any	     =       [1, 306, 4658, 278, 6593, 310, 2834, 338]
       UpperCamelCase     : int	     =       LlamaForCausalLM.from_pretrained("meta-llama/Llama-2-70b-hf"	,							device_map="auto"       )
       UpperCamelCase     : Any	     =       model(torch.tensor(A_       )       )

       UpperCamelCase     : List[str]	     =       torch.tensor(
           [[-4.23_27, -3.33_60, -4.66_65, -4.76_31, -1.81_80, -3.41_70, -1.42_11, -3.18_10]]	,							dtype=torch.floataa       )
       torch.testing.assert_close(out.mean(-1       )	,							A_	,							atol=1e-2	,							rtol=1e-2       )
       # fmt: off
       UpperCamelCase     : int	     =       torch.tensor([-9.49_22, -3.95_51, 1.79_98, -5.67_58, -5.10_55, -5.89_84, -4.83_20, -6.80_86, -6.53_91, -5.61_72, -5.58_20, -5.53_52, 1.78_81, 3.62_89, -6.51_17, -3.47_85, -9.50_00, -6.03_52, -6.81_25, -6.01_95, -6.68_36, -5.47_27, -6.28_12, -6.03_91, -7.33_98, -7.42_97, -7.48_44, -6.58_20, -5.87_89, -5.53_12]       )
       # fmt: on
       torch.testing.assert_close(out[0, 0, :30]	,							A_	,							atol=1e-5	,							rtol=1e-5       )





      @unittest.skip("Model is curently gated"       )
      @slow
      def 	__UpperCamelCase(			self       ):
       '''simple docstring'''




       UpperCamelCase     : List[Any]	     =       "Simply put, the theory of relativity states that 1) the laws of physics are the same everywhere in the universe and 2) the passage of time and the length of objects can vary depending on the observer\'s frame of reference.\n\nThe first part of the theory, that the laws of physics are the same everywhere, is known as the \"princi"
       UpperCamelCase     : int	     =       "Simply put, the theory of relativity states that "
       UpperCamelCase     : Optional[Any]	     =       LlamaTokenizer.from_pretrained("meta-llama/Llama-2-13b-chat-hf"       )
       UpperCamelCase     : Any	     =       tokenizer.encode(A_	,							return_tensors="pt"       )
       UpperCamelCase     : int	     =       LlamaForCausalLM.from_pretrained(
           "meta-llama/Llama-2-13b-chat-hf"	,							device_map="sequential"	,							use_safetensors=A_       )

       # greedy generation outputs
       UpperCamelCase     : List[str]	     =       model.generate(A_	,							max_new_tokens=64	,							top_p=A_	,							temperature=1	,							do_sample=A_       )
       UpperCamelCase     : Tuple	     =       tokenizer.decode(generated_ids[0]	,							skip_special_tokens=A_       )
       self.assertEqual(A_	,							A_       )







from scipy.stats import spearmanr

import datasets


__lowerCamelCase	:					List[str]			  =					"""
The Spearman rank-order correlation coefficient is a measure of the
relationship between two datasets. Like other correlation coefficients,
this one varies between -1 and +1 with 0 implying no correlation.
Positive correlations imply that as data in dataset x increases, so
does data in dataset y. Negative correlations imply that as x increases,
y decreases. Correlations of -1 or +1 imply an exact monotonic relationship.

Unlike the Pearson correlation, the Spearman correlation does not
assume that both datasets are normally distributed.

The p-value roughly indicates the probability of an uncorrelated system
producing datasets that have a Spearman correlation at least as extreme
as the one computed from these datasets. The p-values are not entirely
reliable but are probably reasonable for datasets larger than 500 or so.
"""

__lowerCamelCase	:					List[Any]			  =					"""
Args:
    predictions (`List[float]`): Predicted labels, as returned by a model.
    references (`List[float]`): Ground truth labels.
    return_pvalue (`bool`): If `True`, returns the p-value. If `False`, returns
            only the spearmanr score. Defaults to `False`.
Returns:
    spearmanr (`float`): Spearman correlation coefficient.
    p-value (`float`): p-value. **Note**: is only returned if `return_pvalue=True` is input.
Examples:
    Example 1:
        >>> spearmanr_metric = datasets.load_metric(\"spearmanr\")
        >>> results = spearmanr_metric.compute(references=[1, 2, 3, 4, 5], predictions=[10, 9, 2.5, 6, 4])
        >>> print(results)
        {'spearmanr': -0.7}

    Example 2:
        >>> spearmanr_metric = datasets.load_metric(\"spearmanr\")
        >>> results = spearmanr_metric.compute(references=[1, 2, 3, 4, 5],
        ...                                     predictions=[10, 9, 2.5, 6, 4],
        ...                                     return_pvalue=True)
        >>> print(results['spearmanr'])
        -0.7
        >>> print(round(results['spearmanr_pvalue'], 2))
        0.19
"""

__lowerCamelCase	:					Optional[int]			  =					r"""\
@book{kokoska2000crc,
  title={CRC standard probability and statistics tables and formulae},
  author={Kokoska, Stephen and Zwillinger, Daniel},
  year={2000},
  publisher={Crc Press}
}
@article{2020SciPy-NMeth,
  author  = {Virtanen, Pauli and Gommers, Ralf and Oliphant, Travis E. and
            Haberland, Matt and Reddy, Tyler and Cournapeau, David and
            Burovski, Evgeni and Peterson, Pearu and Weckesser, Warren and
            Bright, Jonathan and {van der Walt}, St{\'e}fan J. and
            Brett, Matthew and Wilson, Joshua and Millman, K. Jarrod and
            Mayorov, Nikolay and Nelson, Andrew R. J. and Jones, Eric and
            Kern, Robert and Larson, Eric and Carey, C J and
            Polat, {\.I}lhan and Feng, Yu and Moore, Eric W. and
            {VanderPlas}, Jake and Laxalde, Denis and Perktold, Josef and
            Cimrman, Robert and Henriksen, Ian and Quintero, E. A. and
            Harris, Charles R. and Archibald, Anne M. and
            Ribeiro, Ant{\^o}nio H. and Pedregosa, Fabian and
            {van Mulbregt}, Paul and {SciPy 1.0 Contributors}},
  title   = {{{SciPy} 1.0: Fundamental Algorithms for Scientific
            Computing in Python}},
  journal = {Nature Methods},
  year    = {2020},
  volume  = {17},
  pages   = {261--272},
  adsurl  = {https://rdcu.be/b08Wh},
  doi     = {10.1038/s41592-019-0686-2},
}
"""



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





      def 	__UpperCamelCase(			self       ):
       '''simple docstring'''




       return datasets.MetricInfo(
           description=_DESCRIPTION	,							citation=_CITATION	,							inputs_description=_KWARGS_DESCRIPTION	,							features=datasets.Features(
               {
                   "predictions": datasets.Value("float"       ),
                   "references": datasets.Value("float"       ),
               }       )	,							reference_urls=["https://docs.scipy.org/doc/scipy/reference/generated/scipy.stats.spearmanr.html"]	,							)





      def 	__UpperCamelCase(			self	,							A_	,							A_	,							A_=False       ):
       '''simple docstring'''




       UpperCamelCase     : Tuple	     =       spearmanr(A_	,							A_       )
       if return_pvalue:
        return {"spearmanr": results[0], "spearmanr_pvalue": results[1]}
       else:
        return {"spearmanr": results[0]}
