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
f0ae860c
Unverified
Commit
f0ae860c
authored
Sep 05, 2022
by
Tim Dettmers
Committed by
GitHub
Sep 05, 2022
Browse files
Merge pull request #25 from TimDettmers/remove_unused_code
Remove unused code, switch to warnings
parents
eab4d823
aca55881
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
4 additions
and
133 deletions
+4
-133
bitsandbytes/__main__.py
bitsandbytes/__main__.py
+3
-4
bitsandbytes/autograd/_functions.py
bitsandbytes/autograd/_functions.py
+0
-4
bitsandbytes/cuda_setup/compute_capability.py
bitsandbytes/cuda_setup/compute_capability.py
+0
-79
bitsandbytes/cuda_setup/main.py
bitsandbytes/cuda_setup/main.py
+0
-4
bitsandbytes/cuda_setup/paths.py
bitsandbytes/cuda_setup/paths.py
+1
-15
bitsandbytes/functional.py
bitsandbytes/functional.py
+0
-18
bitsandbytes/utils.py
bitsandbytes/utils.py
+0
-9
No files found.
bitsandbytes/__main__.py
View file @
f0ae860c
...
...
@@ -3,8 +3,9 @@
# cli()
import
os
import
sys
import
torch
from
warnings
import
warn
import
torch
HEADER_WIDTH
=
60
...
...
@@ -32,8 +33,6 @@ print()
from
.
import
COMPILED_WITH_CUDA
,
PACKAGE_GITHUB_URL
from
.cuda_setup.main
import
get_compute_capabilities
,
get_cuda_lib_handle
from
.cuda_setup.env_vars
import
to_be_ignored
from
.utils
import
print_stderr
print_header
(
"POTENTIALLY LIBRARY-PATH-LIKE ENV VARS"
)
for
k
,
v
in
os
.
environ
.
items
():
...
...
@@ -84,7 +83,7 @@ try:
except
ImportError
:
print
()
print_stderr
(
warn
(
f
"WARNING:
{
__package__
}
is currently running as CPU-only!
\n
"
"Therefore, 8-bit optimizers and GPU quantization are unavailable.
\n\n
"
f
"If you think that this is so erroneously,
\n
please report an issue!"
...
...
bitsandbytes/autograd/_functions.py
View file @
f0ae860c
import
operator
import
torch
import
bitsandbytes
as
bnb
import
bitsandbytes.functional
as
F
from
dataclasses
import
dataclass
...
...
@@ -378,9 +377,6 @@ class MatMul8bitLt(torch.autograd.Function):
return
grad_A
,
grad_B
,
None
,
grad_bias
,
None
matmul
=
MatMul8bitLt
.
apply
def
matmul
(
A
:
tensor
,
B
:
tensor
,
...
...
bitsandbytes/cuda_setup/compute_capability.py
deleted
100644 → 0
View file @
eab4d823
import
ctypes
from
dataclasses
import
dataclass
,
field
@
dataclass
class
CudaLibVals
:
# code bits taken from
# https://gist.github.com/f0k/63a664160d016a491b2cbea15913d549
nGpus
:
ctypes
.
c_int
=
field
(
default
=
ctypes
.
c_int
())
cc_major
:
ctypes
.
c_int
=
field
(
default
=
ctypes
.
c_int
())
cc_minor
:
ctypes
.
c_int
=
field
(
default
=
ctypes
.
c_int
())
device
:
ctypes
.
c_int
=
field
(
default
=
ctypes
.
c_int
())
error_str
:
ctypes
.
c_char_p
=
field
(
default
=
ctypes
.
c_char_p
())
cuda
:
ctypes
.
CDLL
=
field
(
init
=
False
,
repr
=
False
)
ccs
:
List
[
str
,
...]
=
field
(
init
=
False
)
def
_initialize_driver_API
(
self
):
self
.
check_cuda_result
(
self
.
cuda
.
cuInit
(
0
))
def
_load_cuda_lib
(
self
):
"""
1. find libcuda.so library (GPU driver) (/usr/lib)
init_device -> init variables -> call function by reference
"""
libnames
=
"libcuda.so"
for
libname
in
libnames
:
try
:
self
.
cuda
=
ctypes
.
CDLL
(
libname
)
except
OSError
:
continue
else
:
break
else
:
raise
OSError
(
"could not load any of: "
+
" "
.
join
(
libnames
))
def
call_cuda_func
(
self
,
function_obj
,
**
kwargs
):
CUDA_SUCCESS
=
0
# constant taken from cuda.h
pass
# if (CUDA_SUCCESS := function_obj(
def
_error_handle
(
cuda_lib_call_return_value
):
"""
2. call extern C function to determine CC
(see https://docs.nvidia.com/cuda/cuda-driver-api/group__CUDA__DEVICE__DEPRECATED.html)
"""
CUDA_SUCCESS
=
0
# constant taken from cuda.h
if
cuda_lib_call_return_value
!=
CUDA_SUCCESS
:
self
.
cuda
.
cuGetErrorString
(
cuda_lib_call_return_value
,
ctypes
.
byref
(
self
.
error_str
),
)
print
(
"Count not initialize CUDA - failure!"
)
raise
Exception
(
"CUDA exception!"
)
return
cuda_lib_call_return_value
def
__post_init__
(
self
):
self
.
_load_cuda_lib
()
self
.
_initialize_driver_API
()
self
.
check_cuda_result
(
self
.
cuda
,
self
.
cuda
.
cuDeviceGetCount
(
ctypes
.
byref
(
self
.
nGpus
))
)
tmp_ccs
=
[]
for
gpu_index
in
range
(
self
.
nGpus
.
value
):
check_cuda_result
(
self
.
cuda
,
self
.
cuda
.
cuDeviceGet
(
ctypes
.
byref
(
self
.
device
),
gpu_index
),
)
check_cuda_result
(
self
.
cuda
,
self
.
cuda
.
cuDeviceComputeCapability
(
ctypes
.
byref
(
self
.
cc_major
),
ctypes
.
byref
(
self
.
cc_minor
),
self
.
device
,
),
)
tmp_ccs
.
append
(
f
"
{
self
.
cc_major
.
value
}
.
{
self
.
cc_minor
.
value
}
"
)
self
.
ccs
=
sorted
(
tmp_ccs
,
reverse
=
True
)
bitsandbytes/cuda_setup/main.py
View file @
f0ae860c
...
...
@@ -17,10 +17,7 @@ evaluation:
"""
import
ctypes
import
torch
from
pathlib
import
Path
from
..utils
import
execute_and_return
from
.paths
import
determine_cuda_runtime_lib_path
...
...
@@ -81,7 +78,6 @@ def get_compute_capabilities(cuda):
cc_major
=
ctypes
.
c_int
()
cc_minor
=
ctypes
.
c_int
()
result
=
ctypes
.
c_int
()
device
=
ctypes
.
c_int
()
check_cuda_result
(
cuda
,
cuda
.
cuDeviceGetCount
(
ctypes
.
byref
(
nGpus
)))
...
...
bitsandbytes/cuda_setup/paths.py
View file @
f0ae860c
...
...
@@ -2,23 +2,11 @@ from pathlib import Path
from
typing
import
Set
,
Union
from
warnings
import
warn
from
..utils
import
print_stderr
from
.env_vars
import
get_potentially_lib_path_containing_env_vars
CUDA_RUNTIME_LIB
:
str
=
"libcudart.so"
def
purge_unwanted_semicolon
(
tentative_path
:
Path
)
->
Path
:
"""
Special function to handle the following exception:
__LMOD_REF_COUNT_PATH=/sw/cuda/11.6.2/bin:2;/mmfs1/home/dettmers/git/sched/bin:1;/mmfs1/home/dettmers/data/anaconda3/bin:1;/mmfs1/home/dettmers/data/anaconda3/condabin:1;/mmfs1/home/dettmers/.local/bin:1;/mmfs1/home/dettmers/bin:1;/usr/local/bin:1;/usr/bin:1;/usr/local/sbin:1;/usr/sbin:1;/mmfs1/home/dettmers/.fzf/bin:1;/mmfs1/home/dettmers/data/local/cuda-11.4/bin:1
"""
# if ';' in str(tentative_path):
# path_as_str, _ = str(tentative_path).split(';')
pass
def
extract_candidate_paths
(
paths_list_candidate
:
str
)
->
Set
[
Path
]:
return
{
Path
(
ld_path
)
for
ld_path
in
paths_list_candidate
.
split
(
":"
)
if
ld_path
}
...
...
@@ -29,7 +17,7 @@ def remove_non_existent_dirs(candidate_paths: Set[Path]) -> Set[Path]:
}
if
non_existent_directories
:
print_stderr
(
warn
(
"WARNING: The following directories listed in your path were found to "
f
"be non-existent:
{
non_existent_directories
}
"
)
...
...
@@ -117,8 +105,6 @@ def determine_cuda_runtime_lib_path() -> Union[Path, None]:
if
env_var
not
in
{
"CONDA_PREFIX"
,
"LD_LIBRARY_PATH"
}
}
cuda_runtime_libs
=
set
()
for
env_var
,
value
in
remaining_candidate_env_vars
.
items
():
cuda_runtime_libs
.
update
(
find_cuda_lib_in
(
value
))
...
...
bitsandbytes/functional.py
View file @
f0ae860c
...
...
@@ -5,7 +5,6 @@
import
ctypes
as
ct
import
operator
import
random
import
math
import
torch
from
typing
import
Tuple
...
...
@@ -243,23 +242,6 @@ def get_transform_func(dtype, orderA, orderOut, transpose=False):
return
getattr
(
lib
,
name
)
class
GlobalData
(
object
):
_instance
=
None
def
__init__
(
self
):
raise
RuntimeError
(
"Call get_instance() instead"
)
def
initialize
(
self
):
self
.
data
=
{}
@
classmethod
def
get_instance
(
cls
):
if
cls
.
_instance
is
None
:
cls
.
_instance
=
cls
.
__new__
(
cls
)
cls
.
_instance
.
initialize
()
return
cls
.
_instance
def
get_transform_buffer
(
shape
,
dtype
,
device
,
to_order
,
from_order
=
"row"
,
transpose
=
False
):
...
...
bitsandbytes/utils.py
View file @
f0ae860c
import
shlex
import
subprocess
import
sys
from
typing
import
Tuple
...
...
@@ -22,11 +21,3 @@ def execute_and_return(command_string: str) -> Tuple[str, str]:
std_out
,
std_err
=
execute_and_return_decoded_std_streams
(
command_string
)
return
std_out
,
std_err
def
print_stderr
(
s
:
str
)
->
None
:
print
(
s
,
file
=
sys
.
stderr
)
def
warn_of_missing_prerequisite
(
s
:
str
)
->
None
:
print_stderr
(
"WARNING, missing pre-requisite: "
+
s
)
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