2023-06-28 16:02:56 +00:00
|
|
|
import pickle
|
2023-06-07 07:50:19 +00:00
|
|
|
from time import sleep
|
2023-06-28 16:02:56 +00:00
|
|
|
from gpu_power_func import total_watt_consumed
|
2023-06-07 07:50:19 +00:00
|
|
|
|
2023-06-28 16:02:56 +00:00
|
|
|
with (open("configuration.pkl", "rb")) as file:
|
|
|
|
while True:
|
|
|
|
try:
|
|
|
|
cfg = pickle.load(file)
|
|
|
|
except EOFError:
|
|
|
|
break
|
2023-06-07 07:50:19 +00:00
|
|
|
|
|
|
|
def earlyStopping(early_stopping: list, train_acc: float, epoch: int, sensitivity: float=1e-9):
|
2023-06-01 08:20:51 +00:00
|
|
|
early_stopping.append(train_acc)
|
|
|
|
if epoch % 4 == 0 and epoch > 0:
|
2023-06-07 07:50:19 +00:00
|
|
|
print("Value 1: {} > Value 2: {} > \
|
|
|
|
Value 3: {}".format(early_stopping[0], \
|
|
|
|
abs(early_stopping[1]-sensitivity), \
|
|
|
|
abs(early_stopping[2]-sensitivity)))
|
|
|
|
if train_acc > 0.5:
|
|
|
|
if early_stopping[0] > abs(early_stopping[1]-sensitivity) and \
|
|
|
|
early_stopping[1] > abs(early_stopping[2]-sensitivity):
|
|
|
|
print("Stopping Early")
|
|
|
|
return 1
|
|
|
|
del early_stopping[:]
|
|
|
|
return 0
|
2023-06-01 08:20:51 +00:00
|
|
|
|
|
|
|
|
|
|
|
def energyBound(threshold: float=100000.0):
|
2023-06-07 07:50:19 +00:00
|
|
|
try:
|
2023-06-28 16:02:56 +00:00
|
|
|
energy = total_watt_consumed(cfg["pickle_path"])
|
2023-06-07 07:50:19 +00:00
|
|
|
except Exception as e:
|
|
|
|
sleep(3)
|
2023-06-28 16:02:56 +00:00
|
|
|
energy = total_watt_consumed(cfg["pickle_path"])
|
2023-06-07 07:50:19 +00:00
|
|
|
print("Energy used: {}".format(energy))
|
|
|
|
if energy > threshold:
|
|
|
|
print("Energy bound achieved")
|
|
|
|
return 1
|
|
|
|
return 0
|
2023-06-01 08:20:51 +00:00
|
|
|
|
2023-06-28 16:02:56 +00:00
|
|
|
|
2023-06-01 08:20:51 +00:00
|
|
|
def accuracyBound(train_acc: float, threshold: float=0.99):
|
|
|
|
if train_acc >= threshold:
|
2023-06-07 07:50:19 +00:00
|
|
|
print("Accuracy bound achieved")
|
|
|
|
return 1
|
|
|
|
return 0
|