





import argparse

import torch

from transformers import HubertConfig, HubertForSequenceClassification, WavaVecaFeatureExtractor, logging


logging.set_verbosity_info()
_UpperCamelCase   :							Optional[Any]     =	logging.get_logger(__name__)

_UpperCamelCase   :							Tuple     =	["""UtteranceLevel"""]
@torch.no_grad()
def 				__UpperCamelCase  (		snake_case    ,	snake_case    ,	snake_case    ,	snake_case     )  ->						int:


   '''simple docstring'''







   __A				 =       torch.load(snake_case    ,	map_location='''cpu'''     )
   if checkpoint["Config"]["downstream_expert"]["modelrc"]["select"] not in SUPPORTED_MODELS:
      raise NotImplementedError(F"The supported s3prl models are {SUPPORTED_MODELS}"     )

   __A				 =       checkpoint['''Downstream''']

   __A				 =       HubertConfig.from_pretrained(snake_case     )
   __A				 =       HubertForSequenceClassification.from_pretrained(snake_case    ,	config=snake_case     )
   __A				 =       WavaVecaFeatureExtractor.from_pretrained(
       snake_case    ,	return_attention_mask=snake_case    ,	do_normalize=snake_case     )

   if hf_congfig.use_weighted_layer_sum:
      __A				 =       checkpoint['''Featurizer''']['''weights''']

   __A				 =       downstream_dict['''projector.weight''']
   __A				 =       downstream_dict['''projector.bias''']
   __A				 =       downstream_dict['''model.post_net.linear.weight''']
   __A				 =       downstream_dict['''model.post_net.linear.bias''']

   hf_feature_extractor.save_pretrained(snake_case     )
   hf_model.save_pretrained(snake_case     )


if __name__ == "__main__":
    _UpperCamelCase   :							str     =	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.""")
    _UpperCamelCase   :							str     =	parser.parse_args()
    convert_saprl_checkpoint(args.base_model_name, args.config_path, args.checkpoint_path, args.model_dump_path)








from __future__ import annotations

import sys
def 				__UpperCamelCase  (		snake_case    ,	snake_case     )  ->						tuple[int, int]:


   '''simple docstring'''







   if abs(snake_case     ) == 1:
      return a, 0
   elif abs(snake_case     ) == 1:
      return 0, b

   __A ,						__A				 =       a, b
   __A ,						__A				 =       1, 0
   __A ,						__A				 =       0, 1

   while remainder != 0:
      __A				 =       old_remainder // remainder
      __A ,						__A				 =       remainder, old_remainder - quotient * remainder
      __A ,						__A				 =       coeff_a, old_coeff_a - quotient * coeff_a
      __A ,						__A				 =       coeff_b, old_coeff_b - quotient * coeff_b

   # sign correction for negative numbers
   if a < 0:
      __A				 =       -old_coeff_a
   if b < 0:
      __A				 =       -old_coeff_b

   return old_coeff_a, old_coeff_b
def 				__UpperCamelCase  (		)  ->						Tuple:


   '''simple docstring'''







   if len(sys.argv     ) < 3:
      print('''2 integer arguments required'''     )
      return 1
   __A				 =       int(sys.argv[1]     )
   __A				 =       int(sys.argv[2]     )
   print(extended_euclidean_algorithm(snake_case    ,	snake_case     )     )
   return 0


if __name__ == "__main__":
    raise SystemExit(main())

