-
Notifications
You must be signed in to change notification settings - Fork 237
Inference streaming support #1750
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
ee25235
c799f54
4fa9c7a
fadff06
8c24122
266420e
f23c60f
1451a14
f5a5de3
69b3423
5024f1e
9abd39d
1a7a2b3
43c983b
ab324bf
3de2216
55cf350
7f2140e
482a499
124e6be
1eefd22
d9119ae
245b477
91b23c2
795dd26
3cf01cd
c19fa47
6a01fa5
14a6b25
322fc3e
dd56030
107266c
1ce1ab4
1f7da51
37614c2
c143a50
6a9d134
37ef1e3
c291d7d
26a0812
5435d48
d7d3c74
447e658
12cbccd
d52aca0
2302d99
ccbf945
2cf3cb6
04a2aa8
b632250
37af739
0841790
852cfc1
bf49a3a
499bc9a
d900100
93e3503
0ec59c7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| { | ||
| "name": "text-model", | ||
|
|
||
| "implementation": "text_model.TextModel", | ||
|
|
||
| "versions": ["text-model/v1.2.3"], | ||
| "platform": "mlserver", | ||
| "inputs": [ | ||
| { | ||
| "datatype": "BYTES", | ||
| "name": "prompt", | ||
| "shape": [1] | ||
| } | ||
| ], | ||
| "outputs": [ | ||
| { | ||
| "datatype": "BYTES", | ||
| "name": "output", | ||
| "shape": [1] | ||
| } | ||
| ] | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| { | ||
| "debug": false, | ||
| "parallel_workers": 0, | ||
| "gzip_enabled": false, | ||
| "metrics_endpoint": null | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,45 @@ | ||
| import asyncio | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. should we add an example |
||
| from typing import AsyncIterator | ||
| from mlserver import MLModel | ||
| from mlserver.types import InferenceRequest, InferenceResponse | ||
| from mlserver.codecs import StringCodec | ||
|
|
||
|
|
||
| class TextModel(MLModel): | ||
|
|
||
| async def predict(self, payload: InferenceRequest) -> InferenceResponse: | ||
| text = StringCodec.decode_input(payload.inputs[0])[0] | ||
| return InferenceResponse( | ||
| model_name=self._settings.name, | ||
| outputs=[ | ||
| StringCodec.encode_output( | ||
| name="output", | ||
| payload=[text], | ||
| use_bytes=True, | ||
| ), | ||
| ], | ||
| ) | ||
|
|
||
| async def predict_stream( | ||
| self, payloads: AsyncIterator[InferenceRequest] | ||
| ) -> AsyncIterator[InferenceResponse]: | ||
| payload = [_ async for _ in payloads][0] | ||
| text = StringCodec.decode_input(payload.inputs[0])[0] | ||
| words = text.split(" ") | ||
|
|
||
| split_text = [] | ||
| for i, word in enumerate(words): | ||
| split_text.append(word if i == 0 else " " + word) | ||
|
|
||
| for word in split_text: | ||
| await asyncio.sleep(0.5) | ||
| yield InferenceResponse( | ||
| model_name=self._settings.name, | ||
| outputs=[ | ||
| StringCodec.encode_output( | ||
| name="output", | ||
| payload=[word], | ||
| use_bytes=True, | ||
| ), | ||
| ], | ||
| ) | ||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Uh oh!
There was an error while loading. Please reload this page.