Skip to content

Commit

Permalink
Revert "BUG: disable import cuda error when cpu only in a shared pyth…
Browse files Browse the repository at this point in the history
…on env" (#49)
  • Loading branch information
ChengjieLi28 authored Jul 17, 2023
1 parent a7c94f7 commit c329d28
Showing 1 changed file with 7 additions and 17 deletions.
24 changes: 7 additions & 17 deletions python/xoscar/_utils.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -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_):
Expand Down

0 comments on commit c329d28

Please sign in to comment.