Skip to content
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
3 changes: 2 additions & 1 deletion python/tvm/auto_scheduler/dispatcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@

import logging
import pathlib
from collections.abc import Iterable

import numpy as np

Expand Down Expand Up @@ -199,7 +200,7 @@ def load(self, records, n_lines=None):
if it is not None, only load the first `n_lines` lines of log
"""
joint_records = []
if not isinstance(records, (list, tuple)):
if not isinstance(records, Iterable) or isinstance(records, str):
records = [records]

for rec in records:
Expand Down
5 changes: 3 additions & 2 deletions python/tvm/autotvm/task/dispatcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
from __future__ import absolute_import as _abs

import logging
from collections.abc import Iterable

import numpy as np

Expand Down Expand Up @@ -212,15 +213,15 @@ def load(self, records):
Collection of tuning records.
If is str, then it should be the filename of a records log file.
Each row of this file is an encoded record pair. If it is a list
it can either be a list of paths to logs that will loaded jointly or
it can either be a list of paths to logs that will be loaded jointly or
an iterator of measurement results.
"""
# pylint: disable=import-outside-toplevel
from pathlib import Path
from ..record import load_from_file

joint_records = []
if not isinstance(records, (list, tuple)):
if not isinstance(records, Iterable) or isinstance(records, str):
records = [records]

for rec in records:
Expand Down
7 changes: 7 additions & 0 deletions tests/python/relay/test_auto_scheduler_tuning.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,13 @@ def tune_network(network, target):
best, auto_scheduler.dispatcher.ApplyHistoryBest
), "Unable to load multiple log files jointly."

# Confirm iterables can be directly loaded.
loaded_recs = auto_scheduler.dispatcher.load_records(log_file)
with auto_scheduler.ApplyHistoryBest(iter(loaded_recs)) as best:
assert isinstance(
best, auto_scheduler.dispatcher.ApplyHistoryBest
), "Unable to ingest logs from an interator."

# Sample a schedule when missing
with auto_scheduler.ApplyHistoryBestOrSample(None, num_measure=2):
with tvm.transform.PassContext(
Expand Down
5 changes: 5 additions & 0 deletions tests/python/unittest/test_autotvm_record.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,11 @@ def test_apply_history_best():
x = hist_best.query(target, tsk.workload)
assert str(x) == str(tsk.config_space.get(2))

# Confirm same functionality for iterators.
hist_best = ApplyHistoryBest(iter(records))
x = hist_best.query(target, tsk.workload)
assert str(x) == str(tsk.config_space.get(2))


if __name__ == "__main__":
test_load_dump()
Expand Down