Commit d4df4b79 authored by Titus von Koeller's avatar Titus von Koeller
Browse files

don't error when not calling + doc string

parent 0acab1c6
...@@ -45,11 +45,19 @@ class BNBNativeLibrary: ...@@ -45,11 +45,19 @@ class BNBNativeLibrary:
def __init__(self, lib: ct.CDLL): def __init__(self, lib: ct.CDLL):
self._lib = lib self._lib = lib
def __getattr__(self, item): def __getattr__(self, name):
return getattr(self._lib, item) def throw_on_call(*args, **kwargs):
if hasattr(self._lib, name):
return getattr(self._lib, name)(*args, **kwargs)
raise RuntimeError(
f"Method '{name}' not available in CPU-only version of bitsandbytes.\n"
"Reinstall with GPU support or use CUDA-enabled hardware."
)
return throw_on_call
def __getitem__(self, item): def __getitem__(self, item):
return getattr(self._lib, item) return self.__getattr__(item)
class CudaBNBNativeLibrary(BNBNativeLibrary): class CudaBNBNativeLibrary(BNBNativeLibrary):
...@@ -221,8 +229,12 @@ class ErrorHandlerMockBNBNativeLibrary(BNBNativeLibrary): ...@@ -221,8 +229,12 @@ class ErrorHandlerMockBNBNativeLibrary(BNBNativeLibrary):
) )
def __getattr__(self, name): def __getattr__(self, name):
"""Raise error with detailed message when any attribute is accessed""" """Return a dummy function that throws when called, rather than on attribute access"""
raise RuntimeError(f"{self.formatted_error}Native code method attempted to access: lib.{name}()")
def throw_on_call(*args, **kwargs):
raise RuntimeError(f"{self.formatted_error}Native code method attempted to call: lib.{name}()")
return throw_on_call
def __getitem__(self, name): def __getitem__(self, name):
return self.__getattr__(name) return self.__getattr__(name)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment