Skip to content

Commit

Permalink
Delete models from old location for huggingface download
Browse files Browse the repository at this point in the history
  • Loading branch information
vmpuri committed Oct 9, 2024
1 parent a4aaccf commit 5bf2315
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions torchchat/cli/download.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,14 @@
if os.environ.get("HF_HUB_ENABLE_HF_TRANSFER", None) is None:
os.environ["HF_HUB_ENABLE_HF_TRANSFER"] = "1"

# For each model with huggingface distribution path, clean up the old location.
def _delete_old_hf_models(models_dir: Path):
for model_config in load_model_configs().values():
if model_config.distribution_channel == ModelDistributionChannel.HuggingFaceSnapshot:
if os.path.exists(models_dir / model_config.name):
print(f"Cleaning up old model artifacts in {models_dir / model_config.name}. New artifacts will be downloaded to {HUGGINGFACE_HOME_PATH}")
shutil.rmtree(models_dir / model_config.name)

def _download_hf_snapshot(
model_config: ModelConfig, hf_token: Optional[str]
):
Expand Down Expand Up @@ -273,4 +281,5 @@ def where_main(args) -> None:

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

0 comments on commit 5bf2315

Please sign in to comment.