Skip to content

Commit

Permalink
[BitsandBytes] Verify if GPU is available (huggingface#30533)
Browse files Browse the repository at this point in the history
Change order
  • Loading branch information
NielsRogge authored and zucchini-nlp committed May 10, 2024
1 parent 65554f0 commit c83860d
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 6 deletions.
5 changes: 2 additions & 3 deletions src/transformers/quantizers/quantizer_bnb_4bit.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ def __init__(self, quantization_config, **kwargs):
self.modules_to_not_convert = self.quantization_config.llm_int8_skip_modules

def validate_environment(self, *args, **kwargs):
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()):
raise ImportError(
"Using `bitsandbytes` 8-bit quantization requires Accelerate: `pip install accelerate` "
Expand All @@ -70,9 +72,6 @@ def validate_environment(self, *args, **kwargs):
" sure the weights are in PyTorch format."
)

if not torch.cuda.is_available():
raise RuntimeError("No GPU found. A GPU is needed for quantization.")

device_map = kwargs.get("device_map", None)
if (
device_map is not None
Expand Down
6 changes: 3 additions & 3 deletions src/transformers/quantizers/quantizer_bnb_8bit.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@ def __init__(self, quantization_config, **kwargs):
self.modules_to_not_convert = self.quantization_config.llm_int8_skip_modules

def validate_environment(self, *args, **kwargs):
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()):
raise ImportError(
"Using `bitsandbytes` 8-bit quantization requires Accelerate: `pip install accelerate` "
Expand All @@ -70,9 +73,6 @@ def validate_environment(self, *args, **kwargs):
" sure the weights are in PyTorch format."
)

if not torch.cuda.is_available():
raise RuntimeError("No GPU found. A GPU is needed for quantization.")

device_map = kwargs.get("device_map", None)
if (
device_map is not None
Expand Down

0 comments on commit c83860d

Please sign in to comment.