Skip to content

Commit ad91732

Browse files
finitearthtimo282mo374zCopilot
authored
Feature/welcome capo (#45)
* Feature/workflows (#8) * chore: add codeowners file * chore: add python poetry action and docs workflow * chore: update pre-commit file * chore: update docs * chore: update logo * chore: add cicd pipeline for automated deployment * chore: update poetry version * chore: fix action versioning * chore: add gitattributes to ignore line count in jupyter notebooks * chore: add and update docstrings * chore: fix end of files * chore: update action versions * Update README.md --------- Co-authored-by: mo374z <schlager.mo@t-online.de> * Fix/workflows (#11) * chore: fix workflow execution * chore: fix version check in CICD pipeline * Opro implementation (#7) * update gitignore * initial implementation of opro * formatting of prompt template * added opro test run * opro refinements * fixed sampling error * add docs to opro * fix pre commit issues# * fix pre commit issues# * fixed end of line * Patch/pre commit config (#10) * fixed pre commit config and removed end of file line breaks in tempaltes * added / * Feature/prompt generation (#12) * added prompt_creation.py * change version * Create LICENSE (#14) * Refactor/remove deepinfra (#16) * Remove deepinfra file * change langchain-community version * Usability patches (#15) * renamed get_tasks to get_task and change functionality accordingly. moved templates and data_sets * init * move templates to templates.py * Add nested asyncio to make it useable in notebooks * Update README.md * changed getting_started.ipynb and created helper functions * added sampling of initial population * fixed config * fixed callbacks * adjust runs * fix run evaluation api token * fix naming convention in opro, remove on epoch end for logger callback, fixed to allow for numeric values in class names * Update promptolution/llms/api_llm.py Co-authored-by: Timo Heiß <87521684+timo282@users.noreply.github.com> * fixed comments * Update pyproject.toml * resolve comments --------- Co-authored-by: mo374z <schlager.mo@t-online.de> Co-authored-by: Timo Heiß <87521684+timo282@users.noreply.github.com> Co-authored-by: Moritz Schlager <87517800+mo374z@users.noreply.github.com> * Feature/examplar selection (#17) * implemented random selector * added random search selector * increased version count * fix typos * Update promptolution/predictors/base_predictor.py Co-authored-by: Timo Heiß <87521684+timo282@users.noreply.github.com> * Update promptolution/tasks/classification_tasks.py Co-authored-by: Timo Heiß <87521684+timo282@users.noreply.github.com> * resolve comments * resolve comments --------- Co-authored-by: Timo Heiß <87521684+timo282@users.noreply.github.com> * Chore/docs release notes (#18) * Update release-notes.md * Fix release note links * revert Chore/docs release notes (#18)" This reverts commit e23dd74. * revert last commit * updated release notes and read me * Feature/read from df (#21) * Delete Experiment files * Removed config necessities * improved opro meta-prompts * added read from data frame feature * changed required python version to 3.9 * Update pyproject.toml * Update release-notes.md * merge * merge * resolve merge mistakes * delete duplicated lines * Update release-notes.md (#24) * Fix/dependencies (#28) * delete poetry.lock and upgrade transformers dependency * Update release-notes.md * Add vllm as feature and a llm_test_run_script * small fixes in vllm class * differentiate between vllm and api inference * set up experiment over multiple tasks and prompts * change csv saving * add base llm super class * add changes from PR review * change some VLLM params * fix tensor parallel size to 1 * experiment with batch size * experiment with larger batch sizes * add continuous batch llm * remove arg * remove continuous batch inference try * add batching to vllm * add batching in script * Add release notes and increase version number * remove llm_test_run.py script * change system prompt * Fix/vllm (#33) * add token count, flexible batch size and kwargs to vllm class * add testing script for implementation * fix batch size calculation * small changes * add revision test * add argument to parser * max model len to int * remove script * Change version and Release notes * changed callback behaviour and impelemented token count callback * added super inits * allow for splits not based on white space (such as new line break etc) * include task descriptions * add tokenizer based token count to vllm class * update test run script * use classifiers accordingly * small fix * add storage path * helpers should use classificator * use different model * changes in opro test * change get_predictor function * fix callback calling * change optimizer test run script * small alignments * small alignments * small alignments * some changes to match the current optimizer implementation * changes in template and config * allow for batching of prompt creation * update release notes and version * extend csvcallback functionality * change callback csv export * change step time calculation * small changes * remove llm_test_run script * update release notes * fix issues in token stepswise calculation * small fix --------- Co-authored-by: finitearth <t.zehle@gmail.com> * implement changes from review * add typing to token count callback * Feature/deterministic (#35) * make vllm class deterministic * fixes in prompt creation * Fix/prompt creation (#36) * fixes in the "MarkerBasedClassificator" * generalize the Classificator * add verbosity and callback handling in EvoPromptGA * add timestamp to the callback * add arguements to test script * added some feature notes * Fix/template (#39) * v1.3.1 (#37) #### Added features * new features for the VLLM Wrapper (accept seeding to ensure reproducibility) * fixes in the "MarkerBasedClassificator" * fixes in prompt creation and task description handling * generalize the Classificator * add verbosity and callback handling in EvoPromptGA * add timestamp to the callback * removed datasets from repo * changed task creation (now by default with a dataset) * add generation prompt to vllm input * allow for parquet as fileoutput callback * added sys_prompts * change usage of csv callbacks * add system prompt to token counts * fix merge issues * drag system prompts from api to task * added release notes --------- Co-authored-by: Moritz Schlager <87517800+mo374z@users.noreply.github.com> * Fix/opro (#38) * v1.3.1 (#37) #### Added features * new features for the VLLM Wrapper (accept seeding to ensure reproducibility) * fixes in the "MarkerBasedClassificator" * fixes in prompt creation and task description handling * generalize the Classificator * add verbosity and callback handling in EvoPromptGA * add timestamp to the callback * removed datasets from repo * changed task creation (now by default with a dataset) * opro reimplementation according to the paper * fine opro implementation * opro test scripts alignment * implement opro review * small fix in score handling * adjust hyperparameters * add early stopping at convergence to opro * Update promptolution/optimizers/opro.py Co-authored-by: Timo Heiß <87521684+timo282@users.noreply.github.com> --------- Co-authored-by: Moritz Schlager <87517800+mo374z@users.noreply.github.com> Co-authored-by: mo374z <schlager.mo@t-online.de> Co-authored-by: Timo Heiß <87521684+timo282@users.noreply.github.com> * Refactor/generic api llm (#41) * v1.3.2 (#40) #### Added features * Allow for configuration and evaluation of system prompts in all LLM-Classes * CSV Callback is now FileOutputCallback and able to write Parquet files * Fixed LLM-Call templates in VLLM * refined OPRO-implementation to be closer to the paper * implement api calls * removed default for system messages * roll back renaming --------- Co-authored-by: mo374z <schlager.mo@t-online.de> * Refactor/interfaces (#42) * add token count, flexible batch size and kwargs to vllm class * add testing script for implementation * fix batch size calculation * small changes * add revision test * add argument to parser * max model len to int * remove script * Change version and Release notes * changed callback behaviour and impelemented token count callback * init * small corrections * changes to prevent merge conflicts * small changes * first tests * add api_test * a lot has changed for gangsters * fix * added * removed * fix * Update promptolution/predictors/__init__.py Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * add testing to ci pipeline * Update action.yml * fix test dependencies in pipeline * Add further test dependencies * Refactor dependency groups * Add getting started notebook to documentation * Add workflow call trigger to docs workflow * Add CI and Docs status badges * Add temporary file for docs testing * Remove temporary file for docs testing * Update notebooks/getting_started.ipynb Co-authored-by: Timo Heiß <87521684+timo282@users.noreply.github.com> * Update notebooks/getting_started.ipynb Co-authored-by: Timo Heiß <87521684+timo282@users.noreply.github.com> * comments * end2end * added * new * more * change * update dependencies * added literals to get optimizer * added release notes --------- Co-authored-by: mo374z <schlager.mo@t-online.de> Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> Co-authored-by: Timo Heiß <ti-heiss@t-online.de> Co-authored-by: Timo Heiß <87521684+timo282@users.noreply.github.com> * Remove obsolete Docstring * remove redundant init * remove redundant init * resolve merge chaos * formatting * alternated task to work for capo * bug fixes * formatting * update task interface and preds and eval cache * fix vllm and capo * fix nans when evaluate strategy * fix tests * finalized testing * fix vllm tests * fix vllm mocking * fix capo docstring * update getting_started notebook to include capo * formatting * formatting * formatting * formatting and docstring fix * implemented comments * implemented comments * fix tests * fix tests * fix tests * comments * fix typing of test statistics --------- Co-authored-by: Timo Heiß <87521684+timo282@users.noreply.github.com> Co-authored-by: mo374z <schlager.mo@t-online.de> Co-authored-by: Moritz Schlager <87517800+mo374z@users.noreply.github.com> Co-authored-by: Timo Heiß <ti-heiss@t-online.de> Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
1 parent aea25f8 commit ad91732

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+1814
-1984
lines changed

.coverage

0 Bytes
Binary file not shown.

.pre-commit-config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
fail_fast: true
2-
exclude: '^(?!promptolution/).*$|^promptolution/templates.py'
2+
exclude: '^(?!(promptolution/|tests/)).*$|^promptolution/templates.py'
33
repos:
44
- repo: https://github.com/gitleaks/gitleaks
55
rev: v8.18.2

notebooks/getting_started.ipynb

Lines changed: 85 additions & 86 deletions
Large diffs are not rendered by default.

promptolution/config.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,20 @@ def __init__(self, **kwargs):
1818
for key, value in kwargs.items():
1919
setattr(self, key, value)
2020

21+
def __setattr__(self, name, value):
22+
"""Override attribute setting to track used attributes."""
23+
# Set the attribute using the standard mechanism
24+
object.__setattr__(self, name, value)
25+
if not name.startswith("_") and not callable(value):
26+
self._used_attributes.add(name)
27+
2128
def __getattribute__(self, name):
2229
"""Override attribute access to track used attributes."""
2330
# Get the attribute using the standard mechanism
24-
value = object.__getattribute__(self, name)
25-
31+
try:
32+
value = object.__getattribute__(self, name)
33+
except AttributeError:
34+
return None
2635
if not name.startswith("_") and not callable(value):
2736
self._used_attributes.add(name)
2837

promptolution/helpers.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,11 @@ def run_optimization(df, config: ExperimentConfig):
4646
"""
4747
llm = get_llm(config=config)
4848
predictor = get_predictor(llm, config=config)
49+
4950
config.task_description = config.task_description + " " + predictor.extraction_description
51+
if config.optimizer == "capo" and config.subsample_strategy is None:
52+
logger.info("CAPO requires block evaluation strategy. Setting it to 'sequential_block'.")
53+
config.subsample_strategy = "sequential_block"
5054

5155
task = get_task(df, config)
5256
optimizer = get_optimizer(
@@ -55,7 +59,7 @@ def run_optimization(df, config: ExperimentConfig):
5559
task=task,
5660
config=config,
5761
)
58-
62+
logger.info("Starting optimization...")
5963
prompts = optimizer.optimize(n_steps=config.n_steps)
6064

6165
if hasattr(config, "prepend_exemplars") and config.prepend_exemplars:
@@ -80,7 +84,7 @@ def run_evaluation(df: pd.DataFrame, config: ExperimentConfig, prompts: List[str
8084

8185
llm = get_llm(config=config)
8286
predictor = get_predictor(llm, config=config)
83-
87+
logger.info("Starting evaluation...")
8488
scores = task.evaluate(prompts, predictor)
8589
df = pd.DataFrame(dict(prompt=prompts, score=scores))
8690
df = df.sort_values("score", ascending=False, ignore_index=True)

promptolution/llms/vllm.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
logger = Logger(__name__)
1111

1212
try:
13-
import torch
1413
from transformers import AutoTokenizer
1514
from vllm import LLM, SamplingParams
1615

@@ -75,7 +74,7 @@ def __init__(
7574
"""
7675
if not imports_successful:
7776
raise ImportError(
78-
"Could not import at least one of the required libraries: torch, transformers, vllm. "
77+
"Could not import at least one of the required libraries: transformers, vllm. "
7978
"Please ensure they are installed in your environment."
8079
)
8180

@@ -110,7 +109,9 @@ def __init__(
110109

111110
if batch_size is None:
112111
gpu_blocks = self.llm.llm_engine.model_executor.cache_config.num_gpu_blocks
113-
block_size = self.llm.llm_engine.model_executor.cache_config.block_size
112+
block_size = (
113+
self.llm.llm_engine.model_executor.cache_config.block_size
114+
) # TODO rename, block_size is misleading
114115
self.batch_size = int((gpu_blocks * block_size / self.max_model_len) * 0.95)
115116
logger.info(f"Batch size set to {self.batch_size} based on GPU memory.")
116117
else:

promptolution/optimizers/__init__.py

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
from promptolution.predictors.base_predictor import BasePredictor
88
from promptolution.tasks.base_task import BaseTask
99
from promptolution.templates import (
10+
CAPO_CROSSOVER_TEMPLATE,
11+
CAPO_MUTATION_TEMPLATE,
1012
EVOPROMPT_DE_TEMPLATE,
1113
EVOPROMPT_DE_TEMPLATE_TD,
1214
EVOPROMPT_GA_TEMPLATE,
@@ -16,6 +18,7 @@
1618
)
1719

1820
from .base_optimizer import DummyOptimizer
21+
from .capo import CAPO
1922
from .evoprompt_de import EvoPromptDE
2023
from .evoprompt_ga import EvoPromptGA
2124
from .opro import Opro
@@ -54,8 +57,26 @@ def get_optimizer(
5457
if meta_prompt is None and hasattr(config, "meta_prompt"):
5558
meta_prompt = config.meta_prompt
5659

57-
if optimizer == "dummy":
58-
return DummyOptimizer(predictor=predictor, config=config)
60+
if config.optimizer == "capo":
61+
crossover_template = (
62+
CAPO_CROSSOVER_TEMPLATE.replace("<task_desc>", task_description)
63+
if task_description
64+
else CAPO_CROSSOVER_TEMPLATE
65+
)
66+
mutation_template = (
67+
CAPO_MUTATION_TEMPLATE.replace("<task_desc>", task_description)
68+
if task_description
69+
else CAPO_MUTATION_TEMPLATE
70+
)
71+
72+
return CAPO(
73+
predictor=predictor,
74+
meta_llm=meta_llm,
75+
task=task,
76+
crossover_template=crossover_template,
77+
mutation_template=mutation_template,
78+
config=config,
79+
)
5980

6081
if config.optimizer == "evopromptde":
6182
template = (
@@ -77,4 +98,7 @@ def get_optimizer(
7798
template = OPRO_TEMPLATE_TD.replace("<task_desc>", task_description) if task_description else OPRO_TEMPLATE
7899
return Opro(predictor=predictor, meta_llm=meta_llm, task=task, prompt_template=template, config=config)
79100

101+
if optimizer == "dummy":
102+
return DummyOptimizer(predictor=predictor, config=config)
103+
80104
raise ValueError(f"Unknown optimizer: {config.optimizer}")

promptolution/optimizers/base_optimizer.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@ def __init__(
4545
self.task = task
4646
self.callbacks = callbacks or []
4747
self.predictor = predictor
48-
self.verbosity = 0
4948

5049
if config is not None:
5150
config.apply_to(self)
@@ -97,7 +96,7 @@ def _pre_optimization_loop(self):
9796
pass
9897

9998
@abstractmethod
100-
def _step(self):
99+
def _step(self) -> List[str]:
101100
"""Perform a single optimization step.
102101
103102
This method should be implemented by concrete optimizer classes to define

0 commit comments

Comments
 (0)