okami.mom/strata

git clone https://git.nkp.pet/okami.mom/strata

Niko1221Merge branch 'f-1402-w' into f-140253623e56f

main
2.5 KiB59 linesraw
1#!/usr/bin/env python3
2"""Assemble data/engine.log from the engine log slices this report collected.
3
4The raw slices are one long block per server start (about 500 lines each, one
5per configuration and per interleaved request), which is too much for a PR.
6This keeps what the report is about from every slice:
7
8  * the lines about the layer split, the PCIe probes, the expert caches,
9    the resident stage, --batch and --pipeline-windows,
10  * every completion line (`prompt N tokens = ...`) - the numbers in README,
11  * the lines that say a feature was turned off or adjusted.
12
13and prefixes each section with the slice's name and how many lines it had.
14
15Usage: make_engine_log.py [--data DIR]
16"""
17import argparse
18import re
19from pathlib import Path
20
21DATA = Path(__file__).resolve().parent.parent / 'data'
22
23KEEP = re.compile(
24    r'layer split|PCIe probe|pipeline-windows|--batch|resident|'
25    r'expert cache|token graph|room for experts|prompt \d+ tokens =|'
26    r'loads the dense weights|engine started|off:|WARNING|'
27    r'session is up|KV streaming|GPU \d+:|decode expert cache hit|'
28    r'strata mtp|strata batch|batch window|batch windows|no progress|\bnan\b', re.I)
29
30ORDER = ['engine-interleave.log', 'engine-ab-pipeline-off.log',
31         'engine-ab-stage-trim-off.log', 'engine-ab-resident.log',
32         'soak-engine.log', 'engine-ab-batch2.log', 'engine-ab-batch4.log',
33         'batch-concurrent-batch2.engine.log',
34         'batch-concurrent-batch4.engine.log']
35
36
37def main():
38    p = argparse.ArgumentParser(description=__doc__)
39    p.add_argument('--data', type=Path, default=DATA)
40    p.add_argument('--out', type=Path, default=None)
41    args = p.parse_args()
42    out = args.out or (args.data / 'engine.log')
43    parts = ['= engine.log: the lines of each slice this report kept =\n',
44             'built by scripts/make_engine_log.py; the raw slices sit beside it\n']
45    names = [n for n in ORDER if (args.data / n).exists()]
46    names += sorted(n.name for n in args.data.glob('engine-*.log')
47                    if n.name not in names and n.name != 'engine.log')
48    for name in names:
49        text = (args.data / name).read_text(encoding='utf-8', errors='replace')
50        lines = text.splitlines()
51        kept = [ln for ln in lines if KEEP.search(ln)]
52        parts.append(f'\n=== {name}: {len(lines)} lines, {len(kept)} kept ===\n')
53        parts.extend(ln + '\n' for ln in kept)
54    out.write_text(''.join(parts), encoding='utf-8')
55    print(f'{out}: {out.stat().st_size} bytes from {len(names)} slice(s)')
56
57
58if __name__ == '__main__':
59    main()