Skip to content

Commit 15bfad1

Browse files
Chamberlain0w0kilinchange
authored andcommitted
fix: remove redundant and duplicate codes
1 parent 92ca5d3 commit 15bfad1

3 files changed

Lines changed: 20 additions & 70 deletions

File tree

scripts/compare_loss.py

Lines changed: 3 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -9,24 +9,7 @@
99
import sys
1010
from pathlib import Path
1111
from argparse import ArgumentParser
12-
13-
14-
def collect_log_files(base_dir):
15-
"""Collect comparable training logs keyed by basename."""
16-
files = {}
17-
duplicates = {}
18-
19-
for path in base_dir.rglob('*.log'):
20-
if path.name.startswith('build') or path.name.endswith('_profile.log'):
21-
continue
22-
23-
key = path.name
24-
if key in files:
25-
duplicates.setdefault(key, [files[key]]).append(path)
26-
continue
27-
files[key] = path
28-
29-
return files, duplicates
12+
from compare_utils import collect_log_files, exit_if_duplicate_logs
3013

3114
def get_dtype_from_filename(filename):
3215
"""Determine dtype from filename. Returns 'bfloat16' or 'fp32'."""
@@ -82,18 +65,8 @@ def main():
8265

8366
files1, duplicates1 = collect_log_files(args.dir1)
8467
files2, duplicates2 = collect_log_files(args.dir2)
85-
86-
if duplicates1:
87-
print(f"Found duplicate log basenames in {args.dir1.resolve()}, cannot compare safely:")
88-
for name, paths in sorted(duplicates1.items()):
89-
print(f" {name}: {', '.join(str(p.relative_to(args.dir1)) for p in paths)}")
90-
sys.exit(1)
91-
92-
if duplicates2:
93-
print(f"Found duplicate log basenames in {args.dir2.resolve()}, cannot compare safely:")
94-
for name, paths in sorted(duplicates2.items()):
95-
print(f" {name}: {', '.join(str(p.relative_to(args.dir2)) for p in paths)}")
96-
sys.exit(1)
68+
exit_if_duplicate_logs(args.dir1, duplicates1)
69+
exit_if_duplicate_logs(args.dir2, duplicates2)
9770

9871
only_in_1 = set(files1.keys()) - set(files2.keys())
9972
only_in_2 = set(files2.keys()) - set(files1.keys())

scripts/compare_tps.py

Lines changed: 3 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -9,24 +9,7 @@
99
import sys
1010
from pathlib import Path
1111
from argparse import ArgumentParser
12-
13-
14-
def collect_log_files(base_dir):
15-
"""Collect comparable training logs keyed by basename."""
16-
files = {}
17-
duplicates = {}
18-
19-
for path in base_dir.rglob('*.log'):
20-
if path.name.startswith('build') or path.name.endswith('_profile.log'):
21-
continue
22-
23-
key = path.name
24-
if key in files:
25-
duplicates.setdefault(key, [files[key]]).append(path)
26-
continue
27-
files[key] = path
28-
29-
return files, duplicates
12+
from compare_utils import collect_log_files, exit_if_duplicate_logs
3013

3114
def parse_log(file_path):
3215
"""Extract step -> tok/s mapping from log file."""
@@ -75,18 +58,8 @@ def main():
7558

7659
files1, duplicates1 = collect_log_files(args.dir1)
7760
files2, duplicates2 = collect_log_files(args.dir2)
78-
79-
if duplicates1:
80-
print(f"Found duplicate log basenames in {args.dir1.resolve()}, cannot compare safely:")
81-
for name, paths in sorted(duplicates1.items()):
82-
print(f" {name}: {', '.join(str(p.relative_to(args.dir1)) for p in paths)}")
83-
sys.exit(1)
84-
85-
if duplicates2:
86-
print(f"Found duplicate log basenames in {args.dir2.resolve()}, cannot compare safely:")
87-
for name, paths in sorted(duplicates2.items()):
88-
print(f" {name}: {', '.join(str(p.relative_to(args.dir2)) for p in paths)}")
89-
sys.exit(1)
61+
exit_if_duplicate_logs(args.dir1, duplicates1)
62+
exit_if_duplicate_logs(args.dir2, duplicates2)
9063

9164
only_in_1 = set(files1.keys()) - set(files2.keys())
9265
only_in_2 = set(files2.keys()) - set(files1.keys())

scripts/run_models_and_profile.bash

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,29 @@ set -o pipefail
55

66
usage() {
77
cat <<'EOF'
8-
Usage: run_models_and_profile.bash [config_file] [--only-run tag1,tag2]
8+
Usage: run_models_and_profile.bash [--test-config path] [--only-run tag1,tag2]
99
1010
Options:
11+
--test-config PATH Path to test config JSON. Default: test_config.json.
1112
--only-run TAGS Only run the specified tag groups, separated by commas.
1213
-h, --help Show this help message.
1314
EOF
1415
}
1516

1617
CONFIG_FILE="test_config.json"
1718
ONLY_RUN_TAGS=""
18-
CONFIG_FILE_SET="no"
1919

2020
while [[ $# -gt 0 ]]; do
2121
case "$1" in
22+
--test-config)
23+
[[ $# -lt 2 ]] && { echo "Error: --test-config requires a file path."; exit 1; }
24+
CONFIG_FILE="$2"
25+
shift 2
26+
;;
27+
--test-config=*)
28+
CONFIG_FILE="${1#*=}"
29+
shift
30+
;;
2231
--only-run)
2332
[[ $# -lt 2 ]] && { echo "Error: --only-run requires a comma-separated tag list."; exit 1; }
2433
ONLY_RUN_TAGS="$2"
@@ -38,14 +47,9 @@ while [[ $# -gt 0 ]]; do
3847
exit 1
3948
;;
4049
*)
41-
if [[ "$CONFIG_FILE_SET" == "yes" ]]; then
42-
echo "Error: Multiple config files provided."
43-
usage
44-
exit 1
45-
fi
46-
CONFIG_FILE="$1"
47-
CONFIG_FILE_SET="yes"
48-
shift
50+
echo "Error: Unknown positional argument: $1"
51+
usage
52+
exit 1
4953
;;
5054
esac
5155
done

0 commit comments

Comments
 (0)