chore: trying without json
Browse files- create_zipfiles_and_check_local_endpoint.py +3 -15
- handler.py +3 -16
create_zipfiles_and_check_local_endpoint.py
CHANGED
@@ -10,18 +10,6 @@ from sklearn.model_selection import train_test_split
|
|
10 |
from concrete.ml.sklearn import LogisticRegression
|
11 |
from concrete.ml.deployment import FHEModelClient, FHEModelDev
|
12 |
|
13 |
-
|
14 |
-
def to_json(python_object):
|
15 |
-
if isinstance(python_object, bytes):
|
16 |
-
return {"__class__": "bytes", "__value__": list(python_object)}
|
17 |
-
raise TypeError(repr(python_object) + " is not JSON serializable")
|
18 |
-
|
19 |
-
|
20 |
-
def from_json(python_object):
|
21 |
-
if "__class__" in python_object:
|
22 |
-
return bytes(python_object["__value__"])
|
23 |
-
|
24 |
-
|
25 |
# Fit a model. In the future, we should find an existing model on HF repository
|
26 |
path_to_model = Path("compiled_model")
|
27 |
do_training_and_compilation = True
|
@@ -64,13 +52,13 @@ for i in range(nb_samples):
|
|
64 |
# Prepare the payload, including the evaluation keys which are needed server side
|
65 |
payload = {
|
66 |
"inputs": "fake",
|
67 |
-
"encrypted_inputs":
|
68 |
-
"evaluation_keys":
|
69 |
}
|
70 |
|
71 |
# Run the inference on HF servers
|
72 |
encrypted_prediction = my_handler(payload)
|
73 |
-
encrypted_prediction =
|
74 |
|
75 |
# Decrypt the result and dequantize
|
76 |
prediction_proba = fhemodel_client.deserialize_decrypt_dequantize(encrypted_prediction)[0]
|
|
|
10 |
from concrete.ml.sklearn import LogisticRegression
|
11 |
from concrete.ml.deployment import FHEModelClient, FHEModelDev
|
12 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
13 |
# Fit a model. In the future, we should find an existing model on HF repository
|
14 |
path_to_model = Path("compiled_model")
|
15 |
do_training_and_compilation = True
|
|
|
52 |
# Prepare the payload, including the evaluation keys which are needed server side
|
53 |
payload = {
|
54 |
"inputs": "fake",
|
55 |
+
"encrypted_inputs": encrypted_inputs,
|
56 |
+
"evaluation_keys": evaluation_keys,
|
57 |
}
|
58 |
|
59 |
# Run the inference on HF servers
|
60 |
encrypted_prediction = my_handler(payload)
|
61 |
+
encrypted_prediction = encrypted_prediction
|
62 |
|
63 |
# Decrypt the result and dequantize
|
64 |
prediction_proba = fhemodel_client.deserialize_decrypt_dequantize(encrypted_prediction)[0]
|
handler.py
CHANGED
@@ -3,19 +3,6 @@ import numpy as np
|
|
3 |
from concrete.ml.deployment import FHEModelServer
|
4 |
|
5 |
|
6 |
-
def from_json(python_object):
|
7 |
-
if "__class__" in python_object:
|
8 |
-
return bytes(python_object["__value__"])
|
9 |
-
|
10 |
-
|
11 |
-
def to_json(python_object):
|
12 |
-
if isinstance(python_object, bytes):
|
13 |
-
return {"__class__": "bytes", "__value__": list(python_object)}
|
14 |
-
# if isinstance(python_object, bytes):
|
15 |
-
# return list(python_object)
|
16 |
-
raise TypeError(repr(python_object) + " is not JSON serializable")
|
17 |
-
|
18 |
-
|
19 |
class EndpointHandler:
|
20 |
def __init__(self, path=""):
|
21 |
|
@@ -32,12 +19,12 @@ class EndpointHandler:
|
|
32 |
"""
|
33 |
|
34 |
# Get inputs
|
35 |
-
encrypted_inputs =
|
36 |
|
37 |
# Get keys
|
38 |
-
evaluation_keys =
|
39 |
|
40 |
# Run CML prediction
|
41 |
encrypted_prediction = self.fhemodel_server.run(encrypted_inputs, evaluation_keys)
|
42 |
|
43 |
-
return
|
|
|
3 |
from concrete.ml.deployment import FHEModelServer
|
4 |
|
5 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
6 |
class EndpointHandler:
|
7 |
def __init__(self, path=""):
|
8 |
|
|
|
19 |
"""
|
20 |
|
21 |
# Get inputs
|
22 |
+
encrypted_inputs = data.pop("encrypted_inputs", data)
|
23 |
|
24 |
# Get keys
|
25 |
+
evaluation_keys = data.pop("evaluation_keys", data)
|
26 |
|
27 |
# Run CML prediction
|
28 |
encrypted_prediction = self.fhemodel_server.run(encrypted_inputs, evaluation_keys)
|
29 |
|
30 |
+
return encrypted_prediction
|