


"""simple docstring"""







import argparse

import torch

from transformers import (
    WavaVecaFeatureExtractor,
    WavLMConfig,
    WavLMForAudioFrameClassification,
    WavLMForSequenceClassification,
    WavLMForXVector,
    logging,
)


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






def 					a__ (       _UpperCamelCase	,			_UpperCamelCase	,			_UpperCamelCase ):





						"""simple docstring"""

						UpperCAmelCase__		=    WavLMForSequenceClassification.from_pretrained(_UpperCamelCase	,			config=_UpperCamelCase )
						UpperCAmelCase__		=    downstream_dict['''projector.weight''']
						UpperCAmelCase__		=    downstream_dict['''projector.bias''']
						UpperCAmelCase__		=    downstream_dict['''model.post_net.linear.weight''']
						UpperCAmelCase__		=    downstream_dict['''model.post_net.linear.bias''']
						return model






def 					a__ (       _UpperCamelCase	,			_UpperCamelCase	,			_UpperCamelCase ):





						"""simple docstring"""

						UpperCAmelCase__		=    WavLMForAudioFrameClassification.from_pretrained(_UpperCamelCase	,			config=_UpperCamelCase )
						UpperCAmelCase__		=    downstream_dict['''model.linear.weight''']
						UpperCAmelCase__		=    downstream_dict['''model.linear.bias''']
						return model






def 					a__ (       _UpperCamelCase	,			_UpperCamelCase	,			_UpperCamelCase ):





						"""simple docstring"""

						UpperCAmelCase__		=    WavLMForXVector.from_pretrained(_UpperCamelCase	,			config=_UpperCamelCase )
						UpperCAmelCase__		=    downstream_dict['''connector.weight''']
						UpperCAmelCase__		=    downstream_dict['''connector.bias''']
						for i, kernel_size in enumerate(hf_config.tdnn_kernel ):
												UpperCAmelCase__		=    downstream_dict[
												    F"""model.framelevel_feature_extractor.module.{i}.kernel.weight"""
												]
												UpperCAmelCase__		=    downstream_dict[F"""model.framelevel_feature_extractor.module.{i}.kernel.bias"""]

						UpperCAmelCase__		=    downstream_dict['''model.utterancelevel_feature_extractor.linear1.weight''']
						UpperCAmelCase__		=    downstream_dict['''model.utterancelevel_feature_extractor.linear1.bias''']
						UpperCAmelCase__		=    downstream_dict['''model.utterancelevel_feature_extractor.linear2.weight''']
						UpperCAmelCase__		=    downstream_dict['''model.utterancelevel_feature_extractor.linear2.bias''']
						UpperCAmelCase__		=    downstream_dict['''objective.W''']
						return model






@torch.no_grad()
def 					a__ (       _UpperCamelCase	,			_UpperCamelCase	,			_UpperCamelCase	,			_UpperCamelCase ):





						"""simple docstring"""

						UpperCAmelCase__		=    torch.load(_UpperCamelCase	,			map_location='''cpu''' )

						UpperCAmelCase__		=    checkpoint['''Downstream''']

						UpperCAmelCase__		=    WavLMConfig.from_pretrained(_UpperCamelCase )
						UpperCAmelCase__		=    WavaVecaFeatureExtractor.from_pretrained(
						    _UpperCamelCase	,			return_attention_mask=_UpperCamelCase	,			do_normalize=_UpperCamelCase )

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

						if hf_config.use_weighted_layer_sum:
												UpperCAmelCase__		=    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 collections import defaultdict






def 					a__ (       _UpperCamelCase = 5 ):





						"""simple docstring"""

						UpperCAmelCase__		=    defaultdict(_UpperCamelCase )
						UpperCAmelCase__		=    0

						while True:
												UpperCAmelCase__		=    get_digits(_UpperCamelCase )
												freqs[digits].append(_UpperCamelCase )

												if len(freqs[digits] ) == max_base:
																		UpperCAmelCase__		=    freqs[digits][0] ** 3
																		return base

												num += 1






def 					a__ (       _UpperCamelCase ):





						"""simple docstring"""

						return "".join(sorted(str(num**3 ) ) )


if __name__ == "__main__":
						print(f'''{solution() = }''')