Commit 8e3b5d39 by Cody Yu Committed by Tianqi Chen

fix empty config caused KeyError (#4520)

parent 8541e255
......@@ -183,7 +183,13 @@ def load_from_file(filename):
"""
for row in open(filename):
if row and not row.startswith('#'):
yield decode(row)
inp, res = decode(row)
# Avoid loading the record with an empty config. The TOPI schedule with no entities
# will result in an empty entity map (e.g., depthwise_conv2d_nchw on x86).
# Using an empty config will cause problems when applying alter op like NCHW to NCHWc.
if not inp.config._entity_map:
continue
yield (inp, res)
def split_workload(in_file, clean=True):
......
......@@ -52,9 +52,16 @@ def test_file_io():
inputs = [MeasureInput(target, tsk, tsk.config_space.get(i)) for i in range(0, 10)]
results = [MeasureResult((i, ), 0, 0, 0) for i in range(0, 10)]
invalid_inp = MeasureInput(target, tsk, tsk.config_space.get(10))
invalid_res = MeasureResult((10, ), 0, 0, 0)
# Erase the entity map to test if it will be ignored when loading back.
invalid_inp.config._entity_map = {}
with open(file_path, "w") as fo:
cb = autotvm.callback.log_to_file(fo)
cb(None, inputs, results)
cb(None, [invalid_inp], [invalid_res])
ref = zip(inputs, results)
for x, y in zip(ref, autotvm.record.load_from_file(file_path)):
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment