Skip to content

Commit 4ae2f13

Browse files
SunsetWolfyou-n-g
andauthored
fix: fix mount (#1001)
* docs: document extra_volumes dict format in DockerConf * feat: accept dict values in extra_volumes to specify bind and mode * fix: skip invalid PDF reports to prevent infinite loop * from break to raise self.LoopTerminationError * format with black --------- Co-authored-by: Young <[email protected]>
1 parent bda12ff commit 4ae2f13

File tree

2 files changed

+17
-4
lines changed

2 files changed

+17
-4
lines changed

rdagent/app/qlib_rd_loop/factor_from_report.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,14 +105,21 @@ def __init__(self, report_folder: str = None):
105105
self.judge_pdf_data_items = [i for i in Path(report_folder).rglob("*.pdf")]
106106

107107
self.loop_n = min(len(self.judge_pdf_data_items), FACTOR_FROM_REPORT_PROP_SETTING.report_limit)
108+
self.shift_report = (
109+
0 # some reports does not contain viable factor, so we ship some of them to avoid infinite loop
110+
)
108111

109112
async def direct_exp_gen(self, prev_out: dict[str, Any]):
110113
while True:
111114
if self.get_unfinished_loop_cnt(self.loop_idx) < RD_AGENT_SETTINGS.get_max_parallel():
112-
report_file_path = self.judge_pdf_data_items[self.loop_idx]
115+
report_file_path = self.judge_pdf_data_items[self.loop_idx + self.shift_report]
113116
logger.info(f"Processing number {self.loop_idx} report: {report_file_path}")
114117
exp = extract_hypothesis_and_exp_from_reports(str(report_file_path))
115118
if exp is None:
119+
self.shift_report += 1
120+
self.loop_n -= 1
121+
if self.loop_n < 0: # NOTE: on every step, we self.loop_n -= 1 at first.
122+
raise self.LoopTerminationError("Reach stop criterion and stop loop")
116123
continue
117124
exp.based_experiments = [QlibFactorExperiment(sub_tasks=[], hypothesis=exp.hypothesis)] + [
118125
t[0] for t in self.trace.hist if t[1]

rdagent/utils/env.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -602,6 +602,10 @@ class DockerConf(EnvConf):
602602
default_entry: str # the entry point of the image
603603

604604
extra_volumes: dict = {}
605+
"""It accept a dict of volumes, which can be either
606+
{<host_path>: <container_path>} or
607+
{<host_path>: {"bind": <container_path>, "mode": <mode, ro/rw/default is extra_volume_mode>}}
608+
"""
605609
extra_volume_mode: str = "ro" # by default. only the mount_path should be writable, others are changed to read-only
606610
# Sometime, we need maintain some extra data for the workspace.
607611
# And the extra data may be shared and the downloading can be time consuming.
@@ -662,7 +666,9 @@ class QlibDockerConf(DockerConf):
662666
image: str = "local_qlib:latest"
663667
mount_path: str = "/workspace/qlib_workspace/"
664668
default_entry: str = "qrun conf.yaml"
665-
extra_volumes: dict = {str(Path("~/.qlib/").expanduser().resolve().absolute()): "/root/.qlib/"}
669+
extra_volumes: dict = {
670+
str(Path("~/.qlib/").expanduser().resolve().absolute()): {"bind": "/root/.qlib/", "mode": "rw"}
671+
}
666672
shm_size: str | None = "16g"
667673
enable_gpu: bool = True
668674
enable_cache: bool = False
@@ -854,12 +860,12 @@ def _run_ret_code(
854860

855861
if self.conf.extra_volumes is not None:
856862
for lp, rp in self.conf.extra_volumes.items():
857-
volumes[lp] = {"bind": rp, "mode": self.conf.extra_volume_mode}
863+
volumes[lp] = rp if isinstance(rp, dict) else {"bind": rp, "mode": self.conf.extra_volume_mode}
858864
cache_path = "/tmp/sample" if "/sample/" in "".join(self.conf.extra_volumes.keys()) else "/tmp/full"
859865
Path(cache_path).mkdir(parents=True, exist_ok=True)
860866
volumes[cache_path] = {"bind": T("scenarios.data_science.share:scen.cache_path").r(), "mode": "rw"}
861867
for lp, rp in running_extra_volume.items():
862-
volumes[lp] = {"bind": rp, "mode": self.conf.extra_volume_mode}
868+
volumes[lp] = rp if isinstance(rp, dict) else {"bind": rp, "mode": self.conf.extra_volume_mode}
863869

864870
volumes = normalize_volumes(cast(dict[str, str | dict[str, str]], volumes), self.conf.mount_path)
865871

0 commit comments

Comments
 (0)