Skip to content

armgit / dspy

Public Imported from GitHub
0

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

Python

remove unused utils and comment delimiters

Isaac Millerf2c4bed5c5a8
diff --git a/dspy/clients/anyscale.py b/dspy/clients/anyscale.py
index 1c3662c58..d30f48486 100644
--- a/dspy/clients/anyscale.py
+++ b/dspy/clients/anyscale.py
@@ -19,10 +19,6 @@ try:
except ImportError:
anyscale = None
-#-------------------------------------------------------------------------------
-# Variables
-#-------------------------------------------------------------------------------
-
# List of training methods supported by AnyScale
TRAINING_METHODS_ANYSCALE = [
TrainingMethod.SFT,
@@ -30,11 +26,6 @@ TRAINING_METHODS_ANYSCALE = [
PROVIDER_ANYSCALE = "anyscale"
-
-#-------------------------------------------------------------------------------
-# Launching and killing LMs
-#-------------------------------------------------------------------------------
-
def anyscale_model_launch(model: str, launch_kwargs: Dict[str, Any]):
"""Launch an AnyScale model."""
# TODO: Hardcode resources for launching a select server through docker
@@ -46,12 +37,6 @@ def anyscale_model_kill(model: str, launch_kwargs: Dict[str, Any]):
"""Kill an AnyScale model."""
raise NotImplementedError("Method `anyscale_model_kill` is not implemented.")
-
-#-------------------------------------------------------------------------------
-# Function and classes required for the fine-tune interface
-#-------------------------------------------------------------------------------
-
-
def is_anyscale_model(model: str) -> bool:
"""Check if the model is an AnyScale model."""
# TODO: This needs to be implemented to support fine-tuning
@@ -142,10 +127,6 @@ def finetune_anyscale(
return last_model_checkpoint
-#-------------------------------------------------------------------------------
-# Custom functions to support the finetune_* function
-#-------------------------------------------------------------------------------
-
def wait_for_training(job_id):
"""Wait for the training to complete."""
anyscale.job.wait(id=job_id, timeout_s=18000)
diff --git a/dspy/clients/lm.py b/dspy/clients/lm.py
index d8dadec5b..eb64cecd6 100644
--- a/dspy/clients/lm.py
+++ b/dspy/clients/lm.py
@@ -9,11 +9,6 @@ import uuid
from dspy.utils.logging import logger
from dspy.clients.finetune import FinetuneJob, TrainingMethod
-from dspy.clients.self_hosted import (
- is_self_hosted_model,
- self_hosted_model_launch,
- self_hosted_model_kill,
-)
from dspy.clients.anyscale import (
is_anyscale_model,
anyscale_model_launch,
@@ -247,15 +242,10 @@ def _inspect_history(lm, n: int = 1):
print("\n\n\n")
-
-#-------------------------------------------------------------------------------
-# Fine-tune support
-#-------------------------------------------------------------------------------
# TODO: This part can be moved to a separate module
from dspy.clients.openai import (
FinetuneJobOpenAI,
- is_openai_model,
finetune_openai,
)
from dspy.clients.anyscale import (
@@ -266,26 +256,6 @@ from dspy.clients.anyscale import (
_PROVIDER_ANYSCALE = "anyscale"
_PROVIDER_OPENAI = "openai"
-_SUPPORTED_FINETUNE_PROVIDERS = [
- _PROVIDER_ANYSCALE,
- _PROVIDER_OPENAI,
-]
-
-
-def _get_supported_finetune_provider(model: str) -> Union[str, ValueError]:
- """Return the finetuning provider for the given model.
-
- The provider must be in _SUPPORTED_FINETUNE_PROVIDERS. This function is not
- named `_get_provider` because it does not attempt to find the provider of a
- model if there is no DSPy fine-tuning support for it.
- """
- if is_openai_model(model):
- return _PROVIDER_OPENAI
-
- if is_anyscale_model(model):
- return _PROVIDER_ANYSCALE
-
- return ValueError(f"DSPy does not have fine-tuning support for {model}")
def get_provider_finetune_job_class(provider: str) -> Type[FinetuneJob]:
diff --git a/dspy/clients/openai.py b/dspy/clients/openai.py
index 07e462982..03e64f7c7 100644
--- a/dspy/clients/openai.py
+++ b/dspy/clients/openai.py
@@ -14,11 +14,6 @@ from dspy.clients.finetune import (
save_data,
)
-
-#-------------------------------------------------------------------------------
-# Function and variables to check if a model is an OpenAI model
-#-------------------------------------------------------------------------------
-
# Provider name
PROVIDER_OPENAI = "openai"
@@ -91,11 +86,6 @@ def is_openai_model(model: str) -> bool:
# it is not an OpenAI model.
return False
-
-#-------------------------------------------------------------------------------
-# Function and classes required for the fine-tune interface
-#-------------------------------------------------------------------------------
-
class FinetuneJobOpenAI(FinetuneJob):
def __init__(self, *args, **kwargs):
@@ -183,11 +173,6 @@ def finetune_openai(
return model
-
-#-------------------------------------------------------------------------------
-# Custom functions to support the finetune_* function
-#-------------------------------------------------------------------------------
-
_SUPPORTED_TRAINING_METHODS = [
TrainingMethod.SFT,
]
@@ -321,11 +306,6 @@ def _get_trained_model(job):
finetuned_model = provider_job.fine_tuned_model
return finetuned_model
-
-#-------------------------------------------------------------------------------
-# OpenAI utility function(s)
-#-------------------------------------------------------------------------------
-
# Adapted from https://cookbook.openai.com/examples/chat_finetuning_data_prep
def openai_data_validation(dataset: List[dict[str, Any]]):
format_errors = defaultdict(int)
diff --git a/dspy/predict/predict.py b/dspy/predict/predict.py
index 8e51d5b95..96034cee9 100644
--- a/dspy/predict/predict.py
+++ b/dspy/predict/predict.py
@@ -15,36 +15,6 @@ from dspy.signatures.signature import ensure_signature, signature_to_template
def warn_once(msg: str):
logging.warning(msg)
-
-#-------------------------------------------------------------------------------
-# Helper functions
-#-------------------------------------------------------------------------------
-
-def assert_structural_equivalency_for_predictors(
- predictor1: object,
- predictor2: object,
- ):
- """Assert that the two predictors are structurally equivalent to each other.
-
- Args:
- predictor1: The predictor to compare with.
- predictor2: The predictor to compare with.
-
- Raises:
- AssertionError: If the predictors are not structurally equivalent.
- """
- # Assert that the objects are predictors
- assert isinstance(predictor1, Predict)
- assert isinstance(predictor2, Predict)
-
- # Assert that the predictors have equivalent signatures
- assert predictor1.signature.equals(predictor2.signature)
-
-
-#-------------------------------------------------------------------------------
-# Classes
-#-------------------------------------------------------------------------------
-
class Predict(Module, Parameter):
def __init__(self, signature, _parse_values=True, **config):
self.stage = random.randbytes(8).hex()
diff --git a/dspy/primitives/program.py b/dspy/primitives/program.py
index cfe9deb28..4eea0e347 100644
--- a/dspy/primitives/program.py
+++ b/dspy/primitives/program.py
@@ -5,7 +5,6 @@ from dsp.modules.lm import LM
import dspy
from dspy.primitives.assertions import *
from dspy.primitives.module import BaseModule
-from dspy.primitives.utils import _ERR_MSG_PROGRAM_LM
class ProgramMeta(type):
pass
@@ -33,7 +32,9 @@ class Module(BaseModule, metaclass=ProgramMeta):
AssertionError: If the dspy experimental setting is not enabled.
"""
# Check if the experimental setting is enabled
- err_msg = _ERR_MSG_PROGRAM_LM
+ err_msg = """Setting or getting the LM of a program is an\
+experimental feature. Please enable the 'dspy.settings.experimental' flag\
+to use these features."""
assert dspy.settings.experimental, err_msg
# Set the LM for all predictors
diff --git a/dspy/primitives/utils.py b/dspy/primitives/utils.py
index 652aab117..37b0555b6 100644
--- a/dspy/primitives/utils.py
+++ b/dspy/primitives/utils.py
@@ -26,10 +26,6 @@ LMs set.
{lm_info}"""
-_ERR_MSG_PROGRAM_LM = """Setting or getting the LM of a program is an \
-experimental feature. Please enable the 'dspy.settings.experimental' flag to \
-use these feature."""
-
_INFO_LM_PROGRAM = """The LM set in 'dspy.settings.lm' is an instance of \
'{lname}' LMs set for the predictors in the module are:{pred_lm_info}"""
diff --git a/dspy/teleprompt/finetune_teleprompter.py b/dspy/teleprompt/finetune_teleprompter.py
index d98a32533..5bbe8ca5b 100644
--- a/dspy/teleprompt/finetune_teleprompter.py
+++ b/dspy/teleprompt/finetune_teleprompter.py
@@ -7,11 +7,6 @@ from dspy.primitives.example import Example
from dspy.primitives.program import Program
from dspy.primitives.prediction import Prediction
-
-#-------------------------------------------------------------------------------
-# Templates for the user-facing strings used by this module
-#-------------------------------------------------------------------------------
-
_INFO_DEFAULT_TEACHER = """No teacher provided. Using a copy of the student \
program as the teacher."""
@@ -27,10 +22,6 @@ consistency property."""
_INFO_BOOTSTRAP_DATA = """Bootstrapping data on {} examples with the program \
{}, with {} threads"""
-#-------------------------------------------------------------------------------
-# Helper functions
-#-------------------------------------------------------------------------------
-
# TODO: Shared below are useful functions. Similar procedures are implemented
# separately and used by other DSPy teleprompters. These can be moved to shared
# locations.