-
Notifications
You must be signed in to change notification settings - Fork 5.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Serve][Doc] Add http endpoint for dag pattern doc (#25243)
- Loading branch information
1 parent
905258d
commit 4ad7505
Showing
5 changed files
with
86 additions
and
1 deletion.
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
2 changes: 1 addition & 1 deletion
2
doc/source/serve/deployment-graph/control_flow_based_on_user_inputs.md
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
29 changes: 29 additions & 0 deletions
29
doc/source/serve/deployment-graph/http_endpoint_for_dag_graph.md
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,29 @@ | ||
# Pattern: Http endpoint for dag graph | ||
|
||
This example shows how to configure ingress component of the deployment graph, such as HTTP endpoint prefix, HTTP to python object input adapter. | ||
|
||
## Code | ||
|
||
+++ | ||
|
||
```{eval-rst} | ||
.. literalinclude:: ../doc_code/deployment_graph_dag_http.py | ||
:language: python | ||
``` | ||
|
||
````{note} | ||
1. Serve provide a special driver ([DAGDriver](deployment-graph-e2e-tutorial.html#step-4-driver-deployment-to-handle-http-ingress)) to accept the http request and drive the dag graph execution | ||
2. User can specify the customized http adapter to adopt the cusomized input format | ||
```` | ||
|
||
## Outputs | ||
|
||
Model output1: 1(input) + 0(weight) + 4(len("test")) = 5 \ | ||
Model output2: 1(input) + 1(weight) + 4(len("test")) = 6 \ | ||
So the combine sum is 11 | ||
``` | ||
11 | ||
11 | ||
``` | ||
|
||
+++ |
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,54 @@ | ||
import requests | ||
from pydantic import BaseModel | ||
|
||
import ray | ||
from ray import serve | ||
from ray.serve.drivers import DAGDriver | ||
from ray.experimental.dag.input_node import InputNode | ||
|
||
|
||
ray.init() | ||
serve.start() | ||
|
||
|
||
class ModelInputData(BaseModel): | ||
model_input1: int | ||
model_input2: str | ||
|
||
|
||
@serve.deployment | ||
class Model: | ||
def __init__(self, weight): | ||
self.weight = weight | ||
|
||
def forward(self, input: ModelInputData): | ||
return input.model_input1 + len(input.model_input2) + self.weight | ||
|
||
|
||
@serve.deployment | ||
def combine(value_refs): | ||
return sum(ray.get(value_refs)) | ||
|
||
|
||
with InputNode() as user_input: | ||
model1 = Model.bind(0) | ||
model2 = Model.bind(1) | ||
output1 = model1.forward.bind(user_input) | ||
output2 = model2.forward.bind(user_input) | ||
dag = combine.bind([output1, output2]) | ||
serve_dag = DAGDriver.options(route_prefix="/my-dag").bind( | ||
dag, http_adapter=ModelInputData | ||
) | ||
|
||
dag_handle = serve.run(serve_dag) | ||
|
||
print( | ||
ray.get( | ||
dag_handle.predict.remote(ModelInputData(model_input1=1, model_input2="test")) | ||
) | ||
) | ||
print( | ||
requests.post( | ||
"http://127.0.0.1:8000/my-dag", json={"model_input1": 1, "model_input2": "test"} | ||
).text | ||
) |