Skip to content

Commit 5bf2315

Browse files
author
vmpuri
committed
Delete models from old location for huggingface download
1 parent a4aaccf commit 5bf2315

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

torchchat/cli/download.py

+9
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,14 @@
2525
if os.environ.get("HF_HUB_ENABLE_HF_TRANSFER", None) is None:
2626
os.environ["HF_HUB_ENABLE_HF_TRANSFER"] = "1"
2727

28+
# For each model with huggingface distribution path, clean up the old location.
29+
def _delete_old_hf_models(models_dir: Path):
30+
for model_config in load_model_configs().values():
31+
if model_config.distribution_channel == ModelDistributionChannel.HuggingFaceSnapshot:
32+
if os.path.exists(models_dir / model_config.name):
33+
print(f"Cleaning up old model artifacts in {models_dir / model_config.name}. New artifacts will be downloaded to {HUGGINGFACE_HOME_PATH}")
34+
shutil.rmtree(models_dir / model_config.name)
35+
2836
def _download_hf_snapshot(
2937
model_config: ModelConfig, hf_token: Optional[str]
3038
):
@@ -273,4 +281,5 @@ def where_main(args) -> None:
273281

274282
# Subcommand to download model artifacts.
275283
def download_main(args) -> None:
284+
_delete_old_hf_models(args.model_directory)
276285
download_and_convert(args.model, args.model_directory, args.hf_token)

0 commit comments

Comments
 (0)