Replay capped six-player search with isolated longer-horizon diagnostic
This commit is contained in:
parent
e3178fca2f
commit
b7fb490f8f
3 changed files with 156 additions and 2 deletions
23
ai/strong/diagnose-search-horizon.cjs
Normal file
23
ai/strong/diagnose-search-horizon.cjs
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
// Diagnostic preload only: return the original decision, and retry capped searches separately.
|
||||
const fs = require('node:fs');
|
||||
const search = require('./search.cjs');
|
||||
const choose = search.choose;
|
||||
search.choose = function (g, seat, options) {
|
||||
const original = choose(g, seat, options);
|
||||
if (original.truncated) {
|
||||
const extended = choose(g, seat, { ...options, maxSteps: 2400 });
|
||||
const record = { seat, options, original, extended, state: g };
|
||||
fs.appendFileSync(process.env.SEARCH_DIAGNOSTIC_PATH, JSON.stringify(record) + '\n');
|
||||
console.error(
|
||||
JSON.stringify({
|
||||
diagnostic: 'search_horizon',
|
||||
seed: options.seed,
|
||||
original_truncated: original.truncated,
|
||||
extended_truncated: extended.truncated,
|
||||
original_index: original.index,
|
||||
extended_index: extended.index,
|
||||
})
|
||||
);
|
||||
}
|
||||
return original;
|
||||
};
|
||||
118
ai/strong/diagnose-search-horizon.py
Normal file
118
ai/strong/diagnose-search-horizon.py
Normal file
|
|
@ -0,0 +1,118 @@
|
|||
"""Replay the one capped arena match without changing its actual policy decisions."""
|
||||
|
||||
import json
|
||||
import os
|
||||
from pathlib import Path
|
||||
import sys
|
||||
import time
|
||||
|
||||
from huggingface_hub import HfApi, hf_hub_download
|
||||
|
||||
sys.path.insert(0, str(Path(__file__).resolve().parents[1]))
|
||||
from infer import Model
|
||||
from pool import EnginePool
|
||||
|
||||
repo = "coyotte508/powergrid-ai-germany-v1"
|
||||
model = Model(
|
||||
hf_hub_download(
|
||||
repo,
|
||||
"runs/multiplayer-distillation-v2-hard/best.onnx",
|
||||
revision="ab34dd266010ded1c9a6c818c721e5505dd1ddeb",
|
||||
)
|
||||
)
|
||||
expected_file = hf_hub_download(
|
||||
repo,
|
||||
"runs/multiplayer-hard-e10-search48-search_geo-6p-probe-4/evaluation.json",
|
||||
revision=os.environ["REPORT_REVISION"],
|
||||
)
|
||||
expected = next(
|
||||
r
|
||||
for r in json.loads(Path(expected_file).read_text())["results"]
|
||||
if r["gameSeed"] == "multiplayer-search-strong-probe-v1-6p-5"
|
||||
and r["variant"] == "recharged"
|
||||
and not r["sealed"]
|
||||
and r["seat"] == 1
|
||||
)
|
||||
out = Path("ai/runs/search-horizon-diagnostic-v1")
|
||||
out.mkdir(parents=True, exist_ok=True)
|
||||
os.environ["NODE_OPTIONS"] = "--require " + str(
|
||||
Path("ai/strong/diagnose-search-horizon.cjs").resolve()
|
||||
)
|
||||
os.environ["SEARCH_DIAGNOSTIC_PATH"] = str((out / "capped-searches.jsonl").resolve())
|
||||
pool = EnginePool(
|
||||
1, seed="multiplayer-search-strong-probe-v1-6p", script="ai/strong/bridge.cjs"
|
||||
)
|
||||
start = last = time.monotonic()
|
||||
try:
|
||||
current = pool.call(
|
||||
dict(
|
||||
op="reset",
|
||||
n=1,
|
||||
playerCount=6,
|
||||
offset=127,
|
||||
mode="search_geo",
|
||||
arenaSeed="multiplayer-search-strong-probe-v1-6p",
|
||||
featureRevisions={"learner": "4.0-multiplayer"},
|
||||
)
|
||||
)["observations"]
|
||||
ends = []
|
||||
while current[0] is not None:
|
||||
x = current[0]
|
||||
action, _ = model.predict(x["state"], x["actions"])
|
||||
reply = pool.call(
|
||||
dict(
|
||||
op="step",
|
||||
actions=[dict(proposal=action, searchSamples=48, geography=True)],
|
||||
)
|
||||
)
|
||||
current = reply["observations"]
|
||||
ends.extend(reply["ended"])
|
||||
if time.monotonic() - last >= 30:
|
||||
print(
|
||||
json.dumps(
|
||||
dict(
|
||||
stage="diagnostic_replay",
|
||||
seconds=time.monotonic() - start,
|
||||
round=x["round"],
|
||||
)
|
||||
),
|
||||
flush=True,
|
||||
)
|
||||
last = time.monotonic()
|
||||
finally:
|
||||
pool.close()
|
||||
assert len(ends) == 1
|
||||
actual = ends[0]
|
||||
keys = [
|
||||
"episode",
|
||||
"gameSeed",
|
||||
"truncated",
|
||||
"value",
|
||||
"playerCount",
|
||||
"variant",
|
||||
"sealed",
|
||||
"steps",
|
||||
"roles",
|
||||
"policyMoves",
|
||||
"searchStats",
|
||||
"final",
|
||||
]
|
||||
assert all(actual[k] == expected[k] for k in keys), (
|
||||
"Diagnostic replay diverged from original match"
|
||||
)
|
||||
captured = [
|
||||
json.loads(line)
|
||||
for line in (out / "capped-searches.jsonl").read_text().splitlines()
|
||||
]
|
||||
assert sum(r["original"]["truncated"] for r in captured) == 1
|
||||
report = dict(
|
||||
exact_terminal_replay=True,
|
||||
original=actual,
|
||||
captures=[{k: v for k, v in r.items() if k != "state"} for r in captured],
|
||||
seconds=time.monotonic() - start,
|
||||
)
|
||||
(out / "report.json").write_text(json.dumps(report, indent=2) + "\n")
|
||||
HfApi().upload_folder(
|
||||
repo_id=repo, folder_path=str(out), path_in_repo="runs/search-horizon-diagnostic-v1"
|
||||
)
|
||||
print(json.dumps({k: v for k, v in report.items() if k != "original"}), flush=True)
|
||||
|
|
@ -9286,7 +9286,7 @@
|
|||
}
|
||||
},
|
||||
"six_player_search_horizon_investigation": {
|
||||
"status": "OPEN",
|
||||
"status": "DIAGNOSTIC_SUBMITTED",
|
||||
"current_default_max_steps": 1200,
|
||||
"affected_match": {
|
||||
"seed": "multiplayer-search-strong-probe-v1-6p-5",
|
||||
|
|
@ -9296,6 +9296,19 @@
|
|||
},
|
||||
"truncated_learner_rollouts": 1,
|
||||
"total_learner_rollouts": 2327280,
|
||||
"next_action": "Reproduce affected match with diagnostic capture of the capped simulation. Check whether extending that same simulation terminates, then verify outcome parity for unaffected cases before changing defaults. Retain the original report and do not erase truncated counts."
|
||||
"next_action": "Reproduce affected match with diagnostic capture of the capped simulation. Check whether extending that same simulation terminates, then verify outcome parity for unaffected cases before changing defaults. Retain the original report and do not erase truncated counts.",
|
||||
"job": "6abd8041404719ba37614703",
|
||||
"source": {
|
||||
"archive": "strong-source-v31.tgz",
|
||||
"revision": "9752cbc31db834b8c07b62504997fc0134a8e0ee",
|
||||
"base_revision": "508bc42027cae5bfeea01228b48069c8287b332a",
|
||||
"changed_files": [
|
||||
"ai/strong/diagnose-search-horizon.py",
|
||||
"ai/strong/diagnose-search-horizon.cjs"
|
||||
],
|
||||
"archive_sha256": "7aec51dcc2f2af636965c0496705850ed2d2d6b3dee89021d494e26dc6820cb7",
|
||||
"report_revision": "6f9442ff21521c460e5c6abc14ba06efb3a4dd25"
|
||||
},
|
||||
"actual_policy": "Original 1200-move cap; diagnostic retry does not change decisions"
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue