Repository navigation
STORY-01: source-native builder, SWMD-mini, HG-02 gym #54
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
Draft
patrickdugan
wants to merge
38
commits into
master
Choose a base branch
from
research/storyworld-native-three-mode-gym-20261123
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
38 commits
Select commit
Hold shift + click to select a range
95567b0
feat(storyworld): source-native builder, SWMD mini, and HG-02 gym
patrickdugan 964d2a9
test(storyworld): native cross-repo custody, replay and exact oracle …
patrickdugan 1711258
ci(storyworld): run source-pinned GPTStoryworld native smoke and replay
patrickdugan 0a5bce1
docs(storyworld): document native builder, mini, and hypergame corpus
patrickdugan cb102e4
skill(storyworld): bounded native Storyworld authoring and hypergame …
patrickdugan c2e0c0b
ci(storyworld): install package dependencies before native tests and …
patrickdugan c379585
fix(storyworld): satisfy Ruff length gate
patrickdugan 64b6987
fix(storyworld): redact matching sibling destinations from mini promp…
patrickdugan 95db405
test(storyworld): assert mini context cannot leak sibling gold successor
patrickdugan 46ca726
fix(storyworld): hold out entire source encounters across builder and…
patrickdugan af5ba7c
test(storyworld): assert source-encounter split custody
patrickdugan 945bb66
docs(storyworld): specify source-encounter-level train/test isolation
patrickdugan e59c91f
refactor(storyworld): share frozen encounter split map with native mi…
patrickdugan e68962a
feat(storyworld): native SWMD-MICRO compile/compress/repair/edit SFT …
patrickdugan c59d503
test(storyworld): native mini compiler 4-task corpus and split integrity
patrickdugan 61cd108
ci(storyworld): validate native SWMD-MICRO compiler and SFT export
patrickdugan 6a578e1
docs(storyworld): add native minified compiler SFT and four task types
patrickdugan 7a2c421
fix(storyworld): address micro compiler lint findings
patrickdugan eb05aac
fix(storyworld): address micro compiler lint findings
patrickdugan a006e0e
feat(storyworld): opt-in local Inky player with live HG-02 turns and …
patrickdugan b647b7a
test(storyworld): public-only interactive Inky traces, resume and tam…
patrickdugan b88d23c
ci(storyworld): exercise local player with stub policy and native rol…
patrickdugan efb6943
docs(storyworld): operator-safe local Inky interactive rollout and re…
patrickdugan 28db51f
fix(storyworld): apply new local player lint rules
patrickdugan 2ff07a5
fix(storyworld): apply new local player lint rules
patrickdugan 5abf20d
fix(storyworld): disable inherited HTTP proxies for localhost inference
patrickdugan 2571cd4
feat(storyworld): whole-source-world split override for holdout cohorts
patrickdugan 32138d7
feat(storyworld): match SWMD micro SFT splits to source-world holdouts
patrickdugan 8dcd6ab
data(storyworld): register four source-native worlds with cross-world…
patrickdugan 3660e6d
feat(storyworld): register and replay cross-world builder, Mini and H…
patrickdugan ede1fa2
test(storyworld): four-world holdout custody and source-native replay
patrickdugan d2efe81
style(storyworld): clean cohort imports
patrickdugan cbfc94d
ci(storyworld): verify four pinned worlds with world-level train/hold…
patrickdugan b69f240
fix(storyworld): audit and exclude over-budget source Mini compiler p…
patrickdugan 80c0e12
feat(storyworld): expose Mini overbudget exclusion counts in cohort r…
patrickdugan fe0376c
test(storyworld): assert audited overbudget exclusions and heldout so…
patrickdugan c30f666
docs(storyworld): record source-world splits and measured 4-world CPU…
patrickdugan 58b2442
skill(storyworld): add cross-world custody and local Inky interactive…
patrickdugan File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,59 @@ | ||
| name: Storyworld native three-mode gym | ||
|
|
||
| on: | ||
| push: | ||
| branches: | ||
| - research/storyworld-native-three-mode-gym-20261123 | ||
| pull_request: | ||
| paths: | ||
| - "src/datagoblin/training_gym/rlt_gym/storyworld_native.py" | ||
| - "tests/unit/test_rlt_gym_storyworld_native.py" | ||
| - "training/rlt_gym/storyworld_native/**" | ||
| - ".github/workflows/rlt-storyworld-native.yml" | ||
|
|
||
| jobs: | ||
| native-storyworld: | ||
| runs-on: ubuntu-latest | ||
| timeout-minutes: 15 | ||
| steps: | ||
| - name: Checkout DataGoblin | ||
| uses: actions/checkout@v4 | ||
| - name: Checkout pinned GPTStoryworld files | ||
| uses: actions/checkout@v4 | ||
| with: | ||
| repository: MoralityLabAI/GPTStoryworld | ||
| ref: 5cd0b480e9a01d07418cdf8cb3bedbc9d38ef906 | ||
| path: GPTStoryworld | ||
| filter: blob:none | ||
| sparse-checkout-cone-mode: false | ||
| sparse-checkout: | | ||
| codex-skills/storyworld-building/scripts/sweepweave_validator.py | ||
| codex-skills/storyworld-building/scripts/json_to_swmd.py | ||
| codex-skills/small-storyworld-builder/scripts/swmd_encounter_index.py | ||
| codex-skills/small-storyworld-builder/scripts/swmd_build_qlora_examples.py | ||
| verifiers_envs/storyworld-hypergames-env/src/spiral_ln/hypergames_single_player.py | ||
| verifiers_envs/storyworld-hypergames-env/src/spiral_ln/evaluation_hypergames.py | ||
| storyworlds/diplomacy/forecast_backstab.json | ||
| storyworlds/charter_of_ashen_aegis.json | ||
| storyworlds/the_fifth_testimony_p2.json | ||
| storyworlds/tsun01b_last_train_home/tsun01b.sweepweave.json | ||
| - name: Python | ||
| uses: actions/setup-python@v5 | ||
| with: | ||
| python-version: "3.11" | ||
| - name: Install DataGoblin and lint dependencies | ||
| run: python -m pip install -e '.[dev]' | ||
| - name: Native tests and source-pinned replay | ||
| env: | ||
| PYTHONPATH: src | ||
| GPTSTORYWORLD_SOURCE: GPTStoryworld | ||
| GPTSTORYWORLD_EXPECT_SHA: 5cd0b480e9a01d07418cdf8cb3bedbc9d38ef906 | ||
| run: | | ||
| ruff check src/datagoblin/training_gym/rlt_gym/storyworld_native.py src/datagoblin/training_gym/rlt_gym/storyworld_micro.py src/datagoblin/training_gym/rlt_gym/storyworld_local.py src/datagoblin/training_gym/rlt_gym/storyworld_cohort.py tests/unit/test_rlt_gym_storyworld_native.py tests/unit/test_rlt_gym_storyworld_micro.py tests/unit/test_rlt_gym_storyworld_local.py tests/unit/test_rlt_gym_storyworld_cohort.py | ||
| python -m unittest discover -s tests/unit -p 'test_rlt_gym_storyworld*.py' -v | ||
| python -m datagoblin.training_gym.rlt_gym.storyworld_native --source GPTStoryworld --expect-source-commit "$GPTSTORYWORLD_EXPECT_SHA" --per-mode 2 --seed 23 --out "$RUNNER_TEMP/dg-sw-native" | ||
| python -m datagoblin.training_gym.rlt_gym.storyworld_native --source GPTStoryworld --expect-source-commit "$GPTSTORYWORLD_EXPECT_SHA" --replay "$RUNNER_TEMP/dg-sw-native" | ||
| python -m datagoblin.training_gym.rlt_gym.storyworld_micro --source GPTStoryworld --expect-source-commit "$GPTSTORYWORLD_EXPECT_SHA" --examples-per-encounter 4 --seed 23 --out "$RUNNER_TEMP/dg-sw-micro" | ||
| python -m datagoblin.training_gym.rlt_gym.storyworld_micro --source GPTStoryworld --expect-source-commit "$GPTSTORYWORLD_EXPECT_SHA" --replay "$RUNNER_TEMP/dg-sw-micro" | ||
|
github-advanced-security[bot] marked this conversation as resolved.
Fixed
|
||
| python -m datagoblin.training_gym.rlt_gym.storyworld_cohort --source GPTStoryworld --per-mode 2 --micro-examples 2 --micro-max-encounters 4 --seed 23 --out "$RUNNER_TEMP/dg-sw-cohort" | ||
| python -m datagoblin.training_gym.rlt_gym.storyworld_cohort --source GPTStoryworld --replay "$RUNNER_TEMP/dg-sw-cohort" | ||
|
Comment on lines
+16
to
+59
|
||
179 changes: 179 additions & 0 deletions
179
src/datagoblin/training_gym/rlt_gym/storyworld_cohort.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,179 @@ | ||
| """STORY-02: pinned, multi-world Storyworld gym with source-world holdout custody. | ||
|
|
||
| Native builder/Mini/HG-02 and SWMD-MICRO streams are collected in separate | ||
| world archives. A held-out world's labels cannot enter train SFT exports. | ||
| """ | ||
| from __future__ import annotations | ||
|
|
||
| import argparse | ||
| import hashlib | ||
| import json | ||
| import re | ||
| from pathlib import Path | ||
|
|
||
| from .storyworld_micro import export_micro, replay_micro | ||
| from .storyworld_native import SPLITS, _json, _sha_file, collect, connect, replay_archive | ||
|
|
||
| SCHEMA = "datagoblin.storyworld_cohort.v1" | ||
| REGISTRY_SCHEMA = "datagoblin.storyworld_cohort.registry.v1" | ||
| DEFAULT_REGISTRY = Path("training/rlt_gym/storyworld_native/world_cohort_v1.json") | ||
|
|
||
|
|
||
| def _registry(path: Path) -> dict: | ||
| contents = json.loads(path.read_text(encoding="utf-8")) | ||
| if contents.get("schema") != REGISTRY_SCHEMA: | ||
| raise ValueError("unsupported Storyworld cohort registry schema") | ||
| worlds = contents.get("worlds", []) | ||
| if not isinstance(worlds, list) or not 2 <= len(worlds) <= 12: | ||
| raise ValueError("world cohort requires 2..12 registered sources") | ||
| names, paths = set(), set() | ||
| splits = [] | ||
| for row in worlds: | ||
| name, world, split = row["id"], row["path"], row["split"] | ||
| parts = Path(world) | ||
| if (not isinstance(name, str) or re.fullmatch(r"[a-z][a-z0-9_]{2,40}", name) is None | ||
| or not isinstance(world, str) or parts.is_absolute() or ".." in parts.parts | ||
| or not world.endswith(".json") or split not in SPLITS): | ||
| raise ValueError("invalid source-world registration") | ||
| if name in names or world in paths: | ||
| raise ValueError("duplicate world name or source path") | ||
| names.add(name) | ||
| paths.add(world) | ||
| splits.append(split) | ||
| if "train" not in splits or not any(s in ("ordinary_test", "ood_test") for s in splits): | ||
| raise ValueError("cohort needs a training world and a held-out test world") | ||
| return contents | ||
|
|
||
|
|
||
| def _world_seed(seed: int, name: str, world_hash: str) -> int: | ||
| digest = hashlib.sha256(_json([SCHEMA, seed, name, world_hash]).encode("utf-8")).digest() | ||
| return int.from_bytes(digest[:8], "big") | ||
|
|
||
|
|
||
| def collect_cohort(source: Path, registry: Path, out: Path, *, seed: int = 23, | ||
| per_mode: int = 3, micro_examples: int = 2, micro_max_encounters: int = 6) -> dict: | ||
| if out.exists(): | ||
| raise FileExistsError("world cohort output exists") | ||
| if per_mode < 1 or micro_examples < 1 or micro_max_encounters < 1: | ||
| raise ValueError("cohort sampling counts must be positive") | ||
| contents = _registry(registry) | ||
| pin = contents["source_commit"] | ||
| if contents.get("source_repository") != "MoralityLabAI/GPTStoryworld" or not re.fullmatch(r"[a-f0-9]{40}", pin): | ||
| raise ValueError("invalid source identity in registry") | ||
| # Validate the entire frozen source set before creating any output. | ||
| prepared = [] | ||
| for row in contents["worlds"]: | ||
| native = connect(source, row["path"], expect_commit=pin) | ||
| prepared.append((row, native)) | ||
| out.mkdir(parents=True) | ||
| records = [] | ||
| totals = {"native_tasks": 0, "native_controls": 0, "micro_tasks": 0, | ||
| "train_sft_rows": 0, "micro_overbudget_rows": 0} | ||
| for row, native in prepared: | ||
| name = row["id"] | ||
| split = row["split"] | ||
| world_seed = _world_seed(seed, name, native.hashes["world"]) | ||
| folder = out / name | ||
| folder.mkdir() | ||
| native_manifest = collect(native, folder / "native", seed=world_seed, | ||
| per_mode=per_mode, split_override=split) | ||
| micro_manifest = export_micro( | ||
| source, folder / "micro", seed=world_seed, | ||
| examples_per_encounter=micro_examples, max_encounters=micro_max_encounters, | ||
| world=row["path"], expect_source_commit=pin, split_override=split, | ||
| ) | ||
| native_count = native_manifest["artifacts"]["public_tasks.jsonl"]["rows"] | ||
| controls_count = native_manifest["artifacts"]["baseline_rollouts.jsonl"]["rows"] | ||
| micro_count = micro_manifest["artifacts"]["micro_public.jsonl"]["rows"] | ||
| train_count = micro_manifest["artifacts"]["micro_train_sft.jsonl"]["rows"] | ||
| overbudget = micro_manifest["artifacts"]["micro_oversize.jsonl"]["rows"] | ||
| if split != "train" and (train_count or native_manifest["artifacts"]["train_targets.jsonl"]["rows"]): | ||
| raise ValueError("held-out world produced supervised train examples") | ||
| totals["native_tasks"] += native_count | ||
| totals["native_controls"] += controls_count | ||
| totals["micro_tasks"] += micro_count | ||
| totals["train_sft_rows"] += train_count | ||
| totals["micro_overbudget_rows"] += overbudget | ||
| records.append({ | ||
| "id": name, "split": split, "domain": row.get("domain", ""), | ||
| "path": row["path"], "world_seed": world_seed, | ||
| "source": native.descriptor(), | ||
| "native_manifest_sha256": _sha_file(folder / "native/manifest.json"), | ||
| "micro_manifest_sha256": _sha_file(folder / "micro/manifest.json"), | ||
| "native_tasks": native_count, "micro_tasks": micro_count, | ||
| "train_sft_rows": train_count, "control_rollouts": controls_count, | ||
| "micro_overbudget_rows": overbudget, | ||
| }) | ||
| summary = { | ||
| "schema": SCHEMA, "evidence": "source_native_multiworld_cpu_controls", | ||
| "trained_model_results": False, "seed": seed, "per_mode": per_mode, | ||
| "micro_examples": micro_examples, "micro_max_encounters": micro_max_encounters, | ||
| "source_commit": pin, "registry_sha256": _sha_file(registry), | ||
| "worlds": records, "totals": totals, | ||
| } | ||
| (out / "manifest.json").write_text(_json(summary) + "\n", encoding="utf-8") | ||
| return summary | ||
|
|
||
|
|
||
| def replay_cohort(source: Path, registry: Path, folder: Path) -> dict: | ||
| registered = _registry(registry) | ||
| manifest = json.loads((folder / "manifest.json").read_text(encoding="utf-8")) | ||
| if (manifest.get("schema") != SCHEMA | ||
| or manifest["registry_sha256"] != _sha_file(registry) | ||
| or manifest["source_commit"] != registered["source_commit"]): | ||
| raise ValueError("cohort registry or source pin mismatch") | ||
| if len(manifest["worlds"]) != len(registered["worlds"]): | ||
| raise ValueError("cohort world inventory mismatch") | ||
| for row, archived in zip(registered["worlds"], manifest["worlds"], strict=True): | ||
| if (row["id"] != archived["id"] or row["path"] != archived["path"] | ||
| or row["split"] != archived["split"]): | ||
| raise ValueError("cohort source identity mismatch") | ||
| native = connect(source, row["path"], expect_commit=manifest["source_commit"]) | ||
| if native.descriptor() != archived["source"]: | ||
| raise ValueError("cohort source file changed") | ||
| base = folder / row["id"] | ||
| if (_sha_file(base / "native/manifest.json") != archived["native_manifest_sha256"] | ||
| or _sha_file(base / "micro/manifest.json") != archived["micro_manifest_sha256"]): | ||
| raise ValueError("cohort child manifest digest mismatch") | ||
| replay_archive(native, base / "native") | ||
| replay_micro(source, base / "micro", world=row["path"], | ||
| expect_source_commit=manifest["source_commit"]) | ||
| # Regenerate the cohort to compare every split, child hash and exact seed. | ||
| # This also detects a tampered summary count or reordered evaluation world. | ||
| import tempfile | ||
|
|
||
| with tempfile.TemporaryDirectory(prefix="dg-sw-cohort-replay-") as tmp: | ||
| fresh = collect_cohort( | ||
| source, registry, Path(tmp) / "new", seed=manifest["seed"], | ||
| per_mode=manifest["per_mode"], micro_examples=manifest["micro_examples"], | ||
| micro_max_encounters=manifest["micro_max_encounters"], | ||
| ) | ||
| if fresh != manifest: | ||
| raise ValueError("regenerated cohort manifest mismatch") | ||
| return {"status": "verified", "worlds": len(manifest["worlds"]), "totals": manifest["totals"]} | ||
|
|
||
|
|
||
| def main(argv: list[str] | None = None) -> int: | ||
| parser = argparse.ArgumentParser(description=__doc__) | ||
| parser.add_argument("--source", type=Path, default=Path("../GPTStoryworld")) | ||
| parser.add_argument("--registry", type=Path, default=DEFAULT_REGISTRY) | ||
| parser.add_argument("--seed", type=int, default=23) | ||
| parser.add_argument("--per-mode", type=int, default=3) | ||
| parser.add_argument("--micro-examples", type=int, default=2) | ||
| parser.add_argument("--micro-max-encounters", type=int, default=6) | ||
| action = parser.add_mutually_exclusive_group(required=True) | ||
| action.add_argument("--out", type=Path) | ||
| action.add_argument("--replay", type=Path) | ||
| args = parser.parse_args(argv) | ||
| if args.out: | ||
| result = collect_cohort(args.source, args.registry, args.out, seed=args.seed, | ||
| per_mode=args.per_mode, micro_examples=args.micro_examples, | ||
| micro_max_encounters=args.micro_max_encounters) | ||
| else: | ||
| result = replay_cohort(args.source, args.registry, args.replay) | ||
| print(json.dumps(result, indent=2, sort_keys=True)) | ||
| return 0 | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| raise SystemExit(main()) |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.