





from collections import deque







def 			_SCREAMING_SNAKE_CASE    (       a  )				->				List[str]:
					return input(a  ).strip().split(' '  )







def 			_SCREAMING_SNAKE_CASE    (       a ,						a  )				->				dict[int, list[int]]:
					__A     :						dict[int, list[int]]          =    {}
					for i in range(a  ):
										__A     :						List[str]          =    []

					for e in range(a  ):
										__A   ,    __A     :						List[str]          =    (int(a  ) for i in _input(F"""Edge {e + 1}: <node1> <node2> """  ))
										graph[x].append(a  )
					return graph







def 			_SCREAMING_SNAKE_CASE    (       a ,						a  )				->				dict[int, list[int]]:
					__A     :						dict[int, list[int]]          =    {}
					for i in range(a  ):
										__A     :						Any          =    []

					for e in range(a  ):
										__A   ,    __A     :						Union[str, Any]          =    (int(a  ) for i in _input(F"""Edge {e + 1}: <node1> <node2> """  ))
										graph[x].append(a  )
										graph[y].append(a  )
					return graph







def 			_SCREAMING_SNAKE_CASE    (       a ,						a  )				->				dict[int, list[tuple[int, int]]]:
					__A     :						dict[int, list[tuple[int, int]]]          =    {}
					for i in range(a  ):
										__A     :						Optional[int]          =    []

					for e in range(a  ):
										__A   ,    __A   ,    __A     :						Tuple          =    (int(a  ) for i in _input(F"""Edge {e + 1}: <node1> <node2> <weight> """  ))
										graph[x].append((y, w)  )
										graph[y].append((x, w)  )
					return graph


if __name__ == "__main__":
				UpperCAmelCase  ,			UpperCAmelCase						:       Optional[Any]        =					(int(i) for i in _input('''Number of nodes and edges: '''))

				UpperCAmelCase						:       Optional[int]        =					int(
				    _input(
				        '''Press 1 or 2 or 3 \n'''
				        '''1. Unweighted directed \n'''
				        '''2. Unweighted undirected \n'''
				        '''3. Weighted undirected \n'''
				    )[0]
				)

				UpperCAmelCase						:       List[str]        =					{
				    1: initialize_unweighted_directed_graph,
				    2: initialize_unweighted_undirected_graph,
				    3: initialize_weighted_undirected_graph,
				}[graph_choice](n, m)







def 			_SCREAMING_SNAKE_CASE    (       a ,						a  )				->				int:
					__A   ,    __A     :						Any          =    {s}, [s]
					print(a  )
					while _s:
										__A     :						Optional[Any]          =    0
										for i in g[_s[-1]]:
															if i not in vis:
																				_s.append(a  )
																				vis.add(a  )
																				__A     :						Optional[int]          =    1
																				print(a  )
																				break
										if not flag:
															_s.pop()







def 			_SCREAMING_SNAKE_CASE    (       a ,						a  )				->				Union[str, Any]:
					__A   ,    __A     :						Any          =    {s}, deque([s]  )
					print(a  )
					while q:
										__A     :						List[str]          =    q.popleft()
										for v in g[u]:
															if v not in vis:
																				vis.add(a  )
																				q.append(a  )
																				print(a  )







def 			_SCREAMING_SNAKE_CASE    (       a ,						a  )				->				List[str]:
					__A   ,    __A   ,    __A     :						List[Any]          =    {s: 0}, set(), {s: 0}
					while True:
										if len(a  ) == len(a  ) - 1:
															break
										__A     :						Tuple          =    10_00_00
										for i in dist:
															if i not in known and dist[i] < mini:
																				__A     :						Union[str, Any]          =    dist[i]
																				__A     :						int          =    i
										known.add(a  )
										for v in g[u]:
															if v[0] not in known and dist[u] + v[1] < dist.get(v[0] ,						10_00_00  ):
																				__A     :						int          =    dist[u] + v[1]
																				__A     :						List[str]          =    u
					for i in dist:
										if i != s:
															print(dist[i]  )







def 			_SCREAMING_SNAKE_CASE    (       a ,						a=None ,						a=None  )				->				Any:
					if q is None:
										__A     :						List[str]          =    [1]
					if ind is None:
										__A     :						Any          =    [0] * (len(a  ) + 1)  # SInce oth Index is ignored
										for u in g:
															for v in g[u]:
																				ind[v] += 1
										__A     :						Tuple          =    deque()
										for i in g:
															if ind[i] == 0:
																				q.append(a  )
					if len(a  ) == 0:
										return
					__A     :						List[str]          =    q.popleft()
					print(a  )
					for w in g[v]:
										ind[w] -= 1
										if ind[w] == 0:
															q.append(a  )
					topo(a ,						a ,						a  )







def 			_SCREAMING_SNAKE_CASE    (       )				->				str:
					__A     :						int          =    input().strip()
					__A     :						List[str]          =    []
					for _ in range(a  ):
										a.append(map(a ,						input().strip().split()  )  )
					return a, n







def 			_SCREAMING_SNAKE_CASE    (       a  )				->				Dict:
					((__A)   ,    (__A))     :						int          =    a_and_n
					__A     :						Optional[int]          =    list(a  )
					__A     :						Union[str, Any]          =    [[0] * n for i in range(a  )]
					for k in range(a  ):
										for i in range(a  ):
															for j in range(a  ):
																				if dist[i][j] > dist[i][k] + dist[k][j]:
																									__A     :						str          =    dist[i][k] + dist[k][j]
																									__A     :						Dict          =    k
					print(a  )







def 			_SCREAMING_SNAKE_CASE    (       a ,						a  )				->				List[Any]:
					__A   ,    __A   ,    __A     :						Dict          =    {s: 0}, set(), {s: 0}
					while True:
										if len(a  ) == len(a  ) - 1:
															break
										__A     :						Dict          =    10_00_00
										for i in dist:
															if i not in known and dist[i] < mini:
																				__A     :						Dict          =    dist[i]
																				__A     :						Optional[Any]          =    i
										known.add(a  )
										for v in g[u]:
															if v[0] not in known and v[1] < dist.get(v[0] ,						10_00_00  ):
																				__A     :						Optional[Any]          =    v[1]
																				__A     :						Union[str, Any]          =    u
					return dist







def 			_SCREAMING_SNAKE_CASE    (       )				->				Tuple:
					__A   ,    __A     :						List[Any]          =    map(a ,						input().split(' '  )  )
					__A     :						List[Any]          =    []
					for _ in range(a  ):
										edges.append(map(a ,						input().split(' '  )  )  )
					return edges, n







def 			_SCREAMING_SNAKE_CASE    (       a  )				->				Dict:
					# Sort edges on the basis of distance
					((__A)   ,    (__A))     :						int          =    e_and_n
					e.sort(reverse=a ,						key=lambda a  : x[2]  )
					__A     :						Dict          =    [{i} for i in range(1 ,						n + 1  )]
					while True:
										if len(a  ) == 1:
															break
										print(a  )
										__A     :						Optional[int]          =    e.pop()
										for i in range(len(a  )  ):
															if x[0] in s[i]:
																				break
										for j in range(len(a  )  ):
															if x[1] in s[j]:
																				if i == j:
																									break
																				s[j].update(s[i]  )
																				s.pop(a  )
																				break







def 			_SCREAMING_SNAKE_CASE    (       a  )				->				List[Any]:
					__A     :						str          =    []
					for node in graph:
										if not graph[node]:
															isolated.append(a  )
					return isolated











import argparse

import torch

from transformers import HubertConfig, HubertForSequenceClassification, WavaVecaFeatureExtractor, logging


logging.set_verbosity_info()
UpperCAmelCase						:       Tuple        =					logging.get_logger(__name__)

UpperCAmelCase						:       List[Any]        =					['''UtteranceLevel''']







@torch.no_grad()
def 			_SCREAMING_SNAKE_CASE    (       a ,						a ,						a ,						a  )				->				List[str]:
					__A     :						Any          =    torch.load(a ,						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     :						Dict          =    checkpoint['Downstream']

					__A     :						Optional[Any]          =    HubertConfig.from_pretrained(a  )
					__A     :						Tuple          =    HubertForSequenceClassification.from_pretrained(a ,						config=a  )
					__A     :						str          =    WavaVecaFeatureExtractor.from_pretrained(
					    a ,						return_attention_mask=a ,						do_normalize=a  )

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

					__A     :						Dict          =    downstream_dict['projector.weight']
					__A     :						int          =    downstream_dict['projector.bias']
					__A     :						List[Any]          =    downstream_dict['model.post_net.linear.weight']
					__A     :						int          =    downstream_dict['model.post_net.linear.bias']

					hf_feature_extractor.save_pretrained(a  )
					hf_model.save_pretrained(a  )


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




