fix(annotations): check library through find_spec (#691)

Signed-off-by: Aaron <29749331+aarnphm@users.noreply.github.com>
This commit is contained in:
Aaron Pham
2023-11-18 02:02:16 -05:00
committed by GitHub
parent e9a89b7a7e
commit 4499469efb
2 changed files with 4 additions and 7 deletions

View File

@@ -1,5 +1,6 @@
from __future__ import annotations
import functools
import importlib.util
import logging
import os
import types
@@ -349,12 +350,8 @@ class LLM(t.Generic[M, T], ReprMixin):
@property
def adapter_map(self):
try:
import peft as _ # noqa: F401
except ImportError as err:
raise MissingDependencyError(
"Failed to import 'peft'. Make sure to do 'pip install \"openllm[fine-tune]\"'"
) from err
if importlib.util.find_spec('peft') is None:
raise MissingDependencyError("Failed to import 'peft'. Make sure to do 'pip install \"openllm[fine-tune]\"'")
if not self.has_adapters:
raise AttributeError('Adapter map is not available.')
assert self._adapter_map is not None

View File

@@ -24,7 +24,7 @@ from openllm_core.utils.representation import ReprArgs
from ._quantisation import QuantizationConfig
from ._runners import Runner
InjectedModel = Union[PeftModel | PeftModelForCausalLM | PeftModelForSeq2SeqLM]
InjectedModel = Union[PeftModel, PeftModelForCausalLM, PeftModelForSeq2SeqLM]
class IdentifyingParams(TypedDict):
configuration: str