Skip to content

Commit

Permalink
[Serve] Update AIR Examples to use new API, add linked guide (ray-pro…
Browse files Browse the repository at this point in the history
…ject#27733)

Signed-off-by: Stefan van der Kleij <[email protected]>
  • Loading branch information
simon-mo authored and Stefan van der Kleij committed Aug 18, 2022
1 parent be783cc commit b1738b7
Show file tree
Hide file tree
Showing 9 changed files with 214 additions and 422 deletions.
1 change: 1 addition & 0 deletions doc/source/_toc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,7 @@ parts:
- file: serve/handling-dependencies
- file: serve/http-guide
- file: serve/handle-guide
- file: serve/ray-air-serve-guide
- file: serve/ml-models
- file: serve/batching-guide
- file: serve/model_composition
Expand Down
13 changes: 5 additions & 8 deletions doc/source/ray-air/doc_code/air_key_concepts.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,14 +126,11 @@ async def adapter(request: Request):
return pd.DataFrame.from_dict(content)


serve.start(detached=True)
deployment = PredictorDeployment.options(name="XGBoostService")

deployment.deploy(
XGBoostPredictor, result.checkpoint, batching_params=False, http_adapter=adapter
serve.run(
PredictorDeployment.options(name="XGBoostService").bind(
XGBoostPredictor, result.checkpoint, batching_params=False, http_adapter=adapter
)
)

print(deployment.url)
# __air_deploy_end__

# __air_inference_start__
Expand All @@ -142,6 +139,6 @@ async def adapter(request: Request):
sample_input = test_dataset.take(1)
sample_input = dict(sample_input[0])

output = requests.post(deployment.url, json=[sample_input]).json()
output = requests.post("http:https://localhost:8000/", json=[sample_input]).json()
print(output)
# __air_inference_end__
284 changes: 56 additions & 228 deletions doc/source/ray-air/examples/rl_serving_example.ipynb

Large diffs are not rendered by default.

80 changes: 42 additions & 38 deletions doc/source/ray-air/examples/serving_guide.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -227,12 +227,10 @@
"from ray.serve import PredictorDeployment\n",
"from ray.serve.http_adapters import pandas_read_json\n",
"\n",
"\n",
"serve.start(detached=True)\n",
"deployment = PredictorDeployment.options(name=\"XGBoostService\")\n",
"\n",
"deployment.deploy(\n",
" XGBoostPredictor, result.checkpoint, http_adapter=pandas_read_json\n",
"serve.run(\n",
" PredictorDeployment.options(name=\"XGBoostService\").bind(\n",
" XGBoostPredictor, result.checkpoint, http_adapter=pandas_read_json\n",
" )\n",
")"
]
},
Expand Down Expand Up @@ -272,7 +270,7 @@
"sample_input = test_dataset.take(1)\n",
"sample_input = dict(sample_input[0])\n",
"\n",
"output = requests.post(deployment.url, json=[sample_input]).json()\n",
"output = requests.post(\"http:https://localhost:8000/\", json=[sample_input]).json()\n",
"print(output)"
]
},
Expand Down Expand Up @@ -379,13 +377,12 @@
"from ray import serve\n",
"from ray.serve import PredictorDeployment\n",
"\n",
"# Launch a Ray cluster running Ray Serve\n",
"serve.start()\n",
"\n",
"# Deploy the model behind HTTP endpoint\n",
"PredictorDeployment.options(name=\"Adder\").deploy(\n",
" predictor_cls=AdderPredictor,\n",
" checkpoint=local_checkpoint\n",
"serve.run(\n",
" PredictorDeployment.options(name=\"Adder\").bind(\n",
" predictor_cls=AdderPredictor,\n",
" checkpoint=local_checkpoint\n",
" )\n",
")"
]
},
Expand Down Expand Up @@ -422,7 +419,7 @@
],
"source": [
"import requests\n",
"resp = requests.post(\"http:https://localhost:8000/Adder/\", json={\"array\": [40]})\n",
"resp = requests.post(\"http:https://localhost:8000/\", json={\"array\": [40]})\n",
"resp.raise_for_status()\n",
"resp.json()"
]
Expand Down Expand Up @@ -504,10 +501,12 @@
"source": [
"from ray.serve.http_adapters import pandas_read_json\n",
"\n",
"PredictorDeployment.options(name=\"DataFramePredictor\").deploy(\n",
" predictor_cls=DataFramePredictor,\n",
" checkpoint=local_checkpoint,\n",
" http_adapter=pandas_read_json\n",
"serve.run(\n",
" PredictorDeployment.options(name=\"DataFramePredictor\").bind(\n",
" predictor_cls=DataFramePredictor,\n",
" checkpoint=local_checkpoint,\n",
" http_adapter=pandas_read_json\n",
" )\n",
")"
]
},
Expand Down Expand Up @@ -544,7 +543,7 @@
],
"source": [
"resp = requests.post(\n",
" \"http:https://localhost:8000/DataFramePredictor/\",\n",
" \"http:https://localhost:8000/\",\n",
" json=[{\"base\": 1, \"multiplier\": 2}, {\"base\": 3, \"multiplier\": 4}],\n",
" params={\"orient\": \"records\"},\n",
")\n",
Expand Down Expand Up @@ -599,10 +598,12 @@
"source": [
"from ray.serve.http_adapters import pandas_read_json\n",
"\n",
"PredictorDeployment.options(name=\"DataFramePredictor\").deploy(\n",
" predictor_cls=DataFramePredictor,\n",
" checkpoint=local_checkpoint,\n",
" http_adapter=our_own_http_adapter\n",
"serve.run(\n",
" PredictorDeployment.options(name=\"DataFramePredictor\").bind(\n",
" predictor_cls=DataFramePredictor,\n",
" checkpoint=local_checkpoint,\n",
" http_adapter=our_own_http_adapter\n",
" )\n",
")"
]
},
Expand Down Expand Up @@ -641,7 +642,7 @@
],
"source": [
"resp = requests.post(\n",
" \"http:https://localhost:8000/DataFramePredictor/\",\n",
" \"http:https://localhost:8000/\",\n",
" params={\"base\": 10, \"multiplier\": 4}\n",
")\n",
"resp.raise_for_status()\n",
Expand Down Expand Up @@ -692,9 +693,11 @@
}
],
"source": [
"PredictorDeployment.options(name=\"BatchSizePredictor\").deploy(\n",
" predictor_cls=BatchSizePredictor,\n",
" checkpoint=local_checkpoint,\n",
"serve.run(\n",
" PredictorDeployment.options(name=\"BatchSizePredictor\").bind(\n",
" predictor_cls=BatchSizePredictor,\n",
" checkpoint=local_checkpoint,\n",
" )\n",
")"
]
},
Expand Down Expand Up @@ -766,7 +769,7 @@
" futs = [\n",
" pool.submit(\n",
" requests.post,\n",
" \"http:https://localhost:8000/BatchSizePredictor/\",\n",
" \"http:https://localhost:8000/\",\n",
" json={\"array\": [i]},\n",
" )\n",
" for i in range(10)\n",
Expand Down Expand Up @@ -805,10 +808,12 @@
}
],
"source": [
"PredictorDeployment.options(name=\"BatchSizePredictor\").deploy(\n",
" predictor_cls=BatchSizePredictor,\n",
" checkpoint=local_checkpoint,\n",
" batching_params={\"max_batch_size\": 10, \"batch_wait_timeout_s\": 5}\n",
"serve.run(\n",
" PredictorDeployment.options(name=\"BatchSizePredictor\").bind(\n",
" predictor_cls=BatchSizePredictor,\n",
" checkpoint=local_checkpoint,\n",
" batching_params={\"max_batch_size\": 10, \"batch_wait_timeout_s\": 5}\n",
" )\n",
")"
]
},
Expand Down Expand Up @@ -874,7 +879,7 @@
" futs = [\n",
" pool.submit(\n",
" requests.post,\n",
" \"http:https://localhost:8000/BatchSizePredictor/\",\n",
" \"http:https://localhost:8000/\",\n",
" json={\"array\": [i]},\n",
" )\n",
" for i in range(10)\n",
Expand Down Expand Up @@ -902,7 +907,7 @@
"hash": "3d292ac03404f7ef6351ef2ed79a7f4abdf879ab5af2497c4aeba036dba01cfa"
},
"kernelspec": {
"display_name": "Python 3.6.9 ('base')",
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
Expand All @@ -916,10 +921,9 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.6.9"
},
"orig_nbformat": 4
"version": "3.8.5"
}
},
"nbformat": 4,
"nbformat_minor": 2
"nbformat_minor": 4
}
97 changes: 20 additions & 77 deletions doc/source/ray-air/examples/tfx_tabular_train_to_serve.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -841,19 +841,16 @@
" Returns:\n",
" serve URL.\n",
" \"\"\"\n",
" serve.start(detached=True)\n",
" deployment = PredictorDeployment.options(name=name)\n",
" deployment.deploy(\n",
" TensorflowPredictor,\n",
" checkpoint,\n",
" # This is due to a current limitation on Serve that's\n",
" # being addressed.\n",
" # TODO(xwjiang): Change to True.\n",
" batching_params=dict(max_batch_size=2, batch_wait_timeout_s=5),\n",
" model_definition=model_definition,\n",
" http_adapter=adapter,\n",
" serve.run(\n",
" PredictorDeployment.options(name=name).bind(\n",
" TensorflowPredictor,\n",
" checkpoint,\n",
" batching_params=dict(max_batch_size=2, batch_wait_timeout_s=5),\n",
" model_definition=model_definition,\n",
" http_adapter=adapter,\n",
" )\n",
" )\n",
" return deployment.url\n"
" return f\"http:https://localhost:8000/\""
]
},
{
Expand Down Expand Up @@ -930,69 +927,15 @@
"name": "stdout",
"output_type": "stream",
"text": [
"request0 prediction: 0.004963837098330259 - label: True\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"request1 prediction: 6.652726733591408e-05 - label: False\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"request2 prediction: 0.00018405025184620172 - label: False\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"request3 prediction: 0.00016512417641934007 - label: False\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"request4 prediction: 0.00015515758423134685 - label: False\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"request5 prediction: 5.948602483840659e-05 - label: False\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"request6 prediction: 9.51739348238334e-05 - label: False\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"request7 prediction: 3.4787988170137396e-06 - label: False\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"request8 prediction: 0.00010751552326837555 - label: False\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"request0 prediction: 0.004963837098330259 - label: True\n",
"request1 prediction: 6.652726733591408e-05 - label: False\n",
"request2 prediction: 0.00018405025184620172 - label: False\n",
"request3 prediction: 0.00016512417641934007 - label: False\n",
"request4 prediction: 0.00015515758423134685 - label: False\n",
"request5 prediction: 5.948602483840659e-05 - label: False\n",
"request6 prediction: 9.51739348238334e-05 - label: False\n",
"request7 prediction: 3.4787988170137396e-06 - label: False\n",
"request8 prediction: 0.00010751552326837555 - label: False\n",
"request9 prediction: 0.060329731553792953 - label: True\n"
]
}
Expand All @@ -1012,7 +955,7 @@
"provenance": []
},
"kernelspec": {
"display_name": "Python 3.7.10 ('ray3.7')",
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
Expand All @@ -1026,7 +969,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.7.10"
"version": "3.8.5"
},
"vscode": {
"interpreter": {
Expand Down
Loading

0 comments on commit b1738b7

Please sign in to comment.