binoua commited on
Commit
bb69c02
1 Parent(s): cae0afe

chore: minor updates to be closer to the template

Browse files
Files changed (1) hide show
  1. play_with_endpoint.py +7 -6
play_with_endpoint.py CHANGED
@@ -73,9 +73,10 @@ print(f"Storing the key in the database under {uid=}")
73
  # Test the handler
74
  nb_good = 0
75
  nb_samples = len(X_test)
76
- verbose = False
77
  time_start = time.time()
78
  duration = 0
 
79
 
80
  for i in range(nb_samples):
81
 
@@ -90,8 +91,9 @@ for i in range(nb_samples):
90
  "uid": uid,
91
  }
92
 
93
- if verbose or True:
94
  print(f"Size of the payload: {sys.getsizeof(payload) / 1024} kilobytes")
 
95
 
96
  # Run the inference on HF servers
97
  duration -= time.time()
@@ -106,7 +108,7 @@ for i in range(nb_samples):
106
  prediction_proba = fhemodel_client.deserialize_decrypt_dequantize(encrypted_prediction)[0]
107
  prediction = np.argmax(prediction_proba)
108
 
109
- if verbose or True:
110
  print(
111
  f"for {i}-th input, {prediction=} with expected {Y_test[i]} in {duration_inference:.3f} seconds"
112
  )
@@ -115,6 +117,5 @@ for i in range(nb_samples):
115
  nb_good += Y_test[i] == prediction
116
 
117
  print(f"Accuracy on {nb_samples} samples is {nb_good * 1. / nb_samples}")
118
- print(f"Total time: {time.time() - time_start} seconds")
119
- print(f"Duration in inferences: {duration} seconds")
120
- print(f"Duration per inference: {duration / nb_samples} seconds")
 
73
  # Test the handler
74
  nb_good = 0
75
  nb_samples = len(X_test)
76
+ verbose = True
77
  time_start = time.time()
78
  duration = 0
79
+ is_first = True
80
 
81
  for i in range(nb_samples):
82
 
 
91
  "uid": uid,
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
99
  duration -= time.time()
 
108
  prediction_proba = fhemodel_client.deserialize_decrypt_dequantize(encrypted_prediction)[0]
109
  prediction = np.argmax(prediction_proba)
110
 
111
+ if verbose:
112
  print(
113
  f"for {i}-th input, {prediction=} with expected {Y_test[i]} in {duration_inference:.3f} seconds"
114
  )
 
117
  nb_good += Y_test[i] == prediction
118
 
119
  print(f"Accuracy on {nb_samples} samples is {nb_good * 1. / nb_samples}")
120
+ print(f"Total time: {time.time() - time_start:.3f} seconds")
121
+ print(f"Duration per inference: {duration / nb_samples:.3f} seconds")