diff --git a/train_ms.py b/train_ms.py index 51e8d61..fb7fa9c 100644 --- a/train_ms.py +++ b/train_ms.py @@ -159,6 +159,30 @@ def run(): config.out_dir: The directory for model assets of this model (for inference). default: `model_assets/{model_name}`. """ + + if args.repo_id is not None: + # First try to upload config.json to check if the repo exists + try: + api.upload_file( + path_or_fileobj=args.config, + path_in_repo=f"Data/{config.model_name}/config.json", + repo_id=hps.repo_id, + ) + except Exception as e: + logger.error(e) + logger.error( + f"Failed to upload files to the repo {hps.repo_id}. Please check if the repo exists and you have logged in using `huggingface-cli login`." + ) + raise e + # Upload Data dir for resuming training + api.upload_folder( + repo_id=hps.repo_id, + folder_path=config.dataset_path, + path_in_repo=f"Data/{config.model_name}", + delete_patterns="*.pth", # Only keep the latest checkpoint + run_as_future=True, + ) + os.makedirs(config.out_dir, exist_ok=True) if not args.skip_default_style: @@ -171,16 +195,6 @@ def run(): os.path.join(config.out_dir, "style_vectors.npy"), ) - if args.repo_id is not None: - # Upload Dataset - api.upload_folder( - repo_id=hps.repo_id, - folder_path=config.dataset_path, - path_in_repo=f"Data/{config.model_name}", - delete_patterns="*.pth", - run_as_future=True, - ) - torch.manual_seed(hps.train.seed) torch.cuda.set_device(local_rank) @@ -501,7 +515,7 @@ def run(): repo_id=hps.repo_id, folder_path=config.dataset_path, path_in_repo=f"Data/{config.model_name}", - delete_patterns="*.pth", + delete_patterns="*.pth", # Only keep the latest checkpoint run_as_future=True, ) future2 = api.upload_folder( @@ -802,7 +816,7 @@ def train_and_evaluate( repo_id=hps.repo_id, folder_path=config.dataset_path, path_in_repo=f"Data/{config.model_name}", - delete_patterns="*.pth", + delete_patterns="*.pth", # Only keep the latest checkpoint run_as_future=True, ) api.upload_folder( diff --git a/train_ms_jp_extra.py b/train_ms_jp_extra.py index f53d401..0cc9d2a 100644 --- a/train_ms_jp_extra.py +++ b/train_ms_jp_extra.py @@ -163,6 +163,30 @@ def run(): config.out_dir: The directory for model assets of this model (for inference). default: `model_assets/{model_name}`. """ + + if args.repo_id is not None: + # First try to upload config.json to check if the repo exists + try: + api.upload_file( + path_or_fileobj=args.config, + path_in_repo=f"Data/{config.model_name}/config.json", + repo_id=hps.repo_id, + ) + except Exception as e: + logger.error(e) + logger.error( + f"Failed to upload files to the repo {hps.repo_id}. Please check if the repo exists and you have logged in using `huggingface-cli login`." + ) + raise e + # Upload Data dir for resuming training + api.upload_folder( + repo_id=hps.repo_id, + folder_path=config.dataset_path, + path_in_repo=f"Data/{config.model_name}", + delete_patterns="*.pth", # Only keep the latest checkpoint + ignore_patterns=f"{config.dataset_path}/raw", # Ignore raw data + run_as_future=True, + ) os.makedirs(config.out_dir, exist_ok=True) if not args.skip_default_style: @@ -175,16 +199,6 @@ def run(): os.path.join(config.out_dir, "style_vectors.npy"), ) - if args.repo_id is not None: - # Upload Dataset - api.upload_folder( - repo_id=hps.repo_id, - folder_path=config.dataset_path, - path_in_repo=f"Data/{config.model_name}", - delete_patterns="*.pth", - run_as_future=True, - ) - torch.manual_seed(hps.train.seed) torch.cuda.set_device(local_rank) @@ -589,7 +603,8 @@ def run(): repo_id=hps.repo_id, folder_path=config.dataset_path, path_in_repo=f"Data/{config.model_name}", - delete_patterns="*.pth", + delete_patterns="*.pth", # Only keep the latest checkpoint + ignore_patterns=f"{config.dataset_path}/raw", # Ignore raw data run_as_future=True, ) future2 = api.upload_folder( @@ -959,7 +974,8 @@ def train_and_evaluate( repo_id=hps.repo_id, folder_path=config.dataset_path, path_in_repo=f"Data/{config.model_name}", - delete_patterns="*.pth", + delete_patterns="*.pth", # Only keep the latest checkpoint + ignore_patterns=f"{config.dataset_path}/raw", # Ignore raw data run_as_future=True, ) api.upload_folder(