import json import torch import yaml from hades.config import ModelConfig from hades.evals.run_eval import main from hades.model.model import HadesLM from hades.train.checkpoint import save_checkpoint def test_end_to_end_report(tmp_path, trained_small): tok_path = tmp_path / "tok.json" trained_small.save(tok_path) model_cfg = dict(d_model=32, n_layers=1, n_heads=2, ffn_hidden=64, context_len=1024, vocab_size=trained_small.vocab_size) cfg_path = tmp_path / "cfg.yaml" cfg_path.write_text(yaml.safe_dump({"name": "t", "model": model_cfg, "train": { "peak_lr": 1e-3, "total_steps": 1, "micro_batch_size": 1, "grad_accum": 1, "precision": "fp32", "data_dir": str(tmp_path / "no-data"), "mix": {"logs": 1.0}}})) torch.manual_seed(0) save_checkpoint(tmp_path / "m.pt", HadesLM(ModelConfig(**model_cfg)), None, None, 0, {}) reports = tmp_path / "reports" main(["--ckpt", str(tmp_path / "m.pt"), "--config", str(cfg_path), "--name", "smoke", "--skip-loghub", "--n", "14", "--n-train", "70", "--tokenizer", str(tok_path), "--runs-dir", str(tmp_path / "runs"), "--reports-dir", str(reports), "--max-new-tokens", "4"]) results = json.loads((tmp_path / "runs" / "smoke" / "results.json").read_text()) assert set(results["classification"]) == {"hades", "majority", "rules", "tfidf"} for model_results in results["classification"].values(): assert set(model_results) == {"synthetic_in", "synthetic_heldout"} assert 0.0 <= model_results["synthetic_in"]["macro_f1"] <= 1.0 assert results["classification"]["hades"]["synthetic_in"]["ece"] is not None report = next(reports.glob("001-smoke.md")).read_text() assert report.splitlines()[0].startswith("# Experiment 001") assert "macro-F1" in report and "Tokenizer SHA-256" in report assert (tmp_path / "runs" / "smoke" / "samples.md").exists() main(["--ckpt", str(tmp_path / "m.pt"), "--config", str(cfg_path), "--name", "again", "--skip-loghub", "--n", "7", "--n-train", "70", "--tokenizer", str(tok_path), "--runs-dir", str(tmp_path / "runs"), "--reports-dir", str(reports), "--max-new-tokens", "2"]) assert (reports / "002-again.md").exists() def test_short_context_model_gets_fitting_windows(tmp_path, trained_small): tok_path = tmp_path / "tok.json" trained_small.save(tok_path) model_cfg = dict(d_model=32, n_layers=1, n_heads=2, ffn_hidden=64, context_len=256, vocab_size=trained_small.vocab_size) cfg_path = tmp_path / "cfg.yaml" cfg_path.write_text(yaml.safe_dump({"name": "t", "model": model_cfg, "train": { "peak_lr": 1e-3, "total_steps": 1, "micro_batch_size": 1, "grad_accum": 1, "precision": "fp32", "data_dir": str(tmp_path / "no-data"), "mix": {"logs": 1.0}}})) torch.manual_seed(0) save_checkpoint(tmp_path / "m.pt", HadesLM(ModelConfig(**model_cfg)), None, None, 0, {}) main(["--ckpt", str(tmp_path / "m.pt"), "--config", str(cfg_path), "--name", "short", "--skip-loghub", "--n", "14", "--n-train", "70", "--tokenizer", str(tok_path), "--runs-dir", str(tmp_path / "runs"), "--reports-dir", str(tmp_path / "reports"), "--max-new-tokens", "2"]) results = json.loads((tmp_path / "runs" / "short" / "results.json").read_text()) assert results["window_token_cap"] == 256 - 24 assert "max_tokens" in results["classification_skipped"] assert results["classification"] == {} report = (tmp_path / "reports" / "001-short.md").read_text().lower() assert "window token cap" in report and "classification skipped" in report assert (tmp_path / "runs" / "short" / "samples.md").exists()