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

[TVM][AutoTVM] cast filepath arguments to string #3968

Merged
merged 1 commit into from
Sep 18, 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: 8 additions & 0 deletions python/tvm/autotvm/task/dispatcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@

logger = logging.getLogger('autotvm')


class DispatchContext(object):
"""
Base class of dispatch context.
Expand Down Expand Up @@ -281,8 +282,12 @@ def load(self, records):
Each row of this file is an encoded record pair.
Otherwise, it is an iterator.
"""
from pathlib import Path
from ..record import load_from_file

if isinstance(records, Path):
records = str(records)

if isinstance(records, str):
records = load_from_file(records)
if not records:
Expand Down Expand Up @@ -404,8 +409,10 @@ def update(self, target, workload, cfg):
key = (str(target), workload)
self.memory[key] = cfg


DispatchContext.current = FallbackContext()


def clear_fallback_cache(target, workload):
"""Clear fallback cache. Pass the same argument as _query_inside to this function
to clean the cache.
Expand All @@ -426,6 +433,7 @@ def clear_fallback_cache(target, workload):
context = context._old_ctx
context.clear_cache(target, workload)


class ApplyGraphBest(DispatchContext):
"""Load the graph level tuning optimal schedules.

Expand Down
6 changes: 6 additions & 0 deletions python/tvm/autotvm/tuner/callback.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@

logger = logging.getLogger('autotvm')


def log_to_file(file_out, protocol='json'):
"""Log the tuning records into file.
The rows of the log are stored in the format of autotvm.record.encode.
Expand All @@ -51,6 +52,11 @@ def _callback(_, inputs, results):
else:
for inp, result in zip(inputs, results):
file_out.write(record.encode(inp, result, protocol) + "\n")

from pathlib import Path
if isinstance(file_out, Path):
file_out = str(file_out)

return _callback


Expand Down
4 changes: 4 additions & 0 deletions python/tvm/module.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,10 @@ def export_library(self,
kwargs : dict, optional
Additional arguments passed to fcompile
"""
from pathlib import Path
if isinstance(file_name, Path):
file_name = str(file_name)

if self.type_key == "stackvm":
if not file_name.endswith(".stackvm"):
raise ValueError("Module[%s]: can only be saved as stackvm format."
Expand Down