Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[feat] Add lru_cache to import_utils calls that did not previously have it #1584

Merged
merged 4 commits into from
Mar 26, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/peft/import_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,12 @@
import packaging.version


@lru_cache
def is_bnb_available() -> bool:
return importlib.util.find_spec("bitsandbytes") is not None


@lru_cache
def is_bnb_4bit_available() -> bool:
if not is_bnb_available():
return False
Expand All @@ -31,6 +33,7 @@ def is_bnb_4bit_available() -> bool:
return hasattr(bnb.nn, "Linear4bit")


@lru_cache
def is_auto_gptq_available():
if importlib.util.find_spec("auto_gptq") is not None:
AUTOGPTQ_MINIMUM_VERSION = packaging.version.parse("0.5.0")
Expand All @@ -44,6 +47,7 @@ def is_auto_gptq_available():
)


@lru_cache
def is_optimum_available() -> bool:
return importlib.util.find_spec("optimum") is not None

Expand All @@ -65,9 +69,11 @@ def is_torch_tpu_available(check_device=True):
return False


@lru_cache
def is_aqlm_available():
return importlib.util.find_spec("aqlm") is not None


@lru_cache
def is_auto_awq_available():
return importlib.util.find_spec("awq") is not None
Loading