

'''simple docstring'''




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   _SCREAMING_SNAKE_CASE   :



 def __init__(   self		:   List[str]			,				a__		:   Optional[int]			,				a__		:   Dict=13			,				a__		:   int=7			,				a__		:   Union[str, Any]=True			,				a__		:   Optional[Any]=True			,				a__		:   str=True			,				a__		:   str=True			,				a__		:   List[str]=99			,				a__		:   Union[str, Any]=32			,				a__		:   Union[str, Any]=2			,				a__		:   Optional[int]=4			,				a__		:   Any=37			,				a__		:   Optional[int]="gelu"			,				a__		:   Any=0.1			,				a__		:   Tuple=0.1			,				a__		:   List[Any]=512			,				a__		:   Union[str, Any]=16			,				a__		:   Dict=2			,				a__		:   int=0.02			,				a__		:   Optional[Any]=3			,				a__		:   Any=4			,				a__		:   Tuple=None			,				):
      __magic_name__						       =    parent
      __magic_name__						       =    13
      __magic_name__						       =    7
      __magic_name__						       =    True
      __magic_name__						       =    True
      __magic_name__						       =    True
      __magic_name__						       =    True
      __magic_name__						       =    99
      __magic_name__						       =    32
      __magic_name__						       =    2
      __magic_name__						       =    4
      __magic_name__						       =    37
      __magic_name__						       =    '''gelu'''
      __magic_name__						       =    0.1
      __magic_name__						       =    0.1
      __magic_name__						       =    512
      __magic_name__						       =    16
      __magic_name__						       =    2
      __magic_name__						       =    0.02
      __magic_name__						       =    3
      __magic_name__						       =    4
      __magic_name__						       =    None



 def 			snake_case__  (   self		:   Optional[Any]      ):
      __magic_name__						       =    ids_tensor([self.batch_size, self.seq_length]			,				self.vocab_size      )

      __magic_name__						       =    None
      if self.use_input_mask:
           __magic_name__						       =    random_attention_mask([self.batch_size, self.seq_length]      )

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

      __magic_name__						       =    None
      __magic_name__						       =    None
      __magic_name__						       =    None
      if self.use_labels:
           __magic_name__						       =    ids_tensor([self.batch_size]			,				self.type_sequence_label_size      )
           __magic_name__						       =    ids_tensor([self.batch_size, self.seq_length]			,				self.num_labels      )
           __magic_name__						       =    ids_tensor([self.batch_size]			,				self.num_choices      )

      __magic_name__						       =    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=__SCREAMING_SNAKE_CASE			,				)

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



 def 			snake_case__  (   self		:   Tuple			,				a__		:   Optional[int]			,				a__		:   Tuple			,				a__		:   Tuple			,				a__		:   Tuple			,				a__		:   int			,				a__		:   Any			,				a__		:   List[Any]      ):
      __magic_name__						       =    TFRoFormerModel(config=__SCREAMING_SNAKE_CASE      )
      __magic_name__						       =    {'''input_ids''': input_ids, '''attention_mask''': input_mask, '''token_type_ids''': token_type_ids}

      __magic_name__						       =    [input_ids, input_mask]
      __magic_name__						       =    model(__SCREAMING_SNAKE_CASE      )

      __magic_name__						       =    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		:   int			,				a__		:   Union[str, Any]			,				a__		:   Any			,				a__		:   Dict			,				a__		:   Optional[int]			,				a__		:   List[Any]			,				a__		:   str			,				a__		:   List[Any]      ):
      __magic_name__						       =    True
      __magic_name__						       =    TFRoFormerForCausalLM(config=__SCREAMING_SNAKE_CASE      )
      __magic_name__						       =    {
          '''input_ids''': input_ids,
          '''attention_mask''': input_mask,
          '''token_type_ids''': token_type_ids,
      }
      __magic_name__						       =    model(__SCREAMING_SNAKE_CASE      )['''logits''']
      self.parent.assertListEqual(
          list(prediction_scores.numpy().shape      )			,				[self.batch_size, self.seq_length, self.vocab_size]      )



 def 			snake_case__  (   self		:   Dict			,				a__		:   Union[str, Any]			,				a__		:   Tuple			,				a__		:   str			,				a__		:   Union[str, Any]			,				a__		:   Union[str, Any]			,				a__		:   Any			,				a__		:   Union[str, Any]      ):
      __magic_name__						       =    TFRoFormerForMaskedLM(config=__SCREAMING_SNAKE_CASE      )
      __magic_name__						       =    {
          '''input_ids''': input_ids,
          '''attention_mask''': input_mask,
          '''token_type_ids''': token_type_ids,
      }
      __magic_name__						       =    model(__SCREAMING_SNAKE_CASE      )
      self.parent.assertEqual(result.logits.shape			,				(self.batch_size, self.seq_length, self.vocab_size)      )



 def 			snake_case__  (   self		:   Optional[int]			,				a__		:   Tuple			,				a__		:   Union[str, Any]			,				a__		:   List[str]			,				a__		:   Dict			,				a__		:   List[Any]			,				a__		:   Any			,				a__		:   Optional[int]      ):
      __magic_name__						       =    self.num_labels
      __magic_name__						       =    TFRoFormerForSequenceClassification(config=__SCREAMING_SNAKE_CASE      )
      __magic_name__						       =    {
          '''input_ids''': input_ids,
          '''attention_mask''': input_mask,
          '''token_type_ids''': token_type_ids,
      }

      __magic_name__						       =    model(__SCREAMING_SNAKE_CASE      )
      self.parent.assertEqual(result.logits.shape			,				(self.batch_size, self.num_labels)      )



 def 			snake_case__  (   self		:   Any			,				a__		:   int			,				a__		:   Any			,				a__		:   Dict			,				a__		:   Any			,				a__		:   Union[str, Any]			,				a__		:   str			,				a__		:   str      ):
      __magic_name__						       =    self.num_choices
      __magic_name__						       =    TFRoFormerForMultipleChoice(config=__SCREAMING_SNAKE_CASE      )
      __magic_name__						       =    tf.tile(tf.expand_dims(__SCREAMING_SNAKE_CASE			,				1      )			,				(1, self.num_choices, 1)      )
      __magic_name__						       =    tf.tile(tf.expand_dims(__SCREAMING_SNAKE_CASE			,				1      )			,				(1, self.num_choices, 1)      )
      __magic_name__						       =    tf.tile(tf.expand_dims(__SCREAMING_SNAKE_CASE			,				1      )			,				(1, self.num_choices, 1)      )
      __magic_name__						       =    {
          '''input_ids''': multiple_choice_inputs_ids,
          '''attention_mask''': multiple_choice_input_mask,
          '''token_type_ids''': multiple_choice_token_type_ids,
      }
      __magic_name__						       =    model(__SCREAMING_SNAKE_CASE      )
      self.parent.assertEqual(result.logits.shape			,				(self.batch_size, self.num_choices)      )



 def 			snake_case__  (   self		:   str			,				a__		:   Any			,				a__		:   Optional[Any]			,				a__		:   str			,				a__		:   str			,				a__		:   Tuple			,				a__		:   Any			,				a__		:   List[str]      ):
      __magic_name__						       =    self.num_labels
      __magic_name__						       =    TFRoFormerForTokenClassification(config=__SCREAMING_SNAKE_CASE      )
      __magic_name__						       =    {
          '''input_ids''': input_ids,
          '''attention_mask''': input_mask,
          '''token_type_ids''': token_type_ids,
      }
      __magic_name__						       =    model(__SCREAMING_SNAKE_CASE      )
      self.parent.assertEqual(result.logits.shape			,				(self.batch_size, self.seq_length, self.num_labels)      )



 def 			snake_case__  (   self		:   List[Any]			,				a__		:   List[Any]			,				a__		:   Optional[Any]			,				a__		:   str			,				a__		:   List[Any]			,				a__		:   List[str]			,				a__		:   Optional[int]			,				a__		:   Optional[int]      ):
      __magic_name__						       =    TFRoFormerForQuestionAnswering(config=__SCREAMING_SNAKE_CASE      )
      __magic_name__						       =    {
          '''input_ids''': input_ids,
          '''attention_mask''': input_mask,
          '''token_type_ids''': token_type_ids,
      }

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






@require_tf
class   _SCREAMING_SNAKE_CASE   (   _A		,_A		,unittest.TestCase     ):
 __SCREAMING_SNAKE_CASE					:int      	=					(
     (
         TFRoFormerModel,
         TFRoFormerForCausalLM,
         TFRoFormerForMaskedLM,
         TFRoFormerForQuestionAnswering,
         TFRoFormerForSequenceClassification,
         TFRoFormerForTokenClassification,
         TFRoFormerForMultipleChoice,
     )
     if is_tf_available()
     else ()
 )
 __SCREAMING_SNAKE_CASE					:Optional[Any]      	=					(
     {
         """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 {}
 )

 __SCREAMING_SNAKE_CASE					:int      	=					False
 __SCREAMING_SNAKE_CASE					:str      	=					False



 def 			snake_case__  (   self		:   Optional[int]			,				a__		:   Union[str, Any]			,				a__		:   Optional[Any]			,				a__		:   Any			,				a__		:   List[str]			,				a__		:   Tuple      ):
      if pipeline_test_casse_name == "TextGenerationPipelineTests":
           return True

      return False



 def 			snake_case__  (   self		:   Tuple      ):
      __magic_name__						       =    TFRoFormerModelTester(self      )
      __magic_name__						       =    ConfigTester(self			,				config_class=__SCREAMING_SNAKE_CASE			,				hidden_size=37      )



 def 			snake_case__  (   self		:   str      ):
      self.config_tester.run_common_tests()



 def 			snake_case__  (   self		:   Tuple      ):
      __magic_name__						       =    self.model_tester.prepare_config_and_inputs()
      self.model_tester.create_and_check_model(*__SCREAMING_SNAKE_CASE      )



 def 			snake_case__  (   self		:   Tuple      ):
      __magic_name__						       =    self.model_tester.prepare_config_and_inputs()
      self.model_tester.create_and_check_for_masked_lm(*__SCREAMING_SNAKE_CASE      )



 def 			snake_case__  (   self		:   Union[str, Any]      ):
      __magic_name__						       =    self.model_tester.prepare_config_and_inputs()
      self.model_tester.create_and_check_lm_head(*__SCREAMING_SNAKE_CASE      )



 def 			snake_case__  (   self		:   List[Any]      ):
      __magic_name__						       =    self.model_tester.prepare_config_and_inputs()
      self.model_tester.create_and_check_for_multiple_choice(*__SCREAMING_SNAKE_CASE      )



 def 			snake_case__  (   self		:   List[str]      ):
      __magic_name__						       =    self.model_tester.prepare_config_and_inputs()
      self.model_tester.create_and_check_for_question_answering(*__SCREAMING_SNAKE_CASE      )



 def 			snake_case__  (   self		:   Tuple      ):
      __magic_name__						       =    self.model_tester.prepare_config_and_inputs()
      self.model_tester.create_and_check_for_sequence_classification(*__SCREAMING_SNAKE_CASE      )



 def 			snake_case__  (   self		:   Union[str, Any]      ):
      __magic_name__						       =    self.model_tester.prepare_config_and_inputs()
      self.model_tester.create_and_check_for_token_classification(*__SCREAMING_SNAKE_CASE      )



 @slow
 def 			snake_case__  (   self		:   str      ):
      __magic_name__						       =    TFRoFormerModel.from_pretrained('''junnyu/roformer_chinese_base'''      )
      self.assertIsNotNone(__SCREAMING_SNAKE_CASE      )






@require_tf
class   _SCREAMING_SNAKE_CASE   (   unittest.TestCase     ):



 @slow
 def 			snake_case__  (   self		:   int      ):
      __magic_name__						       =    TFRoFormerForMaskedLM.from_pretrained('''junnyu/roformer_chinese_base'''      )
      __magic_name__						       =    tf.constant([[0, 1, 2, 3, 4, 5]]      )
      __magic_name__						       =    model(__SCREAMING_SNAKE_CASE      )[0]

      # TODO Replace vocab size
      __magic_name__						       =    5_0000

      __magic_name__						       =    [1, 6, vocab_size]
      self.assertEqual(output.shape			,				__SCREAMING_SNAKE_CASE      )

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

      # TODO Replace values below with what was printed above.
      __magic_name__						       =    tf.constant(
          [
              [
                  [-0.12_053_341, -1.0_264_901, 0.29_221_946],
                  [-1.5_133_783, 0.197_433, 0.15_190_607],
                  [-5.0_135_403, -3.900_256, -0.84_038_764],
              ]
          ]      )
      tf.debugging.assert_near(output[:, :3, :3]			,				__SCREAMING_SNAKE_CASE			,				atol=1E-4      )






@require_tf
class   _SCREAMING_SNAKE_CASE   (   unittest.TestCase     ):
 __SCREAMING_SNAKE_CASE					:Union[str, Any]      	=					1E-4



 def 			snake_case__  (   self		:   str      ):
      __magic_name__						       =    tf.constant([[4, 10]]      )
      __magic_name__						       =    TFRoFormerSinusoidalPositionalEmbedding(num_positions=6			,				embedding_dim=6      )

      __magic_name__						       =    emba(input_ids.shape      )
      __magic_name__						       =    tf.constant(
          [[0.0_000, 0.0_000, 0.0_000, 1.0_000, 1.0_000, 1.0_000], [0.8_415, 0.0_464, 0.0_022, 0.5_403, 0.9_989, 1.0_000]]      )

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



 def 			snake_case__  (   self		:   int      ):
      __magic_name__						       =    tf.constant(
          [
              [0.0_000, 0.0_000, 0.0_000, 0.0_000, 0.0_000],
              [0.8_415, 0.8_219, 0.8_020, 0.7_819, 0.7_617],
              [0.9_093, 0.9_364, 0.9_581, 0.9_749, 0.9_870],
          ]      )
      __magic_name__						       =    TFRoFormerSinusoidalPositionalEmbedding(num_positions=512			,				embedding_dim=512      )
      emba([2, 16, 512]      )
      __magic_name__						       =    emba.weight[:3, :5]

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






@require_tf
class   _SCREAMING_SNAKE_CASE   (   unittest.TestCase     ):
 __SCREAMING_SNAKE_CASE					:Tuple      	=					1E-4



 def 			snake_case__  (   self		:   Optional[Any]      ):
      # 2,12,16,64
      __magic_name__						       =    tf.reshape(tf.range(2 * 12 * 16 * 64			,				dtype=tf.floataa      )			,				shape=(2, 12, 16, 64)      ) / 100

      __magic_name__						       =    -tf.reshape(tf.range(2 * 12 * 16 * 64			,				dtype=tf.floataa      )			,				shape=(2, 12, 16, 64)      ) / 100

      __magic_name__						       =    TFRoFormerSinusoidalPositionalEmbedding(num_positions=32			,				embedding_dim=64      )
      __magic_name__						       =    embed_positions([2, 16, 768]      )[None, None, :, :]

      __magic_name__       ,  __magic_name__						       =    TFRoFormerSelfAttention.apply_rotary_position_embeddings(
          __SCREAMING_SNAKE_CASE			,				__SCREAMING_SNAKE_CASE			,				__SCREAMING_SNAKE_CASE      )

      __magic_name__						       =    tf.constant(
          [
              [0.0_000, 0.0_100, 0.0_200, 0.0_300, 0.0_400, 0.0_500, 0.0_600, 0.0_700],
              [-0.2_012, 0.8_897, 0.0_263, 0.9_401, 0.2_074, 0.9_463, 0.3_481, 0.9_343],
              [-1.7_057, 0.6_271, -1.2_145, 1.3_897, -0.6_303, 1.7_647, -0.1_173, 1.8_985],
              [-2.1_731, -1.6_397, -2.7_358, 0.2_854, -2.1_840, 1.7_183, -1.3_018, 2.4_871],
              [0.2_717, -3.6_173, -2.9_206, -2.1_988, -3.6_638, 0.3_858, -2.9_155, 2.2_980],
              [3.9_859, -2.1_580, -0.7_984, -4.4_904, -4.1_181, -2.0_252, -4.4_782, 1.1_253],
          ]      )
      __magic_name__						       =    tf.constant(
          [
              [0.0_000, -0.0_100, -0.0_200, -0.0_300, -0.0_400, -0.0_500, -0.0_600, -0.0_700],
              [0.2_012, -0.8_897, -0.0_263, -0.9_401, -0.2_074, -0.9_463, -0.3_481, -0.9_343],
              [1.7_057, -0.6_271, 1.2_145, -1.3_897, 0.6_303, -1.7_647, 0.1_173, -1.8_985],
              [2.1_731, 1.6_397, 2.7_358, -0.2_854, 2.1_840, -1.7_183, 1.3_018, -2.4_871],
              [-0.2_717, 3.6_173, 2.9_206, 2.1_988, 3.6_638, -0.3_858, 2.9_155, -2.2_980],
              [-3.9_859, 2.1_580, 0.7_984, 4.4_904, 4.1_181, 2.0_252, 4.4_782, -1.1_253],
          ]      )

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




'''simple docstring'''




import json
import sys
import tempfile
import unittest
from pathlib import Path

import transformers
from transformers import (
    CONFIG_MAPPING,
    FEATURE_EXTRACTOR_MAPPING,
    AutoConfig,
    AutoFeatureExtractor,
    WavaVecaConfig,
    WavaVecaFeatureExtractor,
)
from transformers.testing_utils import DUMMY_UNKNOWN_IDENTIFIER, get_tests_dir


sys.path.append(str(Path(__file__).parent.parent.parent.parent / "utils"))

from test_module.custom_configuration import CustomConfig  # noqa E402
from test_module.custom_feature_extraction import CustomFeatureExtractor  # noqa E402


_lowerCAmelCase         =						get_tests_dir("fixtures")
_lowerCAmelCase         =						get_tests_dir("fixtures/dummy_feature_extractor_config.json")
_lowerCAmelCase         =						get_tests_dir("fixtures/dummy-config.json")






class   _SCREAMING_SNAKE_CASE   (   unittest.TestCase     ):



 def 			snake_case__  (   self		:   Union[str, Any]      ):
      __magic_name__						       =    0



 def 			snake_case__  (   self		:   Optional[int]      ):
      __magic_name__						       =    AutoFeatureExtractor.from_pretrained('''facebook/wav2vec2-base-960h'''      )
      self.assertIsInstance(a__			,				a__      )



 def 			snake_case__  (   self		:   Optional[int]      ):
      __magic_name__						       =    AutoFeatureExtractor.from_pretrained(a__      )
      self.assertIsInstance(a__			,				a__      )



 def 			snake_case__  (   self		:   Optional[Any]      ):
      with tempfile.TemporaryDirectory() as tmpdirname:
           __magic_name__						       =    WavaVecaConfig()

           # remove feature_extractor_type to make sure config.json alone is enough to load feature processor locally
           __magic_name__						       =    AutoFeatureExtractor.from_pretrained(a__      ).to_dict()

           config_dict.pop('''feature_extractor_type'''      )
           __magic_name__						       =    WavaVecaFeatureExtractor(**a__      )

           # save in new folder
           model_config.save_pretrained(a__      )
           config.save_pretrained(a__      )

           __magic_name__						       =    AutoFeatureExtractor.from_pretrained(a__      )

           # make sure private variable is not incorrectly saved
           __magic_name__						       =    json.loads(config.to_json_string()      )
           self.assertTrue('''_processor_class''' not in dict_as_saved      )

      self.assertIsInstance(a__			,				a__      )



 def 			snake_case__  (   self		:   Optional[Any]      ):
      __magic_name__						       =    AutoFeatureExtractor.from_pretrained(a__      )
      self.assertIsInstance(a__			,				a__      )



 def 			snake_case__  (   self		:   str      ):
      with self.assertRaisesRegex(
          a__			,				'''bert-base is not a local folder and is not a valid model identifier'''      ):
           __magic_name__						       =    AutoFeatureExtractor.from_pretrained('''bert-base'''      )



 def 			snake_case__  (   self		:   str      ):
      with self.assertRaisesRegex(
          a__			,				r'''aaaaaa is not a valid git identifier \(branch name, tag name or commit id\)'''      ):
           __magic_name__						       =    AutoFeatureExtractor.from_pretrained(a__			,				revision='''aaaaaa'''      )



 def 			snake_case__  (   self		:   Union[str, Any]      ):
      with self.assertRaisesRegex(
          a__			,				'''hf-internal-testing/config-no-model does not appear to have a file named preprocessor_config.json.'''			,				):
           __magic_name__						       =    AutoFeatureExtractor.from_pretrained('''hf-internal-testing/config-no-model'''      )



 def 			snake_case__  (   self		:   Dict      ):
      # If remote code is not set, we will time out when asking whether to load the model.
      with self.assertRaises(a__      ):
           __magic_name__						       =    AutoFeatureExtractor.from_pretrained(
               '''hf-internal-testing/test_dynamic_feature_extractor'''      )
      # If remote code is disabled, we can't load this config.
      with self.assertRaises(a__      ):
           __magic_name__						       =    AutoFeatureExtractor.from_pretrained(
               '''hf-internal-testing/test_dynamic_feature_extractor'''			,				trust_remote_code=a__      )

      __magic_name__						       =    AutoFeatureExtractor.from_pretrained(
          '''hf-internal-testing/test_dynamic_feature_extractor'''			,				trust_remote_code=a__      )
      self.assertEqual(feature_extractor.__class__.__name__			,				'''NewFeatureExtractor'''      )

      # Test feature extractor can be reloaded.
      with tempfile.TemporaryDirectory() as tmp_dir:
           feature_extractor.save_pretrained(a__      )
           __magic_name__						       =    AutoFeatureExtractor.from_pretrained(a__			,				trust_remote_code=a__      )
      self.assertEqual(reloaded_feature_extractor.__class__.__name__			,				'''NewFeatureExtractor'''      )



 def 			snake_case__  (   self		:   int      ):
      try:
           AutoConfig.register('''custom'''			,				a__      )
           AutoFeatureExtractor.register(a__			,				a__      )
           # Trying to register something existing in the Transformers library will raise an error
           with self.assertRaises(a__      ):
                AutoFeatureExtractor.register(a__			,				a__      )

           # Now that the config is registered, it can be used as any other config with the auto-API
           __magic_name__						       =    CustomFeatureExtractor.from_pretrained(a__      )
           with tempfile.TemporaryDirectory() as tmp_dir:
                feature_extractor.save_pretrained(a__      )
                __magic_name__						       =    AutoFeatureExtractor.from_pretrained(a__      )
                self.assertIsInstance(a__			,				a__      )

      finally:
           if "custom" in CONFIG_MAPPING._extra_content:
                del CONFIG_MAPPING._extra_content["custom"]
           if CustomConfig in FEATURE_EXTRACTOR_MAPPING._extra_content:
                del FEATURE_EXTRACTOR_MAPPING._extra_content[CustomConfig]



 def 			snake_case__  (   self		:   int      ):






      class   _SCREAMING_SNAKE_CASE   (   __a     ):
       __SCREAMING_SNAKE_CASE					:Optional[int]      	=					True

      try:
           AutoConfig.register('''custom'''			,				a__      )
           AutoFeatureExtractor.register(a__			,				a__      )
           # If remote code is not set, the default is to use local
           __magic_name__						       =    AutoFeatureExtractor.from_pretrained(
               '''hf-internal-testing/test_dynamic_feature_extractor'''      )
           self.assertEqual(feature_extractor.__class__.__name__			,				'''NewFeatureExtractor'''      )
           self.assertTrue(feature_extractor.is_local      )

           # If remote code is disabled, we load the local one.
           __magic_name__						       =    AutoFeatureExtractor.from_pretrained(
               '''hf-internal-testing/test_dynamic_feature_extractor'''			,				trust_remote_code=a__      )
           self.assertEqual(feature_extractor.__class__.__name__			,				'''NewFeatureExtractor'''      )
           self.assertTrue(feature_extractor.is_local      )

           # If remote is enabled, we load from the Hub
           __magic_name__						       =    AutoFeatureExtractor.from_pretrained(
               '''hf-internal-testing/test_dynamic_feature_extractor'''			,				trust_remote_code=a__      )
           self.assertEqual(feature_extractor.__class__.__name__			,				'''NewFeatureExtractor'''      )
           self.assertTrue(not hasattr(a__			,				'''is_local'''      )      )

      finally:
           if "custom" in CONFIG_MAPPING._extra_content:
                del CONFIG_MAPPING._extra_content["custom"]
           if CustomConfig in FEATURE_EXTRACTOR_MAPPING._extra_content:
                del FEATURE_EXTRACTOR_MAPPING._extra_content[CustomConfig]






