Skip to content

Commit

Permalink
Reduced comments/debugging statements from MIPRO dev
Browse files Browse the repository at this point in the history
  • Loading branch information
XenonMolecule committed Jun 19, 2024
1 parent 34725d0 commit 2ba0abb
Show file tree
Hide file tree
Showing 6 changed files with 11,860 additions and 363 deletions.
12 changes: 1 addition & 11 deletions dspy/propose/grounded_proposer.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,17 +170,7 @@ def forward(
task_demos = ""
basic_instruction = get_signature(program.predictors()[pred_i]).instructions
curr_demos_num = 0
# if self.program_aware: # Use full program demo
# for pred_key in demo_candidates.keys(): # Go through each predictor
# for example in demo_candidates[pred_key][demo_set_i]:
# if "augmented" in example.keys():
# fields_to_use = get_signature(program.predictors()[pred_key]).fields
# example_string = create_example_string(fields_to_use, example)
# task_demos += f"{example_string}\n"
# curr_demos_num+=1
# if curr_demos_num>=max_demos:
# break
# else:

for example in demo_candidates[pred_i][demo_set_i]:
if "augmented" in example.keys():
fields_to_use = get_signature(program.predictors()[pred_i]).fields
Expand Down
68 changes: 1 addition & 67 deletions dspy/propose/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,15 +45,6 @@ def create_instruction_set_history_string(base_program, trial_logs, top_n):

return instruction_set_history_string

# def parse_list_of_instructions(instruction_string):
# # Convert the string representation of a list to an actual list
# try:
# instructions = json.loads(instruction_string)
# except json.JSONDecodeError as e:
# print(f"Error decoding JSON: {e}")
# return []

# return instructions
def parse_list_of_instructions(instruction_string):
# Try to convert the string representation of a list to an actual list using JSON
try:
Expand All @@ -66,13 +57,6 @@ def parse_list_of_instructions(instruction_string):
instructions = re.findall(r'"([^"]*)"', instruction_string)
return instructions

# def get_program_instruction_set_string(program):
# instruction_set_dict = {}
# for i, pred in enumerate(program.predictors()):
# pred_instructions = get_signature(pred).instructions
# instruction_set_dict[f"Module {i} Instruction"] = pred_instructions
# return '\n'.join(f"{key}: {value}" for key, value in instruction_set_dict.items())

def get_program_instruction_set_string(program):
instruction_list = []
for _, pred in enumerate(program.predictors()):
Expand Down Expand Up @@ -147,54 +131,4 @@ def create_example_string(fields, example):
output.append(field_str)

# Joining all the field strings
return '\n'.join(output)

# def create_predictor_level_history_string(base_program, predictor_i, trial_logs, top_n):
# instruction_aggregate = {}

# instruction_history = []
# for trial_num in trial_logs:
# trial = trial_logs[trial_num]
# if "program_path" in trial:
# trial_program = base_program.deepcopy()
# trial_program.load(trial["program_path"])
# instruction_history.append({
# "program": trial_program,
# "score": trial["score"]
# })

# for history_item in instruction_history:
# predictor = history_item["program"].predictors()[predictor_i]
# instruction = get_signature(predictor).instructions
# score = history_item["score"]

# if instruction in instruction_aggregate:
# instruction_aggregate[instruction]['total_score'] += score
# instruction_aggregate[instruction]['count'] += 1
# else:
# instruction_aggregate[instruction] = {'total_score': score, 'count': 1}

# # # Calculate average score for each instruction and prepare for sorting
# # predictor_history = []
# # for instruction, data in instruction_aggregate.items():
# # average_score = data['total_score'] / data['count']
# # predictor_history.append((instruction, average_score))
# # Calculate average score for each instruction and prepare for sorting
# predictor_history = []
# seen_instructions = set()
# for instruction, data in instruction_aggregate.items():
# if instruction not in seen_instructions:
# seen_instructions.add(instruction)
# average_score = data['total_score'] / data['count']
# predictor_history.append((instruction, average_score))

# # Sort by average score and select top N
# top_instructions = sorted(predictor_history, key=lambda x: x[1], reverse=True)[:top_n]
# top_instructions.reverse()

# # Create formatted history string
# predictor_history_string = ""
# for instruction, score in top_instructions:
# predictor_history_string += instruction + f" | Score: {score}\n\n"

# return predictor_history_string
return '\n'.join(output)
239 changes: 0 additions & 239 deletions dspy/teleprompt/hard_bootstrap.py

This file was deleted.

3 changes: 0 additions & 3 deletions dspy/teleprompt/mipro_optimizer_v2.py
Original file line number Diff line number Diff line change
Expand Up @@ -482,9 +482,6 @@ def objective(trial):
program, instruction_candidates, demo_candidates, evaluate, trainset,
)

# if minibatch:
# num_batches = int(num_batches*len(trainset)/(self.minibatch_size + len(trainset)/self.minibatch_full_eval_steps))

sampler = optuna.samplers.TPESampler(seed=seed, multivariate=True)
study = optuna.create_study(direction="maximize", sampler=sampler)
score = study.optimize(objective_function, n_trials=num_batches)
Expand Down
Loading

0 comments on commit 2ba0abb

Please sign in to comment.