2021-09-15 19:32:02 +00:00
|
|
|
import collections
|
2023-03-24 22:29:03 +00:00
|
|
|
import json
|
|
|
|
|
import sys
|
2021-09-01 16:03:10 +00:00
|
|
|
|
|
|
|
|
actual = sys.argv[1]
|
|
|
|
|
expect = sys.argv[2]
|
|
|
|
|
|
|
|
|
|
with open(actual) as file_actual:
|
2022-04-26 16:35:16 +00:00
|
|
|
json_actual = json.loads(file_actual.read())
|
2021-09-01 16:03:10 +00:00
|
|
|
|
|
|
|
|
with open(expect) as file_expect:
|
2022-04-26 16:35:16 +00:00
|
|
|
json_expect = json.loads(file_expect.read())
|
|
|
|
|
|
2021-09-01 16:03:10 +00:00
|
|
|
|
2021-09-15 19:32:02 +00:00
|
|
|
def almost_equal(x, y, threshold=0.05):
|
2022-04-26 16:35:16 +00:00
|
|
|
return abs(x - y) < threshold
|
|
|
|
|
|
2021-09-01 16:03:10 +00:00
|
|
|
|
2021-09-15 19:32:02 +00:00
|
|
|
# loss curve tail match
|
|
|
|
|
loss_tail_length = 4
|
|
|
|
|
loss_tail_matches = collections.deque(maxlen=loss_tail_length)
|
2022-04-26 16:35:16 +00:00
|
|
|
logged_steps = len(json_actual["steps"])
|
|
|
|
|
for i in range(logged_steps):
|
|
|
|
|
step_actual = json_actual["steps"][i]
|
|
|
|
|
step_expect = json_expect["steps"][i]
|
|
|
|
|
|
|
|
|
|
is_match = step_actual["step"] == step_expect["step"]
|
|
|
|
|
is_match = is_match if almost_equal(step_actual["loss"], step_expect["loss"]) else False
|
|
|
|
|
loss_tail_matches.append(is_match)
|
|
|
|
|
|
|
|
|
|
print(
|
|
|
|
|
"step {} loss actual {:.6f} expected {:.6f} match {}".format(
|
|
|
|
|
step_actual["step"],
|
|
|
|
|
step_actual["loss"],
|
|
|
|
|
step_expect["loss"],
|
|
|
|
|
is_match if logged_steps - i <= loss_tail_length else "n/a",
|
|
|
|
|
)
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
success = all(loss_tail_matches)
|
2021-09-15 19:32:02 +00:00
|
|
|
|
|
|
|
|
# performance match
|
2021-09-28 20:06:16 +00:00
|
|
|
threshold = 0.95
|
2022-04-26 16:35:16 +00:00
|
|
|
is_performant = json_actual["samples_per_second"] >= threshold * json_expect["samples_per_second"]
|
2021-09-15 19:32:02 +00:00
|
|
|
success = success if is_performant else False
|
2022-04-26 16:35:16 +00:00
|
|
|
print(
|
|
|
|
|
"samples_per_second actual {:.3f} expected {:.3f} in-range {}".format(
|
|
|
|
|
json_actual["samples_per_second"], json_expect["samples_per_second"], is_performant
|
|
|
|
|
)
|
|
|
|
|
)
|
2021-09-15 19:32:02 +00:00
|
|
|
|
2022-04-26 16:35:16 +00:00
|
|
|
assert success
|