Skip to content

[Nightly] Set different time measure for microbench #1915

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 14 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
146 changes: 107 additions & 39 deletions .github/scripts/op_calculate_best_perf.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,22 +14,48 @@
updated_cases = []
removed_cases = []

def safe_float_convert(value):
try:
return float(value) if value.strip() else None
except (ValueError, AttributeError):
return None

def update_baseline(xpu_file, baseline_file, remove_missing=False):
with open(xpu_file) as f:
xpu_reader = csv.DictReader(f, delimiter=';')
xpu_rows = list(xpu_reader)
xpu_fieldnames = xpu_reader.fieldnames # Keep original field order
fieldnames = [f for f in xpu_fieldnames if f not in ['time(us)', 'E2E total time(us)', 'E2E forward time(us)']]
xpu_data = {make_key(row, fieldnames): (float(row['time(us)']), row) for row in xpu_rows}
xpu_fieldnames = xpu_reader.fieldnames
time_fields = ['time(us)', 'E2E total time(us)', 'E2E forward time(us)']
fieldnames = [f for f in xpu_fieldnames if f not in time_fields]
xpu_data = {}
for row in xpu_rows:
key = make_key(row, fieldnames)
time_values = {}
if 'time(us)' in row:
time_val = safe_float_convert(row['time(us)'])
if time_val is not None:
time_values['time(us)'] = time_val
if 'E2E total time(us)' in row:
e2e_val = safe_float_convert(row['E2E total time(us)'])
if e2e_val is not None:
time_values['E2E total time(us)'] = e2e_val
xpu_data[key] = (time_values, row)

with open(baseline_file) as f:
baseline_reader = csv.DictReader(f, delimiter=';')
baseline_rows = list(baseline_reader)
baseline_fieldnames = baseline_reader.fieldnames

# To add new parameter of new ops into baseline file
all_fieldnames = xpu_fieldnames + [f for f in baseline_fieldnames if f not in xpu_fieldnames]
fieldnames = [f for f in all_fieldnames if f not in ['time(us)', 'E2E total time(us)', 'E2E forward time(us)']]
all_fieldnames = list(set(xpu_fieldnames + baseline_fieldnames))
# Maintain original order as much as possible
ordered_fieldnames = []
for f in xpu_fieldnames:
if f in all_fieldnames and f not in ordered_fieldnames:
ordered_fieldnames.append(f)
for f in baseline_fieldnames:
if f in all_fieldnames and f not in ordered_fieldnames:
ordered_fieldnames.append(f)

baseline_keys = {make_key(row, fieldnames) for row in baseline_rows}
xpu_keys = set(xpu_data.keys())
Expand All @@ -38,75 +64,117 @@ def update_baseline(xpu_file, baseline_file, remove_missing=False):
for row in baseline_rows:
key = make_key(row, fieldnames)
if key in xpu_data:
xpu_time, xpu_row = xpu_data[key]
baseline_time = float(row['time(us)'])

if xpu_time < baseline_time:
updated_row = {}
for field in all_fieldnames:
updated_row[field] = xpu_row.get(field, row.get(field, ''))
updated_row['time(us)'] = str(xpu_time)
if 'E2E total time(us)' in row:
updated_row['E2E total time(us)'] = row['E2E total time(us)']
updated_cases.append((key, baseline_time, xpu_time, updated_row))
updated_rows.append(updated_row)
else:
ordered_row = {}
for field in all_fieldnames:
ordered_row[field] = row.get(field, '')
updated_rows.append(ordered_row)
xpu_times, xpu_row = xpu_data[key]
updated_row = {}

# Copy all fields from baseline first
for field in ordered_fieldnames:
updated_row[field] = row.get(field, '')

# Update with xpu values where they exist
for field in ordered_fieldnames:
if field in xpu_row and xpu_row[field]:
updated_row[field] = xpu_row[field]

# Handle time fields
updated = False
if 'time(us)' in xpu_times and 'time(us)' in row:
baseline_time = safe_float_convert(row['time(us)'])
if baseline_time is not None:
xpu_time = xpu_times['time(us)']
if xpu_time < baseline_time:
updated_row['time(us)'] = str(xpu_time)
updated = True

if 'E2E total time(us)' in xpu_times and 'E2E total time(us)' in row:
baseline_e2e = safe_float_convert(row['E2E total time(us)'])
if baseline_e2e is not None:
xpu_e2e = xpu_times['E2E total time(us)']
if xpu_e2e < baseline_e2e:
updated_row['E2E total time(us)'] = str(xpu_e2e)
updated = True

if updated:
updated_cases.append((key, row, updated_row))
updated_rows.append(updated_row)
elif not remove_missing:
ordered_row = {}
for field in all_fieldnames:
for field in ordered_fieldnames:
ordered_row[field] = row.get(field, '')
updated_rows.append(ordered_row)

# Add new cases
for key in xpu_keys - baseline_keys:
xpu_time, xpu_row = xpu_data[key]
xpu_times, xpu_row = xpu_data[key]
new_row = {}
for field in all_fieldnames:
for field in ordered_fieldnames:
new_row[field] = xpu_row.get(field, '')
new_row['time(us)'] = str(xpu_time)

if 'time(us)' in xpu_times:
new_row['time(us)'] = str(xpu_times['time(us)'])
if 'E2E total time(us)' in xpu_times:
new_row['E2E total time(us)'] = str(xpu_times['E2E total time(us)'])

updated_rows.append(new_row)
added_cases.append((key, xpu_time, new_row))
added_cases.append((key, xpu_times, new_row))

# Resolve removed cases
if remove_missing:
for key in baseline_keys - xpu_keys:
removed_case = next(row for row in baseline_rows if make_key(row, fieldnames) == key)
removed_cases.append((key, float(removed_case['time(us)']), removed_case))
removed_cases.append((key, removed_case))

if added_cases:
print(f"\nAdded {len(added_cases)} new case(s):")
for key, time, row in added_cases:
for key, times, row in added_cases:
print(f"\n[New Case] {format_case(key)}")
print(f"Time: {time} us")
if 'time(us)' in times:
print(f"Time: {times['time(us)']} us")
if 'E2E total time(us)' in times:
print(f"E2E Time: {times['E2E total time(us)']} us")
print("Parameters:")
for k, v in row.items():
if k not in ['time(us)', 'E2E total time(us)', 'E2E forward time(us)']:
if k not in time_fields:
print(f" {k}: {v}")
print("-" * 60)

if updated_cases:
print(f"\nUpdated {len(updated_cases)} case(s):")
for key, old_time, new_time, row in updated_cases:
for key, old_row, new_row in updated_cases:
print(f"\n[Updated] {format_case(key)}")
print(f"Time: {old_time} us → {new_time} us")
if 'time(us)' in old_row and 'time(us)' in new_row:
old_time = safe_float_convert(old_row['time(us)'])
new_time = safe_float_convert(new_row['time(us)'])
if old_time is not None and new_time is not None and old_time != new_time:
print(f"Time: {old_time} us → {new_time} us")

if 'E2E total time(us)' in old_row and 'E2E total time(us)' in new_row:
old_e2e = safe_float_convert(old_row['E2E total time(us)'])
new_e2e = safe_float_convert(new_row['E2E total time(us)'])
if old_e2e is not None and new_e2e is not None and old_e2e != new_e2e:
print(f"E2E Time: {old_e2e} us → {new_e2e} us")

print("Parameters:")
for k, v in row.items():
if k not in ['time(us)', 'E2E total time(us)', 'E2E forward time(us)']:
for k, v in new_row.items():
if k not in time_fields:
print(f" {k}: {v}")
print("-" * 60)

if remove_missing and removed_cases:
print(f"\nRemoved {len(removed_cases)} case(s):")
for key, time, row in removed_cases:
for key, row in removed_cases:
print(f"\n[Removed] {format_case(key)}")
print(f"Time: {time} us")
if 'time(us)' in row:
time_val = safe_float_convert(row['time(us)'])
if time_val is not None:
print(f"Time: {time_val} us")
if 'E2E total time(us)' in row:
e2e_val = safe_float_convert(row['E2E total time(us)'])
if e2e_val is not None:
print(f"E2E Time: {e2e_val} us")
print("Parameters:")
for k, v in row.items():
if k not in ['time(us)', 'E2E total time(us)', 'E2E forward time(us)']:
if k not in time_fields:
print(f" {k}: {v}")
print("-" * 60)

Expand All @@ -117,7 +185,7 @@ def update_baseline(xpu_file, baseline_file, remove_missing=False):
Path(baseline_file).rename(backup_file)

with open(baseline_file, 'w', newline='') as f:
writer = csv.DictWriter(f, fieldnames=all_fieldnames, delimiter=';')
writer = csv.DictWriter(f, fieldnames=ordered_fieldnames, delimiter=';')
writer.writeheader()
writer.writerows(updated_rows)

Expand Down
Loading
Loading