Skip to content

Commit bf0d01b

Browse files
committed
refactor workflow
1 parent 1f1a036 commit bf0d01b

File tree

8 files changed

+93
-33
lines changed

8 files changed

+93
-33
lines changed

.ci/benchmark.py

Lines changed: 55 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,64 @@
1+
import argparse
12
import os
23
import sys
34
from src.benchmark.utils import read_metrics, to_markdown_table
45

5-
if __name__ == "__main__":
6-
# Generate statistics report
7-
statistics_path = sys.argv[1]
8-
metrics = read_metrics(statistics_path, metric="accuracy")
6+
7+
def parse_args():
8+
parser = argparse.ArgumentParser()
9+
parser.add_argument("--path", type=str, required=True, help="Report path.")
10+
parser.add_argument("--write-gh-job-summary", action="store_true", help="Write to GitHub job summary.")
11+
parser.add_argument("--update-readme", action="store_true", help="Update statistics report in README.md.")
12+
return parser.parse_args()
13+
14+
15+
def generate_report(path: str):
16+
metrics = read_metrics(path, metric="accuracy")
917
html_table = to_markdown_table(metrics)
18+
return html_table
1019

11-
# Write to workflow job summary
20+
21+
def write_job_summary(report):
1222
summary_path = os.environ["GITHUB_STEP_SUMMARY"]
1323
with open(summary_path, "a") as f:
1424
f.write("## Torchbenchmark statistics report\n")
15-
f.write(html_table)
25+
f.write(report)
26+
27+
28+
def update_readme(report):
29+
project_path = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
30+
readme_path = os.path.join(project_path, "README.md")
31+
print(readme_path)
32+
with open(readme_path, "r") as f:
33+
readme_content = f.read()
34+
35+
start_marker = "<!-- Torchbenchmark start -->"
36+
end_marker = "<!-- Torchbenchmark end -->"
37+
start_index = readme_content.find(start_marker)
38+
end_index = readme_content.find(end_marker)
39+
assert start_index != -1
40+
assert end_index != -1
41+
42+
start_index += len(start_marker)
43+
new_readme_content = (
44+
readme_content[:start_index] + "\n\n" +
45+
report + "\n\n" +
46+
readme_content[end_index:]
47+
)
48+
with open(readme_path, "w") as f:
49+
f.write(new_readme_content)
50+
51+
52+
if __name__ == "__main__":
53+
args = parse_args()
54+
55+
# Generate statistics report
56+
report = generate_report(args.path)
57+
58+
# Write to workflow job summary
59+
if args.write_gh_job_summary:
60+
write_job_summary(report)
61+
62+
# Update README.md
63+
if args.update_readme:
64+
update_readme(report)

.github/workflows/_ascend_npu_benchmark.yml renamed to .github/workflows/ascend_npu/_ascend_npu_benchmark.yml

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -132,17 +132,23 @@ jobs:
132132
- name: Write to workflow job summary
133133
id: report
134134
run: |
135-
set -x
136-
realpath benchmark/ascend_npu_benchmark.json
137-
ls benchmark
138-
cat benchmark/ascend_npu_benchmark.json
135+
python .ci/benchmark.py --write-gh-job-summary \
136+
--path benchmark/ascend_npu_benchmark.json
139137
140-
output_path=$(realpath benchmark/ascend_npu_benchmark.json)
141-
python .ci/benchmark.py ${output_path}
142-
143-
# TODO(shink)
144138
- name: Update README.md
145-
if: ${{ github.event_name == 'push' }}
139+
if: ${{ github.event_name == 'push' && github.event_name == 'schedule' }}
146140
run: |
147-
echo "${{ github.event_name }}"
148-
echo "${{ github.event_name == 'push' }}"
141+
python .ci/benchmark.py --update-readme \
142+
--path benchmark/ascend_npu_benchmark.json
143+
144+
- name: Update README.md
145+
if: ${{ github.event_name == 'push' || github.event_name == 'schedule' || github.event_name == 'workflow_dispatch' }}
146+
uses: peter-evans/create-pull-request@v7
147+
with:
148+
add-paths: README.md
149+
branch: ascend-npu/benchmark
150+
title: "[Ascend NPU] Update torchbenchmark report in README.md"
151+
commit-message: "Update README.md"
152+
reviewers: |
153+
shink
154+
FFFrog

.github/workflows/ascend_npu_test.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ jobs:
7777
name: Build torch_npu
7878
needs:
7979
- prepare
80-
uses: ./.github/workflows/_ascend_npu_build.yml
80+
uses: ./.github/workflows/ascend_npu/_ascend_npu_build.yml
8181
with:
8282
runner: ${{ needs.prepare.outputs.runner }}
8383
image: ${{ needs.prepare.outputs.image }}
@@ -87,7 +87,7 @@ jobs:
8787
needs:
8888
- prepare
8989
- build
90-
uses: ./.github/workflows/_ascend_npu_test.yml
90+
uses: ./.github/workflows/ascend_npu/_ascend_npu_test.yml
9191
with:
9292
runner: ${{ needs.prepare.outputs.runner }}
9393
image: ${{ needs.prepare.outputs.image }}
@@ -100,7 +100,7 @@ jobs:
100100
- prepare
101101
- build
102102
- test
103-
uses: ./.github/workflows/_ascend_npu_benchmark.yml
103+
uses: ./.github/workflows/ascend_npu/_ascend_npu_benchmark.yml
104104
with:
105105
runner: ${{ needs.prepare.outputs.runner }}
106106
image: ${{ needs.prepare.outputs.image }}

README.md

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,11 @@ across various devices by running comprehensive GitHub workflows.
77

88
## Accelerator Integration Test Results
99

10-
<!-- Start -->
10+
<details>
11+
12+
<summary>Torchbenchmark statistics report</summary>
13+
14+
<!-- Torchbenchmark start -->
1115

1216
| | [torch_npu][1] |
1317
|---------------------------------|----------------|
@@ -121,7 +125,9 @@ across various devices by running comprehensive GitHub workflows.
121125

122126
[3]: https://github.com/cosdt/pytorch-integration-tests/actions/workflows/ascend_npu_test.yml
123127

124-
<!-- End -->
128+
<!-- Torchbenchmark end -->
129+
130+
</details>
125131

126132
## Overview
127133

ascend_npu/matadata.yml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
device: "npu"
2+
backend_extension: "torch_npu"
3+
link: https://github.com/Ascend/pytorch
4+
torchbenchmark:
5+
test:
6+
- train
7+
- eval
8+
models:
9+
skip:
10+
- llava

ascend_npu/metadata.json

Lines changed: 0 additions & 11 deletions
This file was deleted.

0 commit comments

Comments
 (0)