mrcuddle commited on
Commit
2e9ca00
·
verified ·
1 Parent(s): ee2156c

Update hf_merge.py

Browse files
Files changed (1) hide show
  1. hf_merge.py +17 -19
hf_merge.py CHANGED
@@ -3,7 +3,7 @@ import shutil
3
  import argparse
4
  import requests
5
  from tqdm import tqdm
6
- from huggingface_hub import HfApi, hf_hub_download, create_repo
7
  from merge import merge_folder, map_tensors_to_files, copy_nontensor_files, save_tensor_map
8
  import logging
9
 
@@ -47,7 +47,6 @@ class RepositoryManager:
47
  file_url = f"https://huggingface.co/{repo_name}/resolve/main/{file_path}"
48
  hf_hub_download(repo_id=repo_name, filename=file_path, cache_dir=path, local_dir=path)
49
 
50
-
51
  def delete_repo(self, path):
52
  """
53
  Delete a repository from the local filesystem.
@@ -114,24 +113,26 @@ class ModelMerger:
114
  copy_nontensor_files(base_model_path, output_dir)
115
  save_tensor_map(self.tensor_map, output_dir)
116
 
117
-
118
-
119
  def upload_model(self, output_dir, commit_message):
120
- """
121
- Upload the merged model to HuggingFace.
122
-
123
- Args:
124
- output_dir (str): The path to the output directory containing the merged model.
125
- commit_message (str): The commit message for the upload.
126
- """
127
-
128
- # Upload the folder to the repository
129
- self.api.upload_folder(
 
 
 
 
130
  repo_id=self.repo_id,
131
  folder_path=output_dir,
132
  commit_message=commit_message,
133
  token=self.token
134
- )
135
  url = f"https://huggingface.co/{self.repo_id}"
136
  logging.info(f"Model uploaded successfully to {url}")
137
  return url
@@ -139,6 +140,7 @@ class ModelMerger:
139
  logging.error(f"Error: Failed to upload to {self.repo_id}.")
140
  logging.error(e)
141
  return ""
 
142
  def get_max_vocab_size(repo_list):
143
  """
144
  Get the maximum vocabulary size from a list of repositories.
@@ -222,7 +224,3 @@ def main():
222
 
223
  if __name__ == "__main__":
224
  main()
225
-
226
-
227
- if __name__ == "__main__":
228
- main()
 
3
  import argparse
4
  import requests
5
  from tqdm import tqdm
6
+ from huggingface_hub import HfApi, hf_hub_download
7
  from merge import merge_folder, map_tensors_to_files, copy_nontensor_files, save_tensor_map
8
  import logging
9
 
 
47
  file_url = f"https://huggingface.co/{repo_name}/resolve/main/{file_path}"
48
  hf_hub_download(repo_id=repo_name, filename=file_path, cache_dir=path, local_dir=path)
49
 
 
50
  def delete_repo(self, path):
51
  """
52
  Delete a repository from the local filesystem.
 
113
  copy_nontensor_files(base_model_path, output_dir)
114
  save_tensor_map(self.tensor_map, output_dir)
115
 
 
 
116
  def upload_model(self, output_dir, commit_message):
117
+ """
118
+ Upload the merged model to HuggingFace.
119
+
120
+ Args:
121
+ output_dir (str): The path to the output directory containing the merged model.
122
+ commit_message (str): The commit message for the upload.
123
+ """
124
+ try:
125
+ # Create a new repository if it doesn't exist
126
+ if not self.api.repo_exists(repo_id=self.repo_id, token=self.token):
127
+ self.api.create_repo(repo_id=self.repo_id, token=self.token, private=True)
128
+
129
+ # Upload the folder to the repository
130
+ self.api.upload_folder(
131
  repo_id=self.repo_id,
132
  folder_path=output_dir,
133
  commit_message=commit_message,
134
  token=self.token
135
+ )
136
  url = f"https://huggingface.co/{self.repo_id}"
137
  logging.info(f"Model uploaded successfully to {url}")
138
  return url
 
140
  logging.error(f"Error: Failed to upload to {self.repo_id}.")
141
  logging.error(e)
142
  return ""
143
+
144
  def get_max_vocab_size(repo_list):
145
  """
146
  Get the maximum vocabulary size from a list of repositories.
 
224
 
225
  if __name__ == "__main__":
226
  main()