flock/sweep: every team lists every server again (Flock at or after 0401df9, flock#129, spreads concurrent teams' agents); eval/metrics.py reads env files as Flock does (inline comments after quoted and unquoted values), with check.py cases
Browse files- check.py +10 -0
- eval/metrics.py +26 -7
- flock/sweep/README.md +7 -6
- flock/sweep/sweep.py +7 -28
check.py
CHANGED
|
@@ -833,6 +833,16 @@ def check_metrics() -> int:
|
|
| 833 |
"reward: agent-004"]),
|
| 834 |
"an unplanned agent": ("agg-p01-n04", four[:3], {"run.env": "N=2\n"}, "agg-p01-n04", 2,
|
| 835 |
["agents: Trials of agents the spec didn't plan: agent-003"]),
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 836 |
}
|
| 837 |
with tempfile.TemporaryDirectory() as d:
|
| 838 |
for case, (team, agents, env_files, task, count, missing) in cases.items():
|
|
|
|
| 833 |
"reward: agent-004"]),
|
| 834 |
"an unplanned agent": ("agg-p01-n04", four[:3], {"run.env": "N=2\n"}, "agg-p01-n04", 2,
|
| 835 |
["agents: Trials of agents the spec didn't plan: agent-003"]),
|
| 836 |
+
# inline comments, as Flock's read_env_file reads them: after a quoted value's closing
|
| 837 |
+
# quote, and after whitespace in an unquoted one
|
| 838 |
+
"quoted values with comments": ("agg-p03-n04", four[:3],
|
| 839 |
+
{"run.env": 'TEAM="agg-p03-n04" # group\nN="4" # size\n'},
|
| 840 |
+
"agg-p03-n04", 4, ["reward: agent-004"]),
|
| 841 |
+
"unquoted values with comments": ("agg-p02-n02", four[:2],
|
| 842 |
+
{"cluster.env": "N=3 # size\n",
|
| 843 |
+
"run.env": "export TEAM=agg-p02-n02 # group\n"
|
| 844 |
+
"N=2\t# size\n"},
|
| 845 |
+
"agg-p02-n02", 2, []),
|
| 846 |
}
|
| 847 |
with tempfile.TemporaryDirectory() as d:
|
| 848 |
for case, (team, agents, env_files, task, count, missing) in cases.items():
|
eval/metrics.py
CHANGED
|
@@ -186,16 +186,35 @@ def local_run(run: dict) -> dict:
|
|
| 186 |
PLACEHOLDER = re.compile(r"\$\{([A-Z_][A-Z0-9_]*)(?::-([^}]*))?\}")
|
| 187 |
|
| 188 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 189 |
def run_values(run_dir: Path) -> dict[str, str]:
|
| 190 |
-
"""The run's `cluster.env` then `run.env` (later wins), as
|
| 191 |
-
|
| 192 |
values = {}
|
| 193 |
for name in ("cluster.env", "run.env"):
|
| 194 |
-
|
| 195 |
-
|
| 196 |
-
key, sep, value = line.strip().removeprefix("export ").partition("=")
|
| 197 |
-
if sep and not key.startswith("#") and key.isidentifier():
|
| 198 |
-
values[key] = value.strip().strip("'\"")
|
| 199 |
return values
|
| 200 |
|
| 201 |
|
|
|
|
| 186 |
PLACEHOLDER = re.compile(r"\$\{([A-Z_][A-Z0-9_]*)(?::-([^}]*))?\}")
|
| 187 |
|
| 188 |
|
| 189 |
+
def env_values(path: Path) -> dict[str, str]:
|
| 190 |
+
"""NAME=value lines as Flock reads them (flock.specrender.read_env_file): an `export `
|
| 191 |
+
prefix and `#` comment lines allowed; a quoted value ends at its closing quote (what follows
|
| 192 |
+
is a comment), and an unquoted one at whitespace followed by `#`. A line that isn't
|
| 193 |
+
NAME=value is skipped, where Flock refuses the file."""
|
| 194 |
+
values = {}
|
| 195 |
+
for line in path.read_text(encoding="utf-8").splitlines():
|
| 196 |
+
line = line.strip()
|
| 197 |
+
if not line or line.startswith("#"):
|
| 198 |
+
continue
|
| 199 |
+
name, sep, raw = line.removeprefix("export ").partition("=")
|
| 200 |
+
name, value = name.strip(), raw.strip()
|
| 201 |
+
if not sep or not re.fullmatch(r"[A-Za-z_][A-Za-z0-9_]*", name):
|
| 202 |
+
continue
|
| 203 |
+
if value and value[0] in "'\"" and (end := value.find(value[0], 1)) > 0:
|
| 204 |
+
value = value[1:end]
|
| 205 |
+
else:
|
| 206 |
+
value = re.split(r"\s+#", raw, maxsplit=1)[0].strip()
|
| 207 |
+
values[name] = value
|
| 208 |
+
return values
|
| 209 |
+
|
| 210 |
+
|
| 211 |
def run_values(run_dir: Path) -> dict[str, str]:
|
| 212 |
+
"""The run's `cluster.env` then `run.env` (later wins), as Flock reads them: what fills the
|
| 213 |
+
spec's `${VAR}`s."""
|
| 214 |
values = {}
|
| 215 |
for name in ("cluster.env", "run.env"):
|
| 216 |
+
if (run_dir / name).is_file():
|
| 217 |
+
values |= env_values(run_dir / name)
|
|
|
|
|
|
|
|
|
|
| 218 |
return values
|
| 219 |
|
| 220 |
|
flock/sweep/README.md
CHANGED
|
@@ -18,8 +18,9 @@ runs in the private `HuggingFaceSwarms/s3-aggregation-results`.
|
|
| 18 |
|
| 19 |
## Run it
|
| 20 |
|
| 21 |
-
From Flock's checkout (with its Slurm results, huggingface/flock#122, so
|
| 22 |
-
reaches the run directory
|
|
|
|
| 23 |
the teams pin (`DS` below), since the workers read `registries.conf` from it. Two model servers,
|
| 24 |
one GPU each: one B200 is saturated by about 50 agents at a time (the 27B grid needs about 70M
|
| 25 |
prompt and 2M generated tokens), and a job's time limit is 3 hours.
|
|
@@ -42,10 +43,10 @@ workers small enough to be scheduled, except at N = 16, whose 2B teams need 16 C
|
|
| 42 |
run from a second driver (`--agents 16`) on the same root. Then plot both:
|
| 43 |
`plot.py --series Qwen3.5-27B=<root> --series Qwen3.5-2B=<root> --out <dir>`.
|
| 44 |
|
| 45 |
-
Each team is team.py's cluster spec (`--where cluster`) with the model on
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
running the team in rootless podman with a local board, sized to the team (a CPU per agent, at
|
| 50 |
least 4). The board rules, loop and limits are the template's at every N. sweep.py inits and
|
| 51 |
launches a team, waits until its loop is done and its agents are idle, releases it
|
|
|
|
| 18 |
|
| 19 |
## Run it
|
| 20 |
|
| 21 |
+
From Flock's checkout at or after `0401df9` (with its Slurm results, huggingface/flock#122, so
|
| 22 |
+
each Trial's grading reaches the run directory, and huggingface/flock#129, so the teams' agents
|
| 23 |
+
spread over the servers), with this dataset downloaded on the shared disk at the revision
|
| 24 |
the teams pin (`DS` below), since the workers read `registries.conf` from it. Two model servers,
|
| 25 |
one GPU each: one B200 is saturated by about 50 agents at a time (the 27B grid needs about 70M
|
| 26 |
prompt and 2M generated tokens), and a job's time limit is 3 hours.
|
|
|
|
| 43 |
run from a second driver (`--agents 16`) on the same root. Then plot both:
|
| 44 |
`plot.py --series Qwen3.5-27B=<root> --series Qwen3.5-2B=<root> --out <dir>`.
|
| 45 |
|
| 46 |
+
Each team is team.py's cluster spec (`--where cluster`) with the model on all the servers' URLs
|
| 47 |
+
(each agent calls one: Flock at or after `0401df9`, huggingface/flock#129, picks it from the run
|
| 48 |
+
and the agent's name, so concurrent teams' agents spread over the servers; with an older Flock
|
| 49 |
+
every team's `agent-001` lands on the same server): `compute: slurm`, one worker on hopper-cpu
|
| 50 |
running the team in rootless podman with a local board, sized to the team (a CPU per agent, at
|
| 51 |
least 4). The board rules, loop and limits are the template's at every N. sweep.py inits and
|
| 52 |
launches a team, waits until its loop is done and its agents are idle, releases it
|
flock/sweep/sweep.py
CHANGED
|
@@ -6,9 +6,10 @@ Flock's checkout (its environment, and its `.venv` for the workers):
|
|
| 6 |
[--bucket lewtun/s3-aggregation-sweep] [--dataset HuggingFaceSwarms/s3-aggregation-results]
|
| 7 |
|
| 8 |
Each (problem, N) team is its own flock run (`compute: slurm`, podman agents on hopper-cpu, a
|
| 9 |
-
local board on its one worker), from team.py's cluster spec with the sweep's model on
|
| 10 |
-
|
| 11 |
-
|
|
|
|
| 12 |
N), `flock launch`, wait until its loop is done and its agents are idle, `flock stop --release`
|
| 13 |
(each Trial is graded as the worker drains; the results land in the run directory), then
|
| 14 |
eval/metrics.py's row plus the wall time goes to `<root>/rows.jsonl`. Until flock#121
|
|
@@ -45,8 +46,6 @@ REPO = Path.cwd() # Flock's checkout
|
|
| 45 |
MODEL = "Qwen/Qwen3.5-27B"
|
| 46 |
SECRET = re.compile(r"hf_[A-Za-z0-9]{30,}")
|
| 47 |
lock, init_lock = threading.Lock(), threading.Semaphore(4)
|
| 48 |
-
servers_lock = threading.Lock()
|
| 49 |
-
server_load: dict[str, int] = {} # server -> agents of the teams running on it
|
| 50 |
LOST, GONE = "controller lost", "no controller left"
|
| 51 |
# the loop's `until` (and the driver's team timeout) count from the launch, not from the worker's
|
| 52 |
# start: a run whose worker queued longer than this (a busy or scaling partition) doesn't count
|
|
@@ -141,27 +140,7 @@ def wait_done(run_dir: Path, task: str, n: int, timeout: float) -> str:
|
|
| 141 |
|
| 142 |
|
| 143 |
def attempt(args, root: Path, secrets: Path, problem: int, n: int, name: str) -> dict | None:
|
| 144 |
-
"""One run of a team as swarm `name`
|
| 145 |
-
start. The team gets the server with the fewest agents of running teams (an adopted team
|
| 146 |
-
keeps its own): until flock#129, agents pick a server by name alone, so with every server in
|
| 147 |
-
each spec, every concurrent team's agent-001 would land on one server (flock#127)."""
|
| 148 |
-
spec = root / "runs" / name / "experiment" / "spec.yaml"
|
| 149 |
-
kept = None
|
| 150 |
-
if spec.exists():
|
| 151 |
-
kept = (yaml.safe_load(spec.read_text()).get("inference") or {}).get("urls")
|
| 152 |
-
with servers_lock:
|
| 153 |
-
server = kept[0] if kept and len(kept) == 1 else min(
|
| 154 |
-
args.urls, key=lambda url: (server_load.get(url, 0), args.urls.index(url)))
|
| 155 |
-
server_load[server] = server_load.get(server, 0) + n
|
| 156 |
-
try:
|
| 157 |
-
return run_attempt(args, root, secrets, problem, n, name, server)
|
| 158 |
-
finally:
|
| 159 |
-
with servers_lock:
|
| 160 |
-
server_load[server] -= n
|
| 161 |
-
|
| 162 |
-
|
| 163 |
-
def run_attempt(args, root: Path, secrets: Path, problem: int, n: int, name: str,
|
| 164 |
-
server: str) -> dict | None:
|
| 165 |
run_dir, src = root / "runs" / name, root / "src" / name
|
| 166 |
if run_dir.exists() and (any((run_dir / "launch").glob("*.env"))
|
| 167 |
or (run_dir / "hosts" / "controller.host").exists()):
|
|
@@ -175,7 +154,7 @@ def run_attempt(args, root: Path, secrets: Path, problem: int, n: int, name: str
|
|
| 175 |
if run_dir.exists():
|
| 176 |
shutil.rmtree(run_dir) # init failed before: nothing ran
|
| 177 |
started = time.time()
|
| 178 |
-
write_experiment(src, problem, n, name,
|
| 179 |
log = root / "logs" / f"{name}-init.log"
|
| 180 |
log.parent.mkdir(parents=True, exist_ok=True)
|
| 181 |
for tries in range(3):
|
|
@@ -190,7 +169,7 @@ def run_attempt(args, root: Path, secrets: Path, problem: int, n: int, name: str
|
|
| 190 |
failed = [x for x in init.stdout.splitlines() if x.startswith("FAIL")]
|
| 191 |
say(name, "init failed 3 times:", failed or init.stdout[-300:], "(log:", log, ")")
|
| 192 |
return None
|
| 193 |
-
say(name, "launching
|
| 194 |
launch = flock(run_dir, "launch", str(run_dir / "experiment"))
|
| 195 |
if launch.returncode != 0:
|
| 196 |
say(name, "launch failed:", launch.stdout[-600:], launch.stderr[-600:])
|
|
|
|
| 6 |
[--bucket lewtun/s3-aggregation-sweep] [--dataset HuggingFaceSwarms/s3-aggregation-results]
|
| 7 |
|
| 8 |
Each (problem, N) team is its own flock run (`compute: slurm`, podman agents on hopper-cpu, a
|
| 9 |
+
local board on its one worker), from team.py's cluster spec with the sweep's model on `urls`
|
| 10 |
+
(the same board rules, loop and limits at every N). Every team lists every server: Flock at or
|
| 11 |
+
after 0401df9 (flock#129) picks each agent's server from its run and its name, so concurrent
|
| 12 |
+
teams' agents spread over the servers. Per team: `flock init` (a worker sized to
|
| 13 |
N), `flock launch`, wait until its loop is done and its agents are idle, `flock stop --release`
|
| 14 |
(each Trial is graded as the worker drains; the results land in the run directory), then
|
| 15 |
eval/metrics.py's row plus the wall time goes to `<root>/rows.jsonl`. Until flock#121
|
|
|
|
| 46 |
MODEL = "Qwen/Qwen3.5-27B"
|
| 47 |
SECRET = re.compile(r"hf_[A-Za-z0-9]{30,}")
|
| 48 |
lock, init_lock = threading.Lock(), threading.Semaphore(4)
|
|
|
|
|
|
|
| 49 |
LOST, GONE = "controller lost", "no controller left"
|
| 50 |
# the loop's `until` (and the driver's team timeout) count from the launch, not from the worker's
|
| 51 |
# start: a run whose worker queued longer than this (a busy or scaling partition) doesn't count
|
|
|
|
| 140 |
|
| 141 |
|
| 142 |
def attempt(args, root: Path, secrets: Path, problem: int, n: int, name: str) -> dict | None:
|
| 143 |
+
"""One run of a team as swarm `name`: its row, or None when it could not start."""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 144 |
run_dir, src = root / "runs" / name, root / "src" / name
|
| 145 |
if run_dir.exists() and (any((run_dir / "launch").glob("*.env"))
|
| 146 |
or (run_dir / "hosts" / "controller.host").exists()):
|
|
|
|
| 154 |
if run_dir.exists():
|
| 155 |
shutil.rmtree(run_dir) # init failed before: nothing ran
|
| 156 |
started = time.time()
|
| 157 |
+
write_experiment(src, problem, n, name, args.urls, args.model, args.revision)
|
| 158 |
log = root / "logs" / f"{name}-init.log"
|
| 159 |
log.parent.mkdir(parents=True, exist_ok=True)
|
| 160 |
for tries in range(3):
|
|
|
|
| 169 |
failed = [x for x in init.stdout.splitlines() if x.startswith("FAIL")]
|
| 170 |
say(name, "init failed 3 times:", failed or init.stdout[-300:], "(log:", log, ")")
|
| 171 |
return None
|
| 172 |
+
say(name, "launching")
|
| 173 |
launch = flock(run_dir, "launch", str(run_dir / "experiment"))
|
| 174 |
if launch.returncode != 0:
|
| 175 |
say(name, "launch failed:", launch.stdout[-600:], launch.stderr[-600:])
|