Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Icemist committed Aug 24, 2022
1 parent ba0f41b commit 1585196
Show file tree
Hide file tree
Showing 20 changed files with 27 additions and 25 deletions.
2 changes: 1 addition & 1 deletion gallery/how_to/tune_with_autotvm/tune_relay_arm.py
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@ def tune_tasks(
tuner_obj.load_history(autotvm.record.load_from_file(tmp_log_file))

# process tuning
tsk_trial = min(n_trial, len(tsk.config_space))
tsk_trial = min(n_trial, tsk.config_space.filtered_length)
tuner_obj.tune(
n_trial=tsk_trial,
early_stopping=early_stopping,
Expand Down
2 changes: 1 addition & 1 deletion gallery/how_to/tune_with_autotvm/tune_relay_cuda.py
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ def tune_tasks(
tuner_obj.load_history(autotvm.record.load_from_file(tmp_log_file))

# do tuning
tsk_trial = min(n_trial, len(tsk.config_space))
tsk_trial = min(n_trial, tsk.config_space.filtered_length)
tuner_obj.tune(
n_trial=tsk_trial,
early_stopping=early_stopping,
Expand Down
2 changes: 1 addition & 1 deletion gallery/how_to/tune_with_autotvm/tune_relay_mobile_gpu.py
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@ def tune_tasks(
tuner_obj.load_history(autotvm.record.load_from_file(tmp_log_file))

# do tuning
tsk_trial = min(n_trial, len(tsk.config_space))
tsk_trial = min(n_trial, tsk.config_space.filtered_length)
tuner_obj.tune(
n_trial=tsk_trial,
early_stopping=early_stopping,
Expand Down
2 changes: 1 addition & 1 deletion gallery/how_to/tune_with_autotvm/tune_relay_x86.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ def tune_kernels(
raise ValueError("Invalid tuner: " + tuner)

# do tuning
n_trial = len(task.config_space)
n_trial = task.config_space.filtered_length
tuner_obj.tune(
n_trial=n_trial,
early_stopping=early_stopping,
Expand Down
2 changes: 1 addition & 1 deletion gallery/tutorial/autotvm_relay_x86.py
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,7 @@
prefix = "[Task %2d/%2d] " % (i + 1, len(tasks))
tuner_obj = XGBTuner(task, loss_type="rank")
tuner_obj.tune(
n_trial=min(tuning_option["trials"], len(task.config_space)),
n_trial=min(tuning_option["trials"], task.config_space.filtered_length),
early_stopping=tuning_option["early_stopping"],
measure_option=tuning_option["measure_option"],
callbacks=[
Expand Down
2 changes: 2 additions & 0 deletions python/tvm/autotvm/tuner/index_based_tuner.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ def __init__(self, task, range_idx=None):
# we can generate non-repetitive random indices.
self.rand_state = {}
self.rand_max = self.range_length
self.visited = []

def next_batch(self, batch_size):
ret = []
Expand All @@ -110,6 +111,7 @@ def next_batch(self, batch_size):
if cfg:
ret.append(cfg)
self.counter += 1
self.visited.append(index)

# Update the direct index map.
self.rand_state[index_] = self.rand_state.get(self.rand_max, self.rand_max)
Expand Down
2 changes: 1 addition & 1 deletion python/tvm/contrib/torch/pytorch_tvm.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ def tune_tasks(
tuner_obj.load_history(autotvm.record.load_from_file(tmp_log_file))

# do tuning
tsk_trial = min(n_trial, len(tsk.config_space))
tsk_trial = min(n_trial, tsk.config_space.filtered_length)
tuner_obj.tune(
n_trial=tsk_trial,
early_stopping=early_stopping,
Expand Down
2 changes: 1 addition & 1 deletion python/tvm/driver/tvmc/autotuner.py
Original file line number Diff line number Diff line change
Expand Up @@ -692,7 +692,7 @@ def tune_tasks(
logging.info("loaded history in %.2f sec(s)", time.time() - start_time)

tuner_obj.tune(
n_trial=min(trials, len(tsk.config_space)),
n_trial=min(trials, tsk.config_space.filtered_length),
early_stopping=early_stopping,
measure_option=measure_option,
callbacks=[
Expand Down
4 changes: 3 additions & 1 deletion python/tvm/testing/autotvm.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,8 @@ def get_sample_records(n):

inps, ress = [], []
for i in range(n):
inps.append(MeasureInput(target, tsk, tsk.config_space.get(i % len(tsk.config_space))))
inps.append(
MeasureInput(target, tsk, tsk.config_space.get(i % tsk.config_space.filtered_length))
)
ress.append(MeasureResult((i + 1,), 0, i, time.time()))
return list(zip(inps, ress))
2 changes: 1 addition & 1 deletion tests/python/contrib/test_hexagon/test_autotvm.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ def tune_tasks(
if os.path.isfile(tmp_log_file):
tuner_obj.load_history(autotvm.record.load_from_file(tmp_log_file))

tsk_trial = min(n_trial, len(tsk.config_space))
tsk_trial = min(n_trial, tsk.config_space.filtered_length)
tuner_obj.tune(
n_trial=tsk_trial,
early_stopping=early_stopping,
Expand Down
2 changes: 1 addition & 1 deletion tests/python/relay/collage/demo_collage_partitioner.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ def tune_autotvm_tasks(tasks, log_filename):
tuner_obj.load_history(tvm.autotvm.record.load_from_file(tmp_log_filename))

# do tuning
n_trial = min(AUTOTVM_NUM_TRIALS, len(task.config_space))
n_trial = min(AUTOTVM_NUM_TRIALS, task.config_space.filtered_length)
tuner_obj.tune(
n_trial=n_trial,
early_stopping=AUTOTVM_EARLY_STOPPING,
Expand Down
4 changes: 1 addition & 3 deletions tests/python/unittest/test_autotvm_index_tuner.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def test_gridsearch_tuner():

# When no range index, range_length should be the length of config space
tuner = autotvm.tuner.GridSearchTuner(task)
assert tuner.range_length == len(task.config_space)
assert tuner.range_length == task.config_space.total_length
assert tuner.index_offset == 0

# With range index, range_length should be the length of the specified range
Expand Down Expand Up @@ -70,9 +70,7 @@ def test_random_tuner():
tuner.tune(n_trial=8, measure_option=measure_option)
assert tuner.counter == 8
assert not tuner.has_next()
visited = set()
for idx in tuner.visited:
assert idx not in visited
assert 8 <= idx <= 15


Expand Down
2 changes: 1 addition & 1 deletion tests/python/unittest/test_autotvm_space.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def test_split():
cfg = ConfigSpace()

gemm_func(cfg, 128)
assert len(cfg) == 64
assert cfg.total_length == 64
assert len(cfg.space_map["tile_y"]) == 8

# test policy
Expand Down
4 changes: 2 additions & 2 deletions vta/scripts/tune_conv2d.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,11 +166,11 @@ def conv2d(N, CI, H, W, CO, KH, KW, strides, padding, dilation):
# Run Tuner
tuner = autotvm.tuner.RandomTuner(task)
tuner.tune(
n_trial=len(task.config_space),
n_trial=task.config_space.filtered_length,
early_stopping=None,
measure_option=measure_option,
callbacks=[
autotvm.callback.progress_bar(len(task.config_space), prefix=prefix),
autotvm.callback.progress_bar(task.config_space.filtered_length, prefix=prefix),
autotvm.callback.log_to_file(tmp_log_file),
],
)
Expand Down
4 changes: 2 additions & 2 deletions vta/scripts/tune_conv2d_transpose.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,11 +157,11 @@ def conv2d_transpose(N, CI, H, W, CO, KH, KW, strides, padding, opadding):
# Run Tuner
tuner = autotvm.tuner.RandomTuner(task)
tuner.tune(
n_trial=len(task.config_space),
n_trial=task.config_space.filtered_length,
early_stopping=None,
measure_option=measure_option,
callbacks=[
autotvm.callback.progress_bar(len(task.config_space), prefix=prefix),
autotvm.callback.progress_bar(task.config_space.filtered_length, prefix=prefix),
autotvm.callback.log_to_file(tmp_log_file),
],
)
Expand Down
4 changes: 2 additions & 2 deletions vta/scripts/tune_dense.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,11 +123,11 @@ def dense(N, CI, CO):
# Run Tuner
tuner = autotvm.tuner.RandomTuner(task)
tuner.tune(
n_trial=len(task.config_space),
n_trial=task.config_space.filtered_length,
early_stopping=None,
measure_option=measure_option,
callbacks=[
autotvm.callback.progress_bar(len(task.config_space), prefix=prefix),
autotvm.callback.progress_bar(task.config_space.filtered_length, prefix=prefix),
autotvm.callback.log_to_file(tmp_log_file),
],
)
Expand Down
4 changes: 2 additions & 2 deletions vta/scripts/tune_group_conv2d.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,11 +161,11 @@ def group_conv2d(N, CI, H, W, CO, KH, KW, strides, padding, dilation, group):
# Run Tuner
tuner = autotvm.tuner.RandomTuner(task)
tuner.tune(
n_trial=len(task.config_space),
n_trial=task.config_space.filtered_length,
early_stopping=None,
measure_option=measure_option,
callbacks=[
autotvm.callback.progress_bar(len(task.config_space), prefix=prefix),
autotvm.callback.progress_bar(task.config_space.filtered_length, prefix=prefix),
autotvm.callback.log_to_file(tmp_log_file),
],
)
Expand Down
2 changes: 1 addition & 1 deletion vta/scripts/tune_resnet.py
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ def tune_tasks(
tuner_obj.load_history(autotvm.record.load_from_file(tmp_log_file))

# do tuning
n_trial_ = min(n_trial, len(tsk.config_space))
n_trial_ = min(n_trial, tsk.config_space.filtered_length)
tuner_obj.tune(
n_trial_,
early_stopping=early_stopping,
Expand Down
2 changes: 1 addition & 1 deletion vta/tutorials/autotvm/tune_alu_vta.py
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ def tune_tasks(
tuner_obj.load_history(autotvm.record.load_from_file(tmp_log_file))

# do tuning
tsk_trial = min(n_trial, len(tsk.config_space))
tsk_trial = min(n_trial, tsk.config_space.filtered_length)
tuner_obj.tune(
n_trial=tsk_trial,
early_stopping=early_stopping,
Expand Down
2 changes: 1 addition & 1 deletion vta/tutorials/autotvm/tune_relay_vta.py
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ def tune_tasks(
tuner_obj.load_history(autotvm.record.load_from_file(tmp_log_file))

# do tuning
tsk_trial = min(n_trial, len(tsk.config_space))
tsk_trial = min(n_trial, tsk.config_space.filtered_length)
tuner_obj.tune(
n_trial=tsk_trial,
early_stopping=early_stopping,
Expand Down

0 comments on commit 1585196

Please sign in to comment.