From fbcde1de382a6220f0c5ff9fa192351298cbfbf9 Mon Sep 17 00:00:00 2001 From: lxning <23464292+lxning@users.noreply.github.com> Date: Wed, 10 May 2023 22:33:16 +0000 Subject: [PATCH] remove redundent Download_models.py (#2331) --- docs/large_model_inference.md | 2 +- examples/large_models/deepspeed/opt/Readme.md | 2 +- .../large_models/utils/Download_models.py | 51 ------------------- 3 files changed, 2 insertions(+), 53 deletions(-) delete mode 100644 examples/large_models/utils/Download_models.py diff --git a/docs/large_model_inference.md b/docs/large_model_inference.md index 04f4dd4601..3d9b6dd815 100644 --- a/docs/large_model_inference.md +++ b/docs/large_model_inference.md @@ -181,7 +181,7 @@ torch-model-archiver --model-name bloom --version 1.0 --handler deepspeed_handle * Pre-install the model parallel library such as Deepspeed on the container or host. * Pre-download the model checkpoints. For example, if using HuggingFace pretrained model can be pre-downloaded via [Download_model.py](https://github.com/pytorch/serve/blob/75f66dc557b3b67a3ab56536a37d7aa21582cc04/examples/large_models/deepspeed/opt/Readme.md?plain=1#L7) * Set environment variable [HUGGINGFACE_HUB_CACHE](https://huggingface.co/docs/huggingface_hub/guides/manage-cache#understand-caching) and [TRANSFORMERS_CACHE](https://huggingface.co/transformers/v4.0.1/installation.html#caching-models) - * Download model to the HuggingFace cache dir via tool [Download_model.py](https://github.com/pytorch/serve/blob/75f66dc557b3b67a3ab56536a37d7aa21582cc04/examples/large_models/deepspeed/opt/Readme.md?plain=1#L7) + * Download model to the HuggingFace cache dir via tool [Download_model.py](https://github.com/pytorch/serve/blob/4fe5273cd6f98fb5abc570f802b402ac32ecd105/examples/large_models/Huggingface_pippy/Readme.md?plain=1#L20) #### Tune "[responseTimeout](https://github.com/pytorch/serve/blob/5ee02e4f050c9b349025d87405b246e970ee710b/docs/configuration.md?plain=1#L216)" (see [model config YAML file](https://github.com/pytorch/serve/blob/5ee02e4f050c9b349025d87405b246e970ee710b/model-archiver/README.md?plain=1#L164)) if high model loading or inference latency causes response timeout. diff --git a/examples/large_models/deepspeed/opt/Readme.md b/examples/large_models/deepspeed/opt/Readme.md index 0ee6b6ddd8..cb8c06a976 100644 --- a/examples/large_models/deepspeed/opt/Readme.md +++ b/examples/large_models/deepspeed/opt/Readme.md @@ -7,7 +7,7 @@ This document briefs on serving large HG models on multiple GPUs using deepspeed ### Step 1: Download model ```bash -python ../../utils/Download_models.py --model_path model --model_name facebook/opt-350m --revision main +python ../../utils/Download_model.py --model_path model --model_name facebook/opt-350m --revision main ``` The script prints the path where the model is downloaded as below. diff --git a/examples/large_models/utils/Download_models.py b/examples/large_models/utils/Download_models.py deleted file mode 100644 index 5ad5db3c5f..0000000000 --- a/examples/large_models/utils/Download_models.py +++ /dev/null @@ -1,51 +0,0 @@ -import argparse -import os - -from huggingface_hub import HfApi, snapshot_download - - -def dir_path(path_str): - if os.path.isdir(path_str): - return path_str - elif input(f"{path_str} does not exist, create directory? [y/n]").lower() == "y": - os.makedirs(path_str) - return path_str - else: - raise NotADirectoryError(path_str) - - -class HFModelNotFoundError(Exception): - def __init__(self, model_str): - super().__init__(f"HuggingFace model not found: '{model_str}'") - - -def hf_model(model_str): - api = HfApi() - models = [m.modelId for m in api.list_models()] - if model_str in models: - return model_str - else: - raise HFModelNotFoundError(model_str) - - -parser = argparse.ArgumentParser() -parser.add_argument( - "--model_path", - "-o", - type=dir_path, - default="model", - help="Output directory for downloaded model files", -) -parser.add_argument( - "--model_name", "-m", type=hf_model, required=True, help="HuggingFace model name" -) -parser.add_argument("--revision", "-r", type=str, default="main", help="Revision") -args = parser.parse_args() - -snapshot_path = snapshot_download( - repo_id=args.model_name, - revision=args.revision, - cache_dir=args.model_path, - use_auth_token=False, -) -print(f"Files for '{args.model_name}' is downloaded to '{snapshot_path}'")