"""simple docstring"""






import argparse

import torch

from transformers import (
    WavaVecaConfig,
    WavaVecaFeatureExtractor,
    WavaVecaForAudioFrameClassification,
    WavaVecaForSequenceClassification,
    WavaVecaForXVector,
    logging,
)


logging.set_verbosity_info()
__A			   = logging.get_logger(__name__)



def SCREAMING_SNAKE_CASE__			(   __UpperCAmelCase       ,    __UpperCAmelCase       ,    __UpperCAmelCase )  ->  List[Any]:
   lowercase__:   List[str]					=      WavaVecaForSequenceClassification.from_pretrained(__UpperCAmelCase       ,    config=__UpperCAmelCase )
   lowercase__:   str					=      downstream_dict['''projector.weight''']
   lowercase__:   Optional[int]					=      downstream_dict['''projector.bias''']
   lowercase__:   Dict					=      downstream_dict['''model.post_net.linear.weight''']
   lowercase__:   str					=      downstream_dict['''model.post_net.linear.bias''']
   return model



def SCREAMING_SNAKE_CASE__			(   __UpperCAmelCase       ,    __UpperCAmelCase       ,    __UpperCAmelCase )  ->  Any:
   lowercase__:   Optional[int]					=      WavaVecaForAudioFrameClassification.from_pretrained(__UpperCAmelCase       ,    config=__UpperCAmelCase )
   lowercase__:   str					=      downstream_dict['''model.linear.weight''']
   lowercase__:   int					=      downstream_dict['''model.linear.bias''']
   return model



def SCREAMING_SNAKE_CASE__			(   __UpperCAmelCase       ,    __UpperCAmelCase       ,    __UpperCAmelCase )  ->  Optional[Any]:
   lowercase__:   int					=      WavaVecaForXVector.from_pretrained(__UpperCAmelCase       ,    config=__UpperCAmelCase )
   lowercase__:   str					=      downstream_dict['''connector.weight''']
   lowercase__:   List[str]					=      downstream_dict['''connector.bias''']
   for i, kernel_size in enumerate(hf_config.tdnn_kernel ):
      lowercase__:   Optional[int]					=      downstream_dict[
          F"""model.framelevel_feature_extractor.module.{i}.kernel.weight"""
      ]
      lowercase__:   List[str]					=      downstream_dict[F"""model.framelevel_feature_extractor.module.{i}.kernel.bias"""]

   lowercase__:   Optional[int]					=      downstream_dict['''model.utterancelevel_feature_extractor.linear1.weight''']
   lowercase__:   Optional[int]					=      downstream_dict['''model.utterancelevel_feature_extractor.linear1.bias''']
   lowercase__:   Dict					=      downstream_dict['''model.utterancelevel_feature_extractor.linear2.weight''']
   lowercase__:   Union[str, Any]					=      downstream_dict['''model.utterancelevel_feature_extractor.linear2.bias''']
   lowercase__:   str					=      downstream_dict['''objective.W''']
   return model



@torch.no_grad()
def SCREAMING_SNAKE_CASE__			(   __UpperCAmelCase       ,    __UpperCAmelCase       ,    __UpperCAmelCase       ,    __UpperCAmelCase )  ->  Union[str, Any]:
   lowercase__:   str					=      torch.load(__UpperCAmelCase       ,    map_location='''cpu''' )

   lowercase__:   str					=      checkpoint['''Downstream''']

   lowercase__:   int					=      WavaVecaConfig.from_pretrained(__UpperCAmelCase )
   lowercase__:   int					=      WavaVecaFeatureExtractor.from_pretrained(
       __UpperCAmelCase       ,    return_attention_mask=__UpperCAmelCase       ,    do_normalize=__UpperCAmelCase )

   lowercase__:   Union[str, Any]					=      hf_config.architectures[0]
   if arch.endswith('''ForSequenceClassification''' ):
      lowercase__:   Dict					=      convert_classification(__UpperCAmelCase       ,    __UpperCAmelCase       ,    __UpperCAmelCase )
   elif arch.endswith('''ForAudioFrameClassification''' ):
      lowercase__:   Dict					=      convert_diarization(__UpperCAmelCase       ,    __UpperCAmelCase       ,    __UpperCAmelCase )
   elif arch.endswith('''ForXVector''' ):
      lowercase__:   Dict					=      convert_xvector(__UpperCAmelCase       ,    __UpperCAmelCase       ,    __UpperCAmelCase )
   else:
      raise NotImplementedError(F"""S3PRL weights conversion is not supported for {arch}""" )

   if hf_config.use_weighted_layer_sum:
      lowercase__:   Any					=      checkpoint['''Featurizer''']['''weights''']

   hf_feature_extractor.save_pretrained(__UpperCAmelCase )
   hf_model.save_pretrained(__UpperCAmelCase )


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

"""simple docstring"""






from __future__ import annotations

from fractions import Fraction



def SCREAMING_SNAKE_CASE__			(   __UpperCAmelCase       ,    __UpperCAmelCase )  ->  bool:
   return (
       num != den and num % 1_0 == den // 1_0 and (num // 1_0) / (den % 1_0) == num / den
   )



def SCREAMING_SNAKE_CASE__			(   __UpperCAmelCase )  ->  list[str]:
   lowercase__:   str					=      []
   lowercase__:   str					=      1_1
   lowercase__:   str					=      int('''1''' + '''0''' * digit_len )
   for num in range(__UpperCAmelCase       ,    __UpperCAmelCase ):
      while den <= 9_9:
         if (num != den) and (num % 1_0 == den // 1_0) and (den % 1_0 != 0):
            if is_digit_cancelling(__UpperCAmelCase       ,    __UpperCAmelCase ):
               solutions.append(F"""{num}/{den}""" )
         den += 1
      num += 1
      lowercase__:   Dict					=      1_0
   return solutions



def SCREAMING_SNAKE_CASE__			(   __UpperCAmelCase = 2 )  ->  int:
   lowercase__:   List[str]					=      1.0
   for fraction in fraction_list(__UpperCAmelCase ):
      lowercase__:   List[str]					=      Fraction(__UpperCAmelCase )
      result *= frac.denominator / frac.numerator
   return int(__UpperCAmelCase )


if __name__ == "__main__":
       print(solution())
