Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Cherry Pick] 1.7 TextGen and Server UX Updates #1590

Merged
merged 2 commits into from
Feb 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 16 additions & 3 deletions src/deepsparse/pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -702,23 +702,26 @@ def text_generation_pipeline(*args, **kwargs) -> "Pipeline":
:return: text generation pipeline with the given args and
kwargs passed to Pipeline.create
"""
return Pipeline.create("text_generation", *args, **kwargs)
kwargs = _check_model_path_arg(*args, **kwargs)
return Pipeline.create("text_generation", **kwargs)


def code_generation_pipeline(*args, **kwargs) -> "Pipeline":
"""
:return: text generation pipeline with the given args and
kwargs passed to Pipeline.create
"""
return Pipeline.create("code_generation", *args, **kwargs)
kwargs = _check_model_path_arg(*args, **kwargs)
return Pipeline.create("code_generation", **kwargs)


def chat_pipeline(*args, **kwargs) -> "Pipeline":
"""
:return: text generation pipeline with the given args and
kwargs passed to Pipeline.create
"""
return Pipeline.create("chat", *args, **kwargs)
kwargs = _check_model_path_arg(*args, **kwargs)
return Pipeline.create("chat", **kwargs)


TextGeneration = text_generation_pipeline
Expand Down Expand Up @@ -802,3 +805,13 @@ def zero_shot_text_classification_pipeline(*args, **kwargs) -> "Pipeline":
is returned depends on the value of the passed model_scheme argument.
"""
return Pipeline.create("zero_shot_text_classification", *args, **kwargs)


def _check_model_path_arg(*args, **kwargs):
if args:
if len(args) > 1 or "model_path" in kwargs or "model" in kwargs:
raise ValueError(
"Only the model path can be provided as a non-kwarg argument"
)
kwargs["model_path"] = args[0]
return kwargs
32 changes: 14 additions & 18 deletions src/deepsparse/server/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@
),
)

MODEL_ARG = click.argument("model", type=str, default=None, required=False)
MODEL_OPTION = click.option(
"--model_path",
type=str,
Expand Down Expand Up @@ -152,6 +153,7 @@
@PORT_OPTION
@LOG_LEVEL_OPTION
@HOT_RELOAD_OPTION
@MODEL_ARG
@MODEL_OPTION
@BATCH_OPTION
@CORES_OPTION
Expand All @@ -167,6 +169,7 @@ def main(
log_level: str,
hot_reload_config: bool,
model_path: str,
model: str,
batch_size: int,
num_cores: int,
num_workers: int,
Expand Down Expand Up @@ -216,6 +219,17 @@ def main(
...
```
"""
# the server cli can take a model argument or --model_path option
# 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

if integration == INTEGRATION_OPENAI:
if task is None or task != "text_generation":
task = "text_generation"

if ctx.invoked_subcommand is not None:
return

Expand Down Expand Up @@ -254,24 +268,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-file", type=str)
@HOST_OPTION
@PORT_OPTION
@LOG_LEVEL_OPTION
@HOT_RELOAD_OPTION
def openai(
config_file: str, host: str, port: int, log_level: str, hot_reload_config: bool
):

server = OpenAIServer(server_config=config_file)
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
Expand Down
Loading