From 2400130d6ec8993a71d6b7e0e180902ad0349c50 Mon Sep 17 00:00:00 2001 From: Dipika Sikka Date: Thu, 8 Feb 2024 15:47:29 +0000 Subject: [PATCH 1/2] update readmes to no longer use the depreciated pathway --- src/deepsparse/server/README.md | 12 ++-- src/deepsparse/server/cli.py | 97 +-------------------------- src/deepsparse/transformers/README.md | 10 +-- src/deepsparse/yolact/README.md | 2 +- src/deepsparse/yolo/README.md | 2 +- 5 files changed, 12 insertions(+), 111 deletions(-) diff --git a/src/deepsparse/server/README.md b/src/deepsparse/server/README.md index d4beb3907f..1326ce677a 100644 --- a/src/deepsparse/server/README.md +++ b/src/deepsparse/server/README.md @@ -18,15 +18,15 @@ Usage: deepsparse.server [OPTIONS] COMMAND [ARGS]... 1. `deepsparse.server --config_file [OPTIONS] ` - 2. `deepsparse.server task [OPTIONS] + 2. `deepsparse.server --task [OPTIONS] Examples for using the server: `deepsparse.server --config_file server-config.yaml` - `deepsparse.server task question_answering --batch-size 2` + `deepsparse.server --task question_answering --batch-size 2` - `deepsparse.server task question_answering --host "0.0.0.0"` + `deepsparse.server --task question_answering --host "0.0.0.0"` Example config.yaml for serving: @@ -63,10 +63,6 @@ Usage: deepsparse.server [OPTIONS] COMMAND [ARGS]... Options: --help Show this message and exit. - -Commands: - config Run the server using configuration from a .yaml file. - task Run the server using configuration with CLI options, which can... ``` ---

Note on the latest server release

@@ -104,7 +100,7 @@ Example CLI command for serving a single model for the **question answering** ta ```bash deepsparse.server \ - task question_answering \ + --task question_answering \ --model_path "zoo:nlp/question_answering/bert-base/pytorch/huggingface/squad/12layer_pruned80_quant-none-vnni" ``` diff --git a/src/deepsparse/server/cli.py b/src/deepsparse/server/cli.py index acd7b6897c..1154c010a7 100644 --- a/src/deepsparse/server/cli.py +++ b/src/deepsparse/server/cli.py @@ -12,15 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. -""" -There are two sub-commands for the server: -1. `deepsparse.server config [OPTIONS] ` -2. `deepsparse.server task [OPTIONS] -``` -""" - import os -import warnings from tempfile import TemporaryDirectory from typing import Optional, Union @@ -223,6 +215,7 @@ def main( # if the --model_path option is provided, use that # otherwise if the argument is given and --model_path is not used, use the # argument instead + if model and model_path == "default": model_path = model @@ -268,94 +261,6 @@ def main( server.start_server(host, port, log_level, hot_reload_config=hot_reload_config) -@main.command( - context_settings=dict( - token_normalize_func=lambda x: x.replace("-", "_"), show_default=True - ), -) -@click.argument("config-path", type=str) -@HOST_OPTION -@PORT_OPTION -@LOG_LEVEL_OPTION -@HOT_RELOAD_OPTION -def config( - config_path: str, host: str, port: int, log_level: str, hot_reload_config: bool -): - "[DEPRECATED] Run the server using configuration from a .yaml file." - warnings.simplefilter("always", DeprecationWarning) - warnings.warn( - "Using the `config` sub command is deprecated. " - "Use the `--config_file` argument instead.", - category=DeprecationWarning, - ) - - -@main.command( - context_settings=dict( - token_normalize_func=lambda x: x.replace("-", "_"), show_default=True - ), -) -@click.argument( - "task", - type=click.Choice(SupportedTasks.task_names(), case_sensitive=False), -) -@MODEL_OPTION -@BATCH_OPTION -@CORES_OPTION -@WORKERS_OPTION -@HOST_OPTION -@PORT_OPTION -@LOG_LEVEL_OPTION -@HOT_RELOAD_OPTION -@INTEGRATION_OPTION -def task( - task: str, - model_path: str, - batch_size: int, - num_cores: int, - num_workers: int, - host: str, - port: int, - log_level: str, - hot_reload_config: bool, - integration: str, -): - """ - [DEPRECATED] Run the server using configuration with CLI options, - which can only serve a single model. - """ - - warnings.simplefilter("always", DeprecationWarning) - warnings.warn( - "Using the `task` sub command is deprecated. " - "Use the `--task` argument instead.", - category=DeprecationWarning, - ) - - cfg = ServerConfig( - num_cores=num_cores, - num_workers=num_workers, - integration=integration, - endpoints=[ - EndpointConfig( - task=task, - name=f"{task}", - model=model_path, - batch_size=batch_size, - ) - ], - loggers={}, - ) - - with TemporaryDirectory() as tmp_dir: - config_path = os.path.join(tmp_dir, "server-config.yaml") - with open(config_path, "w") as fp: - yaml.dump(cfg.dict(), fp) - - server = _fetch_server(integration=integration, config=config_path) - server.start_server(host, port, log_level, hot_reload_config=hot_reload_config) - - def _fetch_server(integration: str, config: Union[ServerConfig, str]): if isinstance(config, str): with open(config) as fp: diff --git a/src/deepsparse/transformers/README.md b/src/deepsparse/transformers/README.md index 33cc4e758c..f1e38aee85 100644 --- a/src/deepsparse/transformers/README.md +++ b/src/deepsparse/transformers/README.md @@ -118,7 +118,7 @@ inference = qa_pipeline(question="What's my name?", context="My name is Snorlax" Spinning up: ```bash deepsparse.server \ - task question-answering \ + --task question-answering \ --model_path "zoo:nlp/question_answering/bert-base/pytorch/huggingface/squad/12layer_pruned80_quant-none-vnni" ``` @@ -162,7 +162,7 @@ inference = opt_pipeline("Who is the president of the United States?") Spinning up: ```bash deepsparse.server \ - task text-generation \ + --task text-generation \ --model_path zoo:opt-1.3b-opt_pretrain-pruned50_quantW8A8 ``` @@ -210,7 +210,7 @@ inference = sa_pipeline("I hate it!") Spinning up: ```bash deepsparse.server \ - task sentiment-analysis \ + --task sentiment-analysis \ --model_path "zoo:nlp/sentiment_analysis/bert-base/pytorch/huggingface/sst2/pruned80_quant-none-vnni" ``` @@ -263,7 +263,7 @@ inference = tc_pipeline( Spinning up: ```bash deepsparse.server \ - task text-classification \ + --task text-classification \ --model_path "zoo:nlp/text_classification/distilbert-none/pytorch/huggingface/qqp/pruned80_quant-none-vnni" ``` @@ -316,7 +316,7 @@ inference = tc_pipeline("Drive from California to Texas!") Spinning up: ```bash deepsparse.server \ - task token-classification \ + --task token-classification \ --model_path "zoo:nlp/token_classification/bert-base/pytorch/huggingface/conll2003/pruned90-none" ``` diff --git a/src/deepsparse/yolact/README.md b/src/deepsparse/yolact/README.md index e106f4ae75..f4013d6fa3 100644 --- a/src/deepsparse/yolact/README.md +++ b/src/deepsparse/yolact/README.md @@ -121,7 +121,7 @@ If a `--model_filepath` arg isn't provided, then `zoo:cv/segmentation/yolact-dar Spinning up: ```bash deepsparse.server \ - task yolact \ + --task yolact \ --model_path "zoo:cv/segmentation/yolact-darknet53/pytorch/dbolya/coco/pruned82_quant-none" ``` diff --git a/src/deepsparse/yolo/README.md b/src/deepsparse/yolo/README.md index 0802c2589a..cfbcbfe431 100644 --- a/src/deepsparse/yolo/README.md +++ b/src/deepsparse/yolo/README.md @@ -120,7 +120,7 @@ If a `--model_filepath` arg isn't provided, then `zoo:cv/detection/yolov5-s/pyto Spinning up: ```bash deepsparse.server \ - task yolo \ + --task yolo \ --model_path "zoo:cv/detection/yolov5-s/pytorch/ultralytics/coco/pruned_quant-aggressive_94" ``` From aa0f01cafa3d9323059c282cfe0e87fce77b0305 Mon Sep 17 00:00:00 2001 From: Dipika Sikka Date: Thu, 8 Feb 2024 18:12:56 +0000 Subject: [PATCH 2/2] update to get new ux workflows --- src/deepsparse/server/cli.py | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/deepsparse/server/cli.py b/src/deepsparse/server/cli.py index 1154c010a7..6d3952c5f5 100644 --- a/src/deepsparse/server/cli.py +++ b/src/deepsparse/server/cli.py @@ -11,7 +11,6 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. - import os from tempfile import TemporaryDirectory from typing import Optional, Union @@ -229,6 +228,10 @@ def main( if task is None and config_file is None: raise ValueError("Must specify either --task or --config_file. Found neither") + if config_file is not None: + server = _fetch_server(integration=integration, config=config_file) + server.start_server(host, port, log_level, hot_reload_config=hot_reload_config) + if task is not None: cfg = ServerConfig( num_cores=num_cores, @@ -256,10 +259,6 @@ def main( host, port, log_level, hot_reload_config=hot_reload_config ) - if config_file is not None: - server = _fetch_server(integration=integration, config=config_file) - server.start_server(host, port, log_level, hot_reload_config=hot_reload_config) - def _fetch_server(integration: str, config: Union[ServerConfig, str]): if isinstance(config, str):