Skip to content

Commit 971470e

Browse files
committed
adjust critic
1 parent d3afd8a commit 971470e

File tree

2 files changed

+9
-7
lines changed

2 files changed

+9
-7
lines changed

codeflash/result/critic.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,10 @@ def speedup_critic(
9191
)
9292

9393
if original_async_throughput is not None and candidate_result.async_throughput is not None:
94-
# prioritize throughput improvement
95-
return (throughput_improved and throughput_is_best) and (runtime_improved or runtime_is_best)
94+
# When throughput data is available, accept if EITHER throughput OR runtime improves significantly
95+
throughput_acceptance = throughput_improved and throughput_is_best
96+
runtime_acceptance = runtime_improved and runtime_is_best
97+
return throughput_acceptance or runtime_acceptance
9698
return runtime_improved and runtime_is_best
9799

98100

tests/test_critic.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -480,7 +480,7 @@ def test_speedup_critic_with_async_throughput() -> None:
480480
disable_gh_action_noise=True
481481
)
482482

483-
# Test case 2: Runtime improves but throughput doesn't meet threshold
483+
# Test case 2: Runtime improves significantly, throughput doesn't meet threshold (should pass)
484484
candidate_result = OptimizedCandidateResult(
485485
max_loop_count=5,
486486
best_test_runtime=8000, # 20% runtime improvement
@@ -491,7 +491,7 @@ def test_speedup_critic_with_async_throughput() -> None:
491491
async_throughput=105, # Only 5% throughput improvement (below 10% threshold)
492492
)
493493

494-
assert not speedup_critic(
494+
assert speedup_critic(
495495
candidate_result=candidate_result,
496496
original_code_runtime=original_code_runtime,
497497
best_runtime_until_now=None,
@@ -500,7 +500,7 @@ def test_speedup_critic_with_async_throughput() -> None:
500500
disable_gh_action_noise=True
501501
)
502502

503-
# Test case 3: Throughput improves but runtime doesn't meet threshold
503+
# Test case 3: Throughput improves significantly, runtime doesn't meet threshold (should pass)
504504
candidate_result = OptimizedCandidateResult(
505505
max_loop_count=5,
506506
best_test_runtime=9800, # Only 2% runtime improvement (below 5% threshold)
@@ -511,7 +511,7 @@ def test_speedup_critic_with_async_throughput() -> None:
511511
async_throughput=120, # 20% throughput improvement
512512
)
513513

514-
assert not speedup_critic(
514+
assert speedup_critic(
515515
candidate_result=candidate_result,
516516
original_code_runtime=original_code_runtime,
517517
best_runtime_until_now=None,
@@ -565,7 +565,7 @@ def test_speedup_critic_with_async_throughput() -> None:
565565
assert not speedup_critic(
566566
candidate_result=candidate_result,
567567
original_code_runtime=original_code_runtime,
568-
best_runtime_until_now=None,
568+
best_runtime_until_now=7000, # Better runtime already exists
569569
original_async_throughput=original_async_throughput,
570570
best_throughput_until_now=120, # Better throughput already exists
571571
disable_gh_action_noise=True

0 commit comments

Comments
 (0)