"...git@developer.sourcefind.cn:chenpangpang/transformers.git" did not exist on "7533d30acd975027e83a548e4c38e06fa335291b"
Unverified Commit abd4cbd7 authored by Marc Sun's avatar Marc Sun Committed by GitHub
Browse files

Better error message for bitsandbytes import (#27764)

* better error message

* fix logic

* fix log
parent 7b6324e1
...@@ -1010,7 +1010,7 @@ class ModuleUtilsMixin: ...@@ -1010,7 +1010,7 @@ class ModuleUtilsMixin:
else: else:
raise ValueError( raise ValueError(
"bitsandbytes is not installed but it seems that the model has been loaded in 4bit precision, something went wrong" "bitsandbytes is not installed but it seems that the model has been loaded in 4bit precision, something went wrong"
" make sure to install bitsandbytes with `pip install bitsandbytes`." " make sure to install bitsandbytes with `pip install bitsandbytes`. You also need a GPU. "
) )
for param in total_parameters: for param in total_parameters:
...@@ -2746,11 +2746,13 @@ class PreTrainedModel(nn.Module, ModuleUtilsMixin, GenerationMixin, PushToHubMix ...@@ -2746,11 +2746,13 @@ class PreTrainedModel(nn.Module, ModuleUtilsMixin, GenerationMixin, PushToHubMix
) )
if load_in_8bit or load_in_4bit: if load_in_8bit or load_in_4bit:
if not torch.cuda.is_available():
raise RuntimeError("No GPU found. A GPU is needed for quantization.")
if not (is_accelerate_available() and is_bitsandbytes_available()): if not (is_accelerate_available() and is_bitsandbytes_available()):
raise ImportError( raise ImportError(
"Using `load_in_8bit=True` requires Accelerate: `pip install accelerate` and the latest version of" "Using `load_in_8bit=True` requires Accelerate: `pip install accelerate` and the latest version of"
" bitsandbytes `pip install -i https://test.pypi.org/simple/ bitsandbytes` or" " bitsandbytes `pip install -i https://test.pypi.org/simple/ bitsandbytes` or"
" pip install bitsandbytes` " " `pip install bitsandbytes`."
) )
if torch_dtype is None: if torch_dtype is None:
...@@ -2764,10 +2766,7 @@ class PreTrainedModel(nn.Module, ModuleUtilsMixin, GenerationMixin, PushToHubMix ...@@ -2764,10 +2766,7 @@ class PreTrainedModel(nn.Module, ModuleUtilsMixin, GenerationMixin, PushToHubMix
torch_dtype = torch.float16 torch_dtype = torch.float16
if device_map is None: if device_map is None:
if torch.cuda.is_available(): device_map = {"": torch.cuda.current_device()}
device_map = {"": torch.cuda.current_device()}
else:
raise RuntimeError("No GPU found. A GPU is needed for quantization.")
logger.info( logger.info(
"The device_map was not initialized. " "The device_map was not initialized. "
"Setting device_map to {'':torch.cuda.current_device()}. " "Setting device_map to {'':torch.cuda.current_device()}. "
......
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