pytorch
85 строк · 2.4 Кб
1import argparse2import os3import sys4import textwrap5
6import pandas as pd7
8
9def get_field(csv, model_name: str, field: str):10try:11return csv.loc[csv["name"] == model_name][field].item()12except Exception as e:13return None14
15
16def check_graph_breaks(actual_csv, expected_csv, expected_filename):17failed = []18improved = []19
20for model in actual_csv["name"]:21graph_breaks = get_field(actual_csv, model, "graph_breaks")22expected_graph_breaks = get_field(expected_csv, model, "graph_breaks")23
24if graph_breaks == expected_graph_breaks:25status = "PASS"26print(f"{model:34} {status}")27continue28
29elif graph_breaks > expected_graph_breaks:30status = "FAIL:"31failed.append(model)32elif graph_breaks < expected_graph_breaks:33status = "IMPROVED:"34improved.append(model)35print(36f"{model:34} {status:9} graph_breaks={graph_breaks}, expected={expected_graph_breaks}"37)38
39msg = ""40if failed or improved:41if failed:42msg += textwrap.dedent(43f"""44Error: {len(failed)} models have new dynamo graph breaks:45{' '.join(failed)}46
47"""
48)49if improved:50msg += textwrap.dedent(51f"""52Improvement: {len(improved)} models have fixed dynamo graph breaks:53{' '.join(improved)}54
55"""
56)57sha = os.getenv("SHA1", "{your CI commit sha}")58msg += textwrap.dedent(59f"""60If this change is expected, you can update `{expected_filename}` to reflect the new baseline.61from pytorch/pytorch root, run
62`python benchmarks/dynamo/ci_expected_accuracy/update_expected.py {sha}`63and then `git add` the resulting local changes to expected CSVs to your commit.
64"""
65)66return failed or improved, msg67
68
69def main():70parser = argparse.ArgumentParser()71parser.add_argument("--actual", type=str, required=True)72parser.add_argument("--expected", type=str, required=True)73args = parser.parse_args()74
75actual = pd.read_csv(args.actual)76expected = pd.read_csv(args.expected)77
78failed, msg = check_graph_breaks(actual, expected, args.expected)79if failed:80print(msg)81sys.exit(1)82
83
84if __name__ == "__main__":85main()86