chore: rebase from template
Browse files- handler.py +11 -0
- play_with_endpoint.py +42 -8
handler.py
CHANGED
@@ -49,6 +49,17 @@ class EndpointHandler:
|
|
49 |
|
50 |
return {"uid": uid}
|
51 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
52 |
elif method == "inference":
|
53 |
|
54 |
uid = data.pop("uid", data)
|
|
|
49 |
|
50 |
return {"uid": uid}
|
51 |
|
52 |
+
elif method == "append_key":
|
53 |
+
|
54 |
+
# Get key piece
|
55 |
+
evaluation_keys = from_json(data.pop("evaluation_keys", data))
|
56 |
+
|
57 |
+
uid = data.pop("uid", data)
|
58 |
+
|
59 |
+
self.key_database[uid] += evaluation_keys
|
60 |
+
|
61 |
+
return
|
62 |
+
|
63 |
elif method == "inference":
|
64 |
|
65 |
uid = data.pop("uid", data)
|
play_with_endpoint.py
CHANGED
@@ -61,14 +61,48 @@ fhemodel_client.generate_private_and_evaluation_keys()
|
|
61 |
evaluation_keys = fhemodel_client.get_serialized_evaluation_keys()
|
62 |
|
63 |
# Save the key in the database
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
69 |
|
70 |
-
|
71 |
-
print(f"Storing the key in the database under {uid=}")
|
72 |
|
73 |
# Test the handler
|
74 |
nb_good = 0
|
@@ -92,7 +126,7 @@ for i in range(nb_samples):
|
|
92 |
}
|
93 |
|
94 |
if is_first:
|
95 |
-
print(f"Size of the payload: {sys.getsizeof(payload) / 1024} kilobytes")
|
96 |
is_first = False
|
97 |
|
98 |
# Run the inference on HF servers
|
|
|
61 |
evaluation_keys = fhemodel_client.get_serialized_evaluation_keys()
|
62 |
|
63 |
# Save the key in the database
|
64 |
+
evaluation_keys_remaining = evaluation_keys[:]
|
65 |
+
uid = None
|
66 |
+
is_first = True
|
67 |
+
is_finished = False
|
68 |
+
i = 0
|
69 |
+
packet_size = 1024 * 1024 * 100
|
70 |
+
|
71 |
+
while not is_finished:
|
72 |
+
|
73 |
+
# Send by packets of 100M
|
74 |
+
if sys.getsizeof(evaluation_keys_remaining) > packet_size:
|
75 |
+
evaluation_keys_piece = evaluation_keys_remaining[:packet_size]
|
76 |
+
evaluation_keys_remaining = evaluation_keys_remaining[packet_size:]
|
77 |
+
else:
|
78 |
+
evaluation_keys_piece = evaluation_keys_remaining
|
79 |
+
is_finished = True
|
80 |
+
|
81 |
+
print(
|
82 |
+
f"Sending {i}-th piece of the key (remaining size is {sys.getsizeof(evaluation_keys_remaining) / 1024:.2f} kbytes)"
|
83 |
+
)
|
84 |
+
i += 1
|
85 |
+
|
86 |
+
if is_first:
|
87 |
+
is_first = False
|
88 |
+
payload = {
|
89 |
+
"inputs": "fake",
|
90 |
+
"evaluation_keys": to_json(evaluation_keys_piece),
|
91 |
+
"method": "save_key",
|
92 |
+
}
|
93 |
+
|
94 |
+
uid = query(payload)["uid"]
|
95 |
+
print(f"Storing the key in the database under {uid=}")
|
96 |
+
|
97 |
+
else:
|
98 |
+
payload = {
|
99 |
+
"inputs": "fake",
|
100 |
+
"evaluation_keys": to_json(evaluation_keys_piece),
|
101 |
+
"method": "append_key",
|
102 |
+
"uid": uid,
|
103 |
+
}
|
104 |
|
105 |
+
query(payload)
|
|
|
106 |
|
107 |
# Test the handler
|
108 |
nb_good = 0
|
|
|
126 |
}
|
127 |
|
128 |
if is_first:
|
129 |
+
print(f"Size of the payload: {sys.getsizeof(payload) / 1024:.2f} kilobytes")
|
130 |
is_first = False
|
131 |
|
132 |
# Run the inference on HF servers
|