binoua commited on
Commit
8e8b1a3
·
1 Parent(s): 6e245b1

chore: adding a test with DL

Browse files
Files changed (1) hide show
  1. play_with_endpoint.py +9 -9
play_with_endpoint.py CHANGED
@@ -20,8 +20,7 @@ def from_json(python_object):
20
  return bytes(python_object["__value__"])
21
 
22
 
23
- # TODO: put the right link `API_URL` for your entry point
24
- API_URL = "https://XXXXXXX.us-east-1.aws.endpoints.huggingface.cloud"
25
  headers = {
26
  "Authorization": "Bearer " + os.environ.get("HF_TOKEN"),
27
  "Content-Type": "application/json",
@@ -39,12 +38,13 @@ def query(payload):
39
 
40
  path_to_model = Path("compiled_model")
41
 
42
- # BEGIN: replace this part with your privacy-preserving application
43
- from sklearn.datasets import make_classification
44
  from sklearn.model_selection import train_test_split
45
 
46
- x, y = make_classification(n_samples=1000, class_sep=2, n_features=30, random_state=42)
47
- _, X_test, _, Y_test = train_test_split(x, y, test_size=0.2, random_state=42)
 
48
 
49
  # Recover parameters for client side
50
  fhemodel_client = FHEModelClient(path_to_model)
@@ -72,7 +72,7 @@ while not is_finished:
72
  is_finished = True
73
 
74
  print(
75
- f"Sending {i}-th piece of the key (remaining size is {sys.getsizeof(evaluation_keys_remaining)})"
76
  )
77
  i += 1
78
 
@@ -99,7 +99,7 @@ while not is_finished:
99
 
100
  # Test the handler
101
  nb_good = 0
102
- nb_samples = len(X_test)
103
  verbose = True
104
  time_start = time.time()
105
  duration = 0
@@ -119,7 +119,7 @@ for i in range(nb_samples):
119
  }
120
 
121
  if is_first:
122
- print(f"Size of the payload: {sys.getsizeof(payload) / 1024} kilobytes")
123
  is_first = False
124
 
125
  # Run the inference on HF servers
 
20
  return bytes(python_object["__value__"])
21
 
22
 
23
+ API_URL = "https://ml79quhm2orc8dbo.eu-west-1.aws.endpoints.huggingface.cloud"
 
24
  headers = {
25
  "Authorization": "Bearer " + os.environ.get("HF_TOKEN"),
26
  "Content-Type": "application/json",
 
38
 
39
  path_to_model = Path("compiled_model")
40
 
41
+ # DL in FHE
42
+ from sklearn.datasets import load_digits
43
  from sklearn.model_selection import train_test_split
44
 
45
+ X, y = load_digits(return_X_y=True)
46
+ X = np.expand_dims(X.reshape((-1, 8, 8)), 1)
47
+ _, X_test, _, Y_test = train_test_split(X, y, test_size=0.25, shuffle=True, random_state=42)
48
 
49
  # Recover parameters for client side
50
  fhemodel_client = FHEModelClient(path_to_model)
 
72
  is_finished = True
73
 
74
  print(
75
+ f"Sending {i}-th piece of the key (remaining size is {sys.getsizeof(evaluation_keys_remaining) / 1024:.2f} kbytes)"
76
  )
77
  i += 1
78
 
 
99
 
100
  # Test the handler
101
  nb_good = 0
102
+ nb_samples = 10 # len(X_test)
103
  verbose = True
104
  time_start = time.time()
105
  duration = 0
 
119
  }
120
 
121
  if is_first:
122
+ print(f"Size of the payload: {sys.getsizeof(payload) / 1024:.2f} kilobytes")
123
  is_first = False
124
 
125
  # Run the inference on HF servers