binoua commited on
Commit
e20f6b1
·
1 Parent(s): 10021fb

chore: debug

Browse files
Files changed (2) hide show
  1. handler.py +6 -3
  2. play_with_endpoint.py +12 -5
handler.py CHANGED
@@ -30,12 +30,15 @@ class EndpointHandler:
30
  """
31
 
32
  # Get inputs
33
- encrypted_inputs = from_json(data.pop("encrypted_inputs", data))
 
34
 
35
  # Get keys
36
- evaluation_keys = from_json(data.pop("evaluation_keys", data))
 
37
 
38
  # Run CML prediction
39
  encrypted_prediction = self.fhemodel_server.run(encrypted_inputs, evaluation_keys)
40
 
41
- return to_json(encrypted_prediction)
 
 
30
  """
31
 
32
  # Get inputs
33
+ # encrypted_inputs = from_json(data.pop("encrypted_inputs", data))
34
+ encrypted_inputs = data.pop("encrypted_inputs", data)
35
 
36
  # Get keys
37
+ # evaluation_keys = from_json(data.pop("evaluation_keys", data))
38
+ evaluation_keys = data.pop("evaluation_keys", data)
39
 
40
  # Run CML prediction
41
  encrypted_prediction = self.fhemodel_server.run(encrypted_inputs, evaluation_keys)
42
 
43
+ # return to_json(encrypted_prediction)
44
+ return encrypted_prediction
play_with_endpoint.py CHANGED
@@ -20,16 +20,16 @@ def from_json(python_object):
20
  return bytes(python_object["__value__"])
21
 
22
 
23
- # TODO: put the right link `API_URL` for your entryp point
24
  API_URL = "https://yw1dgyuig6ff5pft.us-east-1.aws.endpoints.huggingface.cloud"
25
  headers = {
26
  "Authorization": "Bearer " + os.environ.get("HF_TOKEN"),
27
- "Content-Type": "application/json",
28
  }
29
 
30
 
31
  def query(payload):
32
- response = requests.post(API_URL, headers=headers, json=payload)
33
  return response.json()
34
 
35
 
@@ -74,11 +74,16 @@ for i in range(nb_samples):
74
  # Quantize the input and encrypt it
75
  encrypted_inputs = fhemodel_client.quantize_encrypt_serialize(X_test[i].reshape(1, -1))
76
 
 
 
 
77
  # Prepare the payload, including the evaluation keys which are needed server side
78
  payload = {
79
  "inputs": "fake",
80
- "encrypted_inputs": to_json(encrypted_inputs),
81
- "evaluation_keys": to_json(evaluation_keys),
 
 
82
  }
83
 
84
  # Run the inference on HF servers
@@ -88,6 +93,8 @@ for i in range(nb_samples):
88
 
89
  encrypted_prediction = from_json(encrypted_prediction)
90
 
 
 
91
  if is_first:
92
  is_first = False
93
  print(f"Size of the payload: {sys.getsizeof(payload)} bytes")
 
20
  return bytes(python_object["__value__"])
21
 
22
 
23
+ # TODO: put the right link `API_URL` for your entry point
24
  API_URL = "https://yw1dgyuig6ff5pft.us-east-1.aws.endpoints.huggingface.cloud"
25
  headers = {
26
  "Authorization": "Bearer " + os.environ.get("HF_TOKEN"),
27
+ "Content-Type": "application/octet-stream",
28
  }
29
 
30
 
31
  def query(payload):
32
+ response = requests.post(API_URL, headers=headers, data=payload)
33
  return response.json()
34
 
35
 
 
74
  # Quantize the input and encrypt it
75
  encrypted_inputs = fhemodel_client.quantize_encrypt_serialize(X_test[i].reshape(1, -1))
76
 
77
+ # print(f"Size of encrypted input {sys.getsizeof(encrypted_inputs)}")
78
+ # print(f"Size of keys {sys.getsizeof(evaluation_keys)}")
79
+
80
  # Prepare the payload, including the evaluation keys which are needed server side
81
  payload = {
82
  "inputs": "fake",
83
+ # "encrypted_inputs": to_json(encrypted_inputs),
84
+ # "evaluation_keys": to_json(evaluation_keys),
85
+ "encrypted_inputs": encrypted_inputs,
86
+ "evaluation_keys": evaluation_keys,
87
  }
88
 
89
  # Run the inference on HF servers
 
93
 
94
  encrypted_prediction = from_json(encrypted_prediction)
95
 
96
+ print(f"{encrypted_prediction=}")
97
+
98
  if is_first:
99
  is_first = False
100
  print(f"Size of the payload: {sys.getsizeof(payload)} bytes")