[`bnb`] Add simple check for bnb import (#24995)

add simple check for bnb
This commit is contained in:
Younes Belkada 2023-07-21 17:50:52 +02:00 committed by GitHub
parent f1a1eb4ae1
commit d3ce048c20
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 8 additions and 1 deletions

View File

@ -504,7 +504,14 @@ def is_ipex_available():
def is_bitsandbytes_available():
return _bitsandbytes_available
if not is_torch_available():
return False
# bitsandbytes throws an error if cuda is not available
# let's avoid that by adding a simple check
import torch
return _bitsandbytes_available and torch.cuda.is_available()
def is_torchdistx_available():