Skip to content

Commit af071f5

Browse files
RolandMinruiXuyou-n-g
authored
feat: refine the logic of enabling hyperparameter tuning and add criteira (#1175)
* add 4 tuning criteria * fix equation direction * fix ci * add comment Co-authored-by: you-n-g <you-n-g@users.noreply.github.com> --------- Co-authored-by: Xu <v-xuminrui@microsoft.com> Co-authored-by: you-n-g <you-n-g@users.noreply.github.com>
1 parent cf6e418 commit af071f5

2 files changed

Lines changed: 31 additions & 8 deletions

File tree

rdagent/app/kaggle/conf.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,13 @@ class KaggleBasePropSetting(ExtendedBaseSettings):
7676
"""Enable mini-case study for experiments"""
7777

7878
time_ratio_limit_to_enable_hyperparameter_tuning: float = 1
79-
"""Time ratio limit to enable hyperparameter tuning, if not change, hyperparameter tuning is always enabled in the first evolution."""
79+
"""Runner time ratio limit to enable hyperparameter tuning, if not change, hyperparameter tuning is always enabled in the first evolution."""
80+
81+
res_time_ratio_limit_to_enable_hyperparameter_tuning: float = 1
82+
"""Overall rest time ratio limit to enable hyperparameter tuning, if not change, hyperparameter tuning is always enabled in the first evolution."""
83+
84+
only_enable_tuning_in_merge: bool = False
85+
"""Enable hyperparameter tuning only in the merge stage"""
8086

8187

8288
KAGGLE_IMPLEMENT_SETTING = KaggleBasePropSetting()

rdagent/scenarios/data_science/dev/runner/eval.py

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import json
22
import re
33
from dataclasses import dataclass
4+
from datetime import timedelta
45
from pathlib import Path
56

67
import pandas as pd
@@ -15,6 +16,7 @@
1516
from rdagent.core.evolving_framework import QueriedKnowledge
1617
from rdagent.core.experiment import FBWorkspace, Task
1718
from rdagent.log import rdagent_logger as logger
19+
from rdagent.log.timer import RD_Agent_TIMER_wrapper
1820
from rdagent.scenarios.data_science.test_eval import (
1921
MLETestEval,
2022
NoTestEvalError,
@@ -160,14 +162,29 @@ def evaluate(
160162
submission_check_out, submission_ret_code = test_eval.valid(self.scen.competition, implementation)
161163
stdout += f"\n### Submission check:\n{submission_check_out}\nIf Submission check returns a 'Submission is valid' or similar message, despite some warning messages, you should still consider the submission as valid and give a positive final decision. "
162164

165+
# Whether to enable hyperparameter tuning check
166+
# 1. This is the first loop of evaluation.
167+
c1 = len(queried_knowledge.task_to_former_failed_traces[target_task.get_task_information()][0]) == 0
168+
169+
# 2. The current time spent on runner is less than the time limit ratio for runner timeout.
163170
time_spent_ratio = implementation.running_info.running_time / env.conf.running_timeout_period
164-
# Only enable hyperparameter tuning on the first evaluation.
165-
# Avoid too much time consuming.
166-
enable_hyperparameter_tuning_check = False
167-
if len(queried_knowledge.task_to_former_failed_traces[target_task.get_task_information()][0]) == 0 and (
168-
time_spent_ratio < DS_RD_SETTING.time_ratio_limit_to_enable_hyperparameter_tuning
169-
):
170-
enable_hyperparameter_tuning_check = True
171+
c2 = time_spent_ratio < DS_RD_SETTING.time_ratio_limit_to_enable_hyperparameter_tuning
172+
173+
# 3. Only enable hyperparameter tuning during the merge stage if configured.
174+
# TODO: it is not restricted in merge stage now for fast implementation.
175+
timer = RD_Agent_TIMER_wrapper.timer
176+
res_time = timer.remain_time()
177+
if DS_RD_SETTING.only_enable_tuning_in_merge:
178+
c3 = res_time <= timedelta(hours=DS_RD_SETTING.merge_hours)
179+
else:
180+
c3 = True
181+
182+
# 4. The current time spent on global is less than the time limit ratio for whole timeout.
183+
res_ratio = res_time / timer.all_duration
184+
c4 = res_ratio <= DS_RD_SETTING.res_time_ratio_limit_to_enable_hyperparameter_tuning
185+
186+
# Only enable hyperparameter tuning check if all conditions are met
187+
enable_hyperparameter_tuning_check = c1 and c2 and c3 and c4
171188

172189
system_prompt = T(".prompts:DSCoSTEER_eval.system").r(
173190
scenario=self.scen.get_scenario_all_desc(eda_output=implementation.file_dict.get("EDA.md", None)),

0 commit comments

Comments
 (0)