Question on Creating Backend with Serve

I’m getting a very strange error when trying to run a very basic ray program.

import ray
from ray import serve
import time


# This will start Ray locally and start Serve on top of it.

def my_backend_func(request):
  return "hello"

serve.create_backend("my_backend", my_backend_func)

Running this gives me the following error: AttributeError: module 'ray.serve' has no attribute 'create_backend' .

If I store the object created by calling serve.start() in a variable, and use that to call .create_backend instead of serve it works. Every single test case, example, etc. does not do this so I was wondering what I might be doing wrong. I was able to recreate this issue on every Linux machine I tried it on, and in both python3.6 and python3.8. Thank you!

Hi @jonahrosenblum,

We’re really sorry you ran into this. I think the problem might be that you’re looking at the documentation for the master branch (the nightly builds), but you’re running the latest pip release (Ray 1.2.0). There was a recent breaking API change in the nightly builds.

Here’s the documentation for Ray 1.2.0: Ray Serve: Scalable and Programmable Serving — Ray v1.2.0
The sample code there should run properly. Alternatively, you can install the nightly builds using these instructions: Installing Ray — Ray v2.0.0.dev0

To check your Ray version, you can run ray --version in the terminal, or check ray.__version__ from Python.

1 Like

Ah, this makes a lot more sense. I appreciate you clearing things up for me!