Skip to content

Commit b83c5c8

Browse files
committed
Summarize training steps across all buckets
1 parent 38b6d15 commit b83c5c8

2 files changed

Lines changed: 98 additions & 2 deletions

File tree

scripts/report_training_steps.py

Lines changed: 60 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,58 @@ def _format_int(value: int) -> str:
217217
return f"{value:,}"
218218

219219

220+
def _format_short_tokens(value: int) -> str:
221+
if value >= 1_000_000_000:
222+
return f"{value / 1_000_000_000:.3f}B"
223+
if value >= 1_000_000:
224+
return f"{value / 1_000_000:.1f}M"
225+
return _format_int(value)
226+
227+
228+
def _rows_by_length_and_kind(rows: Iterable[ReportRow]) -> dict[int, dict[str, ReportRow]]:
229+
result: dict[int, dict[str, ReportRow]] = {}
230+
for row in rows:
231+
result.setdefault(row.length, {})[row.kind] = row
232+
return result
233+
234+
235+
def _print_summary(rows: Iterable[ReportRow]) -> None:
236+
"""Print one unambiguous curriculum row per context length."""
237+
print(
238+
"| length | bs | tokens/step | code tokens | code steps | commit+PR-doc tokens | commit steps | main tokens | main steps | standalone PR tokens | +PR total steps | skipped files |"
239+
)
240+
print("|---:|---:|---:|---:|---:|---:|---:|---:|---:|---:|---:|---:|")
241+
for length, by_kind in sorted(_rows_by_length_and_kind(rows).items()):
242+
main = by_kind.get("main_code_plus_commits")
243+
if main is None:
244+
continue
245+
code = by_kind.get("code_only")
246+
commits = by_kind.get("commits_with_pr_docstring")
247+
pr = by_kind.get("standalone_pr_side_stream")
248+
main_pr = by_kind.get("main_plus_standalone_pr")
249+
skipped = sum(row.skipped_files for row in by_kind.values())
250+
print(
251+
"| "
252+
+ " | ".join(
253+
[
254+
str(length),
255+
str(main.batch_size),
256+
_format_int(main.tokens_per_step),
257+
_format_short_tokens(code.trained_tokens) if code else "-",
258+
_format_int(code.steps_by_trained_tokens) if code else "-",
259+
_format_short_tokens(commits.trained_tokens) if commits else "-",
260+
_format_int(commits.steps_by_trained_tokens) if commits else "-",
261+
_format_short_tokens(main.trained_tokens),
262+
_format_int(main.steps_by_trained_tokens),
263+
_format_short_tokens(pr.trained_tokens) if pr else "-",
264+
_format_int(main_pr.steps_by_trained_tokens) if main_pr else "-",
265+
_format_int(skipped),
266+
]
267+
)
268+
+ " |"
269+
)
270+
271+
220272
def _print_markdown(rows: Iterable[ReportRow]) -> None:
221273
print(
222274
"| kind | length | bs | tokens/step | files | skipped | rows | docs | trained tokens | steps(trained) | valid tokens | steps(valid) |"
@@ -272,7 +324,12 @@ def main() -> int:
272324
action="store_true",
273325
help="Skip files that disappear or are unreadable during live conveyor writes, and report the skip count.",
274326
)
275-
parser.add_argument("--format", choices=("text", "markdown", "json"), default="text")
327+
parser.add_argument(
328+
"--format",
329+
choices=("summary", "text", "markdown", "json"),
330+
default="summary",
331+
help="summary prints one row per bucket; text/markdown print every source kind.",
332+
)
276333
args = parser.parse_args()
277334

278335
rows = build_report(
@@ -285,6 +342,8 @@ def main() -> int:
285342
)
286343
if args.format == "json":
287344
print(json.dumps([asdict(row) for row in rows], indent=2, sort_keys=True))
345+
elif args.format == "summary":
346+
_print_summary(rows)
288347
elif args.format == "markdown":
289348
_print_markdown(rows)
290349
else:

tests/test_report_training_steps.py

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import pyarrow as pa
66
import pyarrow.parquet as pq
77

8-
from scripts.report_training_steps import build_report, parse_batch_schedule
8+
from scripts.report_training_steps import build_report, parse_batch_schedule, _print_summary
99

1010

1111
def _write_counter_parquet(path: Path, rows: list[dict[str, int]]) -> None:
@@ -65,6 +65,43 @@ def test_report_keeps_code_commits_main_and_pr_stream_distinct(tmp_path: Path) -
6565
assert by_kind["main_plus_standalone_pr"].steps_by_trained_tokens == 1
6666

6767

68+
def test_summary_reports_every_length_once(tmp_path: Path, capsys) -> None:
69+
code = tmp_path / "code"
70+
commits = tmp_path / "commits"
71+
pr = tmp_path / "pr"
72+
_write_counter_parquet(
73+
code / "1024" / "code.parquet",
74+
[{"valid": 4096, "trained": 4096, "docs": 1}],
75+
)
76+
_write_counter_parquet(
77+
commits / "2048" / "commits.parquet",
78+
[{"valid": 8192, "trained": 8192, "docs": 1}],
79+
)
80+
_write_counter_parquet(
81+
pr / "2048" / "pr.parquet",
82+
[{"valid": 4096, "trained": 4096, "docs": 1}],
83+
)
84+
85+
rows = build_report(
86+
code_root=code,
87+
commit_root=commits,
88+
pr_root=pr,
89+
batch_by_length={1024: 2, 2048: 2},
90+
max_workers=1,
91+
allow_concurrent_skips=False,
92+
)
93+
94+
_print_summary(rows)
95+
out = capsys.readouterr().out
96+
97+
assert "| 1024 | 2 | 2,048 |" in out
98+
assert "| 2048 | 2 | 4,096 |" in out
99+
assert out.count("| 1024 |") == 1
100+
assert out.count("| 2048 |") == 1
101+
assert "main tokens" in out
102+
assert "standalone PR tokens" in out
103+
104+
68105
def test_parse_batch_schedule_rejects_bad_items() -> None:
69106
assert parse_batch_schedule("1024=192,2048=96") == {1024: 192, 2048: 96}
70107

0 commit comments

Comments
 (0)