Skip to content

Commit

Permalink
make psutil optional (#901)
Browse files Browse the repository at this point in the history
  • Loading branch information
eaidova authored Sep 16, 2024
1 parent e70ff84 commit f3b9ddd
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
13 changes: 13 additions & 0 deletions optimum/intel/utils/import_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,15 @@
_numa_available = False


_psutil_available = importlib.util.find_spec("psutil") is not None

if _psutil_available:
try:
importlib_metadata.version("psutil")
except importlib_metadata.PackageNotFoundError:
_psutil_available = False


_sentence_transformers_available = importlib.util.find_spec("sentence_transformers") is not None
_sentence_transformers_available = "N/A"

Expand Down Expand Up @@ -284,6 +293,10 @@ def is_numa_available():
return _numa_available


def is_psutil_available():
return _psutil_available


# This function was copied from: https://github.com/huggingface/accelerate/blob/874c4967d94badd24f893064cc3bef45f57cadf7/src/accelerate/utils/versions.py#L319
def compare_versions(library_or_version: Union[str, Version], operation: str, requirement_version: str):
"""
Expand Down
8 changes: 6 additions & 2 deletions optimum/intel/utils/modeling_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,12 @@
from pathlib import Path
from typing import List, Optional, Union

import psutil
import torch
from huggingface_hub import HfApi, HfFolder

from optimum.exporters import TasksManager

from .import_utils import is_numa_available
from .import_utils import is_numa_available, is_psutil_available


MULTI_QUERY_ATTN_MODELS = {"gpt_bigcode"}
Expand Down Expand Up @@ -190,6 +189,11 @@ def bind_cores_for_best_perf():
if platform.system() != "Linux":
logger.error("bind_cores_for_best_perf: OS not supported, this function can only be run on Linux systems.")
raise OSError("bind_cores_for_best_perf: OS not supported, this function can only be run on Linux systems.")
if not is_psutil_available():
logger.error("`psutil` module not found")
raise ImportError("'psutil' module not found, install with 'pip install psutil'")
import psutil

if not is_numa_available():
logger.error("'numa' module not found")
raise ImportError("'numa' module not found, install with 'pip install numa'")
Expand Down

0 comments on commit f3b9ddd

Please sign in to comment.