ray icon indicating copy to clipboard operation
ray copied to clipboard

[Serve] Call serve.run with a config file path

Open mjsonofharry opened this issue 3 years ago • 5 comments

Description

I would like to have the option to invoke ray.serve.run() with a file path to a Serve config file passed as an argument. For example:

from ray import serve

serve.run(config="config/rayserve.yml")

Right now I can only do this using the subprocess module. For example:

import subprocess

try:
    subprocess.check_call(["serve", "run", "config/rayserve.yml", "--blocking"])
except subprocess.CalledProcessError:
    ...

Alternatively, one could configure all of their deployments using the serve.deployment() decorator arguments and then invoke ray.serve.run() as-is. I'm trying to avoid this because I want all of my configuration to be in the same place (my configuration files).

Use case

The reason I would like to have this feature is that I am implementing dev scripts using the [project.scripts] block in my pyproject.toml configuration file. One of the scripts I'd like to implement is for running the Ray Serve application locally (ie in a development environment on either a laptop or in an Anyscale Workspace).

mjsonofharry avatar Nov 23 '23 15:11 mjsonofharry

@zcin any update on this feature request? This would be helpful for my use case as well.

mathewdhogan avatar May 24 '24 23:05 mathewdhogan

I also need it.

hieubnt235 avatar Jul 07 '25 13:07 hieubnt235

@zcin can I take on this? I'd like to contribute. Thanks

statxc avatar Mar 06 '26 00:03 statxc

Hi @johntaylor-cell, I noticed you unassigned this on Sep 25, and I'd be interested in picking it up. I couldn't find an open PR for it, so before starting implementation, I'd like to align on the API design.

CC @zcin, since you originally triaged this issue, in case you have additional context on the intended design.

Current behavior

Currently, serve run <config.yaml> in python/ray/serve/scripts.py:

  1. Loads the config file and validates it against ServeDeploySchema.
  2. Starts Serve using the config's proxy_location, http_options, grpc_options, controller_options, and tracing configuration.
  3. Calls client.deploy_apps(config) to deploy the applications.

There isn't currently an equivalent Python API for this workflow. serve.run only accepts a single Application created using .bind().

Concern with serve.run(config=...)

A Serve config file can define multiple applications, whereas serve.run returns a single DeploymentHandle for one application.

Also, serve.run is decorated with @PublicAPI(stability="stable"), so I'd prefer not to overload its existing signature without maintainer agreement.

Proposed approach

My proposal is to:

  1. Extract the config loading, validation, Serve startup, and deployment logic from the CLI into a shared internal helper. This would allow both the CLI and the new Python API to use the same code path.
  2. Introduce a small public API, for example, serve.run_config(path, blocking=False), that returns deployment handles keyed by application name.

This would keep the existing serve.run API unchanged while providing a Python equivalent of serve run <config.yaml>.

Questions before I start

  1. API design: Would a new public function like serve.run_config() be acceptable, or would you prefer adding a config= argument to serve.run?
  2. Return value: Should the function return a dictionary of deployment handles keyed by application name, or would you prefer a different return type?
  3. Config-level options: Should it apply config-level http_options, grpc_options, and proxy_location, matching the existing CLI behavior?
  4. Input types: Should it also support an already-parsed dictionary or a ServeDeploySchema instance, in addition to a file path?

If this direction sounds good, I'm happy to open a PR with tests under python/ray/serve/tests/, along with updates to the API reference and production guide.

For transparency, I'm using an AI assistant to help navigate the codebase and draft the proposal, but I'll review and test everything myself before opening a PR.

Thanks!

gamidirohan avatar Nov 19 '26 09:11 gamidirohan

Thanks @gamidirohan, please go ahead.

  1. Add a new serve.run_config(...) marked @PublicAPI(stability="alpha"), and leave serve.run as it is.
  2. Return Dict[str, DeploymentHandle] keyed by app name once every app is RUNNING. Raise on DEPLOY_FAILED, like serve.run does.
  3. Yes, match the CLI.
  4. Accept a path, a dict or a ServeDeploySchema.

It deploys declaratively, like serve deploy: apps from an earlier config that aren't in the new one get deleted. Please document and test that.

johntaylor-cell avatar Nov 19 '26 18:11 johntaylor-cell