Skip to content

armgit / dspy

Public Imported from GitHub
0

DSPy: The framework for programming—not prompting—language models

Python

export HFModel withtout requiring deps

Sri Vardhamanan158b7f4b00da
diff --git a/dsp/modules/__init__.py b/dsp/modules/__init__.py
index 448ffa9b4..c6c402e78 100644
--- a/dsp/modules/__init__.py
+++ b/dsp/modules/__init__.py
@@ -1,6 +1,6 @@
from .cache_utils import *
from .gpt3 import *
-# from .hf import HFModel
+from .hf import HFModel
from .colbertv2 import ColBERTv2
from .sentence_vectorizer import *
from .cohere import *
diff --git a/dsp/modules/hf.py b/dsp/modules/hf.py
index 89af2fb33..b3d5a9aec 100644
--- a/dsp/modules/hf.py
+++ b/dsp/modules/hf.py
@@ -1,7 +1,4 @@
from typing import Optional, Literal
-
-from transformers import AutoModelForSeq2SeqLM, AutoModelForCausalLM, AutoTokenizer
-
from dsp.modules.lm import LM
@@ -32,10 +29,16 @@ class HFModel(LM):
Args:
model (str): HF model identifier to load and use
checkpoint (str, optional): load specific checkpoints of the model. Defaults to None.
- is_client (bool, optional): whether to use hf client or load from local. Defaults to False.
+ is_client (bool, optional): whether to access models via client. Defaults to False.
hf_device_map (str, optional): HF config strategy to load the model.
Recommeded to use "auto", which will help loading large models using accelerate. Defaults to "auto".
"""
+ try:
+ from transformers import AutoModelForSeq2SeqLM, AutoModelForCausalLM, AutoTokenizer
+ except ImportError as exc:
+ raise ModuleNotFoundError(
+ "You need to install Hugging Face transformers library to use HF models."
+ ) from exc
super().__init__(model)
self.provider = "hf"
self.is_client = is_client
diff --git a/dsp/modules/hf_client.py b/dsp/modules/hf_client.py
index 0ce20a46d..589676c7e 100644
--- a/dsp/modules/hf_client.py
+++ b/dsp/modules/hf_client.py
@@ -1,9 +1,6 @@
-import functools
import requests
-from dsp.modules.cache_utils import CacheMemory, NotebookCacheMemory
from dsp.modules.hf import HFModel
-from dsp.utils import dotdict
class HFModelClient(HFModel):