-
Notifications
You must be signed in to change notification settings - Fork 183
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
Sherif akoush/mlsv 42/add alibi explain runtime #320
Changes from 71 commits
1e592ce
9c10981
43b1db6
e472624
af1810e
36acbc5
56d4552
d439648
7bd1bb9
85eb8fb
b469a3f
d90e061
2f48edb
a9ffe5b
1657a2a
d82b0ee
f519352
44698e9
399bb4a
0f420aa
5ff6390
bfc4d2a
a3eb52d
6cf0fe1
7b535db
8c618a7
b64e3ca
6501fcc
b3e8aa8
ebb2b1a
5d68820
b5f8550
99c065e
0d1c9b1
fe197c1
c324c20
9f29391
fb3701d
0fe7fa9
5874335
4b4441a
77bcd5e
7e08766
6daf1aa
c008320
09547b3
d801eb0
e16f5c5
de42b34
642c0e4
cea0446
86e72dd
bc48764
37332e3
b6d27af
2f98c9c
f03a576
82bbc04
7055ea0
0384120
1af15b6
1cc91c9
e82e1cf
588f178
e396277
fc1c255
402df44
acfb093
012f620
5d0b7a4
7eba4a0
ed5f2a3
602cd1f
6925b0a
81a296c
3720a26
e525b56
b992a30
66c0080
5b433d9
9afd2aa
6d272be
03ad825
8f449ff
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,14 @@ | ||
{ | ||
"name": "anchor-image-explain-model", | ||
"implementation": "mlserver_alibi_explain.AlibiExplainRuntime", | ||
"parallel_workers": 0, | ||
"parameters": { | ||
"uri": "./data/mnist_anchor_image", | ||
"version": "v0.1.0", | ||
"extra": { | ||
"explainer_type": "anchor_image", | ||
"infer_uri": "http://localhost:42315/v2/models/test-pytorch-mnist/infer" | ||
} | ||
} | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"debug": "true" | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
from typing import List | ||
|
||
from ..types import RequestInput, ResponseOutput | ||
from ..types import RequestInput, ResponseOutput, Parameters | ||
|
||
from .utils import FirstInputRequestCodec | ||
from .base import InputCodec, register_input_codec, register_request_codec | ||
|
@@ -51,6 +51,18 @@ def decode(cls, request_input: RequestInput) -> List[str]: | |
unpacked = map(_decode_str, unpack(packed, shape)) | ||
return list(unpacked) | ||
|
||
@classmethod | ||
def encode_request_input(cls, name: str, payload: List[str]) -> RequestInput: | ||
# TODO: merge this logic with `encode` | ||
data = cls.encode(name=name, payload=payload) | ||
return RequestInput( | ||
name=data.name, | ||
datatype=data.datatype, | ||
shape=data.shape, | ||
data=data.data.__root__.decode("ascii"), # to allow json serialisation | ||
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. Wouldn't this break serialisation into protobufs? Although we should probably leave that point outside of this PR TBH, as it's not clear how to make something compatible for both. Besides that, should we decode it as 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. this is not removed and we will just pass the |
||
parameters=Parameters(content_type=cls.ContentType), | ||
) | ||
|
||
|
||
@register_request_codec | ||
class StringRequestCodec(FirstInputRequestCodec): | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,7 +26,7 @@ class Config: | |
env_prefix = ENV_PREFIX_ALIBI_DETECT_SETTINGS | ||
|
||
init_detector: bool = False | ||
detector_type: PyObject = "" | ||
detector_type: PyObject = "" # type: ignore | ||
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. If we set it to 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. No, because we need also to set it as |
||
protocol: Optional[str] = "seldon.http" | ||
init_parameters: Optional[dict] = {} | ||
predict_parameters: Optional[dict] = {} | ||
|
@@ -47,7 +47,8 @@ class AlibiDetectRuntime(MLModel): | |
|
||
def __init__(self, settings: ModelSettings): | ||
|
||
self.alibi_detect_settings = AlibiDetectSettings(**settings.parameters.extra) | ||
extra = settings.parameters.extra # type: ignore | ||
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. Why is that 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. good point. |
||
self.alibi_detect_settings = AlibiDetectSettings(**extra) # type: ignore | ||
super().__init__(settings) | ||
|
||
@custom_handler(rest_path="/") | ||
|
@@ -93,7 +94,7 @@ async def predict(self, payload: types.InferenceRequest) -> types.InferenceRespo | |
|
||
async def predict_fn(self, input_data: Any) -> dict: | ||
parameters = self.alibi_detect_settings.predict_parameters | ||
return self._model.predict(input_data, **parameters) | ||
return self._model.predict(input_data, **parameters) # type: ignore | ||
|
||
def _check_request(self, payload: types.InferenceRequest) -> types.InferenceRequest: | ||
if len(payload.inputs) != 1: | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: is there any reason for the name change? I'm wondering whether
request_input
may be more explicit thanv2_data
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cant remember of any reason why I have renamed this variable, will revert.