Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
OpenDAS
bitsandbytes
Commits
d4df4b79
"git@developer.sourcefind.cn:renzhc/diffusers_dcu.git" did not exist on "79c380bc80051d8f82a38c3a7df6f8f4efd1633d"
Commit
d4df4b79
authored
May 06, 2025
by
Titus von Koeller
Browse files
don't error when not calling + doc string
parent
0acab1c6
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
17 additions
and
5 deletions
+17
-5
bitsandbytes/cextension.py
bitsandbytes/cextension.py
+17
-5
No files found.
bitsandbytes/cextension.py
View file @
d4df4b79
...
@@ -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
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment