Skip to content

Commit

Permalink
fix empty config caused KeyError (apache#4520)
Browse files Browse the repository at this point in the history
  • Loading branch information
comaniac authored and zhiics committed Dec 31, 2019
1 parent 4c4c41a commit 77b11f1
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
8 changes: 7 additions & 1 deletion python/tvm/autotvm/record.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
7 changes: 7 additions & 0 deletions tests/python/unittest/test_autotvm_record.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)):
Expand Down

0 comments on commit 77b11f1

Please sign in to comment.