|
156 | 156 | _datasets_available = False
|
157 | 157 |
|
158 | 158 |
|
| 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 | + |
159 | 169 | def is_transformers_available():
|
160 | 170 | return _transformers_available
|
161 | 171 |
|
@@ -196,6 +206,10 @@ def is_datasets_available():
|
196 | 206 | return _datasets_available
|
197 | 207 |
|
198 | 208 |
|
| 209 | +def is_accelerate_available(): |
| 210 | + return _accelerate_available |
| 211 | + |
| 212 | + |
199 | 213 | # This function was copied from: https://github.com/huggingface/accelerate/blob/874c4967d94badd24f893064cc3bef45f57cadf7/src/accelerate/utils/versions.py#L319
|
200 | 214 | def compare_versions(library_or_version: Union[str, Version], operation: str, requirement_version: str):
|
201 | 215 | """
|
@@ -317,13 +331,19 @@ def is_timm_version(operation: str, version: str):
|
317 | 331 | `pip install datasets`. Please note that you may need to restart your runtime after installation.
|
318 | 332 | """
|
319 | 333 |
|
| 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 | + |
320 | 339 | BACKENDS_MAPPING = OrderedDict(
|
321 | 340 | [
|
322 | 341 | ("diffusers", (is_diffusers_available, DIFFUSERS_IMPORT_ERROR)),
|
323 | 342 | ("ipex", (is_ipex_available, IPEX_IMPORT_ERROR)),
|
324 | 343 | ("nncf", (is_nncf_available, NNCF_IMPORT_ERROR)),
|
325 | 344 | ("openvino", (is_openvino_available, OPENVINO_IMPORT_ERROR)),
|
326 | 345 | ("neural_compressor", (is_neural_compressor_available, NEURAL_COMPRESSOR_IMPORT_ERROR)),
|
| 346 | + ("accelerate", (is_accelerate_available, ACCELERATE_IMPORT_ERROR)), |
327 | 347 | ]
|
328 | 348 | )
|
329 | 349 |
|
|
0 commit comments