Skip to content

Commit c5eb9be

Browse files
committed
Remove baseline from tuning records
1 parent dc2510b commit c5eb9be

File tree

3 files changed

+55
-104
lines changed

3 files changed

+55
-104
lines changed

sharktuner/sharktuner/candidate_ordering.py

Lines changed: 5 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -131,9 +131,6 @@ def init_tuning_records(
131131
knobs: list[Optional[common.KnobAssignment]], sorted_order: list[int]
132132
) -> list[TuningRecord]:
133133
tuning_records: list[TuningRecord] = []
134-
tuning_records.append(
135-
TuningRecord(gen_id=0, candidate_id=0, to_compile=True, to_benchmark=True)
136-
)
137134

138135
for can_idx, gen_idx in enumerate(sorted_order, start=1):
139136
tr = TuningRecord(
@@ -155,37 +152,20 @@ def flatten_records(
155152
- Each record becomes one CSV row.
156153
- Top-level attributes (e.g., `gen_id`, `benchmark_time_us`) appear as individual columns.
157154
- Nested objects (e.g., `knob`) are flattened into columns like `knob.M`, `knob.tile_m`.
158-
159-
The original top-level attribute (e.g., 'knob') is removed once nesting is flattened.
160155
"""
161156
rows = []
162-
headers = []
163-
unneeded_headers = []
164-
165157
for tuning_record in tuning_records:
166158
row = {}
167159
for attr, val in vars(tuning_record).items():
168-
if hasattr(val, "__dict__"):
169-
nested = vars(val)
170-
if not nested:
171-
continue
172-
unneeded_headers.append(attr)
173-
for sub_attr, sub_val in nested.items():
174-
key = f"{attr}.{sub_attr}"
175-
row[key] = sub_val
176-
if key not in headers:
177-
headers.append(key)
160+
if isinstance(val, common.KnobAssignment):
161+
knob_dict = val.get_knobs()
162+
for k, v in knob_dict.items():
163+
row[f"{attr}_{k}"] = v
178164
else:
179165
row[attr] = val
180-
if attr not in headers:
181-
headers.append(attr)
182166
rows.append(row)
183167

184-
# Remove top-level attributes (e.g., 'knob') that were replaced by flattened nested fields.
185-
headers = [h for h in headers if h not in unneeded_headers]
186-
for row in rows:
187-
for unneeded in unneeded_headers:
188-
row.pop(unneeded, None)
168+
headers = list(row.keys())
189169

190170
return headers, rows
191171

sharktuner/sharktuner/libtuner.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1275,18 +1275,15 @@ def benchmark(
12751275

12761276
# Benchmarking baselines on each involved device.
12771277
baseline_tracker = tuning_client.candidate_trackers[0]
1278-
tuning_client.tuning_records[0].to_benchmark = True
12791278
first_baseline_result, subprocess_timeout_reference = benchmark_baseline(
12801279
devices=args.devices,
12811280
tuning_client=tuning_client,
12821281
candidate_tracker=baseline_tracker,
12831282
)
12841283
baseline_handler = BaselineResultHandler()
12851284
baseline_handler.add_run(first_baseline_result)
1286-
tuning_client.tuning_records[0].benchmark_status = True
12871285
if not baseline_handler.is_valid():
12881286
logging.warning("Baseline run failed.")
1289-
tuning_client.tuning_records[0].benchmark_status = False
12901287

12911288
if tuning_client.is_auto_iree_benchmark_timeout():
12921289
logging.info(

sharktuner/tests/candidate_ordering_test.py

Lines changed: 50 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -162,12 +162,6 @@ def test_reorder_assignments(
162162
def test_init_tuning_records(
163163
sample_knobs: list[Optional[common.KnobAssignment]],
164164
) -> None:
165-
tr0 = candidate_ordering.TuningRecord(
166-
gen_id=0,
167-
candidate_id=0,
168-
to_compile=True,
169-
to_benchmark=True,
170-
)
171165
tr1 = candidate_ordering.TuningRecord(
172166
gen_id=2,
173167
candidate_id=1,
@@ -186,20 +180,14 @@ def test_init_tuning_records(
186180
sorted_order = [2, 0, 1]
187181
tuning_records = candidate_ordering.init_tuning_records(sample_knobs, sorted_order)
188182

189-
expected = [tr0, tr1, tr2, tr3]
183+
expected = [tr1, tr2, tr3]
190184

191185
assert tuning_records == expected
192186

193187

194188
def test_flatten_records(
195189
sample_knobs: list[Optional[common.KnobAssignment]],
196190
):
197-
tr0 = candidate_ordering.TuningRecord(
198-
gen_id=0,
199-
candidate_id=0,
200-
to_compile=True,
201-
to_benchmark=True,
202-
)
203191
tr1 = candidate_ordering.TuningRecord(
204192
gen_id=2,
205193
candidate_id=1,
@@ -217,13 +205,29 @@ def test_flatten_records(
217205
to_benchmark=True,
218206
benchmark_time_us=153.56,
219207
)
220-
sample_tuning_records = [tr0, tr1, tr2]
208+
sample_tuning_records = [tr1, tr2]
221209

222210
headers, rows = candidate_ordering.flatten_records(sample_tuning_records)
223211

224212
expected_headers = [
225213
"gen_id",
226214
"candidate_id",
215+
"knob_M",
216+
"knob_N",
217+
"knob_K",
218+
"knob_tile_m",
219+
"knob_tile_n",
220+
"knob_tile_k",
221+
"knob_wg_x",
222+
"knob_wg_y",
223+
"knob_wg_z",
224+
"knob_subgroup_m_cnt",
225+
"knob_subgroup_n_cnt",
226+
"knob_intrinsic_mn",
227+
"knob_intrinsic_k",
228+
"knob_subgroup_m",
229+
"knob_subgroup_n",
230+
"knob_subgroup_k",
227231
"to_compile",
228232
"compile_status",
229233
"to_benchmark",
@@ -234,40 +238,10 @@ def test_flatten_records(
234238
"benchmark_time_us",
235239
"benchmark_speedup",
236240
"benchmark_rank_order",
237-
"knob.M",
238-
"knob.N",
239-
"knob.K",
240-
"knob.tile_m",
241-
"knob.tile_n",
242-
"knob.tile_k",
243-
"knob.wg_x",
244-
"knob.wg_y",
245-
"knob.wg_z",
246-
"knob.subgroup_m_cnt",
247-
"knob.subgroup_n_cnt",
248-
"knob.intrinsic_mn",
249-
"knob.intrinsic_k",
250-
"knob.subgroup_m",
251-
"knob.subgroup_n",
252-
"knob.subgroup_k",
253241
]
254242
assert headers == expected_headers
255243

256244
expected_rows = [
257-
{
258-
"baseline_benchmark_time_us": None,
259-
"benchmark_device_id": None,
260-
"benchmark_queue_position": None,
261-
"benchmark_rank_order": None,
262-
"benchmark_speedup": None,
263-
"benchmark_status": False,
264-
"benchmark_time_us": None,
265-
"candidate_id": 0,
266-
"compile_status": False,
267-
"gen_id": 0,
268-
"to_benchmark": True,
269-
"to_compile": True,
270-
},
271245
{
272246
"baseline_benchmark_time_us": 123.4,
273247
"benchmark_device_id": "hip://2",
@@ -279,22 +253,22 @@ def test_flatten_records(
279253
"candidate_id": 1,
280254
"compile_status": False,
281255
"gen_id": 2,
282-
"knob.K": 1280,
283-
"knob.M": 2048,
284-
"knob.N": 10240,
285-
"knob.intrinsic_k": 16,
286-
"knob.intrinsic_mn": 16,
287-
"knob.subgroup_k": 0,
288-
"knob.subgroup_m": 0,
289-
"knob.subgroup_m_cnt": 2,
290-
"knob.subgroup_n": 0,
291-
"knob.subgroup_n_cnt": 4,
292-
"knob.tile_k": 16,
293-
"knob.tile_m": 64,
294-
"knob.tile_n": 256,
295-
"knob.wg_x": 256,
296-
"knob.wg_y": 2,
297-
"knob.wg_z": 1,
256+
"knob_K": 1280,
257+
"knob_M": 2048,
258+
"knob_N": 10240,
259+
"knob_intrinsic_k": 16,
260+
"knob_intrinsic_mn": 16,
261+
"knob_subgroup_k": 0,
262+
"knob_subgroup_m": 0,
263+
"knob_subgroup_m_cnt": 2,
264+
"knob_subgroup_n": 0,
265+
"knob_subgroup_n_cnt": 4,
266+
"knob_tile_k": 16,
267+
"knob_tile_m": 64,
268+
"knob_tile_n": 256,
269+
"knob_wg_x": 256,
270+
"knob_wg_y": 2,
271+
"knob_wg_z": 1,
298272
"to_benchmark": False,
299273
"to_compile": True,
300274
},
@@ -309,22 +283,22 @@ def test_flatten_records(
309283
"candidate_id": 2,
310284
"compile_status": False,
311285
"gen_id": 1,
312-
"knob.K": 1280,
313-
"knob.M": 2048,
314-
"knob.N": 10240,
315-
"knob.intrinsic_k": 16,
316-
"knob.intrinsic_mn": 16,
317-
"knob.subgroup_k": 0,
318-
"knob.subgroup_m": 0,
319-
"knob.subgroup_m_cnt": 1,
320-
"knob.subgroup_n": 0,
321-
"knob.subgroup_n_cnt": 5,
322-
"knob.tile_k": 80,
323-
"knob.tile_m": 64,
324-
"knob.tile_n": 320,
325-
"knob.wg_x": 320,
326-
"knob.wg_y": 1,
327-
"knob.wg_z": 1,
286+
"knob_K": 1280,
287+
"knob_M": 2048,
288+
"knob_N": 10240,
289+
"knob_intrinsic_k": 16,
290+
"knob_intrinsic_mn": 16,
291+
"knob_subgroup_k": 0,
292+
"knob_subgroup_m": 0,
293+
"knob_subgroup_m_cnt": 1,
294+
"knob_subgroup_n": 0,
295+
"knob_subgroup_n_cnt": 5,
296+
"knob_tile_k": 80,
297+
"knob_tile_m": 64,
298+
"knob_tile_n": 320,
299+
"knob_wg_x": 320,
300+
"knob_wg_y": 1,
301+
"knob_wg_z": 1,
328302
"to_benchmark": True,
329303
"to_compile": False,
330304
},

0 commit comments

Comments
 (0)