-
Notifications
You must be signed in to change notification settings - Fork 2
194 lines (168 loc) · 5.83 KB
/
Copy pathbenchmark.yml
File metadata and controls
194 lines (168 loc) · 5.83 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
name: Benchmark
on:
pull_request:
workflow_dispatch:
inputs:
base_ref:
description: "Base git ref to benchmark (default: PR base / main)"
required: false
default: "main"
head_ref:
description: "Head git ref to benchmark (default: PR head / main)"
required: false
default: "main"
permissions:
contents: read
concurrency:
group: benchmark-${{ github.event.pull_request.number || github.run_id }}
cancel-in-progress: true
# Resolve base/head refs once; used by both benchmark jobs.
# For PRs: uses the PR base and head SHAs for exact reproducibility.
# For workflow_dispatch: uses the input values or falls back to main.
env:
BASE_REF: ${{ github.event.pull_request.base.sha || github.event.inputs.base_ref || 'main' }}
HEAD_REF: ${{ github.event.pull_request.head.sha || github.event.inputs.head_ref || 'main' }}
jobs:
# --------------------------------------------------------------------------
# Job 1: benchmark the base commit (main / PR target branch)
# --------------------------------------------------------------------------
benchmark-base:
name: Benchmark base (${{ github.event.pull_request.base.label || 'main' }})
runs-on: ubuntu-latest
permissions:
contents: read
steps:
- uses: actions/checkout@v7
with:
ref: ${{ env.BASE_REF }}
fetch-depth: 0
- name: Setup Python
uses: actions/setup-python@v7
with:
python-version: "3.12"
- name: Cache pip
uses: actions/cache@v6
with:
path: ~/.cache/pip
key: pip-bench-${{ hashFiles('pyproject.toml') }}
restore-keys: pip-bench-
- name: Install PyTorch CPU
run: pip install torch --index-url https://download.pytorch.org/whl/cpu
- name: Install dependencies
run: |
pip install -r requirements/ci/requirements.txt
pip install -e '.[testing]'
- name: Run benchmark
run: python tests/benchmark_build.py --json baseline.json
- name: Upload baseline
uses: actions/upload-artifact@v7
with:
name: benchmark-baseline
path: baseline.json
# --------------------------------------------------------------------------
# Job 2: benchmark the head commit (PR branch)
# --------------------------------------------------------------------------
benchmark-head:
name: Benchmark head
runs-on: ubuntu-latest
permissions:
contents: read
steps:
- uses: actions/checkout@v7
with:
ref: ${{ env.HEAD_REF }}
fetch-depth: 0
- name: Setup Python
uses: actions/setup-python@v7
with:
python-version: "3.12"
- name: Cache pip
uses: actions/cache@v6
with:
path: ~/.cache/pip
key: pip-bench-${{ hashFiles('pyproject.toml') }}
restore-keys: pip-bench-
- name: Install PyTorch CPU
run: pip install torch --index-url https://download.pytorch.org/whl/cpu
- name: Install dependencies
run: |
pip install -r requirements/ci/requirements.txt
pip install -e '.[testing]'
- name: Run benchmark
run: python tests/benchmark_build.py --json current.json
- name: Upload current
uses: actions/upload-artifact@v7
with:
name: benchmark-current
path: current.json
# --------------------------------------------------------------------------
# Job 3: compare results and post PR comment
# --------------------------------------------------------------------------
compare:
name: Compare results
runs-on: ubuntu-latest
needs: [benchmark-base, benchmark-head]
permissions:
contents: read
pull-requests: write
steps:
- uses: actions/checkout@v7
- name: Setup Python
uses: actions/setup-python@v7
with:
python-version: "3.12"
- name: Download baseline
uses: actions/download-artifact@v8
with:
name: benchmark-baseline
- name: Download current
uses: actions/download-artifact@v8
with:
name: benchmark-current
- name: Compare results
run: |
python tests/benchmark_compare.py \
--baseline baseline.json \
--current current.json \
--output comparison.md
- name: Write to job summary
run: cat comparison.md >> "$GITHUB_STEP_SUMMARY"
- name: Comment on PR
if: >-
github.event_name == 'pull_request' &&
github.event.pull_request.head.repo.full_name == github.repository
continue-on-error: true
uses: actions/github-script@v9
with:
script: |
const fs = require('fs');
const body = fs.readFileSync('comparison.md', 'utf8');
const { data: comments } = await github.rest.issues.listComments({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
});
const marker = 'Performance Comparison';
const existing = comments.find(c => c.body.includes(marker));
const params = {
owner: context.repo.owner,
repo: context.repo.repo,
body: body,
};
if (existing) {
await github.rest.issues.updateComment({
...params, comment_id: existing.id,
});
} else {
await github.rest.issues.createComment({
...params, issue_number: context.issue.number,
});
}
- name: Upload comparison
uses: actions/upload-artifact@v7
with:
name: benchmark-comparison
path: |
baseline.json
current.json
comparison.md