Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions codeflash/api/aiservice.py
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ def optimize_python_code_refinement(self, request: list[AIServiceRefinerRequest]
}
for opt in request
]
logger.info(f"Refining {len(request)} optimizations…")
logger.debug(f"Refining {len(request)} optimizations…")
console.rule()
try:
response = self.make_ai_service_request("/refinement", payload=payload, timeout=600)
Expand All @@ -259,7 +259,7 @@ def optimize_python_code_refinement(self, request: list[AIServiceRefinerRequest]

if response.status_code == 200:
refined_optimizations = response.json()["refinements"]
logger.info(f"Generated {len(refined_optimizations)} candidate refinements.")
logger.debug(f"Generated {len(refined_optimizations)} candidate refinements.")
console.rule()
return [
OptimizedCandidate(
Expand Down Expand Up @@ -339,7 +339,6 @@ def get_new_explanation( # noqa: D417

if response.status_code == 200:
explanation: str = response.json()["explanation"]
logger.debug(f"New Explanation: {explanation}")
console.rule()
return explanation
try:
Expand Down
13 changes: 7 additions & 6 deletions codeflash/optimization/function_optimizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -440,6 +440,9 @@ def determine_best_candidate(
# check if this code has been evaluated before by checking the ast normalized code string
normalized_code = ast.unparse(ast.parse(candidate.source_code.flat.strip()))
if normalized_code in ast_code_to_id:
logger.warning(
"Current candidate has been encountered before in testing, Skipping optimization candidate."
)
past_opt_id = ast_code_to_id[normalized_code]["optimization_id"]
# update speedup ratio, is_correct, optimizations_post, optimized_line_profiler_results, optimized_runtimes
speedup_ratios[candidate.optimization_id] = speedup_ratios[past_opt_id]
Expand Down Expand Up @@ -588,8 +591,10 @@ def determine_best_candidate(
if len(possible_refinement) > 0: # if the api returns a valid response
refinement_response.append(possible_refinement[0])
candidates.extend(refinement_response)
logger.info(f"Added {len(refinement_response)} candidates from refinement")
original_len += len(refinement_response)
logger.info(
f"Added {len(refinement_response)} candidates from refinement, total candidates now: {original_len}"
)
refinement_done = True
except KeyboardInterrupt as e:
self.write_code_and_helpers(
Expand Down Expand Up @@ -1099,11 +1104,6 @@ def find_and_process_best_optimization(
if best_optimization:
logger.info("Best candidate:")
code_print(best_optimization.candidate.source_code.flat)
console.print(
Panel(
best_optimization.candidate.explanation, title="Best Candidate Explanation", border_style="blue"
)
)
processed_benchmark_info = None
if self.args.benchmark:
processed_benchmark_info = process_benchmark_data(
Expand Down Expand Up @@ -1227,6 +1227,7 @@ def process_review(
file_path=explanation.file_path,
benchmark_details=explanation.benchmark_details,
)
console.print(Panel(new_explanation_raw_str, title="Best Candidate Explanation", border_style="blue"))
data = {
"original_code": original_code_combined,
"new_code": new_code_combined,
Expand Down
Loading