Skip to content

Commit

Permalink
bump alibi-detect to 0.8.1 in adserver (#3871)
Browse files Browse the repository at this point in the history
* bump alibi-detect to 0.8.1 in adserver

* set numba cache directory such that it is writable

* use tensorflow 2.7.0 for alibi detect server

* make mypy happy
  • Loading branch information
RafalSkolasinski authored Feb 2, 2022
1 parent bfb30c1 commit fd79a63
Show file tree
Hide file tree
Showing 6 changed files with 851 additions and 663 deletions.
3 changes: 3 additions & 0 deletions components/alibi-detect-server/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -70,4 +70,7 @@ COPY --from=builder /opt/conda /opt/conda
COPY --from=builder /usr/bin/rclone /usr/bin/rclone
COPY --from=builder /licenses /licenses

# This is to have writable numba cache directory
ENV NUMBA_CACHE_DIR /tmp/numba-cache

ENTRYPOINT ["python", "-m", "adserver"]
6 changes: 4 additions & 2 deletions components/alibi-detect-server/adserver/cd_model.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import json
from typing import List, Dict, Optional, Union
from typing import List, Dict, Optional, Union, cast
import logging
import numpy as np
from .numpy_encoder import NumpyEncoder
Expand Down Expand Up @@ -52,7 +52,7 @@ def __init__(
"""
super().__init__(name, storage_uri, model)
self.drift_batch_size = drift_batch_size
self.batch: np.array = None
self.batch: Optional[np.ndarray] = None
self.model: Data = model

def process_event(self, inputs: Union[List, Dict], headers: Dict) -> Optional[ModelResponse]:
Expand Down Expand Up @@ -86,6 +86,8 @@ def process_event(self, inputs: Union[List, Dict], headers: Dict) -> Optional[Mo
else:
self.batch = np.concatenate((self.batch, X))

self.batch = cast(np.ndarray, self.batch)

if self.batch.shape[0] >= self.drift_batch_size:
logging.info(
"Running drift detection. Batch size is %d. Needed %d",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def _extract_list(body: Dict) -> List:
raise Exception("Unknown Seldon payload %s" % body)


def _create_seldon_data_def(array: np.array, ty: SeldonPayload):
def _create_seldon_data_def(array: np.ndarray, ty: SeldonPayload):
datadef = {}
if ty == SeldonPayload.TENSOR:
datadef["tensor"] = {"shape": array.shape, "values": array.ravel().tolist()}
Expand Down
7 changes: 3 additions & 4 deletions components/alibi-detect-server/adserver/protocols/v2.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from http import HTTPStatus
from typing import Dict, List
from typing import Dict, List, Any

import numpy as np
import tornado
Expand All @@ -8,10 +8,9 @@
) # pylint: disable=no-name-in-module


def _create_np_from_v2(data: list, ty: str, shape: list) -> np.array:
npty = np.float
def _create_np_from_v2(data: list, ty: str, shape: list) -> np.ndarray:
if ty == "BOOL":
npty = np.bool
npty: Any = bool
elif ty == "UINT8":
npty = np.uint8
elif ty == "UINT16":
Expand Down
Loading

0 comments on commit fd79a63

Please sign in to comment.