9112e845e0
CI / Lint (ruff check) (push) Successful in 27s
CI / Format (ruff format) (push) Successful in 28s
CI / Sync project version with tag (push) Has been skipped
CI / Type check (ty) (push) Successful in 23s
CI / Tests (push) Successful in 1m1s
CI / Lint (ruff check) (pull_request) Successful in 26s
CI / Format (ruff format) (pull_request) Successful in 27s
CI / Sync project version with tag (pull_request) Has been skipped
CI / Type check (ty) (pull_request) Successful in 27s
CI / Tests (pull_request) Successful in 1m2s
Replaces train.py's single global training loop with a StageTrainer hierarchy (FlowDDPMStageTrainer, WGANStageTrainer) — one per active stage, each owning its own optimizer/LR schedule/EMA and reading only the shared batch tuple (stage 2 always teacher-forces on the ground-truth x1_s1, so stages never need each other's output at train time). Supports every stage1/stage2 generator combination, including the design doc's headline mixed case (stage1=flow + stage2=wgan) and its reverse, plus stage1-only/stage2-only ablation runs, routed+gumbel stages, and checkpoint save/resume. metrics.csv/wandb logging are stage-prefixed. validate_marginals calls are guarded with a one-time warning and a Wasserstein-magnitude fallback for wgan best-checkpoint selection, since giant/sample.py still assumes stage1 always owns n_sec_head (decision 1 moved it to stage 2 by default) — deferred to design doc step 6, not silently papered over. pipeline.py's run_setup_stage/run_train_job now read the new nested config directly; the dangling resolve_expert_dims call and the --mode wgan --router rejection are both gone (routed WGAN works). cli.py's train/new-run build correctly-shaped config overrides (architecture flags -> stage1_model only per the approved decision; --mode/--n-critic/--gp-weight/--critic-lr broadcast to both stages, matching migrate_config's own precedent and avoiding a regression on the common --mode case); predict/rollout's dangling build_models tuple-unpack is fixed; new-run now tags config_version, fixing a bug where a re-loaded v0.3 config.toml would have been silently corrupted by migrate_config mistaking it for v0.2. config.py's validate_config rejects mixed particle/material conditioning types for now (ConditionEncoder supports it, the data pipeline in giant/data/transforms.py doesn't yet). analysis/render.py and router_gating.py handle both the new nested model_config shape and legacy flat checkpoints. scripts/warm_setup_cache.py updated for run_setup_stage's new signature. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
120 lines
3.6 KiB
Python
120 lines
3.6 KiB
Python
"""Tests for `giant new-run` (config.toml + run-dir scaffolding)."""
|
|
|
|
from __future__ import annotations
|
|
|
|
import tomllib
|
|
from pathlib import Path
|
|
|
|
from typer.testing import CliRunner
|
|
|
|
from giant.cli import app
|
|
|
|
runner = CliRunner()
|
|
|
|
|
|
def test_writes_config_with_overrides_applied(tmp_path: Path):
|
|
out_dir = tmp_path / "run1"
|
|
result = runner.invoke(
|
|
app,
|
|
[
|
|
"new-run",
|
|
"--out",
|
|
str(out_dir),
|
|
"--mode",
|
|
"ddpm",
|
|
"--hidden-dim",
|
|
"128",
|
|
"--n-blocks",
|
|
"4",
|
|
"--lr",
|
|
"0.0005",
|
|
],
|
|
)
|
|
assert result.exit_code == 0, result.output
|
|
|
|
config_path = out_dir / "config.toml"
|
|
assert config_path.exists()
|
|
with open(config_path, "rb") as f:
|
|
cfg = tomllib.load(f)
|
|
|
|
assert cfg["stage1_model"]["generator"] == "ddpm"
|
|
assert cfg["stage2_model"]["generator"] == "ddpm"
|
|
assert cfg["train"]["lr"] == 0.0005
|
|
assert cfg["stage1_model"]["hidden_dim"] == 128
|
|
assert cfg["stage1_model"]["n_res_blocks"] == 4
|
|
# untouched defaults still present
|
|
assert cfg["train"]["epochs"] == 100
|
|
assert "router" in cfg["stage1_model"]
|
|
|
|
assert str(out_dir) in result.output
|
|
assert "<data.parquet>" in result.output
|
|
assert "giant train" in result.output
|
|
|
|
|
|
def test_comment_and_provenance_recorded_in_meta(tmp_path: Path):
|
|
out_dir = tmp_path / "run2"
|
|
result = runner.invoke(
|
|
app,
|
|
["new-run", "--out", str(out_dir), "--comment", "quick test"],
|
|
)
|
|
assert result.exit_code == 0, result.output
|
|
|
|
with open(out_dir / "config.toml", "rb") as f:
|
|
cfg = tomllib.load(f)
|
|
|
|
assert cfg["meta"]["comment"] == "quick test"
|
|
assert cfg["meta"]["created_by"] == "giant new-run"
|
|
assert "created_at" in cfg["meta"]
|
|
assert "git_hash" in cfg["meta"]
|
|
|
|
|
|
def test_data_flag_fills_printed_next_step_commands(tmp_path: Path):
|
|
out_dir = tmp_path / "run3"
|
|
result = runner.invoke(
|
|
app,
|
|
["new-run", "--out", str(out_dir), "--data", "/ceph/lbogner/train.parquet"],
|
|
)
|
|
assert result.exit_code == 0, result.output
|
|
assert "/ceph/lbogner/train.parquet" in result.output
|
|
assert "<data.parquet>" not in result.output
|
|
|
|
|
|
def test_dry_run_writes_nothing(tmp_path: Path):
|
|
out_dir = tmp_path / "run4"
|
|
result = runner.invoke(
|
|
app,
|
|
["new-run", "--out", str(out_dir), "--hidden-dim", "512", "--dry-run"],
|
|
)
|
|
assert result.exit_code == 0, result.output
|
|
assert "dry-run" in result.output
|
|
assert "hidden_dim = 512" in result.output
|
|
assert not out_dir.exists()
|
|
|
|
|
|
def test_force_guard_refuses_to_clobber_existing_checkpoints(tmp_path: Path):
|
|
out_dir = tmp_path / "run5"
|
|
out_dir.mkdir()
|
|
(out_dir / "last.pt").touch()
|
|
|
|
result = runner.invoke(app, ["new-run", "--out", str(out_dir), "--mode", "ddpm"])
|
|
assert result.exit_code != 0
|
|
assert "already has last.pt" in result.output
|
|
assert not (out_dir / "config.toml").exists()
|
|
|
|
result = runner.invoke(
|
|
app, ["new-run", "--out", str(out_dir), "--mode", "ddpm", "--force"]
|
|
)
|
|
assert result.exit_code == 0, result.output
|
|
assert (out_dir / "config.toml").exists()
|
|
|
|
|
|
def test_default_out_dir_used_when_out_omitted(tmp_path: Path, monkeypatch):
|
|
monkeypatch.chdir(tmp_path)
|
|
result = runner.invoke(app, ["new-run", "--hidden-dim", "64"])
|
|
assert result.exit_code == 0, result.output
|
|
|
|
checkpoints_dir = tmp_path / "checkpoints"
|
|
run_dirs = list(checkpoints_dir.iterdir()) if checkpoints_dir.exists() else []
|
|
assert len(run_dirs) == 1
|
|
assert (run_dirs[0] / "config.toml").exists()
|