Skip to content

Commit 8dc8fc6

Browse files
disable repair if there are correct candidates
1 parent b716573 commit 8dc8fc6

2 files changed

Lines changed: 16 additions & 1 deletion

File tree

codeflash/code_utils/config_consts.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@
3131
TOTAL_LOOPING_TIME_LSP = 10.0 # Kept same timing for LSP mode to avoid in increase in performance reporting
3232
N_CANDIDATES_LP_LSP = 3
3333

34+
# setting this value to 1 will disable repair if there is at least one correct candidate
35+
MIN_CORRECT_CANDIDATES = 2
36+
3437
# Code repair
3538
REPAIR_UNMATCHED_PERCENTAGE_LIMIT = 0.4 # if the percentage of unmatched tests is greater than this, we won't fix it (lowering this value makes the repair more stricted)
3639
MAX_REPAIRS_PER_TRACE = 4 # maximum number of repairs we will do for each function

codeflash/optimization/function_optimizer.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
INDIVIDUAL_TESTCASE_TIMEOUT,
4949
MAX_ADAPTIVE_OPTIMIZATIONS_PER_TRACE,
5050
MAX_REPAIRS_PER_TRACE,
51+
MIN_CORRECT_CANDIDATES,
5152
N_TESTS_TO_GENERATE_EFFECTIVE,
5253
REFINE_ALL_THRESHOLD,
5354
REFINED_CANDIDATE_RANKING_WEIGHTS,
@@ -887,6 +888,7 @@ def process_single_candidate(
887888
baseline_results=original_code_baseline,
888889
original_helper_code=original_helper_code,
889890
file_path_to_helper_classes=file_path_to_helper_classes,
891+
eval_ctx=eval_ctx,
890892
code_context=code_context,
891893
candidate=candidate,
892894
exp_type=exp_type,
@@ -2045,13 +2047,20 @@ def repair_if_possible(
20452047
self,
20462048
candidate: OptimizedCandidate,
20472049
diffs: list[TestDiff],
2050+
eval_ctx: CandidateEvaluationContext,
20482051
code_context: CodeOptimizationContext,
20492052
test_results_count: int,
20502053
exp_type: str,
20512054
) -> None:
20522055
if self.repair_counter >= MAX_REPAIRS_PER_TRACE:
20532056
logger.debug(f"Repair counter reached {MAX_REPAIRS_PER_TRACE}, skipping repair")
20542057
return
2058+
2059+
successful_candidates_count = sum(1 for is_correct in eval_ctx.is_correct.values() if is_correct)
2060+
if successful_candidates_count >= MIN_CORRECT_CANDIDATES:
2061+
logger.debug(f"{successful_candidates_count} of the candidates were correct, no need to repair")
2062+
return
2063+
20552064
if candidate.source not in (OptimizedCandidateSource.OPTIMIZE, OptimizedCandidateSource.OPTIMIZE_LP):
20562065
# only repair the first pass of the candidates for now
20572066
logger.debug(f"Candidate is a result of {candidate.source.value}, skipping repair")
@@ -2089,6 +2098,7 @@ def run_optimized_candidate(
20892098
baseline_results: OriginalCodeBaseline,
20902099
original_helper_code: dict[Path, str],
20912100
file_path_to_helper_classes: dict[Path, set[str]],
2101+
eval_ctx: CandidateEvaluationContext,
20922102
code_context: CodeOptimizationContext,
20932103
candidate: OptimizedCandidate,
20942104
exp_type: str,
@@ -2144,7 +2154,9 @@ def run_optimized_candidate(
21442154
logger.info("h3|Test results matched ✅")
21452155
console.rule()
21462156
else:
2147-
self.repair_if_possible(candidate, diffs, code_context, len(candidate_behavior_results), exp_type)
2157+
self.repair_if_possible(
2158+
candidate, diffs, eval_ctx, code_context, len(candidate_behavior_results), exp_type
2159+
)
21482160
return self.get_results_not_matched_error()
21492161

21502162
logger.info(f"loading|Running performance tests for candidate {optimization_candidate_index}...")

0 commit comments

Comments
 (0)