DSPy: The framework for programming—not prompting—language models
Python
Merge remote-tracking branch 'private/vllm-offline' into origin/dev_finetune
Isaac Miller731f5a3db6ee
diff --cc dspy/clients/lm.pyindex 5175fe2be,45a14f706..dbfaabc28--- a/dspy/clients/lm.py+++ b/dspy/clients/lm.py@@@ -94,59 -60,13 +94,67 @@@ class LMdef inspect_history(self, n: int = 1):_inspect_history(self, n)+ def launch(self):+ """Send a request to the provider to launch the model, if needed."""+ if is_self_hosted_model(self.model):+ self_hosted_model_launch(self.model, self.launch_kwargs)+ elif is_anyscale_model(self.model):+ anyscale_model_launch(self.model, self.launch_kwargs)+ logger.debug(f"`LM.launch()` is called for the auto-launched model {self.model} -- no action is taken.")++ def kill(self):+ """Send a request to the provider to kill the model, if needed."""+ if is_self_hosted_model(self.model):+ self_hosted_model_kill(self.model, self.launch_kwargs)+ elif is_anyscale_model(self.model):+ anyscale_model_kill(self.model, self.launch_kwargs)+ logger.debug(f"`LM.kill()` is called for the auto-launched model {self.model} -- no action is taken.")++ def finetune(self,+ message_completion_pairs: List[Dict[str, str]],+ train_kwargs: Optional[Dict[str, Any]]=None,+ launch_kwargs: Optional[Dict[str, Any]]=None,+ cache_finetune: bool = True,+ ) -> FinetuneJob:+ """Start model fine-tuning, if supported."""+ # Fine-tuning is experimental and requires the experimental flag+ from dspy import settings as settings+ err = "Fine-tuning is an experimental feature and requires `dspy.settings.experimental = True`."+ assert settings.experimental, err++ # Get the fine-tuning provider, if it is supported+ try:+ provider = _get_supported_finetune_provider(self.model)+ except ValueError as err:+ raise err++ # Initialize the finetune job+ FinetuneJobClass = get_provider_finetune_job_class(provider=provider)+ finetune_job = FinetuneJobClass(+ model=self.model,+ message_completion_pairs=message_completion_pairs,+ train_kwargs=train_kwargs,+ )++ # Start asyncronous training+ executor = ThreadPoolExecutor(max_workers=1)+ executor.submit(+ execute_finetune_job,+ finetune_job,+ launch_kwargs=launch_kwargs,+ cache_finetune=cache_finetune+ )+ executor.shutdown(wait=False)++ return finetune_job+++ def copy(self, **kwargs):+ """Returns a copy of the language model with the same parameters."""+ kwargs = {**self.kwargs, **kwargs}+ # model = kwargs.pop("model") or self.model+ init_kwargs = dict(model=self.model, model_type=self.model_type, cache=self.cache, temperature=self.kwargs["temperature"], max_tokens=self.kwargs["max_tokens"])+ init_kwargs = {**init_kwargs, **kwargs}+ return self.__class__(**init_kwargs)@functools.lru_cache(maxsize=None)diff --cc dspy/teleprompt/finetune_teleprompter.pyindex 421053073,bcb97e636..5f750cc6a--- a/dspy/teleprompt/finetune_teleprompter.py+++ b/dspy/teleprompt/finetune_teleprompter.py@@@ -8,7 -8,7 +8,6 @@@ from dspy.primitives.program import Profrom dspy.primitives.prediction import Predictionfrom dspy.signatures.signature import signature_to_template--import concurrent.futures#-------------------------------------------------------------------------------# Templates for the user-facing strings used by this module#-------------------------------------------------------------------------------@@@ -387,7 -357,7 +356,8 @@@ def bootstrap_data_for_round# Ensure that the LM consistency is satisfied, which ensures that either (1)# the global LM is set or (2) all the predictors have an LM set.- program._assert_lm_consistency()++ # TODO(isaac): Uncomment this line after the LM consistency property is+ # program._assert_lm_consistency()# Deepcopy the program and copy the dataset to avoid modifying the originalprogram = program.deepcopy()