mirror of
https://github.com/wassname/ray.git
synced 2026-06-27 18:06:25 +08:00
Add Ray Serve to README.rst (#9688)
This commit is contained in:
+76
@@ -16,6 +16,7 @@ Ray is packaged with the following libraries for accelerating machine learning w
|
||||
- `Tune`_: Scalable Hyperparameter Tuning
|
||||
- `RLlib`_: Scalable Reinforcement Learning
|
||||
- `RaySGD <https://docs.ray.io/en/latest/raysgd/raysgd.html>`__: Distributed Training Wrappers
|
||||
- `Ray Serve`_: Scalable and Programmable Serving
|
||||
|
||||
Install Ray with: ``pip install ray``. For nightly wheels, see the
|
||||
`Installation page <https://docs.ray.io/en/latest/installation.html>`__.
|
||||
@@ -182,6 +183,81 @@ RLlib Quick Start
|
||||
.. _`RLlib`: https://docs.ray.io/en/latest/rllib.html
|
||||
|
||||
|
||||
Ray Serve Quick Start
|
||||
---------------------
|
||||
|
||||
.. image:: https://raw.githubusercontent.com/ray-project/ray/master/doc/source/serve/logo.svg
|
||||
:width: 400
|
||||
|
||||
`Ray Serve`_ is a scalable model-serving library built on Ray. It is:
|
||||
|
||||
- Framework Agnostic: Use the same toolkit to serve everything from deep
|
||||
learning models built with frameworks like PyTorch or Tensorflow & Keras
|
||||
to Scikit-Learn models or arbitrary business logic.
|
||||
- Python First: Configure your model serving with pure Python code - no more
|
||||
YAMLs or JSON configs.
|
||||
- Performance Oriented: Turn on batching, pipelining, and GPU acceleration to
|
||||
increase the throughput of your model.
|
||||
- Composition Native: Allow you to create "model pipelines" by composing multiple
|
||||
models together to drive a single prediction.
|
||||
- Horizontally Scalable: Serve can linearly scale as you add more machines. Enable
|
||||
your ML-powered service to handle growing traffic.
|
||||
|
||||
To run this example, you will need to install the following:
|
||||
|
||||
.. code-block:: bash
|
||||
|
||||
$ pip install scikit-learn
|
||||
$ pip install "ray[serve]"
|
||||
|
||||
This example runs serves a scikit-learn gradient boosting classifier.
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
from ray import serve
|
||||
import pickle
|
||||
import requests
|
||||
from sklearn.datasets import load_iris
|
||||
from sklearn.ensemble import GradientBoostingClassifier
|
||||
|
||||
# Train model
|
||||
iris_dataset = load_iris()
|
||||
model = GradientBoostingClassifier()
|
||||
model.fit(iris_dataset["data"], iris_dataset["target"])
|
||||
|
||||
# Define Ray Serve model,
|
||||
class BoostingModel:
|
||||
def __init__(self):
|
||||
self.model = model
|
||||
self.label_list = iris_dataset["target_names"].tolist()
|
||||
|
||||
def __call__(self, flask_request):
|
||||
payload = flask_request.json["vector"]
|
||||
print("Worker: received flask request with data", payload)
|
||||
|
||||
prediction = self.model.predict([payload])[0]
|
||||
human_name = self.label_list[prediction]
|
||||
return {"result": human_name}
|
||||
|
||||
|
||||
# Deploy model
|
||||
serve.init()
|
||||
serve.create_backend("iris:v1", BoostingModel)
|
||||
serve.create_endpoint("iris_classifier", backend="iris:v1", route="/iris")
|
||||
|
||||
# Query it!
|
||||
sample_request_input = {"vector": [1.2, 1.0, 1.1, 0.9]}
|
||||
response = requests.get("http://localhost:8000/iris", json=sample_request_input)
|
||||
print(response.text)
|
||||
# Result:
|
||||
# {
|
||||
# "result": "versicolor"
|
||||
# }
|
||||
|
||||
|
||||
.. _`Ray Serve`: https://docs.ray.io/en/latest/serve/index.html
|
||||
|
||||
|
||||
More Information
|
||||
----------------
|
||||
|
||||
|
||||
Reference in New Issue
Block a user