Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: grading using mlebench #471

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
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
grading using mlebench
  • Loading branch information
taozhiwang committed Nov 4, 2024
commit 8698042db0a4f5f637fbf9d53a6516690b6468d1
3 changes: 3 additions & 0 deletions rdagent/app/kaggle/conf.py
Original file line number Diff line number Diff line change
@@ -72,6 +72,9 @@ class Config:
auto_submit: bool = False
"""Automatically upload and submit each experiment result to Kaggle platform"""

mle_submit: bool = False
"""Automatically upload and submit each experiment result to mlebench"""

mini_case: bool = False
"""Enable mini-case study for experiments"""

22 changes: 22 additions & 0 deletions rdagent/app/kaggle/loop.py
Original file line number Diff line number Diff line change
@@ -113,6 +113,28 @@ def running(self, prev_out: dict[str, Any]):
except Exception as e:
logger.error(f"Other exception when use kaggle api:\n{e}")

if KAGGLE_IMPLEMENT_SETTING.mle_submit:
csv_path = exp.experiment_workspace.workspace_path / "submission.csv"
try:
result = subprocess.run(
[
"mlebench",
"grade-sample",
str(csv_path.absolute()),
KAGGLE_IMPLEMENT_SETTING.competition,
],
check=True,
capture_output=True,
text=True,
)
with open(exp.experiment_workspace.workspace_path / "mle_submission_report.txt", "w") as f:
f.write(result.stdout)
f.write(result.stderr)
except subprocess.CalledProcessError as e:
logger.error(f"Auto submission failed: \n{e}")
except Exception as e:
logger.error(f"Other exception when use mle api:\n{e}")

return exp

skip_loop_error = (ModelEmptyError, FactorEmptyError)
29 changes: 29 additions & 0 deletions rdagent/scenarios/kaggle/developer/runner.py
Original file line number Diff line number Diff line change
@@ -71,6 +71,35 @@ def develop(self, exp: KGModelExperiment) -> KGModelExperiment:

return exp

class MLEModelRunner(KGCachedRunner[KGModelExperiment]):
@cache_with_pickle(KGCachedRunner.get_cache_key, KGCachedRunner.assign_cached_result)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we can use the previous runner; it's just that if MLE is doing the benchmark, we need to submit the submission.csv file to the Grade server.

def develop(self, exp: KGModelExperiment) -> KGModelExperiment:
if exp.based_experiments and exp.based_experiments[-1].result is None:
exp.based_experiments[-1] = self.init_develop(exp.based_experiments[-1])

sub_ws = exp.sub_workspace_list[0]
if sub_ws is not None:
# TODO: There's a possibility of generating a hybrid model (lightgbm + xgboost), which results in having two items in the model_type list.
model_type = sub_ws.target_task.model_type

if sub_ws.code_dict == {}:
raise ModelEmptyError("No model is implemented.")
else:
model_file_name = f"model/model_{model_type.lower()}.py"
exp.experiment_workspace.inject_code(**{model_file_name: sub_ws.code_dict["model.py"]})
env_to_use = {"PYTHONPATH": "./"}

result = exp.experiment_workspace.execute(run_env=env_to_use)

if result is None:
raise CoderError("No result is returned from the experiment workspace")

report_path = exp.experiment_workspace.workspace_path / "mle_submission_report.txt"
with open(report_path, "r") as f:
exp.result = f.read()

return exp


class KGFactorRunner(KGCachedRunner[KGFactorExperiment]):
@cache_with_pickle(KGCachedRunner.get_cache_key, KGCachedRunner.assign_cached_result)
Loading
Oops, something went wrong.