From c329d2804686f68bcd64747a904069779b47138d Mon Sep 17 00:00:00 2001 From: Chengjie Li <109656400+ChengjieLi28@users.noreply.github.com> Date: Mon, 17 Jul 2023 18:23:56 +0800 Subject: [PATCH] Revert "BUG: disable import cuda error when cpu only in a shared python env" (#49) --- python/xoscar/_utils.pyx | 24 +++++++----------------- 1 file changed, 7 insertions(+), 17 deletions(-) diff --git a/python/xoscar/_utils.pyx b/python/xoscar/_utils.pyx index 0dacc2f9..bb5c2c39 100644 --- a/python/xoscar/_utils.pyx +++ b/python/xoscar/_utils.pyx @@ -66,23 +66,13 @@ cdef class TypeDispatcher: cdef _reload_lazy_handlers(self): for k, v in self._lazy_handlers.items(): mod_name, obj_name = k.rsplit('.', 1) - imported = False - try: - with warnings.catch_warnings(): - # the lazy imported cudf will warn no device found, - # when we set visible device to -1 for CPU processes, - # ignore the warning to not distract users - warnings.simplefilter("ignore") - mod = importlib.import_module(mod_name, __name__) - imported = True - # The reason all exceptions are caught here instead of ImportError is that - # when, for example, a cpu machine tries to import cuda, the exception thrown is CudaAPIError. - except: # pragma: no cover - imported = False - warnings.warn(f'Import {mod_name} failed. Please check your current Python environment.') - - if imported: - self.register(getattr(mod, obj_name), v) + with warnings.catch_warnings(): + # the lazy imported cudf will warn no device found, + # when we set visible device to -1 for CPU processes, + # ignore the warning to not distract users + warnings.simplefilter("ignore") + mod = importlib.import_module(mod_name, __name__) + self.register(getattr(mod, obj_name), v) self._lazy_handlers = dict() cpdef get_handler(self, object type_):