Files
NexQuant/rdagent/components/coder/data_science/conf.py
T

88 lines
2.7 KiB
Python
Raw Normal View History

2025-03-12 11:36:28 +08:00
from typing import Literal
2025-04-09 23:24:12 +08:00
from rdagent.app.data_science.conf import DS_RD_SETTING
from rdagent.components.coder.CoSTEER.config import CoSTEERSettings
2025-03-12 11:36:28 +08:00
from rdagent.utils.env import (
CondaConf,
DockerEnv,
DSDockerConf,
Env,
LocalEnv,
MLEBDockerConf,
MLECondaConf,
)
class DSCoderCoSTEERSettings(CoSTEERSettings):
"""Data Science CoSTEER settings"""
class Config:
env_prefix = "DS_Coder_CoSTEER_"
max_seconds_multiplier: int = 4
2025-03-12 11:36:28 +08:00
env_type: str = "docker"
# TODO: extract a function for env and conf.
2025-08-06 12:24:44 +08:00
extra_evaluator: list[str] = []
"""Extra evaluators to use"""
2025-03-12 11:36:28 +08:00
extra_eval: list[str] = []
"""
Extra evaluators
The evaluator follows the following assumptions:
- It runs after previous evaluator (So the running results are already there)
It is not a complete feature due to it is only implemented in DS Pipeline & Coder.
TODO: The complete version should be implemented in the CoSTEERSettings.
"""
2025-03-12 11:36:28 +08:00
2025-04-10 17:56:57 +08:00
def get_ds_env(
conf_type: Literal["kaggle", "mlebench"] = "kaggle",
extra_volumes: dict = {},
running_timeout_period: int | None = DS_RD_SETTING.debug_timeout,
enable_cache: bool | None = None,
2025-04-10 17:56:57 +08:00
) -> Env:
2025-03-12 11:36:28 +08:00
"""
Retrieve the appropriate environment configuration based on the env_type setting.
Returns:
Env: An instance of the environment configured either as DockerEnv or LocalEnv.
Raises:
ValueError: If the env_type is not recognized.
"""
conf = DSCoderCoSTEERSettings()
assert conf_type in ["kaggle", "mlebench"], f"Unknown conf_type: {conf_type}"
if conf.env_type == "docker":
env_conf = DSDockerConf() if conf_type == "kaggle" else MLEBDockerConf()
env = DockerEnv(conf=env_conf)
elif conf.env_type == "conda":
env = LocalEnv(
conf=(
CondaConf(conda_env_name=conf_type) if conf_type == "kaggle" else MLECondaConf(conda_env_name=conf_type)
)
)
else:
raise ValueError(f"Unknown env type: {conf.env_type}")
env.conf.extra_volumes = extra_volumes.copy()
2025-04-10 17:56:57 +08:00
env.conf.running_timeout_period = running_timeout_period
if enable_cache is not None:
env.conf.enable_cache = enable_cache
env.prepare()
2025-03-12 11:36:28 +08:00
return env
2025-04-09 23:24:12 +08:00
def get_clear_ws_cmd(stage: Literal["before_training", "before_inference"] = "before_training") -> str:
"""
Clean the files in workspace to a specific stage
"""
assert stage in ["before_training", "before_inference"], f"Unknown stage: {stage}"
if DS_RD_SETTING.enable_model_dump and stage == "before_training":
cmd = "rm -r submission.csv scores.csv models trace.log"
2025-04-09 23:24:12 +08:00
else:
cmd = "rm submission.csv scores.csv trace.log"
2025-04-09 23:24:12 +08:00
return cmd