Configuring a class with the @serve.deployment programmatically

How severe does this issue affect your experience of using Ray?

  • High: It blocks me to complete my task.

I’m working on a platform where partners use base classes that we provide to add individual functionality. I need to import their inherited class using importlib python package and then deploy it at scale.

However, per the examples provided for ray serve, I need to decorate the class with @serve.deployment before I can deploy it on Ray.

Is there a way to programmatically specify that a specific imported class is a serve deployment?

I’m also not aware of any pythonic way to decorate an imported class

You can also use serve.deployment(...) on functions or classes without the decorator syntax:

from ray import serve

# Both of these are equivalent. Fill in the ... with
# Serve deployment options (e.g. `num_replicas`).

# 1. No decorator syntax
import MyClass

MyClassDeployment = serve.deployment(...)(MyClass)
app = MyClassDeployment.bind()
serve.run(app)

# 2. Decorator syntax
@serve.deployment(...)
class MyClass:
    pass

app = MyClass.bind()
serve.run(app)

Thank you very much!