forked from ray-project/ray
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Serve] [Doc] Update intro page (ray-project#27735)
Signed-off-by: Stefan van der Kleij <[email protected]>
- Loading branch information
Showing
6 changed files
with
130 additions
and
105 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import requests | ||
from ray import serve | ||
from ray.serve.drivers import DAGDriver | ||
from ray.serve.dag import InputNode | ||
from ray.serve.http_adapters import json_request | ||
|
||
|
||
# 1. Define the models in our composition graph | ||
@serve.deployment | ||
class Adder: | ||
def __init__(self, increment: int): | ||
self.increment = increment | ||
|
||
def predict(self, inp: int): | ||
return self.increment + inp | ||
|
||
|
||
@serve.deployment | ||
def combine_average(*input_values) -> float: | ||
return {"result": sum(input_values) / len(input_values)} | ||
|
||
|
||
# 2: Define the model composition graph and call it. | ||
with InputNode() as input_node: | ||
adder_1 = Adder.bind(increment=1) | ||
adder_2 = Adder.bind(increment=2) | ||
dag = combine_average.bind( | ||
adder_1.predict.bind(input_node), adder_2.predict.bind(input_node) | ||
) | ||
|
||
serve.run(DAGDriver.bind(dag, http_adapter=json_request)) | ||
|
||
# 3: Query the deployment and print the result. | ||
print(requests.post("https://localhost:8000/", json=100).json()) | ||
# {"result": 101.5} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters