mirror of
https://github.com/vale981/ray
synced 2025-03-06 10:31:39 -05:00
[Serve] Add a minimal cli (#5854)
* Add a minimal cli * Integrate serve_cli with ray scripts
This commit is contained in:
parent
085a6713a0
commit
e08b5d0cae
2 changed files with 57 additions and 0 deletions
50
python/ray/experimental/serve/scripts.py
Normal file
50
python/ray/experimental/serve/scripts.py
Normal file
|
@ -0,0 +1,50 @@
|
|||
import json
|
||||
|
||||
import click
|
||||
|
||||
import ray
|
||||
import ray.experimental.serve as serve
|
||||
|
||||
|
||||
@click.group("serve", help="Commands working with ray serve")
|
||||
def serve_cli():
|
||||
pass
|
||||
|
||||
|
||||
@serve_cli.command(help="Initialize ray serve components")
|
||||
def init():
|
||||
ray.init(address="auto")
|
||||
serve.init(blocking=True)
|
||||
|
||||
|
||||
@serve_cli.command(help="Split traffic for a endpoint")
|
||||
@click.argument("endpoint", required=True, type=str)
|
||||
# TODO(simon): Make traffic dictionary more ergonomic. e.g.
|
||||
# --traffic backend1=0.5 --traffic backend2=0.5
|
||||
@click.option(
|
||||
"--traffic",
|
||||
required=True,
|
||||
type=str,
|
||||
help="Traffic dictionary in JSON format")
|
||||
def split(endpoint, traffic):
|
||||
ray.init(address="auto")
|
||||
serve.init()
|
||||
|
||||
serve.split(endpoint, json.loads(traffic))
|
||||
|
||||
|
||||
@serve_cli.command(help="Scale the number of replicas for a backend")
|
||||
@click.argument("backend", required=True, type=str)
|
||||
@click.option(
|
||||
"--num-replicas",
|
||||
required=True,
|
||||
type=int,
|
||||
help="New number of replicas to set")
|
||||
def scale(backend_tag, num_replicas):
|
||||
if num_replicas <= 0:
|
||||
click.Abort(
|
||||
"Cannot set number of replicas to be smaller or equal to 0.")
|
||||
ray.init(address="auto")
|
||||
serve.init()
|
||||
|
||||
serve.scale(backend_tag, num_replicas)
|
|
@ -827,6 +827,13 @@ cli.add_command(timeline)
|
|||
cli.add_command(project_cli)
|
||||
cli.add_command(session_cli)
|
||||
|
||||
try:
|
||||
from ray.experimental.serve.scripts import serve_cli
|
||||
cli.add_command(serve_cli)
|
||||
except Exception as e:
|
||||
logger.debug(
|
||||
"Integrating ray serve command line tool failed with {}".format(e))
|
||||
|
||||
|
||||
def main():
|
||||
return cli()
|
||||
|
|
Loading…
Add table
Reference in a new issue