import os
from pathlib import Path
from typing import Dict, List

import fire
import torch

from transformers import AutoModelForSeqaSeqLM, AutoTokenizer
from transformers.utils.logging import get_logger


__snake_case			      =    get_logger(__name__)





def   lowerCAmelCase_ (				__lowerCAmelCase		,					__lowerCAmelCase						)->  Optional[int]:






      '''simple docstring'''





      if text.startswith(__lowerCAmelCase						):
            return text[len(__lowerCAmelCase						) :]
      return text  # or whatever





def   lowerCAmelCase_ (				__lowerCAmelCase						)->  List[str]:






      '''simple docstring'''





      return {remove_prefix(__lowerCAmelCase		,					'''model.'''						): v for k, v in sd.items()}





def   lowerCAmelCase_ (				__lowerCAmelCase						)->  Tuple:






      '''simple docstring'''





      UpperCAmelCase    : Any      ={}
      for k in state_dicts[0].keys():
            UpperCAmelCase    : int      =[sd[k] for sd in state_dicts]
            UpperCAmelCase    : Tuple      =sum(__lowerCAmelCase						) / len(__lowerCAmelCase						)
            assert isinstance(__lowerCAmelCase		,					torch.Tensor						)
            UpperCAmelCase    : Tuple      =new_t
      return new_sd





def   lowerCAmelCase_ (				__lowerCAmelCase		,					__lowerCAmelCase		,					__lowerCAmelCase						)->  None:






      '''simple docstring'''





      UpperCAmelCase    : Any      =AutoModelForSeqaSeqLM.from_pretrained(__lowerCAmelCase						)
      if os.path.isfile(__lowerCAmelCase						):
            UpperCAmelCase    : Union[str, Any]      =[pl_ckpt_path]
      else:
            assert os.path.isdir(__lowerCAmelCase						)
            UpperCAmelCase    : str      =list(Path(__lowerCAmelCase						).glob('''*.ckpt'''						)						)
            assert ckpt_files, f'''could not find any ckpt files inside the {pl_ckpt_path} directory'''

      if len(__lowerCAmelCase						) > 1:
            logger.info(f'''averaging the weights of {ckpt_files}'''						)

      UpperCAmelCase    : int      =[sanitize(torch.load(__lowerCAmelCase		,					map_location='''cpu'''						)['''state_dict''']						) for x in ckpt_files]
      UpperCAmelCase    : Optional[int]      =average_state_dicts(__lowerCAmelCase						)

      UpperCAmelCase  ,						UpperCAmelCase    : int      =hf_model.load_state_dict(__lowerCAmelCase		,					strict=__lowerCAmelCase						)
      assert not missing, f'''missing keys: {missing}'''
      hf_model.save_pretrained(__lowerCAmelCase						)
      try:
            UpperCAmelCase    : str      =AutoTokenizer.from_pretrained(__lowerCAmelCase						)
            tok.save_pretrained(__lowerCAmelCase						)
      except Exception:
            pass
            # dont copy tokenizer if cant


if __name__ == "__main__":
     fire.Fire(convert_pl_to_hf)

def   lowerCAmelCase_ (				__lowerCAmelCase		,					__lowerCAmelCase						)->  list[tuple[int, int, int]]:






      '''simple docstring'''





      UpperCAmelCase    : List[Any]      =sorted(__lowerCAmelCase		,					key=lambda __lowerCAmelCase						: edge[2]						)

      UpperCAmelCase    : Union[str, Any]      =list(range(__lowerCAmelCase						)						)

      def find_parent(__lowerCAmelCase						):
            if i != parent[i]:
                  UpperCAmelCase    : Optional[int]      =find_parent(parent[i]						)
            return parent[i]

      UpperCAmelCase    : Optional[Any]      =0
      UpperCAmelCase    : List[str]      =[]

      for edge in edges:
            UpperCAmelCase    : Dict      =find_parent(edge[0]						)
            UpperCAmelCase    : Optional[Any]      =find_parent(edge[1]						)
            if parent_a != parent_b:
                  minimum_spanning_tree_cost += edge[2]
                  minimum_spanning_tree.append(__lowerCAmelCase						)
                  UpperCAmelCase    : Optional[Any]      =parent_b

      return minimum_spanning_tree


if __name__ == "__main__":  # pragma: no cover
     __snake_case      ,  __snake_case			      =    list(map(int, input().strip().split()))
     __snake_case			      =    []

     for _ in range(num_edges):
          __snake_case      ,  __snake_case      ,  __snake_case			      =    (int(x) for x in input().strip().split())
          edges.append((nodea, nodea, cost))

     kruskal(num_nodes, edges)
