Skip to content
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

[AutoTVM] Fix Empty Config caused Crashing #4520

Merged
merged 1 commit into from
Dec 16, 2019
Merged
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
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