Skip to content

Commit 84fb519

Browse files
committed
WIP.
1 parent 0914c4a commit 84fb519

33 files changed

+688
-245
lines changed

docs/examples/sklearn/infer.py

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import requests
2+
from sklearn import datasets, svm, metrics
3+
from sklearn.model_selection import train_test_split
4+
5+
# The digits dataset
6+
digits = datasets.load_digits()
7+
8+
# To apply a classifier on this data, we need to flatten the image, to
9+
# turn the data in a (samples, feature) matrix:
10+
n_samples = len(digits.images)
11+
data = digits.images.reshape((n_samples, -1))
12+
13+
# Create a classifier: a support vector classifier
14+
classifier = svm.SVC(gamma=0.001)
15+
16+
# Split data into train and test subsets
17+
X_train, X_test, y_train, y_test = train_test_split(
18+
data, digits.target, test_size=0.5, shuffle=False)
19+
20+
21+
x_0 = X_test[0:1]
22+
inference_request = {
23+
"inputs": [
24+
{
25+
"name": "predict",
26+
"shape": x_0.shape,
27+
"datatype": "FP32",
28+
"data": x_0.tolist()
29+
}
30+
]
31+
}
32+
print(inference_request)
33+
34+
endpoint = "http://localhost:8080/v2/models/mnist-svm/versions/v0.1.0/infer"
35+
response = requests.post(endpoint, json=inference_request)
36+
37+
print(response.json())

mlserver/metrics/prometheus.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,21 @@ def configure_metrics(settings: Settings):
3131
values.ValueClass = values.get_value_class()
3232

3333

34+
async def try_remove(filename: str):
35+
try:
36+
os.remove(filename)
37+
except FileNotFoundError:
38+
pass
39+
3440
async def stop_metrics(settings: Settings, pid: int):
3541
if not settings.parallel_workers:
3642
return
3743

3844
mark_process_dead(pid)
3945
pattern = os.path.join(settings.metrics_dir, f"*_{pid}.db")
4046
matching_files = glob.glob(pattern)
41-
await asyncio.gather(*[remove(f) for f in matching_files])
47+
if len(matching_files) > 0:
48+
await asyncio.gather(*[try_remove(f) for f in matching_files])
4249

4350

4451
class PrometheusEndpoint:

mlserver/settings.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ class Settings(BaseSettings):
165165
extra="ignore",
166166
)
167167

168-
debug: bool = True
168+
debug: bool = False
169169

170170
parallel_workers: int = DEFAULT_PARALLEL_WORKERS
171171
"""When parallel inference is enabled, number of workers to run inference

mlserver/utils.py

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -78,31 +78,6 @@ def event_loop_policy(self) -> asyncio.AbstractEventLoopPolicy:
7878
else:
7979
return asyncio.DefaultEventLoopPolicy
8080

81-
def install_uvloop_when_available(self):
82-
"""
83-
In python versions < 3.16, install uvloop as the default event loop policy.
84-
Deprecated from python 3.12, but used within pytest tests until pytest itself provides
85-
an alternative way to manage event loops across different python versions.
86-
"""
87-
python_version_info = sys.version_info[:2]
88-
if python_version_info >= (3, 12):
89-
warnings.warn(
90-
'AsyncManager::install() is deprecated in favor of AsyncManager::run() '
91-
'for Python >= 3.12.',
92-
DeprecationWarning,
93-
stacklevel=1,
94-
)
95-
if python_version_info < (3, 16):
96-
if type(asyncio.get_event_loop_policy()).__module__.startswith("uvloop"):
97-
return
98-
if self._event_loop_backend == EventLoopBackend.UVLOOP:
99-
import uvloop
100-
uvloop.install()
101-
else:
102-
raise RuntimeError(
103-
"uvloop install via EventLoopPolicy is only supported for Python < 3.16"
104-
)
105-
10681
def run(self,
10782
coro: Coroutine[Any, Any, _CoroRetT], *,
10883
debug: Optional[bool] = None) -> _CoroRetT:

poetry.lock

Lines changed: 289 additions & 54 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ aiohttp = "3.12.8"
127127
aiohttp-retry = "2.9.1"
128128
## Used for FastAPI Async testing
129129
httpx = "0.27.0"
130-
kafka-python-ng = "2.2.3"
130+
kafka-python = "2.2.15"
131131
tenacity = "8.4.1"
132132
pyyaml = "6.0.1"
133133
conda-pack = "0.7.1"
@@ -188,7 +188,7 @@ torch = "^2.4"
188188
pytorch-lightning = "^2.4"
189189
torchmetrics = "1.6.0"
190190
torchvision = "0.19.1"
191-
mlflow = "2.19.0"
191+
mlflow = ">=3.0.0"
192192

193193
## Dev dependencies from HuggingFace
194194
# TODO: Relax when we deprecate Conversation pipeline
File renamed without changes.

runtimes/alibi-detect/tests/conftest.py renamed to runtimes/alibi-detect/tests_alibi_detect/conftest.py

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import pytest
22
import os
3-
import asyncio
43
import numpy as np
54
import tensorflow as tf
65

@@ -13,7 +12,6 @@
1312
from mlserver.context import model_context
1413
from mlserver.settings import ModelSettings, ModelParameters
1514
from mlserver.types import InferenceRequest
16-
from mlserver.utils import AsyncManager
1715

1816
from mlserver_alibi_detect import AlibiDetectRuntime
1917

@@ -26,16 +24,6 @@
2624
TESTS_PATH = os.path.dirname(__file__)
2725
TESTDATA_PATH = os.path.join(TESTS_PATH, "testdata")
2826

29-
30-
# @pytest.fixture(autouse=True)
31-
# def event_loop():
32-
# # By default use uvloop for tests
33-
# AsyncManager().install_uvloop()
34-
# loop = asyncio.get_event_loop()
35-
# yield loop
36-
# loop.close()
37-
38-
3927
@pytest.fixture
4028
def inference_request() -> InferenceRequest:
4129
payload_path = os.path.join(TESTDATA_PATH, "inference-request.json")

runtimes/alibi-detect/tests/test_drift_detector.py renamed to runtimes/alibi-detect/tests_alibi_detect/test_drift_detector.py

File renamed without changes.

runtimes/alibi-detect/tests/test_outlier_detector.py renamed to runtimes/alibi-detect/tests_alibi_detect/test_outlier_detector.py

File renamed without changes.

0 commit comments

Comments
 (0)