Skip to content

Commit 2f7fc60

Browse files
set the right effort level for each case
1 parent f4be23b commit 2f7fc60

4 files changed

Lines changed: 8 additions & 8 deletions

File tree

codeflash/code_utils/config_consts.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ class EffortKeys(StrEnum):
4242
N_GENERATED_TESTS = auto()
4343
MAX_CODE_REPAIRS_PER_TRACE = auto()
4444
REPAIR_UNMATCHED_PERCENTAGE_LIMIT = auto()
45-
REFINE_ALL_THRESHOLD = auto()
4645
TOP_VALID_CANDIDATES_FOR_REFINEMENT = auto()
4746

4847

@@ -54,14 +53,12 @@ class EffortKeys(StrEnum):
5453
# maximum number of repairs we will do for each function
5554
EffortKeys.MAX_CODE_REPAIRS_PER_TRACE.value: {EffortLevel.LOW: 2, EffortLevel.MEDIUM: 4, EffortLevel.HIGH: 5},
5655
# if the percentage of unmatched tests is greater than this, we won't fix it (lowering this value makes the repair more stricted)
57-
# on the low effort we lower the limit to 20% to be more strict (less repairs)
56+
# on the low effort we lower the limit to 20% to be more strict (less repairs, less time)
5857
EffortKeys.REPAIR_UNMATCHED_PERCENTAGE_LIMIT.value: {
5958
EffortLevel.LOW: 0.2,
6059
EffortLevel.MEDIUM: 0.4,
6160
EffortLevel.HIGH: 0.5,
6261
},
63-
# when valid optimizations count is N or less, refine all optimizations
64-
EffortKeys.REFINE_ALL_THRESHOLD.value: {EffortLevel.LOW: 2, EffortLevel.MEDIUM: 3, EffortLevel.HIGH: 4},
6562
# Top valid candidates for refinements
6663
EffortKeys.TOP_VALID_CANDIDATES_FOR_REFINEMENT: {EffortLevel.LOW: 2, EffortLevel.MEDIUM: 3, EffortLevel.HIGH: 4},
6764
}

codeflash/lsp/server.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
from pygls.lsp.server import LanguageServer
88
from pygls.protocol import LanguageServerProtocol
99

10+
from codeflash.code_utils.config_consts import EffortLevel
1011
from codeflash.either import Result
1112
from codeflash.models.models import CodeOptimizationContext
1213

@@ -37,6 +38,7 @@ def prepare_optimizer_arguments(self, config_file: Path) -> None:
3738
args.config_file = config_file
3839
args.no_pr = True # LSP server should not create PRs
3940
args.worktree = True
41+
args.effort = EffortLevel.LOW.value # low effort for high speed
4042
self.args = args
4143
# avoid initializing the optimizer during initialization, because it can cause an error if the api key is invalid
4244

codeflash/optimization/function_optimizer.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -192,14 +192,13 @@ def _process_refinement_results(self) -> OptimizedCandidate | None:
192192
future_refinements: list[concurrent.futures.Future] = []
193193
top_n_candidates = int(
194194
min(
195-
get_effort_value(EffortKeys.TOP_VALID_CANDIDATES_FOR_REFINEMENT, self.effort),
195+
int(get_effort_value(EffortKeys.TOP_VALID_CANDIDATES_FOR_REFINEMENT, self.effort)),
196196
len(self.all_refinements_data),
197197
)
198198
)
199199

200-
if top_n_candidates == len(self.all_refinements_data) or len(self.all_refinements_data) <= get_effort_value(
201-
EffortKeys.REFINE_ALL_THRESHOLD, self.effort
202-
):
200+
if top_n_candidates == len(self.all_refinements_data):
201+
# if we'll refine all candidates, we can skip the ranking and just refine them all
203202
for data in self.all_refinements_data:
204203
future_refinements.append(self.refine_optimizations([data])) # noqa: PERF401
205204
else:

codeflash/tracer.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
from codeflash.cli_cmds.console import console
2525
from codeflash.code_utils.code_utils import get_run_tmp_file
2626
from codeflash.code_utils.compat import SAFE_SYS_EXECUTABLE
27+
from codeflash.code_utils.config_consts import EffortLevel
2728
from codeflash.code_utils.config_parser import parse_config_file
2829
from codeflash.tracing.pytest_parallelization import pytest_split
2930

@@ -214,6 +215,7 @@ def main(args: Namespace | None = None) -> ArgumentParser:
214215

215216
from codeflash.optimization import optimizer
216217

218+
args.effort = EffortLevel.HIGH.value
217219
optimizer.run_with_args(args)
218220

219221
# Delete the trace file and the replay test file if they exist

0 commit comments

Comments
 (0)