

from __future__ import annotations

import unittest

from transformers import RoFormerConfig, is_tf_available
from transformers.testing_utils import require_tf, slow

from ...test_configuration_common import ConfigTester
from ...test_modeling_tf_common import TFModelTesterMixin, ids_tensor, random_attention_mask
from ...test_pipeline_mixin import PipelineTesterMixin


if is_tf_available():
  import tensorflow as tf

  from transformers import (
      TFRoFormerForCausalLM,
      TFRoFormerForMaskedLM,
      TFRoFormerForMultipleChoice,
      TFRoFormerForQuestionAnswering,
      TFRoFormerForSequenceClassification,
      TFRoFormerForTokenClassification,
      TFRoFormerModel,
  )
  from transformers.models.roformer.modeling_tf_roformer import (
      TFRoFormerSelfAttention,
      TFRoFormerSinusoidalPositionalEmbedding,
  )






class 							A_ :


     def __init__(							self			:		List[str]			,  UpperCAmelCase			:		Optional[Any]			,  UpperCAmelCase			:		Optional[Any]=1_3			,  UpperCAmelCase			:		Optional[int]=7			,  UpperCAmelCase			:		Any=True			,  UpperCAmelCase			:		str=True			,  UpperCAmelCase			:		str=True			,  UpperCAmelCase			:		str=True			,  UpperCAmelCase			:		Optional[int]=9_9			,  UpperCAmelCase			:		List[str]=3_2			,  UpperCAmelCase			:		Union[str, Any]=2			,  UpperCAmelCase			:		Optional[Any]=4			,  UpperCAmelCase			:		str=3_7			,  UpperCAmelCase			:		Optional[int]="gelu"			,  UpperCAmelCase			:		Any=0.1			,  UpperCAmelCase			:		Optional[int]=0.1			,  UpperCAmelCase			:		List[Any]=5_1_2			,  UpperCAmelCase			:		Optional[Any]=1_6			,  UpperCAmelCase			:		Tuple=2			,  UpperCAmelCase			:		List[Any]=0.02			,  UpperCAmelCase			:		str=3			,  UpperCAmelCase			:		str=4			,  UpperCAmelCase			:		List[Any]=None			,  )							->	Optional[int]:
      __lowerCAmelCase:   Tuple   	=      parent
      __lowerCAmelCase:   List[Any]   	=      1_3
      __lowerCAmelCase:   List[str]   	=      7
      __lowerCAmelCase:   List[str]   	=      True
      __lowerCAmelCase:   str   	=      True
      __lowerCAmelCase:   int   	=      True
      __lowerCAmelCase:   str   	=      True
      __lowerCAmelCase:   str   	=      9_9
      __lowerCAmelCase:   int   	=      3_2
      __lowerCAmelCase:   Dict   	=      2
      __lowerCAmelCase:   str   	=      4
      __lowerCAmelCase:   Tuple   	=      3_7
      __lowerCAmelCase:   Dict   	=      'gelu'
      __lowerCAmelCase:   Any   	=      0.1
      __lowerCAmelCase:   Optional[Any]   	=      0.1
      __lowerCAmelCase:   Any   	=      5_1_2
      __lowerCAmelCase:   Union[str, Any]   	=      1_6
      __lowerCAmelCase:   List[Any]   	=      2
      __lowerCAmelCase:   List[str]   	=      0.02
      __lowerCAmelCase:   str   	=      3
      __lowerCAmelCase:   Tuple   	=      4
      __lowerCAmelCase:   int   	=      None


     def   UpperCAmelCase  (							self			:		int					)							->	str:
      __lowerCAmelCase:   str   	=      ids_tensor([self.batch_size, self.seq_length]			,  self.vocab_size					)

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

      __lowerCAmelCase:   Any   	=      None
      if self.use_token_type_ids:
       __lowerCAmelCase:   Union[str, Any]   	=      ids_tensor([self.batch_size, self.seq_length]			,  self.type_vocab_size					)

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

      __lowerCAmelCase:   Tuple   	=      RoFormerConfig(
          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			,  initializer_range=self.initializer_range			,  return_dict=__lowerCAmelCase			,  )

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


     def   UpperCAmelCase  (							self			:		Dict			,  UpperCAmelCase			:		Dict			,  UpperCAmelCase			:		Optional[Any]			,  UpperCAmelCase			:		Dict			,  UpperCAmelCase			:		Any			,  UpperCAmelCase			:		Optional[int]			,  UpperCAmelCase			:		List[Any]			,  UpperCAmelCase			:		Optional[Any]					)							->	str:
      __lowerCAmelCase:   Union[str, Any]   	=      TFRoFormerModel(config=__lowerCAmelCase					)
      __lowerCAmelCase:   Optional[Any]   	=      {'input_ids': input_ids, 'attention_mask': input_mask, 'token_type_ids': token_type_ids}

      __lowerCAmelCase:   Tuple   	=      [input_ids, input_mask]
      __lowerCAmelCase:   Optional[Any]   	=      model(__lowerCAmelCase					)

      __lowerCAmelCase:   Tuple   	=      model(__lowerCAmelCase					)

      self.parent.assertEqual(result.last_hidden_state.shape			,  (self.batch_size, self.seq_length, self.hidden_size)					)


     def   UpperCAmelCase  (							self			:		Union[str, Any]			,  UpperCAmelCase			:		int			,  UpperCAmelCase			:		List[Any]			,  UpperCAmelCase			:		str			,  UpperCAmelCase			:		List[str]			,  UpperCAmelCase			:		Any			,  UpperCAmelCase			:		Dict			,  UpperCAmelCase			:		Optional[Any]					)							->	Tuple:
      __lowerCAmelCase:   Tuple   	=      True
      __lowerCAmelCase:   Optional[Any]   	=      TFRoFormerForCausalLM(config=__lowerCAmelCase					)
      __lowerCAmelCase:   List[str]   	=      {
          'input_ids': input_ids,
          'attention_mask': input_mask,
          'token_type_ids': token_type_ids,
      }
      __lowerCAmelCase:   Dict   	=      model(__lowerCAmelCase					)['logits']
      self.parent.assertListEqual(
          list(prediction_scores.numpy().shape					)			,  [self.batch_size, self.seq_length, self.vocab_size]					)


     def   UpperCAmelCase  (							self			:		List[Any]			,  UpperCAmelCase			:		Dict			,  UpperCAmelCase			:		Tuple			,  UpperCAmelCase			:		List[str]			,  UpperCAmelCase			:		Any			,  UpperCAmelCase			:		List[str]			,  UpperCAmelCase			:		Optional[int]			,  UpperCAmelCase			:		Dict					)							->	Tuple:
      __lowerCAmelCase:   Dict   	=      TFRoFormerForMaskedLM(config=__lowerCAmelCase					)
      __lowerCAmelCase:   Any   	=      {
          'input_ids': input_ids,
          'attention_mask': input_mask,
          'token_type_ids': token_type_ids,
      }
      __lowerCAmelCase:   List[Any]   	=      model(__lowerCAmelCase					)
      self.parent.assertEqual(result.logits.shape			,  (self.batch_size, self.seq_length, self.vocab_size)					)


     def   UpperCAmelCase  (							self			:		Union[str, Any]			,  UpperCAmelCase			:		List[str]			,  UpperCAmelCase			:		Optional[int]			,  UpperCAmelCase			:		Any			,  UpperCAmelCase			:		Any			,  UpperCAmelCase			:		Union[str, Any]			,  UpperCAmelCase			:		List[Any]			,  UpperCAmelCase			:		Any					)							->	Tuple:
      __lowerCAmelCase:   Dict   	=      self.num_labels
      __lowerCAmelCase:   List[str]   	=      TFRoFormerForSequenceClassification(config=__lowerCAmelCase					)
      __lowerCAmelCase:   Any   	=      {
          'input_ids': input_ids,
          'attention_mask': input_mask,
          'token_type_ids': token_type_ids,
      }

      __lowerCAmelCase:   Tuple   	=      model(__lowerCAmelCase					)
      self.parent.assertEqual(result.logits.shape			,  (self.batch_size, self.num_labels)					)


     def   UpperCAmelCase  (							self			:		Dict			,  UpperCAmelCase			:		Any			,  UpperCAmelCase			:		str			,  UpperCAmelCase			:		List[Any]			,  UpperCAmelCase			:		Optional[Any]			,  UpperCAmelCase			:		Optional[int]			,  UpperCAmelCase			:		str			,  UpperCAmelCase			:		Optional[Any]					)							->	List[Any]:
      __lowerCAmelCase:   str   	=      self.num_choices
      __lowerCAmelCase:   Tuple   	=      TFRoFormerForMultipleChoice(config=__lowerCAmelCase					)
      __lowerCAmelCase:   List[Any]   	=      tf.tile(tf.expand_dims(__lowerCAmelCase			,  1					)			,  (1, self.num_choices, 1)					)
      __lowerCAmelCase:   Union[str, Any]   	=      tf.tile(tf.expand_dims(__lowerCAmelCase			,  1					)			,  (1, self.num_choices, 1)					)
      __lowerCAmelCase:   Tuple   	=      tf.tile(tf.expand_dims(__lowerCAmelCase			,  1					)			,  (1, self.num_choices, 1)					)
      __lowerCAmelCase:   Tuple   	=      {
          'input_ids': multiple_choice_inputs_ids,
          'attention_mask': multiple_choice_input_mask,
          'token_type_ids': multiple_choice_token_type_ids,
      }
      __lowerCAmelCase:   Any   	=      model(__lowerCAmelCase					)
      self.parent.assertEqual(result.logits.shape			,  (self.batch_size, self.num_choices)					)


     def   UpperCAmelCase  (							self			:		Dict			,  UpperCAmelCase			:		Dict			,  UpperCAmelCase			:		List[Any]			,  UpperCAmelCase			:		Union[str, Any]			,  UpperCAmelCase			:		List[Any]			,  UpperCAmelCase			:		Any			,  UpperCAmelCase			:		int			,  UpperCAmelCase			:		List[Any]					)							->	Union[str, Any]:
      __lowerCAmelCase:   List[Any]   	=      self.num_labels
      __lowerCAmelCase:   int   	=      TFRoFormerForTokenClassification(config=__lowerCAmelCase					)
      __lowerCAmelCase:   Optional[int]   	=      {
          'input_ids': input_ids,
          'attention_mask': input_mask,
          'token_type_ids': token_type_ids,
      }
      __lowerCAmelCase:   Dict   	=      model(__lowerCAmelCase					)
      self.parent.assertEqual(result.logits.shape			,  (self.batch_size, self.seq_length, self.num_labels)					)


     def   UpperCAmelCase  (							self			:		Tuple			,  UpperCAmelCase			:		Tuple			,  UpperCAmelCase			:		int			,  UpperCAmelCase			:		Optional[int]			,  UpperCAmelCase			:		Optional[Any]			,  UpperCAmelCase			:		List[str]			,  UpperCAmelCase			:		Optional[Any]			,  UpperCAmelCase			:		Tuple					)							->	List[str]:
      __lowerCAmelCase:   int   	=      TFRoFormerForQuestionAnswering(config=__lowerCAmelCase					)
      __lowerCAmelCase:   str   	=      {
          'input_ids': input_ids,
          'attention_mask': input_mask,
          'token_type_ids': token_type_ids,
      }

      __lowerCAmelCase:   Tuple   	=      model(__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   UpperCAmelCase  (							self			:		List[str]					)							->	List[Any]:
      __lowerCAmelCase:   Optional[int]   	=      self.prepare_config_and_inputs()
      (
          (
          __lowerCAmelCase 
      )	,							(
          __lowerCAmelCase 
      )	,							(
          __lowerCAmelCase 
      )	,							(
          __lowerCAmelCase 
      )	,							(
          __lowerCAmelCase 
      )	,							(
          __lowerCAmelCase 
      )	,							(
          __lowerCAmelCase 
      )	,							 
      ):   str   	=      config_and_inputs
      __lowerCAmelCase:   Any   	=      {'input_ids': input_ids, 'token_type_ids': token_type_ids, 'attention_mask': input_mask}
      return config, inputs_dict







@require_tf
class 							A_ (		lowerCAmelCase_							,	lowerCAmelCase_							,	unittest.TestCase					):
     _lowercase			:     Optional[Any]								=	(
         (
             TFRoFormerModel,
             TFRoFormerForCausalLM,
             TFRoFormerForMaskedLM,
             TFRoFormerForQuestionAnswering,
             TFRoFormerForSequenceClassification,
             TFRoFormerForTokenClassification,
             TFRoFormerForMultipleChoice,
         )
         if is_tf_available()
         else ()
     )
     _lowercase			:     int								=	(
         {
             'feature-extraction': TFRoFormerModel,
             'fill-mask': TFRoFormerForMaskedLM,
             'question-answering': TFRoFormerForQuestionAnswering,
             'text-classification': TFRoFormerForSequenceClassification,
             'text-generation': TFRoFormerForCausalLM,
             'token-classification': TFRoFormerForTokenClassification,
             'zero-shot': TFRoFormerForSequenceClassification,
         }
         if is_tf_available()
         else {}
     )

     _lowercase			:     Tuple								=	False
     _lowercase			:     Optional[Any]								=	False


     def   UpperCAmelCase  (							self			:		List[str]			,  UpperCAmelCase			:		str			,  UpperCAmelCase			:		Any			,  UpperCAmelCase			:		List[Any]			,  UpperCAmelCase			:		Optional[Any]			,  UpperCAmelCase			:		Any					)							->	Optional[int]:
      if pipeline_test_casse_name == "TextGenerationPipelineTests":
       return True

      return False


     def   UpperCAmelCase  (							self			:		int					)							->	str:
      __lowerCAmelCase:   Any   	=      TFRoFormerModelTester(self					)
      __lowerCAmelCase:   Tuple   	=      ConfigTester(self			,  config_class=__lowerCAmelCase			,  hidden_size=3_7					)


     def   UpperCAmelCase  (							self			:		Tuple					)							->	Optional[int]:
      self.config_tester.run_common_tests()


     def   UpperCAmelCase  (							self			:		Optional[Any]					)							->	str:
      __lowerCAmelCase:   Dict   	=      self.model_tester.prepare_config_and_inputs()
      self.model_tester.create_and_check_model(*__lowerCAmelCase					)


     def   UpperCAmelCase  (							self			:		str					)							->	Optional[int]:
      __lowerCAmelCase:   Tuple   	=      self.model_tester.prepare_config_and_inputs()
      self.model_tester.create_and_check_for_masked_lm(*__lowerCAmelCase					)


     def   UpperCAmelCase  (							self			:		List[Any]					)							->	Any:
      __lowerCAmelCase:   List[str]   	=      self.model_tester.prepare_config_and_inputs()
      self.model_tester.create_and_check_lm_head(*__lowerCAmelCase					)


     def   UpperCAmelCase  (							self			:		Dict					)							->	Any:
      __lowerCAmelCase:   List[Any]   	=      self.model_tester.prepare_config_and_inputs()
      self.model_tester.create_and_check_for_multiple_choice(*__lowerCAmelCase					)


     def   UpperCAmelCase  (							self			:		List[str]					)							->	Dict:
      __lowerCAmelCase:   Union[str, Any]   	=      self.model_tester.prepare_config_and_inputs()
      self.model_tester.create_and_check_for_question_answering(*__lowerCAmelCase					)


     def   UpperCAmelCase  (							self			:		Tuple					)							->	Tuple:
      __lowerCAmelCase:   int   	=      self.model_tester.prepare_config_and_inputs()
      self.model_tester.create_and_check_for_sequence_classification(*__lowerCAmelCase					)


     def   UpperCAmelCase  (							self			:		Optional[int]					)							->	List[str]:
      __lowerCAmelCase:   Dict   	=      self.model_tester.prepare_config_and_inputs()
      self.model_tester.create_and_check_for_token_classification(*__lowerCAmelCase					)


     @slow
     def   UpperCAmelCase  (							self			:		Any					)							->	List[Any]:
      __lowerCAmelCase:   Dict   	=      TFRoFormerModel.from_pretrained('junnyu/roformer_chinese_base'					)
      self.assertIsNotNone(__lowerCAmelCase					)







@require_tf
class 							A_ (		unittest.TestCase					):


     @slow
     def   UpperCAmelCase  (							self			:		Dict					)							->	Optional[Any]:
      __lowerCAmelCase:   Optional[Any]   	=      TFRoFormerForMaskedLM.from_pretrained('junnyu/roformer_chinese_base'					)
      __lowerCAmelCase:   Tuple   	=      tf.constant([[0, 1, 2, 3, 4, 5]]					)
      __lowerCAmelCase:   Optional[int]   	=      model(__lowerCAmelCase					)[0]

      # TODO Replace vocab size
      __lowerCAmelCase:   int   	=      5_0_0_0_0

      __lowerCAmelCase:   str   	=      [1, 6, vocab_size]
      self.assertEqual(output.shape			,  __lowerCAmelCase					)

      print(output[:, :3, :3]					)

      # TODO Replace values below with what was printed above.
      __lowerCAmelCase:   Union[str, Any]   	=      tf.constant(
          [
              [
                  [-0.12053341, -1.0264901, 0.29221946],
                  [-1.5133783, 0.197433, 0.15190607],
                  [-5.0135403, -3.900256, -0.84038764],
              ]
          ]					)
      tf.debugging.assert_near(output[:, :3, :3]			,  __lowerCAmelCase			,  atol=1E-4					)







@require_tf
class 							A_ (		unittest.TestCase					):
     _lowercase			:     str								=	1E-4


     def   UpperCAmelCase  (							self			:		int					)							->	Optional[int]:
      __lowerCAmelCase:   Optional[int]   	=      tf.constant([[4, 1_0]]					)
      __lowerCAmelCase:   List[str]   	=      TFRoFormerSinusoidalPositionalEmbedding(num_positions=6			,  embedding_dim=6					)

      __lowerCAmelCase:   Optional[Any]   	=      emba(input_ids.shape					)
      __lowerCAmelCase:   Any   	=      tf.constant(
          [[0.0000, 0.0000, 0.0000, 1.0000, 1.0000, 1.0000], [0.8415, 0.0464, 0.0022, 0.5403, 0.9989, 1.0000]]					)

      tf.debugging.assert_near(__lowerCAmelCase			,  __lowerCAmelCase			,  atol=self.tolerance					)


     def   UpperCAmelCase  (							self			:		Union[str, Any]					)							->	List[Any]:
      __lowerCAmelCase:   int   	=      tf.constant(
          [
              [0.0000, 0.0000, 0.0000, 0.0000, 0.0000],
              [0.8415, 0.8219, 0.8020, 0.7819, 0.7617],
              [0.9093, 0.9364, 0.9581, 0.9749, 0.9870],
          ]					)
      __lowerCAmelCase:   Optional[int]   	=      TFRoFormerSinusoidalPositionalEmbedding(num_positions=5_1_2			,  embedding_dim=5_1_2					)
      emba([2, 1_6, 5_1_2]					)
      __lowerCAmelCase:   Dict   	=      emba.weight[:3, :5]

      tf.debugging.assert_near(__lowerCAmelCase			,  __lowerCAmelCase			,  atol=self.tolerance					)







@require_tf
class 							A_ (		unittest.TestCase					):
     _lowercase			:     int								=	1E-4


     def   UpperCAmelCase  (							self			:		Any					)							->	Optional[int]:
      # 2,12,16,64
      __lowerCAmelCase:   List[Any]   	=      tf.reshape(tf.range(2 * 1_2 * 1_6 * 6_4			,  dtype=tf.floataa					)			,  shape=(2, 1_2, 1_6, 6_4)					) / 1_0_0

      __lowerCAmelCase:   int   	=      -tf.reshape(tf.range(2 * 1_2 * 1_6 * 6_4			,  dtype=tf.floataa					)			,  shape=(2, 1_2, 1_6, 6_4)					) / 1_0_0

      __lowerCAmelCase:   int   	=      TFRoFormerSinusoidalPositionalEmbedding(num_positions=3_2			,  embedding_dim=6_4					)
      __lowerCAmelCase:   Tuple   	=      embed_positions([2, 1_6, 7_6_8]					)[None, None, :, :]

      __lowerCAmelCase	,							__lowerCAmelCase:   str   	=      TFRoFormerSelfAttention.apply_rotary_position_embeddings(
          __lowerCAmelCase			,  __lowerCAmelCase			,  __lowerCAmelCase					)

      __lowerCAmelCase:   str   	=      tf.constant(
          [
              [0.0000, 0.0100, 0.0200, 0.0300, 0.0400, 0.0500, 0.0600, 0.0700],
              [-0.2012, 0.8897, 0.0263, 0.9401, 0.2074, 0.9463, 0.3481, 0.9343],
              [-1.7057, 0.6271, -1.2145, 1.3897, -0.6303, 1.7647, -0.1173, 1.8985],
              [-2.1731, -1.6397, -2.7358, 0.2854, -2.1840, 1.7183, -1.3018, 2.4871],
              [0.2717, -3.6173, -2.9206, -2.1988, -3.6638, 0.3858, -2.9155, 2.2980],
              [3.9859, -2.1580, -0.7984, -4.4904, -4.1181, -2.0252, -4.4782, 1.1253],
          ]					)
      __lowerCAmelCase:   Any   	=      tf.constant(
          [
              [0.0000, -0.0100, -0.0200, -0.0300, -0.0400, -0.0500, -0.0600, -0.0700],
              [0.2012, -0.8897, -0.0263, -0.9401, -0.2074, -0.9463, -0.3481, -0.9343],
              [1.7057, -0.6271, 1.2145, -1.3897, 0.6303, -1.7647, 0.1173, -1.8985],
              [2.1731, 1.6397, 2.7358, -0.2854, 2.1840, -1.7183, 1.3018, -2.4871],
              [-0.2717, 3.6173, 2.9206, 2.1988, 3.6638, -0.3858, 2.9155, -2.2980],
              [-3.9859, 2.1580, 0.7984, 4.4904, 4.1181, 2.0252, 4.4782, -1.1253],
          ]					)

      tf.debugging.assert_near(query_layer[0, 0, :6, :8]			,  __lowerCAmelCase			,  atol=self.tolerance					)
      tf.debugging.assert_near(key_layer[0, 0, :6, :8]			,  __lowerCAmelCase			,  atol=self.tolerance					)






"""simple docstring"""


UpperCAmelCase__     						=  {
    """meter""": """m""",
    """kilometer""": """km""",
    """megametre""": """Mm""",
    """gigametre""": """Gm""",
    """terametre""": """Tm""",
    """petametre""": """Pm""",
    """exametre""": """Em""",
    """zettametre""": """Zm""",
    """yottametre""": """Ym""",
}
# Exponent of the factor(meter)
UpperCAmelCase__     						=  {
    """m""": 0,
    """km""": 3,
    """Mm""": 6,
    """Gm""": 9,
    """Tm""": 1_2,
    """Pm""": 1_5,
    """Em""": 1_8,
    """Zm""": 2_1,
    """Ym""": 2_4,
}






def 			__UpperCAmelCase    (	lowercase      ,lowercase      ,lowercase						):







  """simple docstring"""
  _UpperCAmelCase         =					from_type.lower().strip("""s"""						)
  _UpperCAmelCase         =					to_type.lower().strip("""s"""						)

  _UpperCAmelCase         =					UNIT_SYMBOL.get(lowercase      ,lowercase						)
  _UpperCAmelCase         =					UNIT_SYMBOL.get(lowercase      ,lowercase						)

  if from_sanitized not in METRIC_CONVERSION:
    _UpperCAmelCase         =					(
        f'''Invalid \'from_type\' value: {from_type!r}.\n'''
        f'''Conversion abbreviations are: {", ".join(lowercase						)}'''
    )
    raise ValueError(lowercase						)
  if to_sanitized not in METRIC_CONVERSION:
    _UpperCAmelCase         =					(
        f'''Invalid \'to_type\' value: {to_type!r}.\n'''
        f'''Conversion abbreviations are: {", ".join(lowercase						)}'''
    )
    raise ValueError(lowercase						)
  _UpperCAmelCase         =					METRIC_CONVERSION[from_sanitized]
  _UpperCAmelCase         =					METRIC_CONVERSION[to_sanitized]
  _UpperCAmelCase         =					1

  if from_exponent > to_exponent:
    _UpperCAmelCase         =					from_exponent - to_exponent
  else:
    _UpperCAmelCase         =					-(to_exponent - from_exponent)

  return value * pow(10      ,lowercase						)


if __name__ == "__main__":
    from doctest import testmod

    testmod()
