-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into mp/aggregation-benchmarks
- Loading branch information
Showing
26 changed files
with
440 additions
and
67 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
path: "micpst/bird-iql" | ||
path: "deepsense-ai/bird-iql" | ||
split: "dev" | ||
db_ids: ["superhero"] | ||
difficulties: ["simple", "moderate", "challenging"] |
3 changes: 2 additions & 1 deletion
3
extra/prompt_tuning/config/config.yaml → extra/prompt_tuning/config/evaluate.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,8 @@ | ||
defaults: | ||
- data: superhero | ||
- llm: gpt-3.5-turbo | ||
- program: filtering-assessor-baseline | ||
- prompt: prompt | ||
- _self_ | ||
|
||
num_threads: 32 | ||
neptune: False |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
name: COPRO | ||
params: | ||
breadth: 4 | ||
depth: 15 | ||
init_temperature: 1.5 | ||
compile: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
name: MIPRO | ||
params: | ||
num_candidates: 3 | ||
init_temperature: 1.4 | ||
|
||
compile: | ||
max_bootstrapped_demos: 3 | ||
max_labeled_demos: 0 | ||
num_trials: 10 |
2 changes: 0 additions & 2 deletions
2
extra/prompt_tuning/config/program/filtering-assessor-baseline.yaml
This file was deleted.
Oops, something went wrong.
2 changes: 0 additions & 2 deletions
2
extra/prompt_tuning/config/program/filtering-assessor-cot.yaml
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
id: CoT |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
id: CoTH |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
id: Predict |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
defaults: | ||
- type: filtering-assessor | ||
- signature: baseline | ||
- program: predict | ||
- _self_ | ||
|
||
num_threads: 32 | ||
neptune: False |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
id: Baseline |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
id: Optimized |
1 change: 1 addition & 0 deletions
1
extra/prompt_tuning/config/prompt/type/aggregation-assessor.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
id: AggregationAssessor |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
id: FilteringAssessor |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
defaults: | ||
- data: superhero | ||
- llm: gpt-3.5-turbo | ||
- prompt: prompt | ||
- optimizer: copro | ||
- _self_ | ||
|
||
num_threads: 32 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
import asyncio | ||
import logging | ||
from pathlib import Path | ||
|
||
import dspy | ||
import dspy.teleprompt | ||
import hydra | ||
from omegaconf import DictConfig | ||
from tuning import DATALOADERS, METRICS | ||
from tuning.programs import PROGRAMS | ||
from tuning.signatures import SIGNATURES | ||
|
||
logging.getLogger("httpx").setLevel(logging.ERROR) | ||
logging.getLogger("anthropic").setLevel(logging.ERROR) | ||
log = logging.getLogger(__name__) | ||
|
||
|
||
async def train(config: DictConfig) -> None: | ||
""" | ||
Function running training for all datasets and training tasks defined in hydra config. | ||
Args: | ||
config: Hydra configuration. | ||
""" | ||
signature_name = f"{config.prompt.type.id}{config.prompt.signature.id}" | ||
program_name = f"{config.prompt.type.id}{config.prompt.program.id}" | ||
|
||
log.info("Starting training: %s(%s) program with %s optimizer", program_name, signature_name, config.optimizer.name) | ||
|
||
dataloader = DATALOADERS[config.prompt.type.id](config) | ||
metric = METRICS[config.prompt.type.id] | ||
signature = SIGNATURES[signature_name] | ||
program = PROGRAMS[program_name](signature) | ||
|
||
dataset = await dataloader.load() | ||
|
||
lm = dspy.__dict__[config.llm.provider](model=config.llm.model_name) | ||
dspy.settings.configure(lm=lm) | ||
|
||
optimizer = dspy.teleprompt.__dict__[config.optimizer.name](metric=metric, **config.optimizer.params) | ||
compiled_program = optimizer.compile( | ||
student=program, | ||
trainset=dataset, | ||
eval_kwargs={ | ||
"num_threads": config.num_threads, | ||
"display_progress": True, | ||
}, | ||
**(config.optimizer.compile or {}), | ||
) | ||
|
||
log.info("Training finished. Saving compiled program...") | ||
|
||
output_dir = Path(hydra.core.hydra_config.HydraConfig.get().runtime.output_dir) | ||
program_file = output_dir / f"{program.__class__.__name__}Optimized.json" | ||
compiled_program.save(program_file) | ||
|
||
log.info("Compiled program saved under directory: %s", output_dir) | ||
|
||
|
||
@hydra.main(config_path="config", config_name="train", version_base="3.2") | ||
def main(config: DictConfig) -> None: | ||
""" | ||
Function running evaluation for all datasets and evaluation tasks defined in hydra config. | ||
Args: | ||
config: Hydra configuration. | ||
""" | ||
asyncio.run(train(config)) | ||
|
||
|
||
if __name__ == "__main__": | ||
main() # pylint: disable=no-value-for-parameter |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
from enum import Enum | ||
|
||
from .loaders import IQLGenerationDataLoader | ||
from .metrics import aggregation_assess_acc, filtering_assess_acc | ||
|
||
|
||
class ProgramType(Enum): | ||
""" | ||
Program types. | ||
""" | ||
|
||
FILTERING_ASSESSOR = "FilteringAssessor" | ||
AGGREGATION_ASSESSOR = "AggregationAssessor" | ||
|
||
|
||
DATALOADERS = { | ||
ProgramType.FILTERING_ASSESSOR.value: IQLGenerationDataLoader, | ||
ProgramType.AGGREGATION_ASSESSOR.value: IQLGenerationDataLoader, | ||
} | ||
|
||
METRICS = { | ||
ProgramType.FILTERING_ASSESSOR.value: filtering_assess_acc, | ||
ProgramType.AGGREGATION_ASSESSOR.value: aggregation_assess_acc, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
from .iql import filtering_assess_acc | ||
from .iql import aggregation_assess_acc, filtering_assess_acc | ||
|
||
__all__ = ["filtering_assess_acc"] | ||
__all__ = ["aggregation_assess_acc", "filtering_assess_acc"] |
Oops, something went wrong.