From d0f83664b84cd8437eabb179df56c5b57f8610df Mon Sep 17 00:00:00 2001 From: sf-wind Date: Wed, 16 Jan 2019 21:31:58 -0800 Subject: [PATCH] Avoid runtime exception when file doesn't exist (#2441) * Avoid runtime exception when file doesn't exist * Update the check based on feedback * Revert the old fix --- python/tvm/autotvm/tophub.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/python/tvm/autotvm/tophub.py b/python/tvm/autotvm/tophub.py index b611f3cee054..9ec9becc7245 100644 --- a/python/tvm/autotvm/tophub.py +++ b/python/tvm/autotvm/tophub.py @@ -77,7 +77,8 @@ def context(target, extra_files=None): for name in possible_names: name = _alias(name) if name in all_packages: - check_backend(name) + if not check_backend(name): + continue filename = "%s_%s.log" % (name, PACKAGE_VERSION[name]) best_context.load(os.path.join(AUTOTVM_TOPHUB_ROOT_PATH, filename)) @@ -98,6 +99,11 @@ def check_backend(backend): ---------- backend: str The name of backend. + + Returns + ---------- + success: bool + Whether the check is successful. """ backend = _alias(backend) assert backend in PACKAGE_VERSION, 'Cannot find backend "%s" in TopHub' % backend @@ -105,7 +111,7 @@ def check_backend(backend): version = PACKAGE_VERSION[backend] package_name = "%s_%s.log" % (backend, version) if os.path.isfile(os.path.join(AUTOTVM_TOPHUB_ROOT_PATH, package_name)): - return + return True if sys.version_info >= (3,): import urllib.request as urllib2 @@ -113,8 +119,10 @@ def check_backend(backend): import urllib2 try: download_package(package_name) + return True except urllib2.URLError as e: logging.warning("Failed to download tophub package for %s: %s", backend, e) + return False def download_package(package_name):