code: 
  
  
  
  
  
  
  import json
  import os
  import shutil
  import tempfile
  import unittest
  
  from transformers.models.wavaveca import WavaVecaCTCTokenizer, WavaVecaFeatureExtractor, WavaVecaProcessor
  from transformers.models.wavaveca.tokenization_wavaveca import VOCAB_FILES_NAMES
  from transformers.utils import FEATURE_EXTRACTOR_NAME
  
  from .test_feature_extraction_wavaveca import floats_list
  
  class 					snake_case_							(       unittest.TestCase      ):
  
  
  
  
  
  
  
     """simple docstring"""
  
  
  
     def 			SCREAMING_SNAKE_CASE__				(    self:	Any	)  ->		Union[str, Any]:
  
  
         """simple docstring"""
  
  
  
         _lowercase     =	'<pad> <s> </s> <unk> | E T A O N I H S R D L U M W C F G Y P B V K \' X J Q Z'.split(' '	)
         _lowercase     =	dict(zip(snake_case__   ,       range(len(snake_case__	)	)	)	)
  
         _lowercase     =	{
             'pad_token': '<pad>',
             'unk_token': '<unk>',
             'bos_token': '<s>',
             'eos_token': '</s>',
         }
         _lowercase     =	{
             'feature_size': 1,
             'padding_value': 0.0,
             'sampling_rate': 16_000,
             'return_attention_mask': False,
             'do_normalize': True,
         }
  
         _lowercase     =	tempfile.mkdtemp()
         _lowercase     =	os.path.join(self.tmpdirname   ,       VOCAB_FILES_NAMES['vocab_file']	)
         _lowercase     =	os.path.join(self.tmpdirname   ,       snake_case__	)
         with open(self.vocab_file   ,       'w'   ,       encoding='utf-8'	) as fp:
             fp.write(json.dumps(snake_case__	) + '\n'	)
  
         with open(self.feature_extraction_file   ,       'w'   ,       encoding='utf-8'	) as fp:
             fp.write(json.dumps(snake_case__	) + '\n'	)
  
     def 			SCREAMING_SNAKE_CASE__				(    self:	List[Any]   ,       **snake_case__:	List[Any]	)  ->		int:
  
  
         """simple docstring"""
  
  
  
         _lowercase     =	self.add_kwargs_tokens_map.copy()
         kwargs.update(snake_case__	)
         return WavaVecaCTCTokenizer.from_pretrained(self.tmpdirname   ,       **snake_case__	)
  
     def 			SCREAMING_SNAKE_CASE__				(    self:	Optional[int]   ,       **snake_case__:	Dict	)  ->		Optional[int]:
  
  
         """simple docstring"""
  
  
  
         return WavaVecaFeatureExtractor.from_pretrained(self.tmpdirname   ,       **snake_case__	)
  
     def 			SCREAMING_SNAKE_CASE__				(    self:	List[str]	)  ->		Tuple:
  
  
         """simple docstring"""
  
  
  
         shutil.rmtree(self.tmpdirname	)
  
     def 			SCREAMING_SNAKE_CASE__				(    self:	Tuple	)  ->		List[Any]:
  
  
         """simple docstring"""
  
  
  
         _lowercase     =	self.get_tokenizer()
         _lowercase     =	self.get_feature_extractor()
  
         _lowercase     =	WavaVecaProcessor(tokenizer=snake_case__   ,       feature_extractor=snake_case__	)
  
         processor.save_pretrained(self.tmpdirname	)
         _lowercase     =	WavaVecaProcessor.from_pretrained(self.tmpdirname	)
  
         self.assertEqual(processor.tokenizer.get_vocab()   ,       tokenizer.get_vocab()	)
         self.assertIsInstance(processor.tokenizer   ,       snake_case__	)
  
         self.assertEqual(processor.feature_extractor.to_json_string()   ,       feature_extractor.to_json_string()	)
         self.assertIsInstance(processor.feature_extractor   ,       snake_case__	)
  
     def 			SCREAMING_SNAKE_CASE__				(    self:	int	)  ->		Dict:
  
  
         """simple docstring"""
  
  
  
         _lowercase     =	WavaVecaProcessor(tokenizer=self.get_tokenizer()   ,       feature_extractor=self.get_feature_extractor()	)
         processor.save_pretrained(self.tmpdirname	)
  
         _lowercase     =	self.get_tokenizer(bos_token='(BOS)'   ,       eos_token='(EOS)'	)
         _lowercase     =	self.get_feature_extractor(do_normalize=snake_case__   ,       padding_value=1.0	)
  
         _lowercase     =	WavaVecaProcessor.from_pretrained(
             self.tmpdirname   ,       bos_token='(BOS)'   ,       eos_token='(EOS)'   ,       do_normalize=snake_case__   ,       padding_value=1.0	)
  
         self.assertEqual(processor.tokenizer.get_vocab()   ,       tokenizer_add_kwargs.get_vocab()	)
         self.assertIsInstance(processor.tokenizer   ,       snake_case__	)
  
         self.assertEqual(processor.feature_extractor.to_json_string()   ,       feature_extractor_add_kwargs.to_json_string()	)
         self.assertIsInstance(processor.feature_extractor   ,       snake_case__	)
  
     def 			SCREAMING_SNAKE_CASE__				(    self:	Tuple	)  ->		int:
  
  
         """simple docstring"""
  
  
  
         _lowercase     =	self.get_feature_extractor()
         _lowercase     =	self.get_tokenizer()
  
         _lowercase     =	WavaVecaProcessor(tokenizer=snake_case__   ,       feature_extractor=snake_case__	)
  
         _lowercase     =	floats_list((3, 1_000)	)
  
         _lowercase     =	feature_extractor(snake_case__   ,       return_tensors='np'	)
         _lowercase     =	processor(snake_case__   ,       return_tensors='np'	)
  
         for key in input_feat_extract.keys():
             self.assertAlmostEqual(input_feat_extract[key].sum()   ,       input_processor[key].sum()   ,       delta=1E-2	)
  
     def 			SCREAMING_SNAKE_CASE__				(    self:	str	)  ->		Dict:
  
  
         """simple docstring"""
  
  
  
         _lowercase     =	self.get_feature_extractor()
         _lowercase     =	self.get_tokenizer()
  
         _lowercase     =	WavaVecaProcessor(tokenizer=snake_case__   ,       feature_extractor=snake_case__	)
  
         _lowercase     =	'This is a test string'
  
         _lowercase     =	processor(text=snake_case__	)
  
         _lowercase     =	tokenizer(snake_case__	)
  
         for key in encoded_tok.keys():
             self.assertListEqual(encoded_tok[key]   ,       encoded_processor[key]	)
  
     def 			SCREAMING_SNAKE_CASE__				(    self:	Tuple	)  ->		Dict:
  
  
         """simple docstring"""
  
  
  
         _lowercase     =	self.get_feature_extractor()
         _lowercase     =	self.get_tokenizer()
  
         _lowercase     =	WavaVecaProcessor(tokenizer=snake_case__   ,       feature_extractor=snake_case__	)
  
         _lowercase     =	[[1, 4, 5, 8, 1, 0, 8], [3, 4, 3, 1, 1, 8, 9]]
  
         _lowercase     =	processor.batch_decode(snake_case__	)
         _lowercase     =	tokenizer.batch_decode(snake_case__	)
  
         self.assertListEqual(snake_case__   ,       snake_case__	)
  
     def 			SCREAMING_SNAKE_CASE__				(    self:	Dict	)  ->		int:
  
  
         """simple docstring"""
  
  
  
         _lowercase     =	self.get_feature_extractor()
         _lowercase     =	self.get_tokenizer()
  
         _lowercase     =	WavaVecaProcessor(tokenizer=snake_case__   ,       feature_extractor=snake_case__	)
  
         self.assertListEqual(
             processor.model_input_names   ,       feature_extractor.model_input_names   ,       msg='`processor` and `feature_extractor` model input names do not match'   ,       )
  
style_context: 
  
  
  
  
  
  
  import argparse
  
  import torch
  
  from transformers import HubertConfig, HubertForSequenceClassification, WavaVecaFeatureExtractor, logging
  
  
  logging.set_verbosity_info()
  lowerCamelCase										=  logging.get_logger(__name__)
  
  lowerCamelCase										=  ['''UtteranceLevel''']
  @torch.no_grad()
  def        UpperCAmelCase      (   _lowercase,      _lowercase,      _lowercase,      _lowercase      ):
  
  
      '''simple docstring'''
  
  
  
      _lowercase     =	torch.load(_lowercase,      map_location='cpu'      )
      if checkpoint["Config"]["downstream_expert"]["modelrc"]["select"] not in SUPPORTED_MODELS:
          raise NotImplementedError(f'''The supported s3prl models are {SUPPORTED_MODELS}'''      )
  
      _lowercase     =	checkpoint['Downstream']
  
      _lowercase     =	HubertConfig.from_pretrained(_lowercase      )
      _lowercase     =	HubertForSequenceClassification.from_pretrained(_lowercase,      config=_lowercase      )
      _lowercase     =	WavaVecaFeatureExtractor.from_pretrained(
          _lowercase,      return_attention_mask=_lowercase,      do_normalize=_lowercase      )
  
      if hf_congfig.use_weighted_layer_sum:
          _lowercase     =	checkpoint['Featurizer']['weights']
  
      _lowercase     =	downstream_dict['projector.weight']
      _lowercase     =	downstream_dict['projector.bias']
      _lowercase     =	downstream_dict['model.post_net.linear.weight']
      _lowercase     =	downstream_dict['model.post_net.linear.bias']
  
      hf_feature_extractor.save_pretrained(_lowercase      )
      hf_model.save_pretrained(_lowercase      )
  
  
  if __name__ == "__main__":
     lowerCamelCase										=  argparse.ArgumentParser()
     parser.add_argument(
         '''--base_model_name''', default=None, type=str, help='''Name of the huggingface pretrained base model.'''
     )
     parser.add_argument('''--config_path''', default=None, type=str, help='''Path to the huggingface classifier config.''')
     parser.add_argument('''--checkpoint_path''', default=None, type=str, help='''Path to the s3prl checkpoint.''')
     parser.add_argument('''--model_dump_path''', default=None, type=str, help='''Path to the final converted model.''')
     lowerCamelCase										=  parser.parse_args()
     convert_saprl_checkpoint(args.base_model_name, args.config_path, args.checkpoint_path, args.model_dump_path)
  