Skip to content

Commit 103620a

Browse files
committed
Add accelerate to import backend mapping
1 parent ef90dc0 commit 103620a

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

optimum/intel/utils/import_utils.py

+20
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,16 @@
156156
_datasets_available = False
157157

158158

159+
_accelerate_available = importlib.util.find_spec("accelerate") is not None
160+
_accelerate_version = "N/A"
161+
162+
if _accelerate_available:
163+
try:
164+
_accelerate_version = importlib_metadata.version("accelerate")
165+
except importlib_metadata.PackageNotFoundError:
166+
_accelerate_available = False
167+
168+
159169
def is_transformers_available():
160170
return _transformers_available
161171

@@ -196,6 +206,10 @@ def is_datasets_available():
196206
return _datasets_available
197207

198208

209+
def is_accelerate_available():
210+
return _accelerate_available
211+
212+
199213
# This function was copied from: https://github.com/huggingface/accelerate/blob/874c4967d94badd24f893064cc3bef45f57cadf7/src/accelerate/utils/versions.py#L319
200214
def compare_versions(library_or_version: Union[str, Version], operation: str, requirement_version: str):
201215
"""
@@ -317,13 +331,19 @@ def is_timm_version(operation: str, version: str):
317331
`pip install datasets`. Please note that you may need to restart your runtime after installation.
318332
"""
319333

334+
ACCELERATE_IMPORT_ERROR = """
335+
{0} requires the accelerate library but it was not found in your environment. You can install it with pip:
336+
`pip install accelerate`. Please note that you may need to restart your runtime after installation.
337+
"""
338+
320339
BACKENDS_MAPPING = OrderedDict(
321340
[
322341
("diffusers", (is_diffusers_available, DIFFUSERS_IMPORT_ERROR)),
323342
("ipex", (is_ipex_available, IPEX_IMPORT_ERROR)),
324343
("nncf", (is_nncf_available, NNCF_IMPORT_ERROR)),
325344
("openvino", (is_openvino_available, OPENVINO_IMPORT_ERROR)),
326345
("neural_compressor", (is_neural_compressor_available, NEURAL_COMPRESSOR_IMPORT_ERROR)),
346+
("accelerate", (is_accelerate_available, ACCELERATE_IMPORT_ERROR)),
327347
]
328348
)
329349

0 commit comments

Comments
 (0)