Raise err if minimum Accelerate version isn't available (#22841)
* Add warning about accelerate * Version block Accelerate * Include parse * Apply suggestions from code review Co-authored-by: Sylvain Gugger <35901082+sgugger@users.noreply.github.com> * Check partial state * Update param --------- Co-authored-by: Sylvain Gugger <35901082+sgugger@users.noreply.github.com>
This commit is contained in:
@@ -1531,6 +1531,10 @@ class TrainingArguments:
|
|||||||
def _setup_devices(self) -> "torch.device":
|
def _setup_devices(self) -> "torch.device":
|
||||||
requires_backends(self, ["torch"])
|
requires_backends(self, ["torch"])
|
||||||
logger.info("PyTorch: setting up devices")
|
logger.info("PyTorch: setting up devices")
|
||||||
|
if not is_sagemaker_mp_enabled() and not is_accelerate_available(check_partial_state=True):
|
||||||
|
raise ImportError(
|
||||||
|
"Using the `Trainer` with `PyTorch` requires `accelerate`: Run `pip install --upgrade accelerate`"
|
||||||
|
)
|
||||||
if self.no_cuda:
|
if self.no_cuda:
|
||||||
self.distributed_state = PartialState(cpu=True)
|
self.distributed_state = PartialState(cpu=True)
|
||||||
device = self.distributed_state.device
|
device = self.distributed_state.device
|
||||||
|
|||||||
@@ -575,8 +575,15 @@ def is_protobuf_available():
|
|||||||
return importlib.util.find_spec("google.protobuf") is not None
|
return importlib.util.find_spec("google.protobuf") is not None
|
||||||
|
|
||||||
|
|
||||||
def is_accelerate_available():
|
def is_accelerate_available(check_partial_state=False):
|
||||||
return importlib.util.find_spec("accelerate") is not None
|
accelerate_available = importlib.util.find_spec("accelerate") is not None
|
||||||
|
if accelerate_available:
|
||||||
|
if check_partial_state:
|
||||||
|
return version.parse(importlib_metadata.version("accelerate")) >= version.parse("0.17.0")
|
||||||
|
else:
|
||||||
|
return True
|
||||||
|
else:
|
||||||
|
return False
|
||||||
|
|
||||||
|
|
||||||
def is_optimum_available():
|
def is_optimum_available():
|
||||||
|
|||||||
Reference in New Issue
Block a user