Skip to content

Commit f3b9ddd

Browse files
authored
make psutil optional (#901)
1 parent e70ff84 commit f3b9ddd

File tree

2 files changed

+19
-2
lines changed

2 files changed

+19
-2
lines changed

optimum/intel/utils/import_utils.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,15 @@
149149
_numa_available = False
150150

151151

152+
_psutil_available = importlib.util.find_spec("psutil") is not None
153+
154+
if _psutil_available:
155+
try:
156+
importlib_metadata.version("psutil")
157+
except importlib_metadata.PackageNotFoundError:
158+
_psutil_available = False
159+
160+
152161
_sentence_transformers_available = importlib.util.find_spec("sentence_transformers") is not None
153162
_sentence_transformers_available = "N/A"
154163

@@ -284,6 +293,10 @@ def is_numa_available():
284293
return _numa_available
285294

286295

296+
def is_psutil_available():
297+
return _psutil_available
298+
299+
287300
# This function was copied from: https://github.com/huggingface/accelerate/blob/874c4967d94badd24f893064cc3bef45f57cadf7/src/accelerate/utils/versions.py#L319
288301
def compare_versions(library_or_version: Union[str, Version], operation: str, requirement_version: str):
289302
"""

optimum/intel/utils/modeling_utils.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,12 @@
2020
from pathlib import Path
2121
from typing import List, Optional, Union
2222

23-
import psutil
2423
import torch
2524
from huggingface_hub import HfApi, HfFolder
2625

2726
from optimum.exporters import TasksManager
2827

29-
from .import_utils import is_numa_available
28+
from .import_utils import is_numa_available, is_psutil_available
3029

3130

3231
MULTI_QUERY_ATTN_MODELS = {"gpt_bigcode"}
@@ -190,6 +189,11 @@ def bind_cores_for_best_perf():
190189
if platform.system() != "Linux":
191190
logger.error("bind_cores_for_best_perf: OS not supported, this function can only be run on Linux systems.")
192191
raise OSError("bind_cores_for_best_perf: OS not supported, this function can only be run on Linux systems.")
192+
if not is_psutil_available():
193+
logger.error("`psutil` module not found")
194+
raise ImportError("'psutil' module not found, install with 'pip install psutil'")
195+
import psutil
196+
193197
if not is_numa_available():
194198
logger.error("'numa' module not found")
195199
raise ImportError("'numa' module not found, install with 'pip install numa'")

0 commit comments

Comments
 (0)